Convert templated parameter type to string
Posted
by wheaties
on Stack Overflow
See other posts from Stack Overflow
or by wheaties
Published on 2010-04-09T21:00:15Z
Indexed on
2010/04/09
21:03 UTC
Read the original article
Hit count: 358
I've got a small bit of DRY going on in code I and others have written that I'd like to reduce but I'm failing to figure out how to get it done. This is legacy COM code but it's interfering with the readability. I'd like to do the following:
bool queryInterface<class T, class V>(T &_input, V &_output, Logger &_logger){
if( FAILED( _input->QueryInterface( &_output ) ) ){
_logger.error() << "Failed to Query Interface between " << MAGICHAPPENS<T>()
<< " and " << MAGICHAPPENS<V>();
return false;
}
if( _output == NULL ){
_logger.warn() << "Unable to Query Interface between " << MAGICHAPPENS<T>()
<< " and " << MAGICHAPPENS<V>();
return false;
}
}
Wherein the "MAGICHAPPENS()" function would spit out the name of the variable type. Such that if "V" were a IQueryFilter
I'd get back a string of "IQueryFilter." I can't think of any reasonable solution without having to write a bunch of template specializations totally defeating the point in the first place.
Is there a way to write ANDMAGICHAPPENS?
© Stack Overflow or respective owner