Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82130 - in sandbox/static_vector: boost/container boost/container/detail test
From: adam.wulkiewicz_at_[hidden]
Date: 2012-12-20 22:26:39


Author: awulkiew
Date: 2012-12-20 22:26:38 EST (Thu, 20 Dec 2012)
New Revision: 82130
URL: http://svn.boost.org/trac/boost/changeset/82130

Log:
Two versions of swap_dispatch() added. Headers and comments cleaned.
Text files modified:
   sandbox/static_vector/boost/container/detail/static_vector_util.hpp | 7 ++
   sandbox/static_vector/boost/container/static_vector.hpp | 102 ++++++++++++++++-----------------------
   sandbox/static_vector/test/static_vector.cpp | 33 +++++++-----
   3 files changed, 69 insertions(+), 73 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-20 22:26:38 EST (Thu, 20 Dec 2012)
@@ -22,6 +22,7 @@
 #include <boost/mpl/or.hpp>
 #include <boost/mpl/int.hpp>
 
+#include <boost/type_traits/is_same.hpp>
 #include <boost/type_traits/remove_const.hpp>
 #include <boost/type_traits/has_trivial_assign.hpp>
 #include <boost/type_traits/has_trivial_copy.hpp>
@@ -43,6 +44,12 @@
 
 namespace boost { namespace container { namespace static_vector_detail {
 
+// TODO
+// Does BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION checks have any sense?
+// Boost.MPL and Boost.Container might not be used but
+// Boost.Iterator also uses partial specialization
+// and in fact iterator_traits won't work if there is no partial specialization
+
 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
 
 template <typename I>

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-20 22:26:38 EST (Thu, 20 Dec 2012)
@@ -18,21 +18,17 @@
 #include <boost/config.hpp>
 #include <boost/swap.hpp>
 #include <boost/integer.hpp>
-#include <boost/iterator/reverse_iterator.hpp>
 
 #include <boost/mpl/assert.hpp>
-#include <boost/mpl/if.hpp>
-#include <boost/mpl/and.hpp>
-#include <boost/mpl/or.hpp>
 
 #include <boost/type_traits/is_unsigned.hpp>
-#include <boost/type_traits/is_same.hpp>
 #include <boost/type_traits/alignment_of.hpp>
 #include <boost/type_traits/aligned_storage.hpp>
-#include <boost/type_traits/has_trivial_assign.hpp>
-#include <boost/type_traits/has_trivial_copy.hpp>
-#include <boost/type_traits/has_trivial_constructor.hpp>
-#include <boost/type_traits/has_trivial_destructor.hpp>
+
+// TODO - use std::reverse_iterator and std::iterator_traits
+// instead Boost.Iterator to remove dependency?
+// or boost/detail/iterator.hpp ?
+#include <boost/iterator/reverse_iterator.hpp>
 
 namespace boost { namespace container {
 
@@ -78,17 +74,6 @@
                                        typename container::static_vector<V, C, S>::const_iterator position)
     {
         BOOST_ASSERT_MSG(v.begin() <= position && position < v.end(), "iterator out of bounds");
-
- /*BOOST_GEOMETRY_INDEX_ASSERT_UNUSED_PARAM(
- difference_type dist = std::distance(this->begin(), position);
- )
- BOOST_ASSERT_MSG(
- 0 <= dist &&
- ( sizeof(dist) <= sizeof(m_size) ?
- (static_cast<size_type>(dist) < m_size) :
- ( dist < static_cast<difference_type>(m_size))
- ), "invalid iterator"
- );*/
     }
 
     template <typename V, std::size_t C, typename S>
@@ -96,17 +81,6 @@
                                       typename container::static_vector<V, C, S>::const_iterator position)
     {
         BOOST_ASSERT_MSG(v.begin() <= position && position <= v.end(), "iterator out of bounds");
-
- /*BOOST_GEOMETRY_INDEX_ASSERT_UNUSED_PARAM(
- difference_type dist = std::distance(this->begin(), position);
- )
- BOOST_ASSERT_MSG(
- 0 <= dist &&
- ( sizeof(dist) <= sizeof(m_size) ?
- (static_cast<size_type>(dist) <= m_size) :
- ( dist <= static_cast<difference_type>(m_size))
- ), "invalid iterator"
- );*/
     }
 };
 
@@ -217,34 +191,7 @@
     // swap (note: linear complexity)
     void swap(static_vector & other)
     {
-// namespace sv = static_vector_detail;
-// iterator it = this->begin();
-// iterator other_it = other.begin();
-
-// if ( this->size() < other.size() )
-// {
-// for (; it != this->end() ; ++it, ++other_it)
-// boost::swap(*it, *other_it); // may throw
-// sv::uninitialized_copy(other_it, other.end(), it); // may throw
-// sv::destroy(other_it, other.end());
-// boost::swap(m_size, other.m_size);
-// }
-// else
-// {
-// for (; other_it != other.end() ; ++it, ++other_it)
-// boost::swap(*it, *other_it); // may throw
-// sv::uninitialized_copy(it, this->end(), other_it); // may throw
-// sv::destroy(it, this->end());
-// boost::swap(m_size, other.m_size);
-// };
-
- // TODO - this may be too big for stack
- aligned_storage_type temp;
- Value * temp_ptr = reinterpret_cast<Value*>(temp.address());
- ::memcpy(temp_ptr, this->data(), sizeof(Value) * this->size());
- ::memcpy(this->data(), other.data(), sizeof(Value) * other.size());
- ::memcpy(other.data(), temp_ptr, sizeof(Value) * this->size());
- boost::swap(m_size, other.m_size);
+ this->swap_dispatch(other, boost::true_type());
     }
 
     // basic
@@ -571,6 +518,43 @@
 
 private:
 
+ // swap
+
+ void swap_dispatch(static_vector & other, boost::true_type const& /*nonthrowing_version*/)
+ {
+ // TODO - this may be too big for stack
+ aligned_storage_type temp;
+ Value * temp_ptr = reinterpret_cast<Value*>(temp.address());
+ ::memcpy(temp_ptr, this->data(), sizeof(Value) * this->size());
+ ::memcpy(this->data(), other.data(), sizeof(Value) * other.size());
+ ::memcpy(other.data(), temp_ptr, sizeof(Value) * this->size());
+ boost::swap(m_size, other.m_size);
+ }
+
+ void swap_dispatch(static_vector & other, boost::false_type const& /*throwing_version*/)
+ {
+ namespace sv = static_vector_detail;
+ iterator it = this->begin();
+ iterator other_it = other.begin();
+
+ if ( this->size() < other.size() )
+ {
+ for (; it != this->end() ; ++it, ++other_it)
+ boost::swap(*it, *other_it); // may throw
+ sv::uninitialized_copy(other_it, other.end(), it); // may throw
+ sv::destroy(other_it, other.end());
+ boost::swap(m_size, other.m_size);
+ }
+ else
+ {
+ for (; other_it != other.end() ; ++it, ++other_it)
+ boost::swap(*it, *other_it); // may throw
+ sv::uninitialized_copy(it, this->end(), other_it); // may throw
+ sv::destroy(it, this->end());
+ boost::swap(m_size, other.m_size);
+ }
+ }
+
     // insert
 
     template <typename Iterator>

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-20 22:26:38 EST (Thu, 20 Dec 2012)
@@ -19,11 +19,14 @@
 
 #include <vector>
 #include <list>
-#include <boost/container/vector.hpp>
-#include <boost/container/stable_vector.hpp>
 #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
+
 using namespace boost::container;
 
 class value_ndc
@@ -131,8 +134,8 @@
       return *this;
    }
    
- bool operator==(const clone_ptr&){
-
+ bool operator==(const clone_ptr& p){
+ return p.ptr == ptr;
    }
 };
 
@@ -304,16 +307,12 @@
     static_vector<T, N> s;
     std::vector<T> v;
     std::list<T> l;
- stable_vector<T> bsv;
- vector<T> bv;
 
     for ( size_t i = 0 ; i < N ; ++i )
     {
         s.push_back(T(i));
         v.push_back(T(i));
         l.push_back(T(i));
- bsv.push_back(T(i));
- bv.push_back(T(i));
     }
     // copy ctor
     {
@@ -334,8 +333,6 @@
     test_copy_and_assign<T, N>(s);
     test_copy_and_assign<T, N>(v);
     test_copy_and_assign<T, N>(l);
- test_copy_and_assign<T, N>(bsv);
- test_copy_and_assign<T, N>(bv);
 
     // assign(N, V)
     {
@@ -345,6 +342,13 @@
         s1.assign(N, val);
         test_compare_ranges(a.begin(), a.end(), s1.begin(), s1.end());
     }
+
+#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
+ stable_vector<T> bsv(s.begin(), s.end());
+ vector<T> bv(s.begin(), s.end());
+ test_copy_and_assign<T, N>(bsv);
+ test_copy_and_assign<T, N>(bv);
+#endif
 }
 
 template <typename T, size_t N>
@@ -443,8 +447,6 @@
     static_vector<T, N> s, ss;
     std::vector<T> v;
     std::list<T> l;
- vector<T> bv;
- stable_vector<T> bsv;
 
     typedef typename static_vector<T, N>::iterator It;
 
@@ -454,8 +456,6 @@
         ss.push_back(T(100 + i));
         v.push_back(T(100 + i));
         l.push_back(T(100 + i));
- bv.push_back(T(100 + i));
- bsv.push_back(T(100 + i));
     }
 
     // insert(pos, val)
@@ -494,8 +494,13 @@
     test_insert<T, N>(s, ss);
     test_insert<T, N>(s, v);
     test_insert<T, N>(s, l);
+
+#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
+ stable_vector<T> bsv(ss.begin(), ss.end());
+ vector<T> bv(ss.begin(), ss.end());
     test_insert<T, N>(s, bv);
     test_insert<T, N>(s, bsv);
+#endif
 }
 
 template <typename T>


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