*编辑:不知何故,我认为编译器正在创建B
as A<int, int, string>
,这导致我假设 is_same 应该如何评估它们,而不管继承/派生如何。我的错 :( 抱歉后来的误解 :\ *
制作一些元函数来检查我的自定义类型,并遇到了这个问题,但不确定我是否理解这里发生了什么。我想我可以通过将已知类型的 this_t 成员与传递的任何参数的 this_t 进行比较来解决它,但我只想了解为什么第一个和第三个 is_same 测试失败:
template<typename... Args> struct A {
typedef A<Args...> this_t;
};
struct B : A<int, int, string> {
};
//tests
std::is_same<A<int, int, string>, B>::value; //false
std::is_same<A<int, int, string>, typename B::this_t>::value; //true
std::is_same<B, typename B::this_t>::value; //false
//more tests for kicks
std::is_base_of<A<int, int, string>, B>::value; //true
std::is_base_of<A<int, int, string>, typename B::this_t>::value; //true
std::is_base_of<B, typename B::this_t>::value; //false
is_same 是否通过A<...>
基础进行区分?A<int, int, string>
和之间有什么明显区别B
?