Boost logo

Boost :

From: Vincent Poinot (vincent.poinot_at_[hidden])
Date: 2007-06-23 12:24:59


shunsuke wrote:

> Vincent Poinot wrote:
>> As you can see, the available comparison function objects operates on
>> objects X, the deref() helper function creates a new function object that
>> will call the original less<>() after dereferencing its arguments,
>> allowing sort() to work as expected.
>
> It seems boost::indirect_fun?
> http://www.boost.org/libs/ptr_container/doc/indirect_fun.html
>
>
You are right, I was not aware of this...
However, a remark: the example I gave in my first post using accumulate()
does not work with make_indirect_fun():

X sum = accumulate(v.begin(), v.end(), X(), deref<X*>(plus<X>())) ;

Indeed, accumulate() will call its function object like this:

op(start, *current_element) ;

whereas make_function_indirect() returns a function object providing a
binary operator() that will dereference both arguments (instead of one, as
needed in this case).

I guess the fix, if needed, would be to add two overloads to operator(), one
to account for the case where only the left argument should be
dereferenced, and similarly with the right argument.

Vincent Poinot.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk