Boost logo

Boost :

Subject: Re: [boost] [Foreach] Supporting range adaptors for temporary containers
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2011-04-21 16:32:19

On Thu, Apr 21, 2011 at 1:07 PM, Michel MORIN <mimomorin_at_[hidden]> wrote:

> 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.


I believe BOOST_FOREACH correctly accounts for rvalue range expressions.
See second-to-last example from

Does this address your concern?

- Jeff

Boost list run by bdawes at, gregod at, cpdaniel at, john at