How can I check for the decltype attribute?

I have a C ++ module that is compiled in both a C ++ 03 context and a C ++ 11 context. Compiling it as C ++ 11 I am using decltype

to find the type of a variable. In C ++ 03 I can (for my purposes) define decltype

as a macro in non-standard terms typeof

:

// add zero to get rid of const qualifier on the type
#define decltype(x) typeof((x) + 0)

      

Of course, I want to use the original decltype

one if available, and only define the macro if it's not available. How do I check for availability decltype

?

I tried #ifndef __cpp_decltype

as suggested at http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3694.htm but it doesn't work.

+3


source to share


2 answers


You should probably use Boost.Config and check the macro BOOST_NO_CXX11_DECLTYPE

.



+5


source


You can try to use the value of a __cplusplus

predefined macro. For C ++ 11, this is 201103L

. For an older compiler, this should be a lower number.



+6


source







All Articles