|
Boost Users : |
Subject: Re: [Boost-users] reference access with boost::make_transform_iterator
From: Nathan Crookston (nathan.crookston_at_[hidden])
Date: 2011-01-24 20:24:51
Hi Patrick,
On Mon, Jan 24, 2011 at 3:55 PM, Patrick Sauer <pat05.mlst_at_[hidden]> wrote:
> In my problem, the values of the map are containers which hold large data.
> Since I can't afford to copy the data, I would like to access the data by
> reference via the iterator. However, when doing this,
> the data is corrupted, as is exemplified by the output of the simple
> example I have attached.
The problem isn't actually with transform_iterator -- it's the
result_type of from_key.
The transform_iterator result used a copy of the internal holder
object. Since the holder::v is not a reference, accessing it from the
copy of holder resulted in a dangling reference.
The solution is to change the typedef below:
> class from_key
> {
> public:
>
> typedef holder result_type;
^^ Change to:
typedef holder const& result_type;
HTH,
Nate
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