id,summary,reporter,owner,description,type,status,milestone,component,version,severity,resolution,keywords,cc 7630,Range adaptors do not play nicely with range-based for loops,gromer@…,Neil Groves,"Consider the following C++11 code, adapted from the Range documentation: {{{ std::vector vec; for (int val : vec | boost::adaptors::reversed | boost::adaptors::uniqued) { // Do stuff with val } }}} The behavior of this natural-seeming code is actually undefined, due to a dangling reference: per the C++ standard, it is equivalent to {{{ { auto && __range = (vec | boost::adaptors::reversed | boost::adaptors::uniqued); for ( auto __begin = __range.begin(), __end = __range.end(); __begin != __end; ++__begin ) { int val = *__begin; // Do stuff with val } } }}} The problem is that the value returned by the subexpression `vec | boost::adaptors::reversed` is a temporary, so its lifetime ends at the end of the statement containing it, namely the declaration of `__range`. Thus, `__range` is left holding a dangling reference to the range it's adapting. The fix is for each range adaptor to use an rvalue-reference overload to detect whether the input range is a temporary, and if so, move it into the adaptor (i.e. with `std::move`) in order to extend its lifetime. ",Bugs,assigned,To Be Determined,range,Boost 1.51.0,Problem,,range,jyasskin@… roman.perepelitsa@… mikhailberis@…