views:

142

answers:

1

GCC up to 4.5 doesn't have standard C++0x type trait template has_nothrow_move_constructor. I could use it in my package for optimization, but I don't want to rule out one of the common compilers and don't want to overload configuration with symbols like HAVE_STD_HAS_NOTHROW_MOVE_CONSTRUCTOR. Is it somehow possible to use that template if present and just fall back to copying if not present without using any predefined configuration symbols? I also don't want to depend on Boost, since my library is small and doesn't need Boost for any other reasons.

In pseudocode, 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 features for the above definition, if at all possible.

+1  A: 

boost::variant has an implementation of has_nothrow_move for its own internal use - you could use that, although it's not as reliable as a proper compiler implementation would be. The source for it is here - I don't know how reliable it is, so YMMV.

Apart from that, you could test compiler version macros (__GNUC__ and __GNUC_MINOR__) to determine presence, and stub it out if not present. Unfortunately it seems has_nothrow_move_constructor isn't supported in any released version of G++ yet, so you'll have to wait a bit before you'll know the right version to use.

bdonlan