How to make a header for C ++ 0x / 11 and not C ++ 0x / 11?

I want to create a header for both C ++ 0x / 11 and non-C ++ 0x / 11 in order to have backward compatibility:

class Foo{
public:
  Foo(){}
  Foo(Foo&){}
#ifdef CXX0X //How to make it work here?
  Foo(Foo&&){}
#endif
};
+3
source share
2 answers

I would recommend not checking __cplusplus, since neither MSVC nor GCC raised it to 201103L, and both of them have been supporting rvalue references for several years.

You can count on compiler-specific macros to do what you would like:

. , . , __GXX_EXPERIMENTAL_CXX0X__ .

, , Boost.Config. BOOST_NO_RVALUE_REFERENCES.

- :

#include <boost/config.hpp>

class Foo{
public:
  Foo();
  Foo(Foo&);
#ifndef BOOST_NO_RVALUE_REFERENCES
  Foo(Foo&&);
#endif
};

, .

+2

All Articles