Tuple to parameter pack

后端 未结 2 566
情深已故
情深已故 2020-12-24 08:48

This below code from user Faheem Mitha, is based on user Johannes Schaub - litb\'s answer in this SO. This code perfectly does what I seek, which is conversion of a tu

2条回答
  •  悲哀的现实
    2020-12-24 09:09

    With C++17 you can use "if constexpr" to create a sequence wrapper:

    template  class spack, int ... seq>
    constexpr auto get_seq17()
    {
        static_assert(indxMax >= 0, "Sequence size must be equal to or greater than 0!");
        if constexpr (indxMax > 0)
        {
            typedef decltype(spack{}) frst;
            constexpr int next = indxMax - 1;
            return get_seq17();
        }
        else
        {
            return spack{};
        }
    }
    
    template  class pack>
    struct seq_pack
    {
        typedef decltype(get_seq17()) seq;
    };
    
    
    //creating a sequence wrapper
    template 
    struct seqpack {};
    
    //usage
    seq_pack<4, seqpack>::seq; //seqpack<0, 1, 2, 3, 4> 
    

    Though this implementation is easier to understand, it is preferable to use std::make_index_sequence as Julius has mentioned in the comments below.

提交回复
热议问题