Boost logo

Boost :

From: scleary_at_[hidden]
Date: 2001-02-12 21:31:24


> Unfortunately, this example isn't very compelling. It would be better if
the
> input to the object generator was the result of calling a function whose
> result type was big or impossible to deduce. Can anyone come up with a
> plausible example which is more motivating?

I think it's fine as it is. But here's another example, combining a binder
and a pointer-to-member-function adapter:

Given:

struct MyStruct {
  void call_me(int);
};
std::vector<MyStruct *> struct_ptrs;

You can call the member function of all the structs with:

void call_all_structs(int arg)
{
  std::for_each(struct_ptrs.begin(), struct_ptrs.end(),
      std::bind2nd(std::mem_fun(&MyStruct::call_me), arg));
}

As opposed to:

void call_all_structs(int arg)
{
  std::for_each(struct_ptrs.begin(), struct_ptrs.end(),
      std::binder2nd<std::mem_fun1_t<void, MyStruct, int> >(
          std::mem_fun1_t<void, MyStruct, int>(&MyStruct::call_me), arg));
}

Of course, the lambda/functional libraries should handle this even better.

        -Steve


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