You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Travis Vitek <Tr...@roguewave.com> on 2008/05/20 03:15:19 UTC
FW: std::is_same and std::type_info::operator== equivalent?
Eric Lemings wrote:
>
>The code
>
>typeid(T1) == typeid(T2)
>
>is the runtime equivalent of
>
>std::is_same<T1, T2>::value
>
>correct?
>
According to 5.2.8/4 of the current draft...
When typeid is applied to a type-id, the result refers to a
std::type_info object representing the type of the type-id.
If the type of the type-id is a reference to a possibly cv-
qualified type, the result of the typeid expression refers
to a std::type_info object representing the cv-unqualified
referenced type. If the type of the type-id is a class type
or a reference to a class type, the class shall be
completely-defined.
>From what I read, is_same doesn't require the two types to be fully defined and it doesn't strip cv-qualifiers when comparing types. So the following testcase would fail...
#include <typeinfo>
#include <type_traits>
#include <cassert>
template <class T, class U>
bool is_same_type()
{
return (typeid(T) == typeid(U));
}
class C;
int main ()
{
#define TEST(T,U) assert ((std::is_same<T,U>::value == is_same_type<T,U>()));
TEST (int&, const int&); // fails statement 2
TEST (C, C); // fails statement 3
return 0;
}
>Brad.