Boost logo

Boost Users :

From: Nico Galoppo (nico_at_[hidden])
Date: 2006-02-24 14:26:32


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.

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? 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.

Thanks,

--nico

   template <class Iterator>
   class map_data_iterator
     : public iterator_adaptor< map_data_iterator<Iterator>, Iterator, typename
Iterator::value_type::second_type >
   {
     typedef typename map_data_iterator::iterator_adaptor_ super_t;

     typedef typename Iterator::value_type pair_type;
     typedef typename pair_type::second_type second_type;

     friend class iterator_core_access;

   public:
     map_data_iterator() {}

     // should be explicit, but removed to give OpenTissue backwards compatibility
     map_data_iterator(Iterator x)
       : super_t(x) {}

     template<class OtherIterator>
       map_data_iterator(
       map_data_iterator<OtherIterator> const& r
       , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0
       )
       : super_t(r.base())
     {}

   private:
     second_type & dereference() const { return this->base()->second; }

     // added to give support for comparison with base type iterators
     //bool equal(Iterator const& other) const
     //{
     // return (this->base() == other);
     //}
     //bool equal(super_t const& other) const
     //{
      // return (*this == other);
     //}

   };

-- 
nico galoppo von borries     @  address: 105 creel st., chapel hill
comp. graphics phd. student  @           north carolina, 27516 USA
UNC, chapel hill             @  phone: +1 (919) 962-1898 (office)
                              @         +1 (919) 942-7609 (home)
                              @  email: nico at cs dot unc dot edu
                              @  homepage: http://www.cs.unc.edu/~nico
--- debian linux :: vim powered

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