|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2006-02-24 15:16:06
Nico Galoppo <nico_at_[hidden]> writes:
> Hi,
>
> regarding iterator_adaptor<>, I've created a custom iterator over a map as
> below. Basically, it allows to iterate over map values without being worried
> with key values.
For that I would use transform_iterator with an appropriate select_2nd
function object.
> Anyway, if I would want to do something like this:
>
> typedef map<int,int> map_type;
> typedef map_data_iterator<map_type::iterator> map_iterator;
> map_type map;
>
> map_iterator it = map_data_iterator(map.begin());
> for (; it != map.end(); ++map)
> ...
>
> I'd have to add an equal method to the map_data_iterator class that takes the
> base type iterator, right?
Something like that. Of course you need != as well (that doesn't come
along for free). A family of free friend functions would be better,
since in the usage above, it would have to be a member of
map_iterator, which you don't control.
> I tried to do so below, but it still complains about
> not being able to convert:
>
> binary '!=' : no operator found which takes a left-hand operand of type
> 'OpenTissue::DepthFirstTesselator<Types>::prism_iterator' (or there is no
> acceptable conversion)
>
> I know this is probably not the right thing(tm) to do , but I basically need to
> be able to do this comparison for backward compatibility with deprecated code.
You shouldn't need the != and == overloads at all since you have an
implicit converting constructor. So I think there's something wrong
with your compiler or there's some deeper subtlety here. Is map.end()
returning the map's const_iterator? You don't have a conversion for
that one.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
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