|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r82676 - in sandbox/static_vector: boost/container/detail test
From: adam.wulkiewicz_at_[hidden]
Date: 2013-02-06 20:23:54
Author: awulkiew
Date: 2013-01-31 23:38:05 EST (Thu, 31 Jan 2013)
New Revision: 82676
URL: http://svn.boost.org/trac/boost/changeset/82676
Log:
Fixed compilation error when calling emplace_back() with 0 parameters
Text files modified:
sandbox/static_vector/boost/container/detail/static_vector_util.hpp | 27 +++++++++++++++++++++++++++
sandbox/static_vector/test/static_vector_test.cpp | 19 +++++++++++++++++++
2 files changed, 46 insertions(+), 0 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 2013-01-31 23:38:05 EST (Thu, 31 Jan 2013)
@@ -562,6 +562,33 @@
#else // !BOOST_NO_VARIADIC_TEMPLATES
+// construct(I)
+
+template <typename I>
+inline
+void construct_dispatch(I pos,
+ ::boost::mpl::bool_<true> const& /*empty_constr*/)
+{}
+
+template <typename I>
+inline
+void construct_dispatch(I pos,
+ ::boost::mpl::bool_<false> const& /*empty_constr*/)
+{
+ typedef typename ::boost::iterator_value<I>::type V;
+ new (static_cast<void*>(::boost::addressof(*pos))) V(); // may throw
+}
+
+template <typename I>
+inline
+void construct(I pos)
+{
+ typedef typename ::boost::iterator_value<I>::type V;
+ typedef typename ::boost::has_trivial_constructor<V>::type empty_constr;
+
+ construct_dispatch(pos, empty_constr()); // may throw
+}
+
// BOOST_NO_RVALUE_REFERENCES -> P0 const& p0
// !BOOST_NO_RVALUE_REFERENCES -> P0 && p0
// which means that version with one parameter may take V const& v
Modified: sandbox/static_vector/test/static_vector_test.cpp
==============================================================================
--- sandbox/static_vector/test/static_vector_test.cpp (original)
+++ sandbox/static_vector/test/static_vector_test.cpp 2013-01-31 23:38:05 EST (Thu, 31 Jan 2013)
@@ -583,6 +583,22 @@
}
template <typename T, size_t N>
+void test_emplace_0p()
+{
+ //emplace_back()
+ {
+ static_vector<T, N, bad_alloc_strategy<T> > v;
+
+ for (int i = 0 ; i < int(N) ; ++i )
+ v.emplace_back();
+ BOOST_CHECK(v.size() == N);
+#ifndef BOOST_NO_EXCEPTIONS
+ BOOST_CHECK_THROW(v.emplace_back(), std::bad_alloc);
+#endif
+ }
+}
+
+template <typename T, size_t N>
void test_emplace_2p()
{
//emplace_back(pos, int, int)
@@ -746,6 +762,9 @@
test_swap_and_move_nd<shptr_value, 10>();
test_swap_and_move_nd<copy_movable, 10>();
+ test_emplace_0p<counting_value, 10>();
+ BOOST_CHECK(counting_value::count() == 0);
+
test_emplace_2p<counting_value, 10>();
BOOST_CHECK(counting_value::count() == 0);
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