The following program...
#include <iostream>
#include <type_traits>
template <typename T>
struct Template{};
template <typename T>
using Alias = Template<T>;
template
<
template <typename>
class T1,
template <typename>
class T2
>
struct is_same_template : std::false_type{};
template
<
template <typename>
class T
>
struct is_same_template<T, T> : std::true_type{};
int main() {
std::cout << std::boolalpha;
std::cout << "Template == Template: " << is_same_template<Template, Template>::value << std::endl;
std::cout << "Template == Alias: " << is_same_template<Template, Alias>::value << std::endl;
std::cout << "Alias == Alias: " << is_same_template<Alias, Alias>::value << std::endl;
}
...outputs...
Template == Template: true
Template == Alias: false
Alias == Alias: true
...compiled with g++ 4.8.1, clang 3.4 and vc++ 18.00.21005.1.
Is it a bug in these compilers or a requirement of the standard?
true/true/true
of course as it is for type aliases andstd::is_same
. – Anaya...
to thetypename
s in youris_same_template
. Now addtemplate<T,U>foo
andbar<T>=foo<T,T>
. What should happen tois_same_template<foo,bar>
? – Greigefalse
(and it does). But in your example templates arguments count of a template and its alias are even unequal. How can they be equivalent in such case? What do you mean here? – Anayatemplate<class T> using vec = std::vector<T>;
(is that a template alias?) ortemplate<class T> using Templ = Template<T*>;
(is that a template alias?). A special rule would be required to specify exactly those cases where an alias template is a template alias. – Smoothspoken