1 Upstream-Status: Inappropriate [Backport]
2 From 95c034f0075055720f37e340fd008d8d7cb45b4e Mon Sep 17 00:00:00 2001
3 From: paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
4 Date: Fri, 15 Apr 2011 14:52:57 +0000
5 Subject: [PATCH 125/200] 2011-04-15 Takaya Saito <gintensubaru@gmail.com>
8 * include/std/tuple (_Tuple_impl<>::_Tuple_impl(_Tuple_impl<>&&),
9 _Tuple_impl<>::operator=(_Tuple_impl&&), _Tuple_impl<>::operator=
10 (_Tuple_impl<>&&), tuple_cat): Use std::forward where appropriate.
11 * testsuite/20_util/tuple/cons/48476.cc: New.
12 * testsuite/20_util/tuple/48476.cc: Likewise.
13 * testsuite/20_util/tuple/creation_functions/48476.cc: Likewise.
16 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@172498 138bc75d-0d04-0410-961f-82ee72b054a4
18 index 6951328..fb452ae 100644
19 --- a/libstdc++-v3/include/std/tuple
20 +++ b/libstdc++-v3/include/std/tuple
22 // <tuple> -*- C++ -*-
24 -// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
25 +// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
27 // This file is part of the GNU ISO C++ Library. This library is free
28 // software; you can redistribute it and/or modify it under the
29 @@ -177,10 +177,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
30 _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
31 : _Inherited(__in._M_tail()), _Base(__in._M_head()) { }
33 - template<typename... _UElements>
34 - _Tuple_impl(_Tuple_impl<_Idx, _UElements...>&& __in)
35 + template<typename _UHead, typename... _UTails>
36 + _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
37 : _Inherited(std::move(__in._M_tail())),
38 - _Base(std::move(__in._M_head())) { }
39 + _Base(std::forward<_UHead>(__in._M_head())) { }
42 operator=(const _Tuple_impl& __in)
43 @@ -193,7 +193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
45 operator=(_Tuple_impl&& __in)
47 - _M_head() = std::move(__in._M_head());
48 + _M_head() = std::forward<_Head>(__in._M_head());
49 _M_tail() = std::move(__in._M_tail());
52 @@ -207,11 +207,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
56 - template<typename... _UElements>
57 + template<typename _UHead, typename... _UTails>
59 - operator=(_Tuple_impl<_Idx, _UElements...>&& __in)
60 + operator=(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
62 - _M_head() = std::move(__in._M_head());
63 + _M_head() = std::forward<_UHead>(__in._M_head());
64 _M_tail() = std::move(__in._M_tail());
67 @@ -672,7 +672,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
68 const tuple<_UElements...>& __u,
69 const __index_holder<_UIdx...>&)
70 { return tuple<_TElements..., _UElements...>
71 - (std::move(get<_TIdx>(__t))..., get<_UIdx>(__u)...); }
72 + (std::forward<_TElements>(get<_TIdx>(__t))..., get<_UIdx>(__u)...); }
74 template<typename... _TElements, std::size_t... _TIdx,
75 typename... _UElements, std::size_t... _UIdx>
76 @@ -682,7 +682,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
77 tuple<_UElements...>&& __u,
78 const __index_holder<_UIdx...>&)
79 { return tuple<_TElements..., _UElements...>
80 - (get<_TIdx>(__t)..., std::move(get<_UIdx>(__u))...); }
81 + (get<_TIdx>(__t)..., std::forward<_UElements>(get<_UIdx>(__u))...); }
83 template<typename... _TElements, std::size_t... _TIdx,
84 typename... _UElements, std::size_t... _UIdx>
85 @@ -692,7 +692,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
86 tuple<_UElements...>&& __u,
87 const __index_holder<_UIdx...>&)
88 { return tuple<_TElements..., _UElements...>
89 - (std::move(get<_TIdx>(__t))..., std::move(get<_UIdx>(__u))...); }
90 + (std::forward<_TElements>(get<_TIdx>(__t))...,
91 + std::forward<_UElements>(get<_UIdx>(__u))...); }
93 template<typename... _TElements, typename... _UElements>
94 inline tuple<_TElements..., _UElements...>
95 diff --git a/libstdc++-v3/testsuite/20_util/tuple/48476.cc b/libstdc++-v3/testsuite/20_util/tuple/48476.cc
97 index 0000000..efe0007
99 +++ b/libstdc++-v3/testsuite/20_util/tuple/48476.cc
101 +// { dg-options "-std=gnu++0x" }
103 +// Copyright (C) 2011 Free Software Foundation, Inc.
105 +// This file is part of the GNU ISO C++ Library. This library is free
106 +// software; you can redistribute it and/or modify it under the
107 +// terms of the GNU General Public License as published by the
108 +// Free Software Foundation; either version 3, or (at your option)
109 +// any later version.
111 +// This library is distributed in the hope that it will be useful,
112 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
113 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
114 +// GNU General Public License for more details.
116 +// You should have received a copy of the GNU General Public License along
117 +// with this library; see the file COPYING3. If not see
118 +// <http://www.gnu.org/licenses/>.
121 +#include <type_traits>
123 +#include <testsuite_hooks.h>
125 +template<typename T>
126 + typename std::decay<T>::type copy(T&& x)
127 + { return std::forward<T>(x); }
132 + bool test __attribute__((unused)) = true;
134 + std::shared_ptr<int> p(new int()), q, r;
136 + std::tuple<std::shared_ptr<int>&, int> t0(p, 23), t1(q, 0);
137 + t1 = copy(t0); // shall be equivalent to
138 + // q = p; std::get<1>(t1) = std::get<1>(t0);
141 + std::tuple<std::shared_ptr<int>&, char> t2(r, 0);
142 + t2 = copy(t1); // shall be equivalent to
143 + // r = q; std::get<1>(t2) = std::get<1>(t1);
152 diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/48476.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/48476.cc
154 index 0000000..b5e3604
156 +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/48476.cc
158 +// { dg-options "-std=gnu++0x" }
159 +// { dg-do compile }
161 +// Copyright (C) 2011 Free Software Foundation, Inc.
163 +// This file is part of the GNU ISO C++ Library. This library is free
164 +// software; you can redistribute it and/or modify it under the
165 +// terms of the GNU General Public License as published by the
166 +// Free Software Foundation; either version 3, or (at your option)
167 +// any later version.
169 +// This library is distributed in the hope that it will be useful,
170 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
171 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
172 +// GNU General Public License for more details.
174 +// You should have received a copy of the GNU General Public License along
175 +// with this library; see the file COPYING3. If not see
176 +// <http://www.gnu.org/licenses/>.
183 + std::tuple<int&, int> t __attribute__((unused)) = std::forward_as_tuple(i, 0);
185 diff --git a/libstdc++-v3/testsuite/20_util/tuple/creation_functions/48476.cc b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/48476.cc
187 index 0000000..1607e45
189 +++ b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/48476.cc
191 +// { dg-options "-std=gnu++0x" }
193 +// Copyright (C) 2011 Free Software Foundation, Inc.
195 +// This file is part of the GNU ISO C++ Library. This library is free
196 +// software; you can redistribute it and/or modify it under the
197 +// terms of the GNU General Public License as published by the
198 +// Free Software Foundation; either version 3, or (at your option)
199 +// any later version.
201 +// This library is distributed in the hope that it will be useful,
202 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
203 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
204 +// GNU General Public License for more details.
206 +// You should have received a copy of the GNU General Public License along
207 +// with this library; see the file COPYING3. If not see
208 +// <http://www.gnu.org/licenses/>.
211 +#include <type_traits>
212 +#include <testsuite_hooks.h>
214 +template<typename T>
215 + typename std::decay<T>::type copy(T&& x)
216 + { return std::forward<T>(x); }
218 +template<typename... Args1, typename... Args2>
220 + check_tuple_cat(std::tuple<Args1...> t1, std::tuple<Args2...> t2)
222 + bool test __attribute__((unused)) = true;
224 + typedef std::tuple<Args1..., Args2...> concatenated;
226 + auto cat1 = std::tuple_cat( t1, t2 );
227 + auto cat2 = std::tuple_cat(copy(t1), t2 );
228 + auto cat3 = std::tuple_cat( t1, copy(t2));
229 + auto cat4 = std::tuple_cat(copy(t1), copy(t2));
231 + static_assert( std::is_same<decltype(cat1), concatenated>::value, "" );
232 + static_assert( std::is_same<decltype(cat2), concatenated>::value, "" );
233 + static_assert( std::is_same<decltype(cat3), concatenated>::value, "" );
234 + static_assert( std::is_same<decltype(cat4), concatenated>::value, "" );
236 + VERIFY( cat1 == cat2 );
237 + VERIFY( cat1 == cat3 );
238 + VERIFY( cat1 == cat4 );
246 + std::tuple<int&> t1(i);
247 + std::tuple<int&, int> t2(i, 0);
248 + std::tuple<int const&, int, double> t3(i, 0, 0);
250 + check_tuple_cat(t0, t0);
251 + check_tuple_cat(t0, t1);
252 + check_tuple_cat(t0, t2);
253 + check_tuple_cat(t0, t3);
255 + check_tuple_cat(t1, t0);
256 + check_tuple_cat(t1, t1);
257 + check_tuple_cat(t1, t2);
258 + check_tuple_cat(t1, t3);
260 + check_tuple_cat(t2, t0);
261 + check_tuple_cat(t2, t1);
262 + check_tuple_cat(t2, t2);
263 + check_tuple_cat(t2, t3);
265 + check_tuple_cat(t3, t0);
266 + check_tuple_cat(t3, t1);
267 + check_tuple_cat(t3, t2);
268 + check_tuple_cat(t3, t3);