I am having trouble declaring the following:
// c++17
template<typename T, typename ...Before, T v, typename ...After, template<typename ..., T, typename ...> U>
auto enum_to_type() {
// do things with
// U<Before..., v, After...> obj;
// as an example:
return U<Before..., v + 1, After...>{};
}
// demonstrate of usage
template<int v>
struct A {};
template<typename T, int v>
struct B {};
/// call enum_to_type to get next type
/// note: the following does not compile
using next_A = decltype(enum_to_type<int, 0, A>());
// == A<1>
template<typename T>
using next_B = decltype(enum_to_type<int, T, 0, B>());
// == B<1>
The purpose of this function is to write generic code that could make use of non-type template parameter v to construct template class from class template U without the knowledge of how the template parameters are declared in U. Otherwise, one has to write this function for different signatures e.g., U<T v>, U<typename, T v>, U<T v, typename>, and so on.
Edit: I guess what I want is likely not possible.
Before...and make the above code work; you'll still be trying to passUafter a parameter pack, which is a no-go as far as I know.Before...while leavingAfter.... After fixing typos and removing Before, it fails to compile: coliru.stacked-crooked.com/a/41ccc50702c56798U<T, typename =void>for SFAINE, in which case it fails withU<T>. Sorry for the confusion, and thanks for the answers.