From ff515a54ec0229947a28801160e09e215e96c299 Mon Sep 17 00:00:00 2001 From: cfairles Date: Wed, 1 Oct 2008 22:04:02 +0000 Subject: 2008-09-30 Chris Fairles * include/std/tuple (tuple<>::swap): Implement swap for tuple as per DR 522 [Ready]. * testsuite/20_util/tuple/swap.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@140822 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/include/std/tuple | 54 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'libstdc++-v3/include/std') diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index a295e4ef937..33e8731d3aa 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -81,6 +81,8 @@ namespace std _Head& _M_head() { return *this; } const _Head& _M_head() const { return *this; } + + void __swap_impl(_Head&&) { /* no-op */ } }; template @@ -99,6 +101,13 @@ namespace std _Head& _M_head() { return _M_head_impl; } const _Head& _M_head() const { return _M_head_impl; } + void + __swap_impl(_Head&& __h) + { + using std::swap; + swap(__h, _M_head_impl); + } + _Head _M_head_impl; }; @@ -118,7 +127,10 @@ namespace std * inheritance recursion. */ template - struct _Tuple_impl<_Idx> { }; + struct _Tuple_impl<_Idx> + { + void __swap_impl(_Tuple_impl&&) { /* no-op */ } + }; /** * Recursive tuple implementation. Here we store the @c Head element @@ -203,6 +215,13 @@ namespace std _M_tail() = std::move(__in._M_tail()); return *this; } + + void + __swap_impl(_Tuple_impl&& __in) + { + _Base::__swap_impl(__in._M_head()); + _Inherited::__swap_impl(__in._M_tail()); + } }; /// tuple @@ -274,11 +293,19 @@ namespace std static_cast<_Inherited&>(*this) = std::move(__in); return *this; } + + void + swap(tuple&& __in) + { _Inherited::__swap_impl(__in); } }; template<> - class tuple<> { }; + class tuple<> + { + public: + void swap(tuple&&) { /* no-op */ } + }; /// tuple (2-element), with construction and assignment from a pair. template @@ -368,6 +395,14 @@ namespace std this->_M_tail()._M_head() = std::move(__in.second); return *this; } + + void + swap(tuple&& __in) + { + using std::swap; + swap(this->_M_head(), __in._M_head()); + swap(this->_M_tail()._M_head(), __in._M_tail()._M_head()); + } }; @@ -628,6 +663,21 @@ namespace std tie(_Elements&... __args) { return tuple<_Elements&...>(__args...); } + template + inline void + swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y) + { __x.swap(__y); } + + template + inline void + swap(tuple<_Elements...>&& __x, tuple<_Elements...>& __y) + { __x.swap(__y); } + + template + inline void + swap(tuple<_Elements...>& __x, tuple<_Elements...>&& __y) + { __x.swap(__y); } + // A class (and instance) which can be used in 'tie' when an element // of a tuple is not required struct _Swallow_assign -- cgit v1.2.1