summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/std
diff options
context:
space:
mode:
authorcfairles <cfairles@138bc75d-0d04-0410-961f-82ee72b054a4>2008-10-01 22:04:02 +0000
committercfairles <cfairles@138bc75d-0d04-0410-961f-82ee72b054a4>2008-10-01 22:04:02 +0000
commitff515a54ec0229947a28801160e09e215e96c299 (patch)
treec80c91c9977fc87421d209601f52d9891fab6ef7 /libstdc++-v3/include/std
parent290e0184d8acb860923ed7542aa52c5bace535b1 (diff)
downloadgcc-ff515a54ec0229947a28801160e09e215e96c299.tar.gz
2008-09-30 Chris Fairles <cfairles@gcc.gnu.org>
* 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
Diffstat (limited to 'libstdc++-v3/include/std')
-rw-r--r--libstdc++-v3/include/std/tuple54
1 files changed, 52 insertions, 2 deletions
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<std::size_t _Idx, typename _Head>
@@ -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<std::size_t _Idx>
- 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<typename _T1, typename _T2>
@@ -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<typename... _Elements>
+ inline void
+ swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
+ { __x.swap(__y); }
+
+ template<typename... _Elements>
+ inline void
+ swap(tuple<_Elements...>&& __x, tuple<_Elements...>& __y)
+ { __x.swap(__y); }
+
+ template<typename... _Elements>
+ 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