开发者

Conditional compilation for move operations

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_REFEREN开发者_高级运维CES_SUPPORTED

foobar(foobar&& that)
{
    // ...
}

#endif


I'm not aware of any standard preprocessor macro, but:

  • Visual Studio introduced support in VC2010, whose internal version is 1600, so you can check with _MSC_VER >= 1600
  • GCC has supported rvalue references since version 4.3, so you can check for that version along with __GXX_EXPERIMENTAL_CXX0X__
  • Clang defines __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.


The standard method is to check the standard version : If __cplusplus==199711L then you don't have (standard) rvalue references. If __cplusplus==201103L, you do. Obviously, this doesn't cover non-standard compilers or non-standard extensions to C++98.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