samedi 9 septembre 2023

Is there a way to store a variadic template of a specific type C++

Lets say I have the following scenario where I am printing templates of type std::size_t.

template<std::size_t st>
void print_sizes(){std::cout<<st<<std::endl;}

template<std::size_t st, std::size_t M, std::size_t... Rest>
void print_sizes(){
    std::cout<<st<<std::endl;
}

int main(){
    print_sizes<10, 12, 3>();
    return 0;
}

The above is entirely valid. However, I was wondering if there was a way to store the 10,12,3 variadic template like the following:

template<std::size_t st>
void print_sizes(){std::cout<<st<<std::endl;}

template<std::size_t st, std::size_t M, std::size_t... Rest>
void print_sizes(){
    std::cout<<st<<std::endl;
    print_sizes<M, Rest...>();
}

using example = 10,12,3;
int main(){
    print_sizes<example>();
    return 0;
}

Obviously, that doesn't work and throws an error. Is there a way to do something like this though?

Aucun commentaire:

Enregistrer un commentaire