I have an vector of std::type_index
, which indicate the trait types that a particular node has. I'm implementing a function which checks whether the node supports a particular type. It looks like this:
std::vector<std::type_index> traits;
...
template <typename T>
bool hasTrait() {
return std::find(traits.begin(), traits.end(), typeid(T)) != traits.end();
}
However, this won't work if type T
is a derived type of some base type in traits. In order to fix this problem, I wanted to use std::is_convertible
.
However, I only have access to the std::type_index
of the type, so I can't do that. Something like this would be required: std::is_convertible<traitTypeIndex::type, T>
Aucun commentaire:
Enregistrer un commentaire