Why do T1 and T2 have the same typeid but are not the same type? (The output is 1 0)
#include <iostream>
#include <typeinfo>
#include <type_traits>
int main()
{
using T1 = decltype("A");
using T2 = const char[2];
std::cout << (typeid(T1) == typeid(T2)) << "\n";
std::cout << std::is_same_v<T1,T2> << "\n";
}
String literal like
"A"is lvalue expression, as the effectdecltypeleads to lvalue-reference, soT1would beconst char (&)[2].T2isconst char[2], andtypeidonT1will give the result referring to the referenced type, i.e.,const char[2], that's whytypeid(T1) == typeid(T2)istrue, butstd::is_same_v<T1,T2>isfalse.