From bd98b9f24bdf66358b2e49559096fc806d05a21b Mon Sep 17 00:00:00 2001 From: paolo Date: Sun, 30 Dec 2007 22:44:42 +0000 Subject: [PATCH] 2007-12-30 Paolo Carlini * 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@131230 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 22 +++ libstdc++-v3/include/std/tuple | 167 +++++++++++++++++---- .../20_util/tuple/creation_functions/tie2.cc | 39 +++++ libstdc++-v3/testsuite/20_util/tuple/moveable.cc | 51 +++++++ .../6_containers/tuple/creation_functions/tie2.cc | 37 +++++ 5 files changed, 284 insertions(+), 32 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/tuple/creation_functions/tie2.cc create mode 100644 libstdc++-v3/testsuite/20_util/tuple/moveable.cc create mode 100644 libstdc++-v3/testsuite/tr1/6_containers/tuple/creation_functions/tie2.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 34a3fdc..5b472c0 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,25 @@ +2007-12-30 Paolo Carlini + + * 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 * 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 1bec091..61302f1 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -63,8 +63,8 @@ namespace std { typedef _Tp& type; }; template - struct _Head_base; - + struct _Head_base; + template 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 - _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in) - : _Inherited(__in._M_tail()), _Base(__in._M_head()) { } + template + 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 - _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 + _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 + _Tuple_impl& + operator=(const _Tuple_impl<_Idx, _UElements...>& __in) + { + _M_head() = __in._M_head(); + _M_tail() = __in._M_tail(); + return *this; + } + + template + _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 @@ -186,23 +219,27 @@ namespace std : _Inherited() { } explicit - tuple(typename __add_c_ref<_Elements>::type... __elements) + tuple(const _Elements&... __elements) : _Inherited(__elements...) { } template - 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 - tuple& - operator=(const tuple<_UElements...>& __in) - { - static_cast<_Inherited&>(*this) = __in; - return *this; - } + tuple(const tuple<_UElements...>& __in) + : _Inherited(__in) { } + + template + 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 + tuple& + operator=(const tuple<_UElements...>& __in) + { + static_cast<_Inherited&>(*this) = __in; + return *this; + } + + template + 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 - 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 + tuple(const tuple<_U1, _U2>& __in) + : _Inherited(__in) { } + + template + tuple(tuple<_U1, _U2>&& __in) + : _Inherited(std::move(__in)) { } + template 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 - 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 + tuple& + operator=(const tuple<_U1, _U2>& __in) + { + static_cast<_Inherited&>(*this) = __in; + return *this; + } + + template + tuple& + operator=(tuple<_U1, _U2>&& __in) + { + static_cast<_Inherited&>(*this) = std::move(__in); + return *this; + } + template tuple& operator=(const pair<_U1, _U2>& __in) @@ -267,6 +361,15 @@ namespace std this->_M_tail()._M_head() = __in.second; return *this; } + + template + 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 0000000..c0b52f5 --- /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 +#include +#include + +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 0000000..bd2f18a --- /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 +#include +#include + +int main() +{ + bool test __attribute__((unused)) = true; + + std::tuple 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 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 0000000..4682424 --- /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 +#include +#include + +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++" ); +} -- 2.7.4