Boost logo

Boost Users :

Subject: Re: [Boost-users] metafunction question
From: alfC (alfredo.correa_at_[hidden])
Date: 2010-05-13 08:05:55


On May 11, 11:30 am, John Dlugosz <JDlug..._at_[hidden]> wrote:
> A co-worker mentioned an interesting issue.  I thought some metaprogramming, or at least more advanced insight into STL, might apply here.
>
> Consider a class derived from an STL collection.  It features a special find(x) function that works with his search criteria.  It returns an iterator into the collection.  There are two forms needed:
>         iterator find(x);
>         const_iterator find(x) const;
> and the annoying part is that they contain exactly the same code.  The implementation uses the inherited iterators and collection features to do the finding.

Not sure about the details but if the code is repeated in a const and
a non const function then just write one of them (e.g. the const
version) and make one call the other, take care of constness removal/
added with const_cast. As long as you know what you are doing there
is no harm in doing cast, that's why they are there in the first
place. Enjoy life/C++ (please, no c++ tele-evangelist saying "don't do
that!, sinner")

Alfredo


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