On 2015-02-19 14:28, Thiago Macieira wrote: > On Thursday 19 February 2015 17:46:01 Giuseppe D'Angelo wrote: >> That on a non-const shared container >> >> for (auto i : container) >> >> will detach it. That's why having rules instead of saying "just use >> it", I guess... > > And who says it's not what you wanted? > > for (auto &i : container) { > if (i.startsWith("foo")) > i = bar; > }
Correct me if I'm wrong, but: auto c = expensive(); // assume 'c' is shared and a deep copy of c would be really expensive foreach (auto const& item, c) { ... } // does not deep copy for (auto const& item : c) { ... } // *does* deep copy; ouch! I think the point here is that it's easy to incur deep copies using range-based for when there is no need to do so. There really "needs" to be a simple and concise way to stop that from happening. -- Matthew _______________________________________________ Development mailing list Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development