AFAIK you cannot automate from within the code the detection of nullptr
support.
In practice you can read that as “impossible”, it’s a pretty strong “AFAIK”.
The thing to do is therefore to use compiler-specific code and/or build command. For example, in each relevant source add a
#include <cpp/nullptr.h>
and in the build command adjust the include path so that for compiler with nullptr
support, this picks up an empty header, while for an old compiler that lacks nullptr
, it picks up a header that defines it à la Meyers (say).
And then test very thoroughly!
I call the general concept of having multiple versions of a header, with just one selected by the build command, a virtual header. It is possible to build a lot of machinery around that, including conventions that only make sense in a more general case. Happily it’s not necessary for this particular case, but perhaps worth to be aware of.
Summing up: making C++ source code do things magically is not the way to go here. Adding a bit of help at the build level seems about right. :-)