summaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog22
-rw-r--r--libstdc++-v3/include/std/tuple167
-rw-r--r--libstdc++-v3/testsuite/20_util/tuple/creation_functions/tie2.cc39
-rw-r--r--libstdc++-v3/testsuite/20_util/tuple/moveable.cc51
-rw-r--r--libstdc++-v3/testsuite/tr1/6_containers/tuple/creation_functions/tie2.cc37
5 files changed, 284 insertions, 32 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 34a3fdc524f..5b472c06837 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,25 @@
+2007-12-30 Paolo Carlini <pcarlini@suse.de>
+
+ * include/std/tuple (_Tuple_impl<>::_Tuple_impl(typename
+ std::remove_reference<>::type&&, typename
+ std::remove_reference<>::type&&...),
+ _Tuple_impl(const _Tuple_impl<>&), _Tuple_impl(_Tuple_impl&&),
+ _Tuple_impl(_Tuple_impl<>&&), operator=(_Tuple_impl&&),
+ operator=(const _Tuple_impl<>&), operator=(_Tuple_impl<>&&)): Add.
+ (tuple<>::tuple(const _Elements&...), tuple(_UElements&&...),
+ tuple(tuple&&), tuple(const tuple<>&), tuple(tuple<>&&),
+ operator=(tuple&&), operator=(const tuple<>&), operator=(tuple<>&&)):
+ Likewise.
+ (tuple<_T1, _T2>::tuple(const _T1&, const _T2&, tuple(_U1&&, _U2&&),
+ tuple(tuple&&), tuple(tuple<>&&), tuple(pair<>&&), operator=(tuple&&),
+ operator=(tuple<>&&), operator=(pair<>&&)): Likewise.
+ (tuple<>::tuple(typename __add_c_ref<_Elements>::type...),
+ tuple<_T1, _T2>::tuple(typename __add_c_ref<>::type,
+ typename __add_c_ref<>::type)): Remove.
+ * testsuite/tr1/6_containers/tuple/creation_functions/tie2.cc: New.
+ * testsuite/20_util/tuple/creation_functions/tie2.cc: Likewise.
+ * testsuite/20_util/tuple/moveable.cc: Likewise.
+
2007-12-29 Gerald Pfeifer <gerald@pfeifer.com>
* config/os/mingw32/error_constants.h: Fix typo in comment.
diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple
index 1bec09152bd..61302f1da35 100644
--- a/libstdc++-v3/include/std/tuple
+++ b/libstdc++-v3/include/std/tuple
@@ -63,8 +63,8 @@ namespace std
{ typedef _Tp& type; };
template<int _Idx, typename _Head, bool _IsEmpty>
- struct _Head_base;
-
+ struct _Head_base;
+
template<int _Idx, typename _Head>
struct _Head_base<_Idx, _Head, true>
: public _Head
@@ -151,21 +151,28 @@ namespace std
typename __add_c_ref<_Tail>::type... __tail)
: _Inherited(__tail...), _Base(__head) { }
- template<typename... _UElements>
- _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
- : _Inherited(__in._M_tail()), _Base(__in._M_head()) { }
+ template<typename _UHead, typename... _UTail>
+ explicit
+ _Tuple_impl(typename std::remove_reference<_UHead>::type&& __head,
+ typename std::remove_reference<_UTail>::type&&... __tail)
+ : _Inherited(std::forward<_Inherited>(__tail)...),
+ _Base(std::forward<_Base>(__head)) { }
_Tuple_impl(const _Tuple_impl& __in)
: _Inherited(__in._M_tail()), _Base(__in._M_head()) { }
+ _Tuple_impl(_Tuple_impl&& __in)
+ : _Inherited(std::forward<_Inherited>(__in._M_tail())),
+ _Base(std::forward<_Base>(__in._M_head())) { }
+
template<typename... _UElements>
- _Tuple_impl&
- operator=(const _Tuple_impl<_Idx, _UElements...>& __in)
- {
- _M_head() = __in._M_head();
- _M_tail() = __in._M_tail();
- return *this;
- }
+ _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
+ : _Inherited(__in._M_tail()), _Base(__in._M_head()) { }
+
+ template<typename... _UElements>
+ _Tuple_impl(_Tuple_impl<_Idx, _UElements...>&& __in)
+ : _Inherited(std::forward<_Inherited>(__in._M_tail())),
+ _Base(std::forward<_Base>(__in._M_head())) { }
_Tuple_impl&
operator=(const _Tuple_impl& __in)
@@ -174,6 +181,32 @@ namespace std
_M_tail() = __in._M_tail();
return *this;
}
+
+ _Tuple_impl&
+ operator=(_Tuple_impl&& __in)
+ {
+ _M_head() = std::move(__in._M_head());
+ _M_tail() = std::move(__in._M_tail());
+ return *this;
+ }
+
+ template<typename... _UElements>
+ _Tuple_impl&
+ operator=(const _Tuple_impl<_Idx, _UElements...>& __in)
+ {
+ _M_head() = __in._M_head();
+ _M_tail() = __in._M_tail();
+ return *this;
+ }
+
+ template<typename... _UElements>
+ _Tuple_impl&
+ operator=(_Tuple_impl<_Idx, _UElements...>&& __in)
+ {
+ _M_head() = std::move(__in._M_head());
+ _M_tail() = std::move(__in._M_tail());
+ return *this;
+ }
};
template<typename... _Elements>
@@ -186,23 +219,27 @@ namespace std
: _Inherited() { }
explicit
- tuple(typename __add_c_ref<_Elements>::type... __elements)
+ tuple(const _Elements&... __elements)
: _Inherited(__elements...) { }
template<typename... _UElements>
- tuple(const tuple<_UElements...>& __in)
- : _Inherited(__in) { }
+ explicit
+ tuple(_UElements&&... __elements)
+ : _Inherited(std::forward<_UElements>(__elements)...) { }
tuple(const tuple& __in)
: _Inherited(__in) { }
+ tuple(tuple&& __in)
+ : _Inherited(std::move(__in)) { }
+
template<typename... _UElements>
- tuple&
- operator=(const tuple<_UElements...>& __in)
- {
- static_cast<_Inherited&>(*this) = __in;
- return *this;
- }
+ tuple(const tuple<_UElements...>& __in)
+ : _Inherited(__in) { }
+
+ template<typename... _UElements>
+ tuple(tuple<_UElements...>&& __in)
+ : _Inherited(std::move(__in)) { }
tuple&
operator=(const tuple& __in)
@@ -210,6 +247,29 @@ namespace std
static_cast<_Inherited&>(*this) = __in;
return *this;
}
+
+ tuple&
+ operator=(tuple&& __in)
+ {
+ static_cast<_Inherited&>(*this) = std::move(__in);
+ return *this;
+ }
+
+ template<typename... _UElements>
+ tuple&
+ operator=(const tuple<_UElements...>& __in)
+ {
+ static_cast<_Inherited&>(*this) = __in;
+ return *this;
+ }
+
+ template<typename... _UElements>
+ tuple&
+ operator=(tuple<_UElements...>&& __in)
+ {
+ static_cast<_Inherited&>(*this) = std::move(__in);
+ return *this;
+ }
};
template<> class tuple<> { };
@@ -225,17 +285,28 @@ namespace std
: _Inherited() { }
explicit
- tuple(typename __add_c_ref<_T1>::type __a1,
- typename __add_c_ref<_T2>::type __a2)
+ tuple(const _T1& __a1, const _T2& __a2)
: _Inherited(__a1, __a2) { }
template<typename _U1, typename _U2>
- tuple(const tuple<_U1, _U2>& __in)
- : _Inherited(__in) { }
+ explicit
+ tuple(_U1&& __a1, _U2&& __a2)
+ : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
tuple(const tuple& __in)
: _Inherited(__in) { }
+ tuple(tuple&& __in)
+ : _Inherited(std::move(__in)) { }
+
+ template<typename _U1, typename _U2>
+ tuple(const tuple<_U1, _U2>& __in)
+ : _Inherited(__in) { }
+
+ template<typename _U1, typename _U2>
+ tuple(tuple<_U1, _U2>&& __in)
+ : _Inherited(std::move(__in)) { }
+
template<typename _U1, typename _U2>
tuple(const pair<_U1, _U2>& __in)
: _Inherited(_Tuple_impl<0,
@@ -243,14 +314,14 @@ namespace std
typename __add_c_ref<_U2>::type>(__in.first,
__in.second))
{ }
-
+
template<typename _U1, typename _U2>
- tuple&
- operator=(const tuple<_U1, _U2>& __in)
- {
- static_cast<_Inherited&>(*this) = __in;
- return *this;
- }
+ tuple(pair<_U1, _U2>&& __in)
+ : _Inherited(_Tuple_impl<0,
+ typename std::remove_reference<_U1>::type&&,
+ typename std::remove_reference<_U2>::type&&>
+ (std::move(__in.first), std::move(__in.second)))
+ { }
tuple&
operator=(const tuple& __in)
@@ -259,6 +330,29 @@ namespace std
return *this;
}
+ tuple&
+ operator=(tuple&& __in)
+ {
+ static_cast<_Inherited&>(*this) = std::move(__in);
+ return *this;
+ }
+
+ template<typename _U1, typename _U2>
+ tuple&
+ operator=(const tuple<_U1, _U2>& __in)
+ {
+ static_cast<_Inherited&>(*this) = __in;
+ return *this;
+ }
+
+ template<typename _U1, typename _U2>
+ tuple&
+ operator=(tuple<_U1, _U2>&& __in)
+ {
+ static_cast<_Inherited&>(*this) = std::move(__in);
+ return *this;
+ }
+
template<typename _U1, typename _U2>
tuple&
operator=(const pair<_U1, _U2>& __in)
@@ -267,6 +361,15 @@ namespace std
this->_M_tail()._M_head() = __in.second;
return *this;
}
+
+ template<typename _U1, typename _U2>
+ tuple&
+ operator=(pair<_U1, _U2>&& __in)
+ {
+ this->_M_head() = std::move(__in.first);
+ this->_M_tail()._M_head() = std::move(__in.second);
+ return *this;
+ }
};
diff --git a/libstdc++-v3/testsuite/20_util/tuple/creation_functions/tie2.cc b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/tie2.cc
new file mode 100644
index 00000000000..c0b52f57a00
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/tie2.cc
@@ -0,0 +1,39 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2007 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// Tuple
+
+#include <tuple>
+#include <string>
+#include <testsuite_hooks.h>
+
+int
+main()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ int i;
+ string s;
+
+ tie(i, ignore, s) = make_tuple(42, 3.14, "C++");
+ VERIFY( i == 42 );
+ VERIFY( s == "C++" );
+}
diff --git a/libstdc++-v3/testsuite/20_util/tuple/moveable.cc b/libstdc++-v3/testsuite/20_util/tuple/moveable.cc
new file mode 100644
index 00000000000..bd2f18ad86e
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/tuple/moveable.cc
@@ -0,0 +1,51 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2007 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+// NOTE: This makes use of the fact that we know how moveable
+// is implemented on tuple. If the implementation changed
+// this test may begin to fail.
+
+#include <tuple>
+#include <utility>
+#include <testsuite_hooks.h>
+
+int main()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::tuple<int, double> a(1, 2.0), b;
+ b = std::move(a);
+ VERIFY( std::get<0>(b) == 1 && std::get<1>(b) == 2.0 );
+ VERIFY( std::get<0>(a) == 1 && std::get<1>(a) == 2.0 );
+
+ std::tuple<int, double> c(std::move(b));
+ VERIFY( std::get<0>(c) == 1 && std::get<1>(c) == 2.0 );
+ VERIFY( std::get<0>(b) == 1 && std::get<1>(b) == 2.0 );
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/tr1/6_containers/tuple/creation_functions/tie2.cc b/libstdc++-v3/testsuite/tr1/6_containers/tuple/creation_functions/tie2.cc
new file mode 100644
index 00000000000..4682424cafa
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/6_containers/tuple/creation_functions/tie2.cc
@@ -0,0 +1,37 @@
+// Copyright (C) 2007 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// Tuple
+
+#include <tr1/tuple>
+#include <string>
+#include <testsuite_hooks.h>
+
+int
+main()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std::tr1;
+
+ int i;
+ std::string s;
+
+ tie(i, ignore, s) = make_tuple(42, 3.14, "C++");
+ VERIFY( i == 42 );
+ VERIFY( s == "C++" );
+}