I'm struggling to make this code work
template <typename T, typename U = int, auto... Params>
class Foo {};
int main()
{
auto foo1 = Foo<int, int, 1, 2, 3>{};
auto foo2 = Foo<int, 1, 2, 3>{}; // I want it to compile
}
It looks like I need some hack. I tried partial specialization, but it doesn't work either
template <typename T, typename U, auto... Params>
class Foo {};
template <typename T, auto... Params>
class Foo<T, int, Params...> {};
int main()
{
auto foo1 = Foo<int, int, 1, 2, 3>{};
auto foo2 = Foo<int, 1, 2, 3>{}; // I want it to compile
}
I can't find anything closely related to this, help pls :)
Unfortunately due to the way that template deduction works, this is ...not going to work.
Here's one alternative approach where the first template parameter is always a tuple, with one or two types, with the second type defaulting to an
int:With a little bit more elbow grease it should be possible to require a formal
std::tupleonly when the 2nd optional type needs to be specified, and just specify the primary type directly (although that will create some avoidable confusion if the primary type is astd::tuple, itself).