1 From 95c034f0075055720f37e340fd008d8d7cb45b4e Mon Sep 17 00:00:00 2001
2 From: paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
3 Date: Fri, 15 Apr 2011 14:52:57 +0000
4 Subject: [PATCH 125/200] 2011-04-15 Takaya Saito <gintensubaru@gmail.com>
7 * include/std/tuple (_Tuple_impl<>::_Tuple_impl(_Tuple_impl<>&&),
8 _Tuple_impl<>::operator=(_Tuple_impl&&), _Tuple_impl<>::operator=
9 (_Tuple_impl<>&&), tuple_cat): Use std::forward where appropriate.
10 * testsuite/20_util/tuple/cons/48476.cc: New.
11 * testsuite/20_util/tuple/48476.cc: Likewise.
12 * testsuite/20_util/tuple/creation_functions/48476.cc: Likewise.
15 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@172498 138bc75d-0d04-0410-961f-82ee72b054a4
17 index 6951328..fb452ae 100644
18 --- a/libstdc++-v3/include/std/tuple
19 +++ b/libstdc++-v3/include/std/tuple
21 // <tuple> -*- C++ -*-
23 -// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
24 +// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
26 // This file is part of the GNU ISO C++ Library. This library is free
27 // software; you can redistribute it and/or modify it under the
28 @@ -177,10 +177,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
29 _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
30 : _Inherited(__in._M_tail()), _Base(__in._M_head()) { }
32 - template<typename... _UElements>
33 - _Tuple_impl(_Tuple_impl<_Idx, _UElements...>&& __in)
34 + template<typename _UHead, typename... _UTails>
35 + _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
36 : _Inherited(std::move(__in._M_tail())),
37 - _Base(std::move(__in._M_head())) { }
38 + _Base(std::forward<_UHead>(__in._M_head())) { }
41 operator=(const _Tuple_impl& __in)
42 @@ -193,7 +193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
44 operator=(_Tuple_impl&& __in)
46 - _M_head() = std::move(__in._M_head());
47 + _M_head() = std::forward<_Head>(__in._M_head());
48 _M_tail() = std::move(__in._M_tail());
51 @@ -207,11 +207,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
55 - template<typename... _UElements>
56 + template<typename _UHead, typename... _UTails>
58 - operator=(_Tuple_impl<_Idx, _UElements...>&& __in)
59 + operator=(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
61 - _M_head() = std::move(__in._M_head());
62 + _M_head() = std::forward<_UHead>(__in._M_head());
63 _M_tail() = std::move(__in._M_tail());
66 @@ -672,7 +672,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
67 const tuple<_UElements...>& __u,
68 const __index_holder<_UIdx...>&)
69 { return tuple<_TElements..., _UElements...>
70 - (std::move(get<_TIdx>(__t))..., get<_UIdx>(__u)...); }
71 + (std::forward<_TElements>(get<_TIdx>(__t))..., get<_UIdx>(__u)...); }
73 template<typename... _TElements, std::size_t... _TIdx,
74 typename... _UElements, std::size_t... _UIdx>
75 @@ -682,7 +682,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
76 tuple<_UElements...>&& __u,
77 const __index_holder<_UIdx...>&)
78 { return tuple<_TElements..., _UElements...>
79 - (get<_TIdx>(__t)..., std::move(get<_UIdx>(__u))...); }
80 + (get<_TIdx>(__t)..., std::forward<_UElements>(get<_UIdx>(__u))...); }
82 template<typename... _TElements, std::size_t... _TIdx,
83 typename... _UElements, std::size_t... _UIdx>
84 @@ -692,7 +692,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
85 tuple<_UElements...>&& __u,
86 const __index_holder<_UIdx...>&)
87 { return tuple<_TElements..., _UElements...>
88 - (std::move(get<_TIdx>(__t))..., std::move(get<_UIdx>(__u))...); }
89 + (std::forward<_TElements>(get<_TIdx>(__t))...,
90 + std::forward<_UElements>(get<_UIdx>(__u))...); }
92 template<typename... _TElements, typename... _UElements>
93 inline tuple<_TElements..., _UElements...>
94 diff --git a/libstdc++-v3/testsuite/20_util/tuple/48476.cc b/libstdc++-v3/testsuite/20_util/tuple/48476.cc
96 index 0000000..efe0007
98 +++ b/libstdc++-v3/testsuite/20_util/tuple/48476.cc
100 +// { dg-options "-std=gnu++0x" }
102 +// Copyright (C) 2011 Free Software Foundation, Inc.
104 +// This file is part of the GNU ISO C++ Library. This library is free
105 +// software; you can redistribute it and/or modify it under the
106 +// terms of the GNU General Public License as published by the
107 +// Free Software Foundation; either version 3, or (at your option)
108 +// any later version.
110 +// This library is distributed in the hope that it will be useful,
111 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
112 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
113 +// GNU General Public License for more details.
115 +// You should have received a copy of the GNU General Public License along
116 +// with this library; see the file COPYING3. If not see
117 +// <http://www.gnu.org/licenses/>.
120 +#include <type_traits>
122 +#include <testsuite_hooks.h>
124 +template<typename T>
125 + typename std::decay<T>::type copy(T&& x)
126 + { return std::forward<T>(x); }
131 + bool test __attribute__((unused)) = true;
133 + std::shared_ptr<int> p(new int()), q, r;
135 + std::tuple<std::shared_ptr<int>&, int> t0(p, 23), t1(q, 0);
136 + t1 = copy(t0); // shall be equivalent to
137 + // q = p; std::get<1>(t1) = std::get<1>(t0);
140 + std::tuple<std::shared_ptr<int>&, char> t2(r, 0);
141 + t2 = copy(t1); // shall be equivalent to
142 + // r = q; std::get<1>(t2) = std::get<1>(t1);
151 diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/48476.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/48476.cc
153 index 0000000..b5e3604
155 +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/48476.cc
157 +// { dg-options "-std=gnu++0x" }
158 +// { dg-do compile }
160 +// Copyright (C) 2011 Free Software Foundation, Inc.
162 +// This file is part of the GNU ISO C++ Library. This library is free
163 +// software; you can redistribute it and/or modify it under the
164 +// terms of the GNU General Public License as published by the
165 +// Free Software Foundation; either version 3, or (at your option)
166 +// any later version.
168 +// This library is distributed in the hope that it will be useful,
169 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
170 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
171 +// GNU General Public License for more details.
173 +// You should have received a copy of the GNU General Public License along
174 +// with this library; see the file COPYING3. If not see
175 +// <http://www.gnu.org/licenses/>.
182 + std::tuple<int&, int> t __attribute__((unused)) = std::forward_as_tuple(i, 0);
184 diff --git a/libstdc++-v3/testsuite/20_util/tuple/creation_functions/48476.cc b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/48476.cc
186 index 0000000..1607e45
188 +++ b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/48476.cc
190 +// { dg-options "-std=gnu++0x" }
192 +// Copyright (C) 2011 Free Software Foundation, Inc.
194 +// This file is part of the GNU ISO C++ Library. This library is free
195 +// software; you can redistribute it and/or modify it under the
196 +// terms of the GNU General Public License as published by the
197 +// Free Software Foundation; either version 3, or (at your option)
198 +// any later version.
200 +// This library is distributed in the hope that it will be useful,
201 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
202 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
203 +// GNU General Public License for more details.
205 +// You should have received a copy of the GNU General Public License along
206 +// with this library; see the file COPYING3. If not see
207 +// <http://www.gnu.org/licenses/>.
210 +#include <type_traits>
211 +#include <testsuite_hooks.h>
213 +template<typename T>
214 + typename std::decay<T>::type copy(T&& x)
215 + { return std::forward<T>(x); }
217 +template<typename... Args1, typename... Args2>
219 + check_tuple_cat(std::tuple<Args1...> t1, std::tuple<Args2...> t2)
221 + bool test __attribute__((unused)) = true;
223 + typedef std::tuple<Args1..., Args2...> concatenated;
225 + auto cat1 = std::tuple_cat( t1, t2 );
226 + auto cat2 = std::tuple_cat(copy(t1), t2 );
227 + auto cat3 = std::tuple_cat( t1, copy(t2));
228 + auto cat4 = std::tuple_cat(copy(t1), copy(t2));
230 + static_assert( std::is_same<decltype(cat1), concatenated>::value, "" );
231 + static_assert( std::is_same<decltype(cat2), concatenated>::value, "" );
232 + static_assert( std::is_same<decltype(cat3), concatenated>::value, "" );
233 + static_assert( std::is_same<decltype(cat4), concatenated>::value, "" );
235 + VERIFY( cat1 == cat2 );
236 + VERIFY( cat1 == cat3 );
237 + VERIFY( cat1 == cat4 );
245 + std::tuple<int&> t1(i);
246 + std::tuple<int&, int> t2(i, 0);
247 + std::tuple<int const&, int, double> t3(i, 0, 0);
249 + check_tuple_cat(t0, t0);
250 + check_tuple_cat(t0, t1);
251 + check_tuple_cat(t0, t2);
252 + check_tuple_cat(t0, t3);
254 + check_tuple_cat(t1, t0);
255 + check_tuple_cat(t1, t1);
256 + check_tuple_cat(t1, t2);
257 + check_tuple_cat(t1, t3);
259 + check_tuple_cat(t2, t0);
260 + check_tuple_cat(t2, t1);
261 + check_tuple_cat(t2, t2);
262 + check_tuple_cat(t2, t3);
264 + check_tuple_cat(t3, t0);
265 + check_tuple_cat(t3, t1);
266 + check_tuple_cat(t3, t2);
267 + check_tuple_cat(t3, t3);