Implementation C++14 make_integer_sequence

前端 未结 7 690
-上瘾入骨i
-上瘾入骨i 2020-11-22 03:28

I tried to implement the C++14 alias template make_integer_sequence, which simplifies the creation of the class template integer_sequence.

templ         


        
7条回答
  •  失恋的感觉
    2020-11-22 04:08

    Simple implementation O(N). Probably not what you want for large N, but my application is only for calling functions with indexed arguments, and I wouldn't expect an arity of more than about 10. I haven't filled in the members of integer_sequence. I'm looking forward to using a standard library implementation and nuking this :)

    template 
    struct integer_sequence
    { };
    
    template 
    struct make_integer_sequence_impl
    {
        template 
        struct tmp;
    
        template 
        struct tmp>
        {
            using type = integer_sequence;
        };
    
        using type = typename tmp::type>::type;
    };
    
    template 
    struct make_integer_sequence_impl::type>
    { using type = integer_sequence; };
    
    template 
    using make_integer_sequence = typename make_integer_sequence_impl::type;
    

提交回复
热议问题