From db624b3b4b3a15d06cef746f2db07a334d669084 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 18 Sep 2017 13:02:19 +0100 Subject: [PATCH] Use built-in for std::make_integer_sequnce * include/std/utility (_Itup_cat, _Make_integer_sequence): Remove. (_Build_index_tuple, make_integer_sequence): Use built-in to generate pack expansion. From-SVN: r252923 --- libstdc++-v3/ChangeLog | 4 +++ libstdc++-v3/include/std/utility | 53 ++++++++++++-------------------- 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 9974675aee6..c83f0758beb 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,9 @@ 2017-09-18 Jonathan Wakely + * include/std/utility (_Itup_cat, _Make_integer_sequence): Remove. + (_Build_index_tuple, make_integer_sequence): Use built-in to generate + pack expansion. + PR libstdc++/71187 * include/std/type_traits (__declval): New function to deduce return type of declval. diff --git a/libstdc++-v3/include/std/utility b/libstdc++-v3/include/std/utility index c18bcb6f72d..29a626004f9 100644 --- a/libstdc++-v3/include/std/utility +++ b/libstdc++-v3/include/std/utility @@ -267,32 +267,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // extract the elements in a tuple. template struct _Index_tuple { }; - // Concatenates two _Index_tuples. - template struct _Itup_cat; - - template - struct _Itup_cat<_Index_tuple<_Ind1...>, _Index_tuple<_Ind2...>> - { - using __type = _Index_tuple<_Ind1..., (_Ind2 + sizeof...(_Ind1))...>; - }; +#ifdef __has_builtin +# if __has_builtin(__make_integer_seq) +# define _GLIBCXX_USE_MAKE_INTEGER_SEQ 1 +# endif +#endif // Builds an _Index_tuple<0, 1, 2, ..., _Num-1>. template struct _Build_index_tuple - : _Itup_cat::__type, - typename _Build_index_tuple<_Num - _Num / 2>::__type> - { }; - - template<> - struct _Build_index_tuple<1> { - typedef _Index_tuple<0> __type; - }; +#if _GLIBCXX_USE_MAKE_INTEGER_SEQ + template + using _IdxTuple = _Index_tuple<_Indices...>; - template<> - struct _Build_index_tuple<0> - { - typedef _Index_tuple<> __type; + using __type = __make_integer_seq<_IdxTuple, size_t, _Num>; +#else + using __type = _Index_tuple<__integer_pack(_Num)...>; +#endif }; #if __cplusplus > 201103L @@ -307,23 +299,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION 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; +#if _GLIBCXX_USE_MAKE_INTEGER_SEQ + = __make_integer_seq; +#else + = integer_sequence<_Tp, __integer_pack(_Num)...>; +#endif + +#undef _GLIBCXX_USE_MAKE_INTEGER_SEQ /// Alias template index_sequence template -- 2.30.2