问题描述
这类似于。但是在这种情况下,我想通过预处理器检测。
我们应该如何防范(和) )当源在C ++ 03和C ++ 11中使用时?
下面是足够的(是这样的情况?
对不起,问。我没有一些这样的编译器来测试,像Visual Studio 2012,英特尔ICC和Comeau。
strong> EDIT :库使用GNUmakefile和Standard C ++ 03.它不使用Autotools,它不使用Cmake,它不使用Boost。
#if(__cpluplus> = 201103L)
....
#endif
同样地,比如说,essential作为自变量和新的语义。 >
当然,一旦你进入编译器细节的土地,如破碎的编译器,或者如果你想移动语义工作在提供C ++ 0x或仿真的编译器模式而不是真实的东西,那么...好吧,你进入编译器细节的土地。对于一个好的子集,你不需要甚至采用任何外部库(无论是Boost,cxxomfort等),但只需复制和适应相关的宏和测试在。
This is similar to What differences, if any, between C++03 and C++11 can be detected at run-time?. But in this case, I want detection to occur via the preprocessor.
How should we guard the move constructor (and move assignment) when the sources are used in both C++03 and C++11?
Is the following sufficient (is move semantics something all C++ compilers adopted due to it being essential/core feature)?
#if (__cpluplus >= 201103L)
Foo(Foo&& other);
#endif
Or do I need to get into compiler specifics? If we need compiler specific macros, then how do we handle situations like Visual Studio 2012 __cplusplus and C++ 11?
Sorry to ask. I don't have some of these compilers to test on, like Visual Studio 2012, Intel ICC and Comeau.
EDIT: the library uses a GNUmakefile and Standard C++ 03. It does not use Autotools, it does not use Cmake, and it does not use Boost.
Move semantics is one of the core C++11 new features (it is one of the reasons for the new Standard, in some ways) and thus for any conforming compiler it should suffice with:
#if (__cpluplus >= 201103L)
....
#endif
Ditto with, say, something as "essential" as variadics and the new semantics for auto.
Of course, once you get into the land of compiler specifics, such as a broken compiler or if you want move semantics to work in compilers that provide "C++0x" or emulation mode instead of the real thing, then... well, you get into the land of compiler specifics. For a good subset of those you don't need to even adopt any external library (be it Boost, cxxomfort, etc) but simply copy and adapt the relevant macros and tests in the Predef Wiki.
这篇关于如何保护移动构造函数的C ++ 03和C ++ 11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!