Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82091 - in sandbox/static_vector/boost/container: . detail
From: adam.wulkiewicz_at_[hidden]
Date: 2012-12-18 23:06:54


Author: awulkiew
Date: 2012-12-18 23:06:53 EST (Tue, 18 Dec 2012)
New Revision: 82091
URL: http://svn.boost.org/trac/boost/changeset/82091

Log:
sv:: fill() and move_backward() moved to detail
Text files modified:
   sandbox/static_vector/boost/container/detail/static_vector_util.hpp | 78 +++++++++++++++++++++++++++++++++++++++
   sandbox/static_vector/boost/container/static_vector.hpp | 42 ++++----------------
   2 files changed, 86 insertions(+), 34 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-18 23:06:53 EST (Tue, 18 Dec 2012)
@@ -158,7 +158,7 @@
 
 // move
 
-// TODO use boost::move(I, I, O) instead of copy/assignment
+// TODO use boost::move(I, I, O) instead of copy
 
 template <typename V>
 V * move_dispatch(const V * first, const V * last, V * dst,
@@ -191,6 +191,70 @@
     return move_dispatch(first, last, dst, use_memmove()); // may throw
 }
 
+// move_backward
+
+// TODO use boost::move_backward(I, I, O) instead of copy_backward
+
+template <typename V>
+V * move_backward_dispatch(const V * first, const V * last, V * dst,
+ boost::mpl::bool_<true> const& /*use_memmove*/)
+{
+ typename std::iterator_traits<V*>::difference_type d = std::distance(first, last);
+ ::memmove(dst - d, first, sizeof(V) * d);
+ return dst - d;
+}
+
+template <typename BDI, typename BDO>
+BDO move_backward_dispatch(BDI first, BDI last, BDO dst,
+ boost::mpl::bool_<false> const& /*use_memmove*/)
+{
+ return std::copy_backward(first, last, dst); // may throw
+}
+
+template <typename BDI, typename BDO>
+BDO move_backward(BDI first, BDI last, BDO dst)
+{
+ typedef typename
+ ::boost::mpl::and_<
+ are_corresponding_pointers<BDI, BDO>,
+ ::boost::has_trivial_assign<
+ typename ::boost::iterator_value<BDO>::type
+ >
+ >::type
+ use_memmove;
+
+ return move_backward_dispatch(first, last, dst, use_memmove()); // may throw
+}
+
+// fill
+
+template <typename V>
+void fill_dispatch(V * ptr, V const& v,
+ boost::mpl::bool_<true> const& /*use_memcpy*/)
+{
+ ::memcpy(ptr, boost::addressof(v), sizeof(V));
+}
+
+template <typename I, typename V>
+void fill_dispatch(I pos, V const& v,
+ boost::mpl::bool_<false> const& /*use_memcpy*/)
+{
+ *pos = v; // may throw
+}
+
+template <typename I, typename V>
+void fill(I pos, V const& v)
+{
+ typedef typename
+ ::boost::mpl::and_<
+ is_corresponding_value<I, V>,
+ ::boost::has_trivial_assign<V>
+ >::type
+ use_memcpy;
+
+ fill_dispatch(pos, v, use_memcpy()); // may throw
+}
+
 #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
 
 template <typename I, typename O>
@@ -217,6 +281,18 @@
     return std::copy(first, last, dst); // may throw
 }
 
+template <typename BDI, typename BDO>
+BDO move_backward(BDI first, BDI last, BDO dst)
+{
+ return std::copy_backward(first, last, dst); // may throw
+}
+
+template <typename I, typename V>
+void fill(I pos, V const& v)
+{
+ *pos = v; // may throw
+}
+
 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
 
 }}}} // namespace boost::container::detail::static_vector

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-18 23:06:53 EST (Tue, 18 Dec 2012)
@@ -699,7 +699,7 @@
     inline static void copy(Iterator first, Iterator last, iterator dst)
     {
         namespace sv = detail::static_vector;
- sv::copy(first, last, dst);
+ sv::copy(first, last, dst); // may throw
     }
 
     // uninitialized_copy
@@ -708,7 +708,7 @@
     void uninitialized_copy(Iterator first, Iterator last, iterator dst)
     {
         namespace sv = detail::static_vector;
- sv::uninitialized_copy(first, last, dst);
+ sv::uninitialized_copy(first, last, dst); // may throw
     }
 
     // uninitialized_fill
@@ -717,7 +717,7 @@
     void uninitialized_fill(iterator dst, V const& v)
     {
         namespace sv = detail::static_vector;
- sv::uninitialized_fill(dst, v);
+ sv::uninitialized_fill(dst, v); // may throw
     }
 
     // move
@@ -725,48 +725,24 @@
     void move(iterator first, iterator last, iterator dst)
     {
         namespace sv = detail::static_vector;
- sv::move(first, last, dst);
+ sv::move(first, last, dst); // may throw
     }
 
     // move_backward
 
     void move_backward(iterator first, iterator last, iterator dst)
     {
- this->move_backward_dispatch(first, last, dst, has_trivial_assign<value_type>()); // may throw
- }
-
- void move_backward_dispatch(value_type * first, value_type * last, value_type * dst,
- boost::true_type const& /*has_trivial_assign*/)
- {
- difference_type n = std::distance(first, last);
- ::memmove(dst - n, first, sizeof(value_type) * n);
- }
-
- void move_backward_dispatch(value_type * first, value_type * last, value_type * dst,
- boost::false_type const& /*has_trivial_assign*/)
- {
- std::copy_backward(first, last, dst); // may throw
+ namespace sv = detail::static_vector;
+ sv::move_backward(first, last, dst); // may throw
     }
 
- // uninitialized_fill
+ // fill
 
     template <typename V>
     void fill(iterator dst, V const& v)
     {
- fill_dispatch(dst, v, has_trivial_assign<value_type>()); // may throw
- }
-
- void fill_dispatch(value_type * ptr, value_type const& v,
- boost::true_type const& /*has_trivial_assign*/)
- {
- ::memcpy(ptr, boost::addressof(v), sizeof(value_type));
- }
-
- template <typename V>
- void fill_dispatch(value_type * ptr, V const& v,
- boost::false_type const& /*has_trivial_assign*/)
- {
- *ptr = v; // may throw
+ namespace sv = detail::static_vector;
+ sv::fill(dst, v); // may throw
     }
 
     // destroy


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