diff --git a/libuavcan/include/uavcan/impl_constants.hpp b/libuavcan/include/uavcan/impl_constants.hpp index 65aba84a1b..8f8dedd96e 100644 --- a/libuavcan/include/uavcan/impl_constants.hpp +++ b/libuavcan/include/uavcan/impl_constants.hpp @@ -16,6 +16,21 @@ namespace uavcan { +/** + * UAVCAN can be compiled in C++11 mode. + * This macro allows to detect which version of the C++ standard is being used. + */ +#define UAVCAN_CPP11 2011 +#define UAVCAN_CPP03 2003 + +#if __cplusplus > 201200 +# error Unsupported C++ standard +#elif (__cplusplus > 201100) || defined(__GXX_EXPERIMENTAL_CXX0X__) +# define UAVCAN_CPP_VERSION UAVCAN_CPP11 +#else +# define UAVCAN_CPP_VERSION UAVCAN_CPP03 +#endif + /** * UAVCAN can be explicitly told to ignore exceptions, or it can be detected automatically. */ diff --git a/libuavcan/include/uavcan/marshal/float_spec.hpp b/libuavcan/include/uavcan/marshal/float_spec.hpp index 87c282ba0f..af1ce3781c 100644 --- a/libuavcan/include/uavcan/marshal/float_spec.hpp +++ b/libuavcan/include/uavcan/marshal/float_spec.hpp @@ -8,12 +8,16 @@ #include #include #include +#include #include #include -#if __cplusplus > 201100 -# include -#else -# include +#include + +#ifndef UAVCAN_CPP_VERSION +# error UAVCAN_CPP_VERSION +#endif +#if UAVCAN_CPP_VERSION < UAVCAN_CPP11 +# include // Needed for isfinite() #endif namespace uavcan diff --git a/libuavcan/include/uavcan/util/lazy_constructor.hpp b/libuavcan/include/uavcan/util/lazy_constructor.hpp index 675b88eda0..394ab90635 100644 --- a/libuavcan/include/uavcan/util/lazy_constructor.hpp +++ b/libuavcan/include/uavcan/util/lazy_constructor.hpp @@ -8,6 +8,10 @@ #include #include +#ifndef UAVCAN_CPP_VERSION +# error UAVCAN_CPP_VERSION +#endif + namespace uavcan { @@ -31,7 +35,7 @@ class LazyConstructor template struct ParamType { typedef const U& Type; }; template struct ParamType { typedef U& Type; }; -#if __cplusplus > 201100 +#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 template struct ParamType { typedef U&& Type; }; #endif diff --git a/libuavcan/test/test_main.cpp b/libuavcan/test/test_main.cpp index cd16e1fb59..8c044f92d0 100644 --- a/libuavcan/test/test_main.cpp +++ b/libuavcan/test/test_main.cpp @@ -3,9 +3,20 @@ */ #include +#include int main(int argc, char **argv) { +#ifndef UAVCAN_CPP_VERSION +# error UAVCAN_CPP_VERSION +#endif +#if UAVCAN_CPP_VERSION == UAVCAN_CPP11 + std::cout << "C++11" << std::endl; +#elif UAVCAN_CPP_VERSION == UAVCAN_CPP03 + std::cout << "C++03" << std::endl; +#else +# error UAVCAN_CPP_VERSION +#endif ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }