Reputation: 2097
I'm writing an iterator facade for use with a collection which is wrapped into another class. I followed the tutorial until telling the truth, which states:
Now
node_iterator
andnode_const_iterator
behave exactly as you'd expect... almost. We can compare them and we can convert in one direction: fromnode_iterator
tonode_const_iterator
. If we try to convert fromnode_const_iterator
tonode_iterator
, we'll get an error when the converting constructor tries to initializenode_iterator
'sm_node
, anode*
with anode const*
. So what's the problem?
To me this seems exactly what I would want, i.e. not being able to convert a const iterator to a non-const iterator. The conversion being possible, seemingly, would be a failure in const correctness as the iterated node would lose the const
qualifier.
Am I missing something? I'm asking because some of my code fails to compile and this is one possible reason.
Upvotes: 0
Views: 220
Reputation: 385194
You can't just stop reading half-way through the chapter. The very next lines of the source material tell you why this is a problem: we want the conversion itself to not exist. As it is, the conversion exists, but fails someway up the call stack in the innards of the implementation, which results in less than clear diagnostics, and a broken boost::is_convertible<node_const_iterator,node_iterator>
trait.
Upvotes: 2