This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[patch] libstdc++/66059 optimise std::make_integer_sequence
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Tue, 17 Nov 2015 19:54:27 +0000
- Subject: [patch] libstdc++/66059 optimise std::make_integer_sequence
- Authentication-results: sourceware.org; auth=none
I've been talking about a compiler built-in to implement
make_integer_sequence since before the proposal even made it into the
standard, so I tried to implement one that would allow:
template<typename _Tp, _Tp _Num>
using make_integer_sequence = integer_sequence< __intseq(_Tp, _Num) >;
But I don't know the front-end well enough to make that work.
Instead here's a much more efficient implementation that takes a
divide-and-conquer approach rather than building the sequence
linearly.
Tested powerpc64le-linux, committed to trunk.
commit 4bd998a906972eb9ae47ffd87f28b17816112318
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Nov 17 17:55:25 2015 +0000
PR libstdc++/66059 optimise _Build_index_tuple
PR libstdc++/66059
* include/std/utility (_Build_index_tuple): Optimise.
diff --git a/libstdc++-v3/include/std/utility b/libstdc++-v3/include/std/utility
index 89b6852..985bcb2 100644
--- a/libstdc++-v3/include/std/utility
+++ b/libstdc++-v3/include/std/utility
@@ -212,17 +212,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Stores a tuple of indices. Used by tuple and pair, and by bind() to
// extract the elements in a tuple.
- template<size_t... _Indexes>
- struct _Index_tuple
+ template<size_t... _Indexes> struct _Index_tuple { };
+
+ // Concatenates two _Index_tuples.
+ template<typename _Itup1, typename _Itup2> struct _Itup_cat;
+
+ template<size_t... _Ind1, size_t... _Ind2>
+ struct _Itup_cat<_Index_tuple<_Ind1...>, _Index_tuple<_Ind2...>>
{
- typedef _Index_tuple<_Indexes..., sizeof...(_Indexes)> __next;
+ using __type = _Index_tuple<_Ind1..., (_Ind2 + sizeof...(_Ind1))...>;
};
// Builds an _Index_tuple<0, 1, 2, ..., _Num-1>.
template<size_t _Num>
struct _Build_index_tuple
+ : _Itup_cat<typename _Build_index_tuple<_Num / 2>::__type,
+ typename _Build_index_tuple<_Num - _Num / 2>::__type>
+ { };
+
+ template<>
+ struct _Build_index_tuple<1>
{
- typedef typename _Build_index_tuple<_Num - 1>::__type::__next __type;
+ typedef _Index_tuple<0> __type;
};
template<>