Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82181 - in sandbox/static_vector: boost/container boost/container/detail test
From: athundt_at_[hidden]
Date: 2012-12-23 04:18:54


Author: ahundt
Date: 2012-12-23 04:18:51 EST (Sun, 23 Dec 2012)
New Revision: 82181
URL: http://svn.boost.org/trac/boost/changeset/82181

Log:
Added initial support for BOOST_NO_EXCEPTIONS
Text files modified:
   sandbox/static_vector/boost/container/detail/static_vector_util.hpp | 26 ++++++++++++++++++++++++--
   sandbox/static_vector/boost/container/static_vector.hpp | 8 +++++++-
   sandbox/static_vector/test/static_vector.cpp | 36 +++++++++++++++++++++++++++++++++++-
   3 files changed, 66 insertions(+), 4 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-23 04:18:51 EST (Sun, 23 Dec 2012)
@@ -38,9 +38,11 @@
 #include <boost/utility/addressof.hpp>
 #include <boost/iterator/iterator_traits.hpp>
 
+#ifndef BOOST_NO_EXCEPTIONS
 // TODO - move this to the other, optional file?
 #include <vector>
 #include <boost/container/vector.hpp>
+#endif // BOOST_NO_EXCEPTIONS
 
 namespace boost { namespace container { namespace static_vector_detail {
 
@@ -58,6 +60,7 @@
 
 // TODO - move this to the other, optional file?
 
+#ifndef BOOST_NO_EXCEPTIONS
 template <typename Pointer>
 struct are_elements_contiguous< container_detail::vector_const_iterator<Pointer> > : boost::true_type
 {};
@@ -98,9 +101,10 @@
 //> : boost::true_type
 //{};
 
-#else
+#else // OTHER_STDLIB
 // TODO - add other iterators implementations
-#endif
+#endif // OTHER_STDLIB
+#endif // BOOST_NO_EXCEPTIONS
 
 template <typename I, typename O>
 struct are_corresponding :
@@ -298,16 +302,20 @@
     //return boost::uninitialized_move(first, last, dst); // may throw
 
     O o = dst;
+#ifndef BOOST_NO_EXCEPTIONS
     try
+#endif // BOOST_NO_EXCEPTIONS
     {
         typedef typename std::iterator_traits<O>::value_type value_type;
         for (; first != last; ++first, ++o )
             new (boost::addressof(*o)) value_type(boost::move(*first));
     }
+#ifndef BOOST_NO_EXCEPTIONS
     catch (...)
     {
         destroy(dst, o);
     }
+#endif // BOOST_NO_EXCEPTIONS
     return dst;
 }
 
@@ -443,16 +451,20 @@
 {
     typedef typename boost::iterator_value<I>::type value_type;
     I it = first;
+#ifndef BOOST_NO_EXCEPTIONS
     try
+#endif // BOOST_NO_EXCEPTIONS
     {
         for ( ; it != last ; ++it )
             new (boost::addressof(*it)) value_type(); // may throw
     }
+#ifndef BOOST_NO_EXCEPTIONS
     catch(...)
     {
         destroy(first, it);
         throw;
     }
+#endif // BOOST_NO_EXCEPTIONS
 }
 
 template <typename I>
@@ -524,16 +536,21 @@
 {
     typedef typename boost::iterator_value<I>::type value_type;
     I it = first;
+
+#ifndef BOOST_NO_EXCEPTIONS
     try
+#endif // BOOST_NO_EXCEPTIONS
     {
         for ( ; it != last ; ++it )
             new (boost::addressof(*it)) value_type(); // may throw
     }
+#ifndef BOOST_NO_EXCEPTIONS
     catch(...)
     {
         destroy(first, it);
         throw;
     }
+#endif // BOOST_NO_EXCEPTIONS
 }
 
 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
@@ -545,7 +562,9 @@
 {
     std::size_t count = 0;
     F it = dest;
+#ifndef BOOST_NO_EXCEPTIONS
     try
+#endif // BOOST_NO_EXCEPTIONS
     {
         for ( ; first != last ; ++it, ++first, ++count )
         {
@@ -555,11 +574,14 @@
             uninitialized_fill(it, *first); // may throw
         }
     }
+#ifndef BOOST_NO_EXCEPTIONS
     catch(...)
     {
         destroy(dest, it);
         throw;
     }
+#endif // BOOST_NO_EXCEPTIONS
+
     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-23 04:18:51 EST (Sun, 23 Dec 2012)
@@ -12,7 +12,9 @@
 
 #include <boost/container/detail/static_vector_util.hpp>
 
+#ifndef BOOST_NO_EXCEPTIONS
 #include <stdexcept>
+#endif // BOOST_NO_EXCEPTIONS
 
 #include <boost/assert.hpp>
 #include <boost/config.hpp>
@@ -82,8 +84,12 @@
     static void check_at(container::static_vector<V, C, S> const& v,
                                      typename container::static_vector<V, C, S>::size_type i)
     {
+#ifndef BOOST_NO_EXCEPTIONS
         if ( v.size() <= i )
             throw std::out_of_range("index out of bounds");
+#else // BOOST_NO_EXCEPTIONS
+ BOOST_ASSERT_MSG(i <= v.size(), "index out of bounds");
+#endif // BOOST_NO_EXCEPTIONS
     }
 
     template <typename V, std::size_t C, typename S>
@@ -136,7 +142,7 @@
     BOOST_MPL_ASSERT_MSG(
         ( boost::is_unsigned<stored_size_type>::value &&
           sizeof(typename boost::uint_value_t<Capacity>::least) <= sizeof(stored_size_type) ),
- SIZE_TYPE_IS_TOO_SMALL,
+ SIZE_TYPE_IS_TOO_SMALL_FOR_SPECIFIED_CAPACITY,
         (static_vector)
     );
 

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-23 04:18:51 EST (Sun, 23 Dec 2012)
@@ -27,6 +27,14 @@
 #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
@@ -145,7 +153,9 @@
     static_vector<T, N> s;
     BOOST_CHECK_EQUAL(s.size() , 0);
     BOOST_CHECK(s.capacity() == N);
+#ifndef BOOST_NO_EXCEPTIONS
     BOOST_CHECK_THROW( s.at(0), std::out_of_range );
+#endif // BOOST_NO_EXCEPTIONS
 }
 
 template <typename T, size_t N>
@@ -154,7 +164,9 @@
     static_vector<T, N> s(n);
     BOOST_CHECK(s.size() == n);
     BOOST_CHECK(s.capacity() == N);
+#ifndef BOOST_NO_EXCEPTIONS
     BOOST_CHECK_THROW( s.at(n), std::out_of_range );
+#endif // BOOST_NO_EXCEPTIONS
     if ( 1 < n )
     {
         T val10(10);
@@ -174,7 +186,9 @@
     static_vector<T, N> s(n, v);
     BOOST_CHECK(s.size() == n);
     BOOST_CHECK(s.capacity() == N);
+#ifndef BOOST_NO_EXCEPTIONS
     BOOST_CHECK_THROW( s.at(n), std::out_of_range );
+#endif // BOOST_NO_EXCEPTIONS
     if ( 1 < n )
     {
         BOOST_CHECK(v == s[0]);
@@ -198,7 +212,9 @@
     s.resize(n);
     BOOST_CHECK(s.size() == n);
     BOOST_CHECK(s.capacity() == N);
+#ifndef BOOST_NO_EXCEPTIONS
     BOOST_CHECK_THROW( s.at(n), std::out_of_range );
+#endif // BOOST_NO_EXCEPTIONS
     if ( 1 < n )
     {
         T val10(10);
@@ -220,7 +236,9 @@
     s.resize(n, v);
     BOOST_CHECK(s.size() == n);
     BOOST_CHECK(s.capacity() == N);
+#ifndef BOOST_NO_EXCEPTIONS
     BOOST_CHECK_THROW( s.at(n), std::out_of_range );
+#endif // BOOST_NO_EXCEPTIONS
     if ( 1 < n )
     {
         BOOST_CHECK(v == s[0]);
@@ -242,13 +260,17 @@
     static_vector<T, N> s;
 
     BOOST_CHECK(s.size() == 0);
+#ifndef BOOST_NO_EXCEPTIONS
     BOOST_CHECK_THROW( s.at(0), std::out_of_range );
+#endif // BOOST_NO_EXCEPTIONS
 
     for ( size_t i = 0 ; i < N ; ++i )
     {
         s.push_back(T(i));
         BOOST_CHECK(s.size() == i + 1);
+#ifndef BOOST_NO_EXCEPTIONS
         BOOST_CHECK_THROW( s.at(i + 1), std::out_of_range );
+#endif // BOOST_NO_EXCEPTIONS
         BOOST_CHECK(T(i) == s.at(i));
         BOOST_CHECK(T(i) == s[i]);
         BOOST_CHECK(T(i) == s.back());
@@ -268,7 +290,9 @@
     {
         s.pop_back();
         BOOST_CHECK(s.size() == i - 1);
+#ifndef BOOST_NO_EXCEPTIONS
         BOOST_CHECK_THROW( s.at(i - 1), std::out_of_range );
+#endif // BOOST_NO_EXCEPTIONS
         BOOST_CHECK(T(i - 2) == s.at(i - 2));
         BOOST_CHECK(T(i - 2) == s[i - 2]);
         BOOST_CHECK(T(i - 2) == s.back());
@@ -508,8 +532,12 @@
     template <typename V, std::size_t Capacity, typename S>
     static void check_capacity(static_vector<V, Capacity, S> const&, std::size_t s)
     {
+#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
     }
 };
 
@@ -534,6 +562,7 @@
     static_vector<T, 0, bad_alloc_strategy> s;
     BOOST_CHECK(s.size() == 0);
     BOOST_CHECK(s.capacity() == 0);
+#ifndef BOOST_NO_EXCEPTIONS
     BOOST_CHECK_THROW(s.at(0), std::out_of_range);
     BOOST_CHECK_THROW(s.resize(5u, T(0)), std::bad_alloc);
     BOOST_CHECK_THROW(s.push_back(T(0)), std::bad_alloc);
@@ -550,6 +579,7 @@
         static_vector<T, 0, bad_alloc_strategy> s1(5u, T(0));
         BOOST_CHECK(false);
     }catch(std::bad_alloc &){}
+#endif // BOOST_NO_EXCEPTIONS
 }
 
 template <typename T, size_t N>
@@ -557,7 +587,8 @@
 {
     static_vector<T, N> v(N, T(0));
     static_vector<T, N/2, bad_alloc_strategy> s(N/2, T(0));
-
+
+#ifndef BOOST_NO_EXCEPTIONS
     BOOST_CHECK_THROW(s.resize(N, T(0)), std::bad_alloc);
     BOOST_CHECK_THROW(s.push_back(T(0)), std::bad_alloc);
     BOOST_CHECK_THROW(s.insert(s.end(), T(0)), std::bad_alloc);
@@ -573,6 +604,7 @@
         static_vector<T, N/2, bad_alloc_strategy> s1(N, T(0));
         BOOST_CHECK(false);
     }catch(std::bad_alloc &){}
+#endif // BOOST_NO_EXCEPTIONS
 }
 
 template <typename T, size_t N>
@@ -661,6 +693,7 @@
     {
         static_vector<T, N> v(N, T(0));
         static_vector<T, N/2, bad_alloc_strategy> 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);
@@ -669,6 +702,7 @@
             static_vector<T, N/2, bad_alloc_strategy> s2(boost::move(v));
             BOOST_CHECK(false);
         } catch (std::bad_alloc &) {}
+#endif // BOOST_NO_EXCEPTIONS
     }
 }
 


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