Can we detect member function template
, variable template
, class
/struct
/union template
or alias templ
I can show you how to detect a struct template:
template < class > struct check_template : std::false_type {};
// Specialize for template classes
template class X, class... Args>
struct check_template< X > : std::true_type {};
You can then probably play around with declval
, void_t
, etc. to detect member templates.
In case you want to detect types vs. meta-types, i.e. templates like std::vector
and not std::vector
, you can do the following:
#include
template class>
constexpr bool is_template()
{
return true;
}
template
constexpr bool is_template()
{
return false;
}
struct Foo{};
template
struct TemplateFoo{};
int main()
{
std::cout << std::boolalpha;
std::cout << is_template() << std::endl;
std::cout << is_template() << std::endl;
}
Live on Coliru
Note that the solutions won't work if the meta-type has any non-type parameters, like
template struct X{};