|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r82163 - in sandbox/static_vector: boost/container boost/container/detail test
From: adam.wulkiewicz_at_[hidden]
Date: 2012-12-21 22:33:17
Author: awulkiew
Date: 2012-12-21 22:33:16 EST (Fri, 21 Dec 2012)
New Revision: 82163
URL: http://svn.boost.org/trac/boost/changeset/82163
Log:
uninitialized_move() added and used in throwing swap() implementation.
Text files modified:
sandbox/static_vector/boost/container/detail/static_vector_util.hpp | 42 ++++++++++++++++++++++++++++++++++-----
sandbox/static_vector/boost/container/static_vector.hpp | 9 ++++++-
sandbox/static_vector/test/static_vector.cpp | 2
3 files changed, 44 insertions(+), 9 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-21 22:33:16 EST (Fri, 21 Dec 2012)
@@ -187,7 +187,6 @@
F uninitialized_copy_dispatch(I first, I last, F dst,
boost::mpl::bool_<false> const& /*use_memcpy*/)
{
- //return boost::uninitialized_copy_or_move(first, last, dst); // may throw
return std::uninitialized_copy(first, last, dst); // may throw
}
@@ -234,13 +233,46 @@
uninitialized_fill_dispatch(dst, v, use_memcpy()); // may throw
}
-// move(I, I, O)
+// uninitialized_move(I, I, O)
+
+template <typename I, typename O>
+O uninitialized_move_dispatch(I first, I last, O dst,
+ boost::mpl::bool_<true> const& /*use_memcpy*/)
+{
+ typedef typename boost::iterator_value<I>::type value_type;
+ typename boost::iterator_difference<I>::type d = std::distance(first, last);
-// TODO use boost::move(I, I, O) instead of copy
+ ::memcpy(boost::addressof(*dst), boost::addressof(*first), sizeof(value_type) * d);
+ return dst + d;
+}
+
+template <typename I, typename O>
+O uninitialized_move_dispatch(I first, I last, O dst,
+ boost::mpl::bool_<false> const& /*use_memcpy*/)
+{
+ return boost::uninitialized_move(first, last, dst); // may throw
+}
+
+template <typename I, typename O>
+O uninitialized_move(I first, I last, O dst)
+{
+ typedef typename
+ ::boost::mpl::and_<
+ are_corresponding<I, O>,
+ ::boost::has_trivial_copy<
+ typename ::boost::iterator_value<O>::type
+ >
+ >::type
+ use_memcpy;
+
+ return uninitialized_move_dispatch(first, last, dst, use_memcpy()); // may throw
+}
+
+// move(I, I, O)
template <typename I, typename O>
O move_dispatch(I first, I last, O dst,
- boost::mpl::bool_<true> const& /*use_memmove*/)
+ boost::mpl::bool_<true> const& /*use_memmove*/)
{
typedef typename boost::iterator_value<I>::type value_type;
typename boost::iterator_difference<I>::type d = std::distance(first, last);
@@ -273,8 +305,6 @@
// move_backward(BDI, BDI, BDO)
-// TODO use boost::move_backward(I, I, O) instead of copy_backward
-
template <typename BDI, typename BDO>
BDO move_backward_dispatch(BDI first, BDI last, BDO dst,
boost::mpl::bool_<true> const& /*use_memmove*/)
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-21 22:33:16 EST (Fri, 21 Dec 2012)
@@ -657,8 +657,13 @@
namespace sv = static_vector_detail;
for (; first_sm != last_sm ; ++first_sm, ++first_la)
- boost::swap(*first_sm, *first_la); // may throw
- sv::uninitialized_copy(first_la, last_la, first_sm); // may throw
+ {
+ //boost::swap(*first_sm, *first_la); // may throw
+ value_type temp(boost::move(*first_sm)); // may throw
+ *first_sm = boost::move(*first_la); // may throw
+ *first_la = boost::move(temp); // may throw
+ }
+ sv::uninitialized_move(first_la, last_la, first_sm); // may throw
sv::destroy(first_la, last_la);
}
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-21 22:33:16 EST (Fri, 21 Dec 2012)
@@ -599,7 +599,7 @@
s1.swap(v1);
s2 = boost::move(v2);
static_vector<T, N> s3(boost::move(v3));
- v4.swap(s4);
+ s4.swap(v4);
BOOST_CHECK(v1.size() == N/2);
BOOST_CHECK(s1.size() == N);
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