How to guard move constructors for C++03 and C++11?

前端 未结 1 1476
Happy的楠姐
Happy的楠姐 2021-01-19 05:56

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.

1条回答
  •  借酒劲吻你
    2021-01-19 06:26

    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.

    0 讨论(0)
提交回复
热议问题