[英]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_REFERENCES_SUPPORTED
foobar(foobar&& that)
{
// ...
}
#endif
I'm not aware of any standard preprocessor macro, but: 我不知道任何标准的预处理器宏,但是:
_MSC_VER >= 1600
_MSC_VER >= 1600
检查 __GXX_EXPERIMENTAL_CXX0X__
__GXX_EXPERIMENTAL_CXX0X__
__has_feature
macros for doing exactly what you need: __has_feature(cxx_rvalue_references)
__has_feature
宏以完全满足您的需要: __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有一个用于此目的的宏,如果您的项目包含Boost,您可以使用它(否则您可以查看它们的实现)
Boost.Config有BOOST_NO_RVALUE_REFERENCES
。
The standard method is to check the standard version : If __cplusplus==199711L
then you don't have (standard) rvalue references. 标准方法是检查标准版本:如果
__cplusplus==199711L
那么你没有(标准)右值引用。 If __cplusplus==201103L
, you do. 如果
__cplusplus==201103L
,那就行了。 Obviously, this doesn't cover non-standard compilers or non-standard extensions to C++98. 显然,这不包括非标准编译器或C ++ 98的非标准扩展。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.