V
verec
One problem I've come accross in designing a specific version of auto_ptr
is that I have to disntiguish between "polymorphic" arguments and "plain" ones,
because the template has to, internally, cast to void *.
Specifically,
template <typename T> void f(T * t) {
void * p = dynamic_cast<void *>(t) ;
}
will not compile if T isn't of a class that has somewhere at least
a virtual function. In particular, none of the STL containers do qualify
for T.
Yet, because of multiple inheritance, if I want to get down to the base
"most" class, the dynamic_cast<void*> is the way to go.
I could use reinterpret_cast instead, and this would work for all T,
except that I'd lose the "cast to base" feature mentionned above.
I could also use a pair of templates, one for polymorphic types,
and one of "POD". But I'd rather not do that.
I'd be happy with a runtime query ... if I could devise one, that is.
typeid() seems to not be applicable in this context.
Ideally, if I could come up with
template <typename T>
bool is_polymorphic(T t) {
...
}
I would be filled with joy
Any taker?
is that I have to disntiguish between "polymorphic" arguments and "plain" ones,
because the template has to, internally, cast to void *.
Specifically,
template <typename T> void f(T * t) {
void * p = dynamic_cast<void *>(t) ;
}
will not compile if T isn't of a class that has somewhere at least
a virtual function. In particular, none of the STL containers do qualify
for T.
Yet, because of multiple inheritance, if I want to get down to the base
"most" class, the dynamic_cast<void*> is the way to go.
I could use reinterpret_cast instead, and this would work for all T,
except that I'd lose the "cast to base" feature mentionned above.
I could also use a pair of templates, one for polymorphic types,
and one of "POD". But I'd rather not do that.
I'd be happy with a runtime query ... if I could devise one, that is.
typeid() seems to not be applicable in this context.
Ideally, if I could come up with
template <typename T>
bool is_polymorphic(T t) {
...
}
I would be filled with joy
Any taker?