|
Boost : |
From: Gary Powell (Gary.Powell_at_[hidden])
Date: 2000-08-09 11:42:35
> --- In boost_at_[hidden], Kevlin Henney <kevlin_at_c...> wrote:
> > In message <20000809155851.15667.qmail_at_w...>, Dietmar
> > Kuehl <dietmar_kuehl_at_y...> writes
> > >If 'f()' is a function, I would consider this to be more natural:
> > >
> > > spawn_thread(f);
> >
> > Definitely, or something similar.
> >
> > >... and if 'f()' takes three arguments, I would still consider
> > >
> > > spawn_thread(f, 1, 2, 3);
> >
> > I would be inclined towards either recasting f as a function object
> > type:
> >
> > spawn_thread(f(1, 2, 3));
> >
> > Or using a few adaptors, ie a little bit of currying.
>
> Functor adapters are best used by functions that return the adapter.
> For instance, we don't use std::binder1st<Pred>(x), we use
> std::bind1st(Pred, x). Viewed in this light, their's little
> difference if spawn_thread must take a specific functor type and we
> use a function to adapt to this type, or if spawn_thread does the
> adaption automatically. I'd lean towards seperating them only
> because it means we have a *little* bit more in terms of reusability
> of code.
>
Or you could use a library like "lambda" which has binders for just this
sort of thing. (Even more reuse!)
spawn_thread(bind(f,1,2,3) );
or F f;
spawn_thread(bind(&f::m, f, 1, 2, 3) ); // use member function m.
So I'd prefer using nullary functors, then you can use either std function
adaptors or "lambda" style ones. (There are a number of good ideas being
worked on in this area.)
-gary-
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk