Hi Patrick,
On Mon, Jan 24, 2011 at 3:55 PM, Patrick Sauer
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