On Mon, Nov 14, 2005 at 05:57:53PM +0100, Lars Gullik Bjønnes wrote:
> | On Wed, Nov 09, 2005 at 10:21:19AM +0100, Georg Baum wrote:
> | > class ParAddressEqual : public std::unary_function<Paragraph, bool> {
> | > public:
> | >         ParAddressEqual(Paragraph const * par) : par_(par) {}
> | >         bool operator()(Paragraph const & par) const {
> | >                 return &par == par_;
> | >         }
> | > private:
> | >         Paragraph const * par_;
> | > };
> | > 
> | > ParagraphList::iterator it = std::find_if(pars_.begin(), pars_.end(),
> | >                                           ParAddressEqual(&par));
> | > 
> | > IMHO this is overkill if used only once, but is useful if you need it
> | > several times.
> | 
> | Unless 'several' means 'a few dozen and more' I'd dispute 'useful'.
> 
> IMO it is useful even if used only once.
> 
> - makes it _very_ clear that we are looking for something
> - and that the crieteria is ParAddressEqueal (even if I dislike this
>   mixture of offsets and pointers and references and iterators...)

You forget that there is usually quite some distance on screen between
the definition of the functor and its use, so one has to infer from the
name of the functor what it is doing exactly rather than seeing the
'in-line implementation' in the for-case.

As documentation (i.e. the functor's name) and implementation (its
implementation) have a tendency to get out of sync, you are just 
introducing needlessly an additional opportunity for errors.

As I said, thing would be different if we had something like lambda
that would allow to have the implementation near the place of use.

Andre'

Reply via email to