vendredi 25 décembre 2015

How to convert std::vector

I have a local std::vector<std::reference_wrapper<T> > and now I want to return a real copy of its elements (i.e std::vector<T>). Is there a better way than a loop?

Example: std::vector<T> foobar() { std::vector<std::reference_wrapper<T> > refsToLocals; /* do smth with refsToLocals */ std::vector<T> copyOfLocals; for (auto local : refsToLocals) copyOfLocals.insert_back(local.get()); return copyOfLocals; }

Aucun commentaire:

Enregistrer un commentaire