Używanie aliasu szablonu zamiast szablonu w szablonie
Z poprzedniego pytania:
Wykonanie atrybutu static_assert, że typ szablonu jest innym szablonem
Andy Prowl dostarczył mi ten kod, który pozwala mistatic_assert
że typ szablonu jest innym typem szablonu:
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;
}
To działa świetnie.
Ale jeśli zmienię kod w ten sposób, aby użyć aliasufoo
, wszystko idzie źle:
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;
}
Czy można to rozwiązać?