Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2005-09-28 06:57:43


Alexander Borghgraef <alexander.borghgraef.rma_at_[hidden]> writes:

> Hi all,
>
> I've been experimenting with indirect_iterator, which seems to be a very
> useful concept.
> However, I'm having some trouble getting it to work in the case where I want
> to fill a container
> with pointers to values, not just getting at the data. For example, this
> compiles but segfaults:
>
> std::vector < int * > v( 10 );
> std::fill( boost::make_indirect_iterator( v.begin() ),
> boost::make_indirect_iterator( v.end() ),
> 1.0
> );

:) Yes, that's expected. When dereferenced, indirect_iterator gives
you a reference onto an existing value.

> Why isn't this working?

It wasn't designed to do that.

> Also, some way to get it to work as a back_insert_iterator would be
> interesting, does this exist (aside from writing your own)?

Neither exists, but for either one, writing your own is possible using
iterator_facade. The tutorial is at
http://www.boost.org/libs/iterator/doc/iterator_facade.html#tutorial-example
 
> If not, are there any plans to incorporate it in future versions?

There are no such plans. It would impose an overhead on other uses
that people shouldn't have to pay.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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