From the Fundamentals TS.
Tested x86_64-linux, committed to trunk.
commit df1e59560b6723da563f3aae8d95dcfe2781173b Author: Jonathan Wakely <jwak...@redhat.com> Date: Fri Oct 3 17:51:31 2014 +0100 * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/experimental/tuple: New * doc/xml/manual/status_cxx2014.xml: Update. * doc/html/manual/status.html: Regenerate. * testsuite/experimental/feat-lib-fund.cc: Test for new header. * testsuite/experimental/tuple/apply.cc: New. diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2014.xml b/libstdc++-v3/doc/xml/manual/status_cxx2014.xml index 11254d6..b7ed7ed 100644 --- a/libstdc++-v3/doc/xml/manual/status_cxx2014.xml +++ b/libstdc++-v3/doc/xml/manual/status_cxx2014.xml @@ -353,14 +353,13 @@ not in any particular release. </row> <row> - <?dbhtml bgcolor="#C8B0B0" ?> <entry> <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3915.pdf"> N3915 </link> </entry> <entry>apply() call a function with arguments from a tuple</entry> - <entry>N</entry> + <entry>Y</entry> <entry>Library Fundamentals TS</entry> </row> diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 5476a37..dee4a3f 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -642,7 +642,8 @@ experimental_headers = \ ${experimental_srcdir}/any \ ${experimental_srcdir}/optional \ ${experimental_srcdir}/string_view \ - ${experimental_srcdir}/string_view.tcc + ${experimental_srcdir}/string_view.tcc \ + ${experimental_srcdir}/tuple # This is the common subset of C++ files that all three "C" header models use. c_base_srcdir = $(C_INCLUDE_DIR) diff --git a/libstdc++-v3/include/experimental/tuple b/libstdc++-v3/include/experimental/tuple new file mode 100644 index 0000000..bbfbdfa --- /dev/null +++ b/libstdc++-v3/include/experimental/tuple @@ -0,0 +1,70 @@ +// <experimental/tuple> -*- C++ -*- + +// Copyright (C) 2014 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file experimental/tuple + * This is a TS C++ Library header. + */ + +#ifndef _GLIBCXX_EXPERIMENTAL_TUPLE +#define _GLIBCXX_EXPERIMENTAL_TUPLE 1 + +#pragma GCC system_header + +#if __cplusplus <= 201103L +# include <bits/c++14_warning.h> +#else + +#include <tuple> + +namespace std _GLIBCXX_VISIBILITY(default) +{ +namespace experimental +{ +inline namespace fundamentals_v1 +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + template <typename _Fn, typename _Tuple, std::size_t... _Idx> + constexpr decltype(auto) + __apply_impl(_Fn&& f, _Tuple&& t, std::index_sequence<_Idx...>) + { return std::forward<_Fn>(f)(get<_Idx>(forward<_Tuple>(t))...); } + + template <typename _Fn, typename _Tuple> + constexpr decltype(auto) + apply(_Fn&& f, _Tuple&& t) + { + using _Indices = + std::make_index_sequence<std::tuple_size<std::decay_t<_Tuple>>::value>; + return __apply_impl(std::forward<_Fn>(f), std::forward<_Tuple>(t), + _Indices{}); + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace fundamentals_v1 +} // namespace experimental +} // namespace std + +#endif // C++14 + +#endif // _GLIBCXX_EXPERIMENTAL_TUPLE diff --git a/libstdc++-v3/testsuite/experimental/feat-lib-fund.cc b/libstdc++-v3/testsuite/experimental/feat-lib-fund.cc index 50d1ce2..0c73f09 100644 --- a/libstdc++-v3/testsuite/experimental/feat-lib-fund.cc +++ b/libstdc++-v3/testsuite/experimental/feat-lib-fund.cc @@ -23,3 +23,7 @@ #if !__has_include(<experimental/string_view>) # error "<experimental/string_view>" #endif + +#if !__has_include(<experimental/tuple>) +# error "<experimental/tuple>" +#endif diff --git a/libstdc++-v3/testsuite/experimental/tuple/apply.cc b/libstdc++-v3/testsuite/experimental/tuple/apply.cc new file mode 100644 index 0000000..170a8d9 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/tuple/apply.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2014 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 +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++14" } + +#include <experimental/tuple> +#include <testsuite_hooks.h> + +void +test01() +{ + auto t = std::make_tuple(1, '2', 3.0); + std::experimental::apply( [&](int& i, char& c, double& d) { + VERIFY(&i == &std::get<int>(t)); + VERIFY(&c == &std::get<char>(t)); + VERIFY(&d == &std::get<double>(t)); + }, t); +} + +constexpr int func(int i, int j) { return i + j; } + +void +test02() +{ + constexpr auto t = std::make_tuple(1, 2); + constexpr int i = std::experimental::apply(func, t); + VERIFY( i == 3 ); +} + +int +main() +{ + test01(); + test02(); +}