On Jul 1, 2013, at 3:45 PM, Howard Hinnant <[email protected]> wrote:

>> 
>> This is O(n^2). You can do it in O(n log n):
>> 
>> template<typename T, T N, T Parity> struct __make_integer_sequence;
>> template<typename T, T N> using make_integer_sequence =
>> __make_integer_sequence<T, N, N % 2>::type;
>> 
>> template<typename T> struct __make_integer_sequence<T, 0, 0> { typedef
>> integer_sequence<T> type; };
>> template<typename T> struct __make_integer_sequence<T, 1, 1> { typedef
>> integer_sequence<T, 0> type; };
>> 
>> template<typename T, T ...Extra> struct __make_integer_sequence_impl;
>> template<typename T, T ...N, T ...Extra> struct
>> __make_integer_sequence_impl<integer_sequence<T, N...>, Extra...> {
>> typedef integer_sequence<T, N..., sizeof...(N) + N..., Extra...> type;
>> };
>> 
>> template<typename T, T N> struct __make_integer_sequence<T, N, 0> {
>> typedef __make_integer_sequence_impl<make_integer_sequence<T, N /
>> 2>>::type type;
>> };
>> template<typename T, T N> struct __make_integer_sequence<T, N, 1> {
>> typedef __make_integer_sequence_impl<make_integer_sequence<T, N /
>> 2>, N>::type type;
>> };
> 
> This is an interesting suggestion, thanks.  I think it has the potential to 
> make make_integer_sequence much more robust against exceeding recursive 
> template instantiation limits.  However as suggested, the above doesn't 
> compile.  After working with it for a while I got it to compile, but then it 
> didn't give the desired results.

Inspired by your approach, I started from scratch and came up with the 
enclosed.  The compiler will run out of memory before it runs into the 
recursive template instantiation limit, and this works with far higher numbers. 
 It passes all the current intseq tests.

Howard

Attachment: make_integer_seq.patch
Description: Binary data

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to