$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r82322 - in sandbox/static_vector: boost/container test
From: adam.wulkiewicz_at_[hidden]
Date: 2013-01-02 14:12:35
Author: awulkiew
Date: 2013-01-02 14:12:34 EST (Wed, 02 Jan 2013)
New Revision: 82322
URL: http://svn.boost.org/trac/boost/changeset/82322
Log:
Used NullAllocator-like Strategy.
Fixed some errors.
Value*, const Value*, etc. replaced by pointer, const_pointer, etc.
Text files modified: 
   sandbox/static_vector/boost/container/static_vector.hpp        |   167 ++++++++++++++++++++++----------------- 
   sandbox/static_vector/test/Jamfile.v2                          |     4                                         
   sandbox/static_vector/test/static_vector_interprocess_test.cpp |     2                                         
   sandbox/static_vector/test/static_vector_test.cpp              |    60 ++++++++-----                           
   sandbox/static_vector/test/static_vector_test.hpp              |    15 ---                                     
   5 files changed, 132 insertions(+), 116 deletions(-)
Modified: sandbox/static_vector/boost/container/static_vector.hpp
==============================================================================
--- sandbox/static_vector/boost/container/static_vector.hpp	(original)
+++ sandbox/static_vector/boost/container/static_vector.hpp	2013-01-02 14:12:34 EST (Wed, 02 Jan 2013)
@@ -36,25 +36,40 @@
 // or boost/detail/iterator.hpp ?
 #include <boost/iterator/reverse_iterator.hpp>
 
