On my system, wchar_t and int are distinct types with the same properties:
#include <type_traits>
sizeof(wchar_t) == sizeof(int) == 4
std::is_signed<wchar_t> == std::is_signed<int> == std::true_type
std::is_same<wchar_t, int> == std::false_type
In contrast, ptrdiff_t and long int are identical types (same properties, and is_same is true).
Is this distinctness of wchar_t guaranteed? Is it safe to overload for wchar_t and int on all systems? Is there any property in or elsewhere that distinguishes wchar_t and the corresponding int property besides is_same?
(System info: I’m interested in the general case, but my tests so far have been on an OS X machine running g++ 4.8.0 and Apple clang++ 4.1, both with -std=c++11.)
Yes,
wchar_tis guaranteed to be a distinct type (§3.9.1/5):So yes, it’s safe to overload for
wchar_tandinton all systems.However,
wchar_tis also guaranteed to have the same size, signedness and alignment requirements as another integral type, which is its underlying type. This isn’t necessarilyintbut in your case appears to be. This meanswchar_tis probably implemented using one of the integral types, but as far as you are concerned, they are treated as completely distinct types.