mercredi 6 juillet 2016

Check for container type


How can I check for a type of container? I.e.

template <class Container1>
void func (Container1 &cont_1)
{
  if (cont_1 is list container)
    //do stuff
  if (cont_1 is vector container)    
    //do other stuff
}

The only two possibilities I have are list and vector. Note that I don't know the type of values within list/vector, i.e. vector<char> or vector<int>, etc. is possible, thus I just want to get the information of getting a vector or a list. I came across typeid and type info, but did not really get it done.


Aucun commentaire:

Enregistrer un commentaire