is_explicitly_convertible

Just in case someone's interested: I implemented is_explicitly_convertible for GCC 4.4+ (4.3 doesn't work). Since it uses lots of C++0x-ish stuff, it is likely not a good addition to boost::type_traits, but I figured the people here might be interested anyway :) #include <type_traits> namespace boost { namespace impl { template< typename T > T make(); template< typename From, typename To > decltype( To( make< From >() ), make< std::true_type >() ) select( int ); template< typename, typename > std::false_type select( ... ); } template< typename From, typename To > struct is_explicitly_convertible : std::is_same< decltype( impl::select< From, To >( 0 ) ), std::true_type > { }; } struct X { X( double& ); explicit X( int& ); }; #define STATIC_ASSERT( X ) static_assert( X, #X ) int main() { STATIC_ASSERT(( boost::is_explicitly_convertible< double&, X >::value )); STATIC_ASSERT(( boost::is_explicitly_convertible< int&, X >::value )); STATIC_ASSERT(( !boost::is_explicitly_convertible< void*, X >::value )); } Regards, Daniel
participants (1)
-
Daniel Frey