From 0a5c2065bd4c06217c2035e1103d2f73a124285e Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Tue, 10 Aug 2010 07:17:44 +0000 Subject: re PR libstdc++/45228 ([C++0x] Can't copy-construct "tuple" from "const tuple" rvalue) 2010-08-10 Paolo Carlini PR libstdc++/45228 * include/std/tuple (tuple): Constrain converting constructors and assignment operators with sizeof...(_UElements) == sizeof...(_Elements). (tuple(tuple<_UElements...>&): Remove. (tuple): Add. * testsuite/20_util/tuple/cons/45228.cc: New. * testsuite/20_util/tuple/cons/converting.cc: Likewise. * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust dg-error line number. * include/std/tuple (_Tuple_impl<>::_Tuple_impl(const _Tuple_impl&)): Defaulted. * include/std/tuple (tuple ::operator=(pair<_U1, _U2>&&)): Use forward. From-SVN: r163049 --- libstdc++-v3/include/std/tuple | 108 +++++++++++++++++++++++++++++++++-------- 1 file changed, 89 insertions(+), 19 deletions(-) (limited to 'libstdc++-v3/include') diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index 2e35241..67a6eb7 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -160,8 +160,7 @@ namespace std : _Inherited(std::forward<_UTail>(__tail)...), _Base(std::forward<_UHead>(__head)) { } - _Tuple_impl(const _Tuple_impl& __in) - : _Inherited(__in._M_tail()), _Base(__in._M_head()) { } + _Tuple_impl(const _Tuple_impl&) = default; _Tuple_impl(_Tuple_impl&& __in) : _Inherited(std::move(__in._M_tail())), @@ -233,7 +232,9 @@ namespace std tuple(const _Elements&... __elements) : _Inherited(__elements...) { } - template + template::type> explicit tuple(_UElements&&... __elements) : _Inherited(std::forward<_UElements>(__elements)...) { } @@ -243,20 +244,18 @@ namespace std tuple(tuple&& __in) : _Inherited(static_cast<_Inherited&&>(__in)) { } - template + template::type> tuple(const tuple<_UElements...>& __in) - : _Inherited(static_cast&>(__in)) - { } + : _Inherited(static_cast&>(__in)) + { } - template + template::type> tuple(tuple<_UElements...>&& __in) - : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { } - - // XXX http://gcc.gnu.org/ml/libstdc++/2008-02/msg00047.html - template - tuple(tuple<_UElements...>& __in) - : _Inherited(static_cast&>(__in)) - { } + : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { } tuple& operator=(const tuple& __in) @@ -272,7 +271,9 @@ namespace std return *this; } - template + template::type> tuple& operator=(const tuple<_UElements...>& __in) { @@ -280,7 +281,9 @@ namespace std return *this; } - template + template::type> tuple& operator=(tuple<_UElements...>&& __in) { @@ -293,7 +296,6 @@ namespace std { _Inherited::_M_swap_impl(__in); } }; - template<> class tuple<> { @@ -385,8 +387,8 @@ namespace std tuple& operator=(pair<_U1, _U2>&& __in) { - this->_M_head() = std::move(__in.first); - this->_M_tail()._M_head() = std::move(__in.second); + this->_M_head() = std::forward<_U1>(__in.first); + this->_M_tail()._M_head() = std::forward<_U2>(__in.second); return *this; } @@ -399,6 +401,74 @@ namespace std } }; + /// tuple (1-element). + template + class tuple<_T1> : public _Tuple_impl<0, _T1> + { + typedef _Tuple_impl<0, _T1> _Inherited; + + public: + tuple() + : _Inherited() { } + + explicit + tuple(const _T1& __a1) + : _Inherited(__a1) { } + + template::value>::type> + explicit + tuple(_U1&& __a1) + : _Inherited(std::forward<_U1>(__a1)) { } + + tuple(const tuple&) = default; + + tuple(tuple&& __in) + : _Inherited(static_cast<_Inherited&&>(__in)) { } + + template + tuple(const tuple<_U1>& __in) + : _Inherited(static_cast&>(__in)) { } + + template + tuple(tuple<_U1>&& __in) + : _Inherited(static_cast<_Tuple_impl<0, _U1>&&>(__in)) { } + + tuple& + operator=(const tuple& __in) + { + static_cast<_Inherited&>(*this) = __in; + return *this; + } + + tuple& + operator=(tuple&& __in) + { + static_cast<_Inherited&>(*this) = std::move(__in); + return *this; + } + + template + tuple& + operator=(const tuple<_U1>& __in) + { + static_cast<_Inherited&>(*this) = __in; + return *this; + } + + template + tuple& + operator=(tuple<_U1>&& __in) + { + static_cast<_Inherited&>(*this) = std::move(__in); + return *this; + } + + void + swap(tuple& __in) + { _Inherited::_M_swap_impl(__in); } + }; + /// Gives the type of the ith element of a given tuple type. template -- cgit v1.1