mirror of
https://github.com/boostorg/container.git
synced 2025-08-02 14:04:26 +02:00
Fix piecewise_construct pair constructor for compilers with variadics and constructor forwarding. Current code unconditionally moves instead of forwarding.
This commit is contained in:
@@ -214,10 +214,10 @@ struct pair
|
|||||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||||
# if !defined(BOOST_CONTAINER_NO_CXX11_DELEGATING_CONSTRUCTORS)
|
# if !defined(BOOST_CONTAINER_NO_CXX11_DELEGATING_CONSTRUCTORS)
|
||||||
private:
|
private:
|
||||||
template<class Tuple1, class Tuple2, size_t... Indexes1, size_t... Indexes2>
|
template<template<class ...> class Tuple, class... Args1, class... Args2, size_t... Indexes1, size_t... Indexes2>
|
||||||
pair(Tuple1& t1, Tuple2& t2, index_tuple<Indexes1...>, index_tuple<Indexes2...>)
|
pair(Tuple<Args1...>& t1, Tuple<Args2...>& t2, index_tuple<Indexes1...>, index_tuple<Indexes2...>)
|
||||||
: first (get<Indexes1>(::boost::move(t1))...)
|
: first (::boost::forward<Args1>(get<Indexes1>(t1))...)
|
||||||
, second(get<Indexes2>(::boost::move(t2))...)
|
, second(::boost::forward<Args2>(get<Indexes2>(t2))...)
|
||||||
{ (void) t1; (void)t2; }
|
{ (void) t1; (void)t2; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@@ -42,13 +42,13 @@ class tuple<Head, Tail...>
|
|||||||
typedef tuple<Tail...> inherited;
|
typedef tuple<Tail...> inherited;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
tuple() { }
|
tuple()
|
||||||
|
: inherited(), m_head()
|
||||||
|
{}
|
||||||
|
|
||||||
// implicit copy-constructor is okay
|
template<class U, class ...Args>
|
||||||
// Construct tuple from separate arguments.
|
tuple(U &&u, Args && ...args)
|
||||||
tuple(typename add_const_reference<Head>::type v,
|
: inherited(::boost::forward<Args>(args)...), m_head(::boost::forward<U>(u))
|
||||||
typename add_const_reference<Tail>::type... vtail)
|
|
||||||
: inherited(vtail...), m_head(v)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// Construct tuple from another tuple.
|
// Construct tuple from another tuple.
|
||||||
@@ -77,8 +77,8 @@ class tuple<Head, Tail...>
|
|||||||
|
|
||||||
|
|
||||||
template<typename... Values>
|
template<typename... Values>
|
||||||
tuple<Values&&...> tie_forward(Values&&... values)
|
tuple<Values&&...> forward_as_tuple(Values&&... values)
|
||||||
{ return tuple<Values&&...>(values...); }
|
{ return tuple<Values&&...>(::boost::forward<Values>(values)...); }
|
||||||
|
|
||||||
template<int I, typename Tuple>
|
template<int I, typename Tuple>
|
||||||
struct tuple_element;
|
struct tuple_element;
|
||||||
|
@@ -135,6 +135,19 @@ int main ()
|
|||||||
BOOST_TEST(std::get<2>(p.first) == 32.);
|
BOOST_TEST(std::get<2>(p.first) == 32.);
|
||||||
BOOST_TEST(p.second == 'b');
|
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)
|
#endif //#!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_HDR_TUPLE)
|
||||||
return ::boost::report_errors();
|
return ::boost::report_errors();
|
||||||
|
Reference in New Issue
Block a user