Compile pattern detection

GCC before 4.5 does not have a standard C ++ 0x type template has_nothrow_move_constructor. I could use it in my package for optimization, but I do not want to exclude one of the common compilers and I do not want to overload the configuration with symbols such as HAVE_STD_HAS_NOTHROW_MOVE_CONSTRUCTOR. Is it possible to use this template, if it exists, and simply return to copying if it is missing, without using any predefined configuration characters? I also do not want to depend on Boost, since my library is small and does not need Boost for other reasons.

In pseudo code, I need something like:

template <typename type>
struct has_nothrow_move_constructor_robust
  : public integral_constant <bool,
           /* if possible */  has_nothrow_move_constructor <type>::value
           /* otherwise   */  false>
{ };

Since move constructors are only for C ++ 0x anyway, I don't mind using other C ++ 0x functions for the above definition, if at all possible.

+5
source share
1 answer

boost::varianthas an implementation has_nothrow_movefor your own internal use - you can use this, although this is not as reliable as the correct compiler implementation. The source for this is here - I do not know how reliable this is, therefore YMMV.

, (__GNUC__ __GNUC_MINOR__), . , , has_nothrow_move_constructor g++, , , .

+1

All Articles