I need to backport nullptr to a cross platform library we have, but I'm having trouble getting a reliable check of nullptr support.
Initially I had this:
#if __cplusplus >= 201103L || (__cplusplus < 200000 && __cplusplus >= 199711L)
// nullptr should be ok
#else
// Too old
#endif
But then I discovered that compiling a program that just printed out the value of __cplusplus produced unexpected results.
One blog post claimed 199711L was a value that MS compilers use to indicate partial support for C++11. But I notice g++ 5.4 produces that value by default. Until you expressly tell it to use compile with -std=c++11. But then if you tell it the standard is c++98 the value 199711 is still shown. That doesn't sound right to me. So that's not a good check!
Then I saw someone doing this with an answer that claimed it may work. Well it doesn't.
#if !defined(nullptr)
#endif
But I'm not sure you can do that. So I tested it like this:
#if defined(nullptr)
#error "null ptr defined"
#endif
Guess what? that doesn't print out the error when nullptr is actually available. So that doesn't at all.
How do I detect nullptr or compiler version under linux/windows and OSX (clang)/ android.