Suppose I have a templated function that takes various kinds of vectors (but for various reasons I can't mention this in the template parameter). Here's what I'm trying to do: insert a new, default constructed element at a specific spot, without knowing its type:
template <typename T>
void foo(T* v) {
v->insert(v->begin() + 5, decltype(v->at(0))());
}
This doesn't work, but gives you an idea of what I'm trying to do. I also tried to use value_type
from std::vector
but I ran into problems there as well. Any ideas how to solve this problem?
Aucun commentaire:
Enregistrer un commentaire