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
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.