Boost logo

Boost Users :

Subject: Re: [Boost-users] [type_erasure] Problem with iterators
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2015-01-24 15:29:57


AMDG

On 01/24/2015 12:56 AM, Marco Guazzone wrote:
> I need to write a base class with type-erased forward iterators. To do
> so I've taken inspiration from the print_sequence.cpp example I've
> found in the Type Erasure source tree.
> At the end of the email there is the whole code of my tentative,
> called "erasure.cpp".
>
> Unfortunately, I've problems (presumably) with const iterators which
> cause the following compile error:
>

Iterators are mutable by default. If you want
a const iterator, you need to specify the reference
type. (If you look at the range print example,
it uses forward_iterator<_iter, const _t&>)

> $ g++ -Wall -Wextra -pedantic -std=c++11 -I$HOME/sys/src/git/boost -o
> erasure erasure.cpp -lm
>
> *** [begin error] ***
> <snip>
> erasure.cpp:77:73: required from here
> /home/sguazt/sys/src/git/boost/boost/type_erasure/operators.hpp:134:44:
> error: invalid initialization of reference of type ‘double&’ from
> expression of type ‘const double’
> static R apply(const T& arg) { return *arg; }
>
> *** [/end error] ***
>
> The GCC version is 4.9.2.
>
> Here below is the content of "erasure.cpp". If I comment lines below
> the comment "THE FOLLOWING WON'T COMPILE" I get no error. So the
> problem is due to the use of cbegin/cend.
>
>

In Christ,
Steven Watanabe


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