diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index a0991022d43..3309eb62455 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2013-10-31 Jonathan Wakely + + * include/std/tuple (_Index_tuple, _Build_index_tuple): Move to + . + * include/std/utility (integer_sequence, make_integer_sequence, + index_sequence, make_index_sequence, index_sequence_for): Define. + * doc/xml/manual/status_cxx2014.xml: Update. + * testsuite/20_util/integer_sequence/intseq.cc: New. + * testsuite/20_util/integer_sequence/requirements/typedefs.cc: New. + 2013-10-31 Steve Ellcey * configure.ac: Add header checks for fenv.h and complex.h. diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2014.xml b/libstdc++-v3/doc/xml/manual/status_cxx2014.xml index 1f20f0e44de..4ef4334ab34 100644 --- a/libstdc++-v3/doc/xml/manual/status_cxx2014.xml +++ b/libstdc++-v3/doc/xml/manual/status_cxx2014.xml @@ -185,8 +185,8 @@ particular release. Compile-time integer sequences - WIP - Need tests + Y + diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index 063ce02e9c7..2580f7894e6 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -917,27 +917,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ::type>::type>::type { }; - // Stores a tuple of indices. Also used by bind() to extract the elements - // in a tuple. - template - struct _Index_tuple - { - typedef _Index_tuple<_Indexes..., sizeof...(_Indexes)> __next; - }; - - // Builds an _Index_tuple<0, 1, 2, ..., _Num-1>. - template - struct _Build_index_tuple - { - typedef typename _Build_index_tuple<_Num - 1>::__type::__next __type; - }; - - template<> - struct _Build_index_tuple<0> - { - typedef _Index_tuple<> __type; - }; - template struct __make_tuple_impl; diff --git a/libstdc++-v3/include/std/utility b/libstdc++-v3/include/std/utility index ad30ad7a9a3..627f79b9cf1 100644 --- a/libstdc++-v3/include/std/utility +++ b/libstdc++-v3/include/std/utility @@ -194,6 +194,67 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } #endif + // Stores a tuple of indices. Used by tuple and pair, and by bind() to + // extract the elements in a tuple. + template + struct _Index_tuple + { + typedef _Index_tuple<_Indexes..., sizeof...(_Indexes)> __next; + }; + + // Builds an _Index_tuple<0, 1, 2, ..., _Num-1>. + template + struct _Build_index_tuple + { + typedef typename _Build_index_tuple<_Num - 1>::__type::__next __type; + }; + + template<> + struct _Build_index_tuple<0> + { + typedef _Index_tuple<> __type; + }; + +#if __cplusplus > 201103L + /// Class template integer_sequence + template + struct integer_sequence + { + typedef _Tp value_type; + static constexpr size_t size() { return sizeof...(_Idx); } + }; + + template::__type> + struct _Make_integer_sequence; + + template + struct _Make_integer_sequence<_Tp, _Num, _Index_tuple<_Idx...>> + { + static_assert( _Num >= 0, + "Cannot make integer sequence of negative length" ); + + typedef integer_sequence<_Tp, static_cast<_Tp>(_Idx)...> __type; + }; + + /// Alias template make_integer_sequence + template + using make_integer_sequence + = typename _Make_integer_sequence<_Tp, _Num>::__type; + + /// Alias template index_sequence + template + using index_sequence = integer_sequence; + + /// Alias template make_index_sequence + template + using make_index_sequence = make_integer_sequence; + + /// Alias template index_sequence_for + template + using index_sequence_for = make_index_sequence; +#endif + _GLIBCXX_END_NAMESPACE_VERSION } // namespace diff --git a/libstdc++-v3/testsuite/20_util/integer_sequence/intseq.cc b/libstdc++-v3/testsuite/20_util/integer_sequence/intseq.cc new file mode 100644 index 00000000000..0f3ed41ab2c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/integer_sequence/intseq.cc @@ -0,0 +1,27 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do compile } +// +// Copyright (C) 2013 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 +// . + +#include +#include + +using std::integer_sequence; + +static_assert( integer_sequence::size() == 0, "size() == 0" ); +static_assert( integer_sequence::size() == 3, "size() == 3" ); diff --git a/libstdc++-v3/testsuite/20_util/integer_sequence/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/integer_sequence/requirements/typedefs.cc new file mode 100644 index 00000000000..ab26800959c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/integer_sequence/requirements/typedefs.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do compile } +// +// Copyright (C) 2013 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 +// . + +#include +#include + +using std::is_same; +using std::integer_sequence; +using std::make_integer_sequence; +using std::index_sequence; +using std::make_index_sequence; +using std::index_sequence_for; + +static_assert( is_same::value_type, int>::value, + "int value_type"); + +static_assert( is_same::value_type, short>::value, + "short value_type"); + +static_assert( is_same, + integer_sequence>::value, + "make empty int seq" ); + +static_assert( is_same, + integer_sequence>::value, + "make non-empty int seq" ); + +static_assert( is_same, + integer_sequence>::value, + "make empty unsigned seq" ); + +static_assert( is_same, + integer_sequence>::value, + "make non-empty unsigned seq" ); + +static_assert( is_same, + integer_sequence>::value, + "index seq" ); + +static_assert( is_same, index_sequence<0, 1>>::value, + "make index seq" ); + +static_assert( is_same, + index_sequence<0, 1, 2, 3>>::value, + "index_sequence_for" );