[Insight-users] ConstIterator inaccessible from non-const ListSample

Luis Ibanez luis.ibanez at kitware.com
Wed, 14 Apr 2004 13:55:05 -0400


Hi Zach,

Thanks for pointing this out.

...and for doing the right-thing
supporting const-correctness  :-)


The problem is that there were no constructors allowing you
to create a ConstIterator from a non-const Iterator.
This issue was entered as Bug # 746 and has now been fixed.

   http://www.itk.org/Bug/bug.php?op=show&bugid=746&pos=0

Please update your CVS checkout in order to get the fixes.

Let us know if you find any problem,


   Thanks


     Luis


-----------------------
Zachary Pincus wrote:

> Hello,
> 
> I'm using a ListSample, and recently decided to iterate through it. 
> Being a responsible type, and knowing that I didn't want to change the 
> list, I thought that using a ListSample::ConstIterator would be the best 
> way to go.
> 
> Unfortunately, it is not possible to get a ConstIterator easily out of a 
> non-const ListSample object. (And quite possibly, other objects that 
> share the following interface convention.)
> 
> The problem/feature is thus: (from the class definition in the header)
> 
> ConstIterator Begin() const {...}
> Iterator Begin() {...}
> 
> So the Begin() that returns a ConstIterator is only called when the 
> ListSample object itself is const. With a non-const ListSample (which 
> mine is, because I just constructed it), there's no way, aside from an 
> ugly const_cast<> construction, to get a ConstIterator from the Begin() 
> function.
> 
> Is this a design oversight or a specific feature? Or am I missing "the 
> right way" to do this?
> 
> Thanks,
> 
> Zach Pincus
> Department of Biochemistry and Program in Biomedical Informatics
> Stanford University School of Medicine
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>