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.
Might something like Boost's is_instance_of be what you are after?
http://www.boost.org/doc/libs/1_46_1/boost/lambda/detail/is_instance_of.hpp
Here is the short version for 1-argument templates:
#include
#include
template class F>
struct conversion_tester
{
template
conversion_tester (const F &);
};
template class To>
struct is_instance_of
{
static const bool value = std::is_convertible>::value;
};
template
struct foo {};
template
struct bar {};
int main()
{
std::cout << is_instance_of,foo>::value << '\n'; // This will print '1'.
std::cout << is_instance_of,foo>::value << '\n'; // This will print '0'.
}
Unfortunately, if you try to extend this to variadic templates, with current GCC (4.6.0) it will produce an error message. This SO answer implies that this is currently a problem of GCC and that the variadic template version is supposed to work according to the standard.