|
Boost : |
From: williamkempf_at_[hidden]
Date: 2001-06-12 13:37:43
--- In boost_at_y..., larsbj_at_l... wrote:
> Douglas Gregor <gregod_at_c...> writes:
>
> | Deferring calls and binding arguments are orthogonal (though
complementary)
> | activities and they should be separate libraries. Boost.Function
is intended
> | to handle deferred calls and nothing more. There are other
libraries that
> | bind arguments - the Lambda library (http://lambda.cs.utu.fi/) is
one such
> | library, and I though someone was working on a more lightweight
binding
> | library for Boost...
> |
> | You example above, with Boost.Function and a binders library,
would be:
> |
> | function<void> dh = foo;
> | dh();
> | dh = bind(foo, 42);
> | dh();
>
>
> Ok, I see.
>
> What I want to do is:
>
> void foo() { std::cout << "Hello!" << std::endl; }
> void foo1(int i) { std::cout << i << std::endl; }
>
> struct Blob {
> void foo() {
> std::cout << "Goodbye!" << std::endl;
> }
> };
>
>
> int main() {
> Blob blob;
> thread_handle handle = create_thread(bind(&foo));
> thread_handle handle2 = create_thread(bind(&blob,
&Blob::foo));
> thread_handle handle3 = create_thread(bind(&foo1, 42));
> handle.join();
> handle2.join();
> handle3.join();
> }
>
> And I see now that I only need a binder lib for this, not
> Boost.Function.
Actually, Boost.Function is required to get the deferred call
internally in create_thread(). That is, however, an implementation
detail. As a user all you need is a binder lib.
> Is there a binders lib proposed for boost that would allow me to do
> the above?
The Lambda Library will allow constructs similar to this, but with a
richer syntax. I believe there's also a lighter weight binder
library in the files section. Neither are official Boost libraries
(yet), but you can expect something along these lines in the future.
The Boost.Threads library plans to make use of Boost.Function for
deferred calls internally and I expect users to use some sort of
binder library to generate the function objects from other components.
Bill Kempf
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk