I have a function that takes a template type to determine a return value. Is there any way to tell at compile time if the template type is some instantiation of a template c
Here's an option:
#include
#include
#include
template class>
struct is_instance : public std::false_type {};
template class U>
struct is_instance, U> : public std::true_type {};
template
class Second
{};
int main()
{
using A = Second;
using B = Second;
using C = float;
std::cout << is_instance{} << '\n'; // prints 1
std::cout << is_instance{} << '\n'; // prints 1
std::cout << is_instance{} << '\n'; // prints 0
}
It's basically specializing the is_instance
struct for types that are instantiations of a template.