Fix piecewise_construct pair constructor for compilers with variadics and constructor forwarding. Current code unconditionally moves instead of forwarding.

This commit is contained in:
Ion Gaztañaga
2016-08-24 01:52:53 +02:00
parent 79a75f470e
commit db5c24e0e7
3 changed files with 25 additions and 12 deletions

View File

@@ -214,10 +214,10 @@ struct pair
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
# if !defined(BOOST_CONTAINER_NO_CXX11_DELEGATING_CONSTRUCTORS)
private:
template<class Tuple1, class Tuple2, size_t... Indexes1, size_t... Indexes2>
pair(Tuple1& t1, Tuple2& t2, index_tuple<Indexes1...>, index_tuple<Indexes2...>)
: first (get<Indexes1>(::boost::move(t1))...)
, second(get<Indexes2>(::boost::move(t2))...)
template<template<class ...> class Tuple, class... Args1, class... Args2, size_t... Indexes1, size_t... Indexes2>
pair(Tuple<Args1...>& t1, Tuple<Args2...>& t2, index_tuple<Indexes1...>, index_tuple<Indexes2...>)
: first (::boost::forward<Args1>(get<Indexes1>(t1))...)
, second(::boost::forward<Args2>(get<Indexes2>(t2))...)
{ (void) t1; (void)t2; }
public:

View File

@@ -42,13 +42,13 @@ class tuple<Head, Tail...>
typedef tuple<Tail...> inherited;
public:
tuple() { }
tuple()
: inherited(), m_head()
{}
// implicit copy-constructor is okay
// Construct tuple from separate arguments.
tuple(typename add_const_reference<Head>::type v,
typename add_const_reference<Tail>::type... vtail)
: inherited(vtail...), m_head(v)
template<class U, class ...Args>
tuple(U &&u, Args && ...args)
: inherited(::boost::forward<Args>(args)...), m_head(::boost::forward<U>(u))
{}
// Construct tuple from another tuple.
@@ -77,8 +77,8 @@ class tuple<Head, Tail...>
template<typename... Values>
tuple<Values&&...> tie_forward(Values&&... values)
{ return tuple<Values&&...>(values...); }
tuple<Values&&...> forward_as_tuple(Values&&... values)
{ return tuple<Values&&...>(::boost::forward<Values>(values)...); }
template<int I, typename Tuple>
struct tuple_element;

View File

@@ -135,6 +135,19 @@ int main ()
BOOST_TEST(std::get<2>(p.first) == 32.);
BOOST_TEST(p.second == 'b');
}
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
typedef container_detail::pair<test::movable_int, test::movable_int> movable_pair_t;
typedef container_detail::pair<movable_pair_t, movable_pair_t> movable_pair_pair_t;
test::movable_int a(1), b(2), c(3), d(4);
movable_pair_pair_t p( piecewise_construct
, container_detail::forward_as_tuple(boost::move(a), boost::move(b))
, container_detail::forward_as_tuple(boost::move(c), boost::move(d))
);
BOOST_TEST(p.first.first == 1);
BOOST_TEST(p.first.second == 2);
BOOST_TEST(p.second.first == 3);
BOOST_TEST(p.second.second == 4);
#endif
}
#endif //#!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_HDR_TUPLE)
return ::boost::report_errors();