How can I determine if a type is derived from a template class? In particular, I need to determine if a template parameter has std::basic_ostream
as a base class.
I'm not aware of a short and concise way. But you can abuse overloading again
template< typename T, typename U >
std::true_type is_based_impl( std::basic_ostream const volatile& );
std::false_type is_based_impl( ... );
template< typename T >
bool is_based_in_basic_ostream( T&& t ) {
return decltype(is_based_impl(t))::value;
}
It will only detect public inheritance. Note that you can instead detect derivation from ios_base
, which may work for you equally well (this test will also be positive for input streams, so it's only of limited applicability)
std::is_base_of