*Edit: Somehow I thought the compiler was creating B just as A<int, int, string>, leading to my assumption about how is_same should evaluate them, regardless of inheritance/derivation. My bad 🙁 Sorry for subsequent misunderstandings :\ *
Making some meta-functions to check for my custom types, and ran into this issue, but not sure I understand what’s going on here. I think I can work around it by comparing this_t member of a known type to this_t of whatever parameter is passed, but I just want to understand why the 1st and 3rd is_same tests fail:
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 is_same differentiating by way of the A<...> base? What’s the appreciable difference between A<int, int, string> and B?
The is_same is basically a template with a specialization
That will never give you true, unless you have exactly the same type. Note that there is only one
Tin the specialization. It can never match both A and B.