On 2015-05-14 16:37, Thiago Macieira wrote: > On Thursday 14 May 2015 11:34:25 Matthew Woehlke wrote: >> On 2015-05-14 10:58, Thiago Macieira wrote: >>> On Thursday 14 May 2015 14:36:43 Olivier Goffart wrote: >>>> I'm afraid your solution is not working with temporaries containers. >>> >>> That should be submitted as a change request to the standard. There are a >>> couple of other cases where this bites people. >>> >>> It needs a new paper. >> >> Can you (both) please elaborate? >> >> That's... interesting. I'm taking a copy of the container and taking >> iterators from the copy. It seems to me that the RHS expression in a >> range-based for should most definitely not go out of scope within the >> for. Is that not the case? (Does range-based for just not work on >> temporaries at all?) > > for (auto x : function(function2())) > > If function returns a temporary and function passes through a reference, [...]
Er... wait. My bad. Does it resolve the issue if 'Container const& c;' in qtEnumerator is changed to be a copy (i.e. remove the '&') rather than a reference? (I was thinking it was a copy when I wrote the above, and, given that this is likely only going to be used on Qt containers, it probably ought to be a copy.) Back on the subject of C++ standard proposals, I thought there was already a proposal regarding lifetime extension of temporaries? (Or did that die? Or not cover this use case?) -- Matthew _______________________________________________ Development mailing list Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development