Je voudrais passer de foo à bar.Comment utiliser std :: back_inserter pour insérer dans un conteneur (seulement un pointeur sur le conteneur)
struct A
{
explicit A(int d): m_d(d) {};
private:
int m_d;
};
A some_function (int i) { return A(2*i); }
std::vector<int> foo;
std::vector<A> bar; // This is part of a Library not under my control
L'interface ne fournit que antiprotons
std::vector<A>* pbar =&bar; // This is the interface to the part of a Library not under my control
Est-il légal de déréférencer und antiprotons utilisent comme argument pour back_inserter? Pourquoi?
std::transform (foo.begin(), foo.end(), std::back_inserter(*pbar), some_function);
Un exemple complet est ici: http://coliru.stacked-crooked.com/a/2aec8d000cabf78b
@Pourquoi n'est-ce pas légal? En fait, std :: back_insert_iterator utilise en interne un pointeur sur le conteneur. –