Detect template presence at compilation time

Posted by doublep on Stack Overflow See other posts from Stack Overflow or by doublep
Published on 2010-05-09T15:10:00Z Indexed on 2010/05/09 15:18 UTC
Read the original article Hit count: 245

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about c++

Related posts about c++0x