Boost Users :
Subject: Re: [Boost-users] [Iterator]Can dereference() in iterator_adaptor return a temporary value?
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2011-07-31 19:55:13
> Hi, I'd like a const iterator that acts as a proxy by giving access to
> elements of type A as if they were elements of unrelated type B. In
> that case I guess the dereference() member function should return a
> temporary value, right?
> Would that be a correct implementation of the idea? Here I just want to
> access an array of SourceVertexType as if it were an array of
> template<class VertexType>
> class ConstVerticesIterator : public boost::iterator_adaptor<
> ConstVerticesIterator<VertexType>, const SourceVertexType*, const
> VertexType >
Yes, this is fine. This is what transform_iterator does.
However, you should specify the fourth template parameter of
iterator_adaptor (Reference) to be "const VertexType" as well,
otherwise it will default to "const VertexType&" and operator*
will return a reference to the temporary rather than returning
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