Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82216 - in sandbox/static_vector: boost/container boost/container/detail test
From: adam.wulkiewicz_at_[hidden]
Date: 2012-12-26 23:07:07


Author: awulkiew
Date: 2012-12-26 23:07:06 EST (Wed, 26 Dec 2012)
New Revision: 82216
URL: http://svn.boost.org/trac/boost/changeset/82216

Log:
Used Boost TRY-CATCH macros, added emplace_back() - commented out for now
Text files modified:
   sandbox/static_vector/boost/container/detail/static_vector_util.hpp | 39 +++++++++++++++++----------------------
   sandbox/static_vector/boost/container/static_vector.hpp | 38 +++++++++++++++++++++++++++++++++++++-
   sandbox/static_vector/test/static_vector.cpp | 30 +++++++++++++++++++++++++++++-
   3 files changed, 83 insertions(+), 24 deletions(-)

Modified: sandbox/static_vector/boost/container/detail/static_vector_util.hpp
==============================================================================
--- sandbox/static_vector/boost/container/detail/static_vector_util.hpp (original)
+++ sandbox/static_vector/boost/container/detail/static_vector_util.hpp 2012-12-26 23:07:06 EST (Wed, 26 Dec 2012)
@@ -33,21 +33,12 @@
 //#include <boost/type_traits/has_nothrow_assign.hpp>
 //#include <boost/type_traits/has_nothrow_destructor.hpp>
 
+#include <boost/detail/no_exceptions_support.hpp>
 #include <boost/config.hpp>
 #include <boost/move/move.hpp>
 #include <boost/utility/addressof.hpp>
 #include <boost/iterator/iterator_traits.hpp>
 
-#ifdef BOOST_NO_EXCEPTIONS
-#define BOOST_CONTAINER_STATIC_VECTOR_TRY try
-#define BOOST_CONTAINER_STATIC_VECTOR_CATCH_ALL catch(...)
-#define BOOST_CONTAINER_STATIC_VECTOR_THROW throw
-#else
-#define BOOST_CONTAINER_STATIC_VECTOR_TRY
-#define BOOST_CONTAINER_STATIC_VECTOR_CATCH_ALL if(false)
-#define BOOST_CONTAINER_STATIC_VECTOR_THROW
-#endif
-
 // TODO - move vectors iterators optimization to the other, optional file instead of checking defines?
 
 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
@@ -320,17 +311,18 @@
 
     O o = dst;
 
- BOOST_CONTAINER_STATIC_VECTOR_TRY
+ BOOST_TRY
     {
         typedef typename std::iterator_traits<O>::value_type value_type;
         for (; first != last; ++first, ++o )
             new (boost::addressof(*o)) value_type(boost::move(*first));
     }
- BOOST_CONTAINER_STATIC_VECTOR_CATCH_ALL
+ BOOST_CATCH(...)
     {
         destroy(dst, o);
- BOOST_CONTAINER_STATIC_VECTOR_THROW;
+ BOOST_RETHROW;
     }
+ BOOST_CATCH_END
 
     return dst;
 }
@@ -468,16 +460,17 @@
     typedef typename boost::iterator_value<I>::type value_type;
     I it = first;
 
- BOOST_CONTAINER_STATIC_VECTOR_TRY
+ BOOST_TRY
     {
         for ( ; it != last ; ++it )
             new (boost::addressof(*it)) value_type(); // may throw
     }
- BOOST_CONTAINER_STATIC_VECTOR_CATCH_ALL
+ BOOST_CATCH(...)
     {
         destroy(first, it);
- BOOST_CONTAINER_STATIC_VECTOR_THROW;
+ BOOST_RETHROW;
     }
+ BOOST_CATCH_END
 }
 
 template <typename I>
@@ -546,16 +539,17 @@
     typedef typename boost::iterator_value<I>::type value_type;
     I it = first;
     
- BOOST_CONTAINER_STATIC_VECTOR_TRY
+ BOOST_TRY
     {
         for ( ; it != last ; ++it )
             new (boost::addressof(*it)) value_type(); // may throw
     }
- BOOST_CONTAINER_STATIC_VECTOR_CATCH_ALL
+ BOOST_CATCH(...)
     {
         destroy(first, it);
- BOOST_CONTAINER_STATIC_VECTOR_THROW;
+ BOOST_RETHROW;
     }
+ BOOST_CATCH_END
 }
 
 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
@@ -568,7 +562,7 @@
     std::size_t count = 0;
     F it = dest;
 
- BOOST_CONTAINER_STATIC_VECTOR_TRY
+ BOOST_TRY
     {
         for ( ; first != last ; ++it, ++first, ++count )
         {
@@ -578,11 +572,12 @@
             uninitialized_fill(it, *first); // may throw
         }
     }
