News for hackers. Stuff that matters.
Re:Auto Type Deduction in C++ Range-Based For Loops by dbaupp on Friday September 02, 2016 @11:26AM (#12413654)
There definitely can be problems: the reference may escape the for loop, and the reference may be invalidated by a modification of the container (even for something "stable" like ordered_map, the referent may be removed).
Re:Auto Type Deduction in C++ Range-Based For Loops by E6300 on Friday September 02, 2016 @12:50PM (#12414379)
If a pointer/reference escapes the loop you'll have problems whether the thing to the right of the colon is a reference or a copy. If it's a copy, the escaped reference will definitely be invalid once that iteration complete. If it's a reference, it will remain valid in more situations.
Re:Auto Type Deduction in C++ Range-Based For Loops by dbaupp on Friday September 02, 2016 @01:34PM (#12414698)
Yes, I believe that's what I was saying, but your comment sounds like it is disagreeing. Could you clarify?
Re:Auto Type Deduction in C++ Range-Based For Loops by E6300 on Friday September 02, 2016 @02:32PM (#12415154)
Oh, okay, then. I thought you were saying that that was a problem specific to iterating by reference.