How can I check whether my compiler supports rvalue references or not? Is there a standard preprocessor macro, or do different compilers have different macros? Ideally, I would want to write this:
#ifdef RVALUE_REFERENCES_SUPPORTED
foobar(foobar&& that)
{
// ...
}
#endif
Conditional Compilation: Conditional Compilation directives help to compile a specific portion of the program or let us skip compilation of some specific part of the program based on some conditions. In our previous article, we have discussed about two such directives 'ifdef' and 'endif'.
#ifdef means if defined. If the symbol following #ifdef is defined, either using #define in prior source code or using a compiler command-line argument, the text up to the enclosing #endif is included by the preprocessor and therefore compiled. #if works similarly, but it evaluates the boolean expression following it.
The preprocessor supports conditional compilation of parts of source file. This behavior is controlled by #if , #else , #elif , #ifdef , #ifndef , #elifdef , #elifndef (since C++23), and #endif directives.
A conditional is a directive that instructs the preprocessor to select whether or not to include a chunk of code in the final token stream passed to the compiler.
I'm not aware of any standard preprocessor macro, but:
_MSC_VER >= 1600
__GXX_EXPERIMENTAL_CXX0X__
__has_feature
macros for doing exactly what you need: __has_feature(cxx_rvalue_references)
So for most common compilers, it should be fairly easy to cobble something together yourself.
I am also pretty sure that Boost has a macro for this purpose, which you may be able to use if your project includes Boost (otherwise you could look at their implementation)
Boost.Config has BOOST_NO_RVALUE_REFERENCES
for that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With