- BOOST_CONTAINER_STATIC_VECTOR_CATCH_ALL
+ BOOST_CATCH(...)
     {
         destroy(dest, it);
- BOOST_CONTAINER_STATIC_VECTOR_THROW;
+ BOOST_RETHROW;
     }
+ BOOST_CATCH_END
 
     return count;
 }

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 2012-12-26 23:07:06 EST (Wed, 26 Dec 2012)
@@ -12,6 +12,9 @@
 
 #include <boost/container/detail/static_vector_util.hpp>
 
+#include <boost/container/detail/workaround.hpp>
+#include <boost/container/detail/preprocessor.hpp>
+
 #ifndef BOOST_NO_EXCEPTIONS
 #include <stdexcept>
 #endif // BOOST_NO_EXCEPTIONS
@@ -40,7 +43,10 @@
 
 namespace static_vector_detail {
 
-// TODO - remove size_type from here and allow setting it only in traits?
+// 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
 
 struct default_strategy
 {
@@ -54,6 +60,7 @@
     static void check_at(container::static_vector<V, C, S> const& v,
                          typename container::static_vector<V, C, S>::size_type i)
     {
+// TODO - use BOOST_THROW_EXCEPTION here?
 #ifndef BOOST_NO_EXCEPTIONS
         if ( v.size() <= i )
             throw std::out_of_range("index out of bounds");
@@ -523,6 +530,35 @@
         m_size = count; // update end
     }
 
+//#if defined(BOOST_CONTAINER_PERFECT_FORWARDING)
+// template<class ...Args>
+// void emplace_back(Args &&...args)
+// {
+// errh::check_capacity(*this, m_size + 1); // may throw
+
+// namespace sv = static_vector_detail;
+// sv::uninitialized_fill(this->end(), ::boost::forward<Args>(args)); // may throw
+// ++m_size; // update end
+// }
+
+//#else // BOOST_CONTAINER_PERFECT_FORWARDING
+
+// #define BOOST_PP_LOCAL_MACRO(n) \
+// BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \
+// void emplace_back(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
+// { \
+// errh::check_capacity(*this, m_size + 1); /*may throw*/\
+// \
+// namespace sv = static_vector_detail; \
+// sv::uninitialized_fill(this->end() BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _) ); /*may throw*/\
+// ++m_size; /*update end*/ \
+// }
+
+// #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS)
+// #include BOOST_PP_LOCAL_ITERATE()
+
+//#endif // BOOST_CONTAINER_PERFECT_FORWARDING
+
     // nothrow
     void clear()
     {

Modified: sandbox/static_vector/test/static_vector.cpp
==============================================================================
--- sandbox/static_vector/test/static_vector.cpp (original)
+++ sandbox/static_vector/test/static_vector.cpp 2012-12-26 23:07:06 EST (Wed, 26 Dec 2012)
@@ -90,6 +90,16 @@
     int aa;
 };
 
+class value_2p
+{
+public:
+ explicit value_2p(int a, int b) : aa(a), bb(b) {}
+ ~value_2p() {}
+ bool operator==(value_2p const& v) const { return aa == v.aa && bb == v.bb; }
+private:
+ int aa, bb;
+};
+
 class shptr_value
 {
     typedef boost::shared_ptr<int> Ptr;
@@ -693,14 +703,30 @@
     }
 }
 
+//template <typename T, size_t N>
+//void test_emplace_2p()
+//{
+// static_vector<T, N, bad_alloc_strategy> v;
+
+// for (int i = 0 ; i < int(N) ; ++i )
+// v.emplace_back(i, 100 + i);
+// BOOST_CHECK(v.size() == N);
+//#ifndef BOOST_NO_EXCEPTIONS
+// BOOST_CHECK_THROW(v.emplace_back(N, 100 + N), std::bad_alloc);
+//#endif
+// BOOST_CHECK(v.size() == N);
+// for (int i = 0 ; i < int(N) ; ++i )
+// BOOST_CHECK(v[i] == T(i, 100 + i));
+//}
+
 #ifdef BOOST_SINGLE_HEADER_UTF
 BOOST_AUTO_TEST_CASE(static_vector_test)
 #else // BOOST_SINGLE_HEADER_UTF
 int test_main(int, char* [])
 #endif // BOOST_SINGLE_HEADER_UTF
 {
-
     BOOST_CHECK_EQUAL(counting_value::count(), 0);
+
     test_ctor_ndc<int, 10>();
     test_ctor_ndc<value_ndc, 10>();
     test_ctor_ndc<counting_value, 10>();
@@ -799,6 +825,8 @@
     test_swap_and_move_nd<shptr_value, 10>();
     test_swap_and_move_nd<copy_movable, 10>();
 
+ //test_emplace_2p<value_2p, 10>();
+
 #ifndef BOOST_SINGLE_HEADER_UTF
     return 0;
 #endif // BOOST_SINGLE_HEADER_UTF


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk