First, you need is_base_of
. If you don't want to use Boost or C++11, then grab one here:
How does `is_base_of` work?
Then, you can do this:
template <bool B> struct bool_ {};
// ...
bool format() { do_format(bool_<is_base_of<BASECLASS, T>::value>()); }
bool do_format(bool_<false>) {
// not inheriting BASECLASS
}
bool do_format(bool_<true>) {
// inheriting BASECLASS
}
BTW, there is, AFAIK, no way of doing this non-intrusively, i.e. simply by adding a specialization.
Edit: Actually, you can probably do it without is_base_of:
// ...
bool format() { do_format((T*)0); }
bool do_format(void*) { /* not inheriting */ }
bool do_format(BASECLASS*) { /* inheriting */ }
This works because derived->base is a better conversion than class->void.