How to check if a type is instantiated from a certain variadic template class in a template function?

Let’s say I have:

template <typename...>
class Foo { };

Then I define another function:

template <typename... T>
void Bar(const T&... arguments) { }

How do I check if all Ts passed to Bar are all instantiated from Foo? Like:

Foo<int> a;
Foo<int, int> b;
Bar(a, b); // OK
int c;
Bar(a, b, c); // ill-formed

I want a way to detect ill-formed arguments like Bar(a, b, c); Is there a way to do this?

Source: Windows Questions C++

LEAVE A COMMENT