From: Ville Voutilainen Date: Thu, 11 Aug 2016 14:51:47 +0000 (+0300) Subject: Implement C++17 make_from_tuple. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ca1ab6be3b8e40bf689d6aa45451ee9d372b3548;p=gcc.git Implement C++17 make_from_tuple. * include/std/tuple (__make_from_tuple_impl, make_from_tuple): New. * testsuite/20_util/tuple/make_from_tuple/1.cc: Likewise. From-SVN: r239372 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index def5c2960e5..446e8bac71b 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2016-08-11 Ville Voutilainen + + Implement C++17 make_from_tuple. + * include/std/tuple (__make_from_tuple_impl, make_from_tuple): New. + * testsuite/20_util/tuple/make_from_tuple/1.cc: Likewise. + 2016-08-11 Ville Voutilainen Implement LWG 2758. diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index b9074cb1bd9..340304853bd 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -1655,6 +1655,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __apply_impl(std::forward<_Fn>(__f), std::forward<_Tuple>(__t), _Indices{}); } + + template + constexpr _Tp + __make_from_tuple_impl(_Tuple&& __t, index_sequence<_Idx...>) + { return _Tp(get<_Idx>(std::forward<_Tuple>(__t))...); } + + template + constexpr _Tp + make_from_tuple(_Tuple&& __t) + { + return __make_from_tuple_impl<_Tp>( + std::forward<_Tuple>(__t), + make_index_sequence>>{}); + } #endif // C++17 /// @} diff --git a/libstdc++-v3/testsuite/20_util/tuple/make_from_tuple/1.cc b/libstdc++-v3/testsuite/20_util/tuple/make_from_tuple/1.cc new file mode 100644 index 00000000000..459dc74cd04 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/make_from_tuple/1.cc @@ -0,0 +1,54 @@ +// Copyright (C) 2016 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 3, 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 COPYING3. If not see +// . + +// { dg-options "-std=gnu++17" } + +#include +#include + +template +struct ThreeParam +{ + T t; + U u; + V v; + ThreeParam(const T& t, const U& u, const V& v) + : t(t), + u(u), + v(v) {} +}; + +void +test01() +{ + auto x = std::make_tuple(1024, 'x', 2048); + ThreeParam y + = std::make_from_tuple>(x); + VERIFY(y.t == 1024 && y.u == 'x' && y.v == 2048); + auto x2 = std::make_tuple(4096, 'z'); + std::pair z = std::make_from_tuple>(x2); + VERIFY(z.first == 4096 && z.second == 'z'); + auto x3 = std::make_tuple(8192); + int i = std::make_from_tuple(x3); + VERIFY(i == 8192); +} + +int +main() +{ + test01(); +}