[Lemon-user] constness in DijkstraWizard

Marco Blanco blanco at zib.de
Tue Aug 28 11:57:27 CEST 2018


Dear Lemon team,

The function DijkstraWizard::predMap() looks like this:

DijkstraWizard<SetPredMapBase<T> > predMap(const T &t)
{
   Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
   return DijkstraWizard<SetPredMapBase<T> >(*this);
}

In particular, it takes as argument (in my case) an ArcMap t that is 
expected to be const, then ignores the constness and writes to it. I 
understand that the function needs write access (that's what predMap is 
for). What I don't understand is why t is required to be const in the 
function signature. In my case, this led to predMap modifying an ArcMap 
that is a member of my class from within a const member function without 
me (or the compiler) noticing that the function shouldn't be const.

I noticed that if I construct a Dijkstra object explicitly instead of 
using dijkstra(...).predMap(...).run(...), the compiler does notice. 
Does that mean one should in general avoid the function-type-interface? 
What is the reason for expecting const in one version of predMap but not 
in the other?

Kind regards,
Marco Blanco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lemon.cs.elte.hu/pipermail/lemon-user/attachments/20180828/96738227/attachment.html>


More information about the Lemon-user mailing list