nullptr placeholder without #define
Hi all,
I'm a little alergic to #define so when I wanted to make myself a
placeholder
for nullptr keyword for C++0x compability I came up with something
like this:
const struct nullptr_t {
template<class T>
operator T*() const { return 0; }
template<class T, class U>
operator T U::*() const { return 0; }
} nullptr = {};
template<class T>
bool operator==(T* lhs, const nullptr_t rhs) { return lhs == 0; }
template<class T>
bool operator==(const nullptr_t lhs, T* rhs) { return rhs == 0; }
template<class T, class U>
bool operator==(T U::* lhs, const nullptr_t rhs) { return lhs ==
0; }
template<class T, class U>
bool operator==(const nullptr_t lhs, T U::* rhs) { return rhs ==
0; }
It does not pass only one from Basic Cases from n2431:
if( nullptr == 0 ); // error
On GCC 4.3.3 it compiles.
On MinGW-GCC 3.4.5 it crushes the compiler.
I didn't do tests for other compilers nor Advanced Cases from n2431.
Ofcourse while reading n2431 for tests I've found that this is
proposed alternate solution (library implementation instead of
keyword).
Nevertheless I thought that it could interest people as alergic go
#define as I am and who didn't read said C++0x proposal.
Cheers
Sfider
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]