From a previous question:
Doing a static_assert that a template type is another template
Andy Prowl provided me with this code that allows me to static_assert
that a template type is another template type:
template<template<typename...> class TT, typename... Ts>
struct is_instantiation_of : public std::false_type { };
template<template<typename...> class TT, typename... Ts>
struct is_instantiation_of<TT, TT<Ts...>> : public std::true_type { };
template<typename T>
struct foo {};
template<typename FooType>
struct bar {
static_assert(is_instantiation_of<foo,FooType>::value, ""); //success
};
int main(int,char**)
{
bar<foo<int>> b; //success
return 0;
}
This works great.
But if I change the code like this to use an alias of foo
, things go bad:
template<template<typename...> class TT, typename... Ts>
struct is_instantiation_of : public std::false_type { };
template<template<typename...> class TT, typename... Ts>
struct is_instantiation_of<TT, TT<Ts...>> : public std::true_type { };
template<typename T>
struct foo {};
//Added: alias for foo
template<typename T>
using foo_alt = foo<T>;
template<typename FooType>
struct bar {
//Changed: want to use foo_alt instead of foo here
static_assert(is_instantiation_of<foo_alt,FooType>::value, ""); //fail
};
int main(int,char**) {
//both of these fail:
bar<foo<int>> b;
bar<foo_alt<int>> b2;
return 0;
}
Can this be solved?
See Question&Answers more detail:os