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