Determining if types alias to the same underlying type in C++

Posted by emchristiansen on Stack Overflow See other posts from Stack Overflow or by emchristiansen
Published on 2011-01-09T23:09:28Z Indexed on 2011/01/10 0:53 UTC
Read the original article Hit count: 134

Filed under:
|
|

I'd like to write a templated function which changes its behavior depending on template class types passed in. To do this, I'd like to determine the type passed in. For example, something like this:

template <class T>
void foo() {
  if (T == int) { // Sadly, this sort of comparison doesn't work
    printf("Template parameter was int\n");
  } else if (T == char) {
    printf("Template parameter was char\n");
  }
}

Is this possible?

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates