Boost logo

Boost Users :

From: Raider (sraider_at_[hidden])
Date: 2007-07-24 07:58:37


> It's not wrong to want that. But it is for important safety reasons that
> BOOST_FOREACH treats copies of containers as const. In some of the
> examples you've shown so far, you're trying to proxy a temporary object
> so you can modify it. That's never going to work. Like this:
>
>> for (xxx::iterator it(GetVector().begin(), end(GetVector().end());
>> it != end; ++it) { modify(*it); }
>
> That's not even valid C++. But even if it were and GetVector() returns a
> temporary object or a proxy to a temporary object, the vector will be
> destroyed before you can iterate it. The interface I chose preserves
> object lifetimes and prevents inadvertent mutation of temporary objects.
> Weakening its guarantees is a bad idea.

Eric, thanks for detail explanation! The several tradeoffs you met, I
think you choose the right solution.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net