Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-07-27 14:11:36

From: "David Abrahams" <dave_at_[hidden]>
> Given that bind invokes mem_fn automatically, is there any reason to
> learn/use mem_fn directly?

mem_fn(pmf) is shorter to type than bind(pmf, _1, ...). ;-) Also, mem_fn is
closer to std::mem_fun (so code that uses mem_fn is easier to understand if
you don't know about bind), and its "signature" corresponds to the member
function being wrapped, whereas bind has to forward arguments, with the
associated problems. OTOH, in a bind subexpression one needs to use a nested
bind, not mem_fn.

>From library developer point of view, having a mem_fn helps when you want to
treat a member function pointer as a function object (as is the case with
bind.) For example, if you are writing a for_each that lets you do

for_each(first, last, &Shape::draw);

you could simply link to mem_fn.html and say that the above is equvalent to

for_each(first, last, mem_fn(&Shape::draw));

Boost list run by bdawes at, gregod at, cpdaniel at, john at