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. Normally std::is_base_of is the tool for the job. However, std::is_base_of only works for complete types not class templates.
I’m looking for something like this.
template< typename T >
bool is_based_in_basic_ostream( T&& t )
{
if( std::is_base_of< std::basic_ostream< /*anything*/>, T >::value )
{
return true;
}
else
{
return false;
}
}
I’m sure this can be done I can’t think how.
I’m not aware of a short and concise way. But you can abuse overloading again
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)