I have the following type helper to detect whether a type is an instance of a template:
#include <type_traits>
namespace detail
{
template<typename T, template <typename...> typename Template>
struct IsInstanceOf : public std::false_type {};
template<typename... T, template<typename...> typename Template>
struct IsInstanceOf<Template<T...>, Template> : public std::true_type {};
}
template<template <typename...> typename Template, typename T>
constexpr bool is_instance_of = detail::IsInstanceOf<T, Template>::value;
template<typename A>
struct Foo{};
template<typename A, std::size_t B>
struct Bar{};
int main()
{
static_assert(is_instance_of<Foo, Foo<float>>);
//static_assert(is_instance_of<Bar, Bar<float, 1>>);
}
This is working fine in most cases, except when the template contains a parameter that is not a type. I tried to change the template template parameters template arguments to auto..., but then it will not accept types in the template's parameter pack. Is there a way to detect whether type T is an instance of ANY template when the templates passed in might have a non type parameter mixed in with type parameters.