Say I have a class with an integer template argument. How can I add a function that takes arguments of a Ngiven type? If at all possible, I would like to avoid the enable_iflike.
What am I doing now:
template<unsigned int N>
class Foo
{
template <typename To, typename>
using to = To;
public:
template<typename... Args>
void Bar(to<char, Args>... args)
{ }
};
This allows you to call Bar:
Foo<3> myfoo;
myfoo.Bar<int, int, int>('a', 'b', 'c');
However, I see two flaws. First, the number of arguments is not necessarily limited N, with the possible exception of the code inside Bar.
Secondly, the user needs to add template parameters to the function. Their values โโare not actually used, but only the number of arguments. This seems unnecessary as we already have it, namely N.
Optimal use of the function would look like this:
Foo<3> myfoo;
myfoo.Bar('a', 'b', 'c');
. function does not take this many arguments , , void(char, char, char) .
myfoo.Bar('a', 'b');
myfoo.Bar('a', 'b', 'c', 'd');
myfoo.Bar('a', 'b', "flob");