+// TODO - change the name Strategy to NullAllocator?
+
 namespace boost { namespace container {
 
 // Forward declaration
-template <typename Value, std::size_t Capacity, typename Strategy>
+template <typename Value, std::size_t Capacity, typename Strategy/*NullAllocator*/>
 class static_vector;
 
 namespace static_vector_detail {
 
-// TODO - should strategy define only an error handler instead of a check?
-// e.g. check_capacity_failed(...) { assert(false); }
-// this means that the checking condition would allways be checked
-// safer since the user couldn't play with the check, but a penalty in some cases
+template <typename Value>
+struct default_strategy/*null_allocator*/
+{
+    typedef Value value_type;
+    typedef std::size_t size_type;
+    typedef std::ptrdiff_t difference_type;
+    typedef Value* pointer;
+    typedef const Value* const_pointer;
+    typedef Value& reference;
+    typedef const Value& const_reference;
 
-struct default_strategy
+    static void allocate_failed()
+    {
+        BOOST_ASSERT_MSG(false, "size can't exceed the capacity");
+    }
+};
+
+struct default_error_handler
 {
     template <typename V, std::size_t Capacity, typename S>
     static void check_capacity(container::static_vector<V, Capacity, S> const&, std::size_t s)
     {
-        BOOST_ASSERT_MSG(s <= Capacity, "size can't exceed the capacity");
+        if ( Capacity < s )
+            S::allocate_failed();
     }
 
     template <typename V, std::size_t C, typename S>
@@ -98,24 +113,34 @@
     }
 };
 
-template <typename Value, std::size_t Capacity, typename Strategy>
+template <typename Value, std::size_t Capacity, typename Strategy/*NullAllocator*/>
 struct static_vector_traits
 {
-    typedef std::size_t size_type;
+    typedef typename Strategy::value_type value_type;
+    typedef typename Strategy::size_type size_type;
+    typedef typename Strategy::difference_type difference_type;
+    typedef typename Strategy::pointer pointer;
+    typedef typename Strategy::const_pointer const_pointer;
+    typedef typename Strategy::reference reference;
+    typedef typename Strategy::const_reference const_reference;
+
+    typedef default_error_handler error_handler;
+
     typedef boost::false_type use_memop_in_swap_and_move;
     typedef boost::false_type use_optimized_swap;
-    typedef Strategy strategy;
 };
 
 } // namespace static_vector_detail
 
-template <typename Value, std::size_t Capacity, typename Strategy = static_vector_detail::default_strategy >
+template <typename Value, std::size_t Capacity, typename Strategy/*NullAllocator*/ = static_vector_detail::default_strategy<Value>/*null_allocator*/ >
 class static_vector
 {
-    typedef typename
-    static_vector_detail::static_vector_traits<
+    typedef static_vector_detail::static_vector_traits<
         Value, Capacity, Strategy
-    >::size_type stored_size_type;
+    > vt;
+    
+    typedef typename vt::size_type stored_size_type;
+    typedef typename vt::error_handler errh;
 
     BOOST_MPL_ASSERT_MSG(
         ( boost::is_unsigned<stored_size_type>::value &&
@@ -129,11 +154,6 @@
         boost::alignment_of<Value[Capacity]>::value
     > aligned_storage_type;
 
-    typedef typename
-    static_vector_detail::static_vector_traits<
-        Value, Capacity, Strategy
-    >::strategy errh;
-
     template <typename V, std::size_t C, typename S>
     friend class static_vector;
 
@@ -151,15 +171,16 @@
 #endif
 
 public:
-    typedef Value value_type;
+    typedef typename vt::value_type value_type;
     typedef stored_size_type size_type;
-    typedef std::ptrdiff_t difference_type;
-    typedef Value & reference;
-    typedef Value const& const_reference;
-    typedef Value* pointer;
-    typedef const Value* const_pointer;
-    typedef Value* iterator;
-    typedef const Value* const_iterator;
+    typedef typename vt::difference_type difference_type;
+    typedef typename vt::pointer pointer;
+    typedef typename vt::const_pointer const_pointer;
+    typedef typename vt::reference reference;
+    typedef typename vt::const_reference const_reference;
+
+    typedef pointer iterator;
+    typedef const_pointer const_iterator;
     typedef boost::reverse_iterator<iterator> reverse_iterator;
     typedef boost::reverse_iterator<const_iterator> const_reverse_iterator;
 
@@ -707,7 +728,7 @@
 
     //! Throws: If the Strategy throws in check_at().
     //! Complexity: Constant.
-    Value & at(size_type i)
+    reference at(size_type i)
     {
         errh::check_at(*this, i);                                   // may throw
         return *(this->begin() + i);
@@ -715,7 +736,7 @@
 
     //! Throws: If the Strategy throws in check_at().
     //! Complexity: Constant.
-    Value const& at(size_type i) const
+    const_reference at(size_type i) const
     {
         errh::check_at(*this, i);                                   // may throw
         return *(this->begin() + i);
@@ -723,7 +744,7 @@
 
     //! Throws: If the Strategy throws in check_operator_brackets().
     //! Complexity: Constant.
-    Value & operator[](size_type i)
+    reference operator[](size_type i)
     {
         errh::check_operator_brackets(*this, i);
         return *(this->begin() + i);
@@ -731,7 +752,7 @@
 
     //! Throws: If the Strategy throws in check_operator_brackets().
     //! Complexity: Constant.
-    Value const& operator[](size_type i) const
+    const_reference operator[](size_type i) const
     {
         errh::check_operator_brackets(*this, i);
         return *(this->begin() + i);
@@ -739,7 +760,7 @@
 
     //! Throws: If the Strategy throws in check_empty().
     //! Complexity: Constant.
-    Value & front()
+    reference front()
     {
         errh::check_empty(*this);
         return *(this->begin());
@@ -747,7 +768,7 @@
 
     //! Throws: If the Strategy throws in check_empty().
     //! Complexity: Constant.
-    Value const& front() const
+    const_reference front() const
     {
         errh::check_empty(*this);
         return *(this->begin());
@@ -755,7 +776,7 @@
 
     //! Throws: If the Strategy throws in check_empty().
     //! Complexity: Constant.
-    Value & back()
+    reference back()
     {
         errh::check_empty(*this);
         return *(this->end() - 1);
@@ -763,7 +784,7 @@
 
     //! Throws: If the Strategy throws in check_empty().
     //! Complexity: Constant.
-    Value const& back() const
+    const_reference back() const
     {
         errh::check_empty(*this);
         return *(this->end() - 1);
@@ -771,10 +792,10 @@
 
     //! Throws: Nothing.
     //! Complexity: Constant.
-    Value * data() { return this->ptr(); }
+    pointer data() { return boost::addressof(*(this->ptr())); }
     //! Throws: Nothing.
     //! Complexity: Constant.
-    const Value * data() const { return this->ptr(); }
+    const_pointer data() const { return boost::addressof(*(this->ptr())); }
 
     //! Throws: Nothing.
     //! Complexity: Constant.
@@ -1132,14 +1153,14 @@
         m_size = s; // update end
     }
 
-    Value * ptr()
+    pointer ptr()
     {
-        return (reinterpret_cast<Value*>(m_storage.address()));
+        return pointer(static_cast<Value*>(m_storage.address()));
     }
 
-    const Value * ptr() const
+    const_pointer ptr() const
     {
-        return (reinterpret_cast<const Value*>(m_storage.address()));
+        return const_pointer(static_cast<const Value*>(m_storage.address()));
     }
 
     stored_size_type m_size;
@@ -1151,26 +1172,24 @@
 template<typename Value, typename Strategy>
 class static_vector<Value, 0, Strategy>
 {
-    typedef typename
-    static_vector_detail::static_vector_traits<
+    typedef static_vector_detail::static_vector_traits<
         Value, 0, Strategy
-    >::size_type stored_size_type;
+    > vt;
 
-    typedef typename
-    static_vector_detail::static_vector_traits<
-        Value, 0, Strategy
-    >::strategy errh;
+    typedef typename vt::size_type stored_size_type;
+    typedef typename vt::error_handler errh;
 
 public:
-    typedef Value value_type;
+    typedef typename vt::value_type value_type;
     typedef stored_size_type size_type;
-    typedef std::ptrdiff_t difference_type;
-    typedef Value& reference;
-    typedef Value const& const_reference;
-    typedef Value * pointer;
-    typedef const Value* const_pointer;
-    typedef Value* iterator;
-    typedef const Value * const_iterator;
+    typedef typename vt::difference_type difference_type;
+    typedef typename vt::pointer pointer;
+    typedef typename vt::const_pointer const_pointer;
+    typedef typename vt::reference reference;
+    typedef typename vt::const_reference const_reference;
+
+    typedef pointer iterator;
+    typedef const_pointer const_iterator;
     typedef boost::reverse_iterator<iterator> reverse_iterator;
     typedef boost::reverse_iterator<const_iterator> const_reverse_iterator;
 
@@ -1196,8 +1215,8 @@
     }
 
     // strong
-    template <size_t C>
-    static_vector(static_vector<value_type, C> const& other)
+    template <size_t C, typename S>
+    static_vector(static_vector<value_type, C, S> const& other)
     {
         errh::check_capacity(*this, other.size());                                  // may throw
     }
@@ -1217,8 +1236,8 @@
     }
 
     // basic
-    template <size_t C>
-    static_vector & operator=(static_vector<value_type, C> const& other)
+    template <size_t C, typename S>
+    static_vector & operator=(static_vector<value_type, C, S> const& other)
     {
         errh::check_capacity(*this, other.size());                                  // may throw
         return *this;
@@ -1314,64 +1333,64 @@
     void clear() {}
 
     // strong
-    Value & at(size_type i)
+    reference at(size_type i)
     {
         errh::check_at(*this, i);                                   // may throw
         return *(this->begin() + i);
     }
 
     // strong
-    Value const& at(size_type i) const
+    const_reference at(size_type i) const
     {
         errh::check_at(*this, i);                                   // may throw
         return *(this->begin() + i);
     }
 
     // nothrow
-    Value & operator[](size_type i)
+    reference operator[](size_type i)
     {
         errh::check_operator_brackets(*this, i);
         return *(this->begin() + i);
     }
 
     // nothrow
-    Value const& operator[](size_type i) const
+    const_reference operator[](size_type i) const
     {
         errh::check_operator_brackets(*this, i);
         return *(this->begin() + i);
     }
 
     // nothrow
-    Value & front()
+    reference front()
     {
         errh::check_empty(*this);
         return *(this->begin());
     }
 
     // nothrow
-    Value const& front() const
+    const_reference front() const
     {
         errh::check_empty(*this);
         return *(this->begin());
     }
 
     // nothrow
-    Value & back()
+    reference back()
     {
         errh::check_empty(*this);
         return *(this->end() - 1);
     }
 
     // nothrow
-    Value const& back() const
+    const_reference back() const
     {
         errh::check_empty(*this);
         return *(this->end() - 1);
     }
 
     // nothrow
-    Value * data() { return this->ptr(); }
-    const Value * data() const { return this->ptr(); }
+    pointer data() { return boost::addressof(*(this->ptr())); }
+    const_pointer data() const { return boost::addressof(*(this->ptr())); }
 
     // nothrow
     iterator begin() { return this->ptr(); }
@@ -1396,14 +1415,14 @@
 
 private:
 
-    Value * ptr()
+    pointer ptr()
     {
-        return (reinterpret_cast<Value*>(this));
+        return pointer(reinterpret_cast<Value*>(this));
     }
 
-    const Value * ptr() const
+    const_pointer ptr() const
     {
-        return (reinterpret_cast<const Value*>(this));
+        return const_pointer(reinterpret_cast<const Value*>(this));
     }
 };
 
Modified: sandbox/static_vector/test/Jamfile.v2
==============================================================================
--- sandbox/static_vector/test/Jamfile.v2	(original)
+++ sandbox/static_vector/test/Jamfile.v2	2013-01-02 14:12:34 EST (Wed, 02 Jan 2013)
@@ -18,11 +18,11 @@
     ;
 
 test-suite boost-container-static_vector
-    : [ run static_vector.cpp ]
+    : [ run static_vector_test.cpp ]
     ;
 
 test-suite boost-container-static_vector_interprocess
-    : [ run static_vector_interprocess.cpp /boost/thread//boost_thread
+    : [ run static_vector_interprocess_test.cpp /boost/thread//boost_thread
         :  # additional args
         :  # test-files
         :  # requirements
Modified: sandbox/static_vector/test/static_vector_interprocess_test.cpp
==============================================================================
--- sandbox/static_vector/test/static_vector_interprocess_test.cpp	(original)
+++ sandbox/static_vector/test/static_vector_interprocess_test.cpp	2013-01-02 14:12:34 EST (Wed, 02 Jan 2013)
@@ -16,7 +16,7 @@
 #include <boost/test/impl/execution_monitor.ipp>
 #endif // BOOST_SINGLE_HEADER_UTF
 
-#include "static_vector.hpp"
+#include "static_vector_test.hpp"
 
 #include <boost/interprocess/managed_shared_memory.hpp>
 #include <algorithm>
Modified: sandbox/static_vector/test/static_vector_test.cpp
==============================================================================
--- sandbox/static_vector/test/static_vector_test.cpp	(original)
+++ sandbox/static_vector/test/static_vector_test.cpp	2013-01-02 14:12:34 EST (Wed, 02 Jan 2013)
@@ -16,7 +16,23 @@
 #include <boost/test/impl/execution_monitor.ipp>
 #endif // BOOST_SINGLE_HEADER_UTF
 
-#include "static_vector.hpp"
+// TODO: Disable parts of the unit test that should not run when BOOST_NO_EXCEPTIONS
+// if exceptions are enabled there must be a user defined throw_exception function
+#ifdef BOOST_NO_EXCEPTIONS
+namespace boost {
+    void throw_exception(std::exception const & e){}; // user defined
+} // namespace boost
+#endif // BOOST_NO_EXCEPTIONS
+
+#include <vector>
+#include <list>
+
+#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
+#include <boost/container/vector.hpp>
+#include <boost/container/stable_vector.hpp>
+#endif
+
+#include "static_vector_test.hpp"
 
 template <typename T, size_t N>
 void test_ctor_ndc()
@@ -403,17 +419,13 @@
 #endif
 }
 
-struct bad_alloc_strategy : public static_vector_detail::default_strategy
+template <typename V>
+struct bad_alloc_strategy
+    : public static_vector_detail::default_strategy<V>
 {
-    template <typename V, std::size_t Capacity, typename S>
-    static void check_capacity(static_vector<V, Capacity, S> const&, std::size_t s)
+    static void allocate_failed()
     {
-#ifndef BOOST_NO_EXCEPTIONS
-        if ( Capacity < s )
-            throw std::bad_alloc();
-#else // BOOST_NO_EXCEPTIONS
-        BOOST_ASSERT_MSG(!(Capacity < s), "index out of bounds");
-#endif // BOOST_NO_EXCEPTIONS
+        BOOST_THROW_EXCEPTION(std::bad_alloc());
     }
 };
 
@@ -422,7 +434,7 @@
 {
     static_vector<T, 10> v(5u, T(0));
 
-    static_vector<T, 0, bad_alloc_strategy> s;
+    static_vector<T, 0, bad_alloc_strategy<T> > s;
     BOOST_CHECK(s.size() == 0);
     BOOST_CHECK(s.capacity() == 0);
 #ifndef BOOST_NO_EXCEPTIONS
@@ -435,11 +447,11 @@
     BOOST_CHECK_THROW(s.assign(v.begin(), v.end()), std::bad_alloc);
     BOOST_CHECK_THROW(s.assign(5u, T(0)), std::bad_alloc);
     try{
-        static_vector<T, 0, bad_alloc_strategy> s2(v.begin(), v.end());
+        static_vector<T, 0, bad_alloc_strategy<T> > s2(v.begin(), v.end());
         BOOST_CHECK(false);
     }catch(std::bad_alloc &){}
     try{
-        static_vector<T, 0, bad_alloc_strategy> s1(5u, T(0));
+        static_vector<T, 0, bad_alloc_strategy<T> > s1(5u, T(0));
         BOOST_CHECK(false);
     }catch(std::bad_alloc &){}
 #endif // BOOST_NO_EXCEPTIONS
@@ -449,7 +461,7 @@
 void test_exceptions_nd()
 {
     static_vector<T, N> v(N, T(0));
-    static_vector<T, N/2, bad_alloc_strategy> s(N/2, T(0));
+    static_vector<T, N/2, bad_alloc_strategy<T> > s(N/2, T(0));
 
 #ifndef BOOST_NO_EXCEPTIONS
     BOOST_CHECK_THROW(s.resize(N, T(0)), std::bad_alloc);
@@ -460,11 +472,11 @@
     BOOST_CHECK_THROW(s.assign(v.begin(), v.end()), std::bad_alloc);
     BOOST_CHECK_THROW(s.assign(N, T(0)), std::bad_alloc);
     try{
-        static_vector<T, N/2, bad_alloc_strategy> s2(v.begin(), v.end());
+        static_vector<T, N/2, bad_alloc_strategy<T> > s2(v.begin(), v.end());
         BOOST_CHECK(false);
     }catch(std::bad_alloc &){}
     try{
-        static_vector<T, N/2, bad_alloc_strategy> s1(N, T(0));
+        static_vector<T, N/2, bad_alloc_strategy<T> > s1(N, T(0));
         BOOST_CHECK(false);
     }catch(std::bad_alloc &){}
 #endif // BOOST_NO_EXCEPTIONS
@@ -476,7 +488,7 @@
     {
         static_vector<T, N> v1, v2, v3, v4;
         static_vector<T, N> s1, s2;
-        static_vector<T, N, bad_alloc_strategy> s4;
+        static_vector<T, N, bad_alloc_strategy<T> > s4;
 
         for (size_t i = 0 ; i < N ; ++i )
         {
@@ -555,14 +567,14 @@
     }
     {
         static_vector<T, N> v(N, T(0));
-        static_vector<T, N/2, bad_alloc_strategy> s(N/2, T(1));
+        static_vector<T, N/2, bad_alloc_strategy<T> > s(N/2, T(1));
 #ifndef BOOST_NO_EXCEPTIONS
         BOOST_CHECK_THROW(s.swap(v), std::bad_alloc);
         v.resize(N, T(0));
         BOOST_CHECK_THROW(s = boost::move(v), std::bad_alloc);
         v.resize(N, T(0));
         try {
-            static_vector<T, N/2, bad_alloc_strategy> s2(boost::move(v));
+            static_vector<T, N/2, bad_alloc_strategy<T> > s2(boost::move(v));
             BOOST_CHECK(false);
         } catch (std::bad_alloc &) {}
 #endif // BOOST_NO_EXCEPTIONS
@@ -574,7 +586,7 @@
 {
     //emplace_back(pos, int, int)
     {
-        static_vector<T, N, bad_alloc_strategy> v;
+        static_vector<T, N, bad_alloc_strategy<T> > v;
 
         for (int i = 0 ; i < int(N) ; ++i )
             v.emplace_back(i, 100 + i);
@@ -589,11 +601,11 @@
 
     // emplace(pos, int, int)
     {
-        typedef typename static_vector<T, N, bad_alloc_strategy>::iterator It;
+        typedef typename static_vector<T, N, bad_alloc_strategy<T> >::iterator It;
 
         int h = N / 2;
 
-        static_vector<T, N, bad_alloc_strategy> v;
+        static_vector<T, N, bad_alloc_strategy<T> > v;
         for ( int i = 0 ; i < h ; ++i )
             v.emplace_back(i, 100 + i);
 
@@ -615,9 +627,9 @@
 template <typename T, size_t N>
 void test_sv_elem(T const& t)
 {
-    typedef static_vector<T, N, bad_alloc_strategy> V;
+    typedef static_vector<T, N, bad_alloc_strategy<T> > V;
 
-    static_vector<V, N, bad_alloc_strategy> v;
+    static_vector<V, N, bad_alloc_strategy<V> > v;
 
     v.push_back(V(N/2, t));
     V vvv(N/2, t);
Modified: sandbox/static_vector/test/static_vector_test.hpp
==============================================================================
--- sandbox/static_vector/test/static_vector_test.hpp	(original)
+++ sandbox/static_vector/test/static_vector_test.hpp	2013-01-02 14:12:34 EST (Wed, 02 Jan 2013)
@@ -13,24 +13,9 @@
 
 #include <boost/container/static_vector.hpp>
 
-#include <vector>
-#include <list>
 #include <boost/shared_ptr.hpp>
 #include "movable.hpp"
 
-#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
-#include <boost/container/vector.hpp>
-#include <boost/container/stable_vector.hpp>
-#endif
-
-// TODO: Disable parts of the unit test that should not run when BOOST_NO_EXCEPTIONS
-// if exceptions are enabled there must be a user defined throw_exception function
-#ifdef BOOST_NO_EXCEPTIONS
-namespace boost {
-void throw_exception(std::exception const & e){}; // user defined
-} // namespace boost
-#endif // BOOST_NO_EXCEPTIONS
-
 using namespace boost::container;
 
 class value_ndc