$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Daniel Gehriger (gehriger_at_[hidden])
Date: 2007-05-24 13:43:56
Eric Niebler wrote:
> 
> This is by design. get_vector_float() returns a temporary object. You 
> can't modify it. 
> --snip--
> 
Yes, shortly after my post I came to the same conclusion. Thank you for your
reply, though!
My I suggest an addition to BOOST_FOREACH ?
I happen to work with custom containers whose iterators are invalidated when
certain member functions are called on the contained objects. So I typically
use a loop pattern as follows:
-------------------
for (Coll::iterator it = col.begin(); it != col.end(); /* noop */)
{
    Coll::value_type& o = *(it++);
    o.destroy();
}
-------------------
I adapted the BOOST_FOREACH pattern to implement this pattern:
-------------------
#define FOREACH_PRE(VAR, COL)                                                                  
\
    BOOST_FOREACH_PREAMBLE()                                                                   
\
    if (boost::foreach_detail_::auto_any_t _foreach_col =
BOOST_FOREACH_CONTAIN(COL)) {} else   \
    if (boost::foreach_detail_::auto_any_t _foreach_cur =
BOOST_FOREACH_BEGIN(COL)) {} else     \
    if (boost::foreach_detail_::auto_any_t _foreach_end =
BOOST_FOREACH_END(COL)) {} else       \
    for (bool _foreach_continue = true;                                                        
\
              _foreach_continue && !BOOST_FOREACH_DONE(COL);                                   
\
              /* noop */)                                                                      
\
        if  (boost::foreach_detail_::set_false(_foreach_continue)) {} else                     
\
        for (VAR = BOOST_FOREACH_DEREF(COL); !_foreach_continue;
_foreach_continue = true)      \
            if (BOOST_FOREACH_NEXT(COL), false) {} else
-------------------
Would you consider adding it to Boost ?
Regards,
Daniel Gehriger
-- View this message in context: http://www.nabble.com/BOOST_FOREACH-and-iterating-by-reference-tf3806531.html#a10788909 Sent from the Boost - Users mailing list archive at Nabble.com.