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?