
----- "Michel MORIN" <mimomorin@gmail.com> a écrit :
Sometimes it is convenient to apply range adaptors to a temporary container and iterate over it:
// `using namespace boost::adaptors;` is assumed BOOST_FOREACH(auto x, std::string("Hello, world!") | reversed) {...}
However, the lifetime of the temporary container ends before the loop body begins. This problem also exists in C++0x range-based for. To solve this, I'd like to propose an extension of BOOST_FOREACH macro:
IIUC, the line below is broken: auto const & broken_range = std::string("Hello, world!") | reversed; So it seems you're proposing to adapt BOOST_FOREACH to solve a problem in adaptors. How do you intend to fix C++11 builtin foreach? In C++11, I think this could be fixed with rvalue refs detection. Shouldn't any function relying on the fact that its arguments still exist after the call do that check? So either delete the &&-function or ... [disclaimer: ugly but funny] make it move the range inside the adaptor somehow. Ivan