Boost logo

Boost Users :

Subject: [Boost-users] [iterator_adaptor] Does the base need a const version of operator* ?
From: Andre Massing (massing_at_[hidden])
Date: 2009-09-03 09:47:36


Hi,

I am trying to wrap our kind of iterators (for meshes) with the
iterator_adaptor class template, something like

   class CellBoostIterator
       : public boost::iterator_adaptor<
           CellBoostIterator //Derived
         , CellIterator //Base
         , Cell //Value
         , boost::forward_traversal_tag // CategoryOrTraversal
>
     {
     ...
     };

Since the base class CellIterator already provides a operator* and a
operator-> (both non-const version) I did not redefine any of these
within the CellBoostIterator class.
If I now want to use with code-snippet

  typedef Mesh_2::CellBoostIterator MIT;

   MIT mit;
   Mesh_2 mesh_2(omega1);

   for (MIT mit = mesh_2.begin(); mit != mesh_2.end(); ++mit)
   {
     std::cout << mit->index() <<std::endl;
   }

I get a compile error

/usr/include/boost/iterator/iterator_adaptor.hpp:312: error: passing
‘const dolfin::CellIterator’ as ‘this’ argument of ‘dolfin::Cell&
dolfin::CellIterator::operator*()’ discards qualifiers

I looked at the corresponding line
/usr/include/boost/iterator/iterator_adaptor.hpp:312:

  typename super_t::reference dereference() const
         { return *m_iterator; }

So it seems to me that I have to provide a const version of operator*,
or do I get something wrong? I am a bit confused, since I have not found
this kind of requirements in the documentation.

Any enlightening, hints or pointers are greatly appreciated!

Greetings,
Andre


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