Search code examples
c++templatesinstanceof

Instanceof equivalent in template class in C++


I have template class

template <typename T>
class BST {
public:
      Node<T>* root;
...

and I would like to modify behaviour of insert function depending on T type.

I look for something like

if(T instanceof Pair){

}

Solution

  • You can use std::is_same:

    if (std::is_same<T, Pair>::value)