
This is _NOT_ your fault. You've created an excellent library and do a great job of support on this list. I'm a very old-school C++ person (I started with C-Front) and a lot of Boost concepts are new to me (e.g. function objects, I don't even want to think about the lambda stuff). I dove off the deep end on this project. I should have done more research. The examples will be great (I got the distribtion, I haven't even looked in CVS - that's the pointer I needed). Thanks, - Mark William E. Kempf wrote:
Mark Sizer said:
This is also stuff that has been answered before. I really have searched. Links to the answers will be as appreciate as an inline responses.
I've been using free file-scoped functions up to now because I really don't understand what a boost::function0<void>& is.
It's a "function object" which takes no parameters and returns nothing. Function pointers are valid "function objects", but so are class instances with an overloaded operator().
I get, I think, that it can't be a member function, because there is no 'this' attached.
Not directly, however boost::bind can be used to create a function object that does call a member function.
However, I'm having trouble with two things:
#1 from: function.tutorial.html <quote> boost::function2
f; struct int_div { float operator()(int x, int y) const { return ((float)x)/y; }; };
f = int_div(); </quote>
operator() _is_ a member function. When assigning int_div() to f, which of potentially zillions of instances of int_div is being referenced? Is a new one created on invocation? (the example uses std::cout << f(5,2) << endl;)
The syntax "int_div()" is a call to the int_div constructor. So, 'f' is being assigned to a new instance of int_div. This can be done, because int_div *is a function object* who's signature matches that required by boost::function2
. I'm missing a theoretical bit of information that makes this hang together. Help, please.
#2 from: http://www.cuj.com/articles/2002/0205/0205a/0205a.htm?topic=articles <quote> However, because Boost.Threads uses a function object instead of just a function pointer, it is possible for the function object to carry data needed by the thread. This approach is actually more flexible and is type safe. When combined with functional libraries, such as Boost.Bind, this design actually allows you to easily pass any amount of data to the newly created thread. </quote>
BUT HOW?!?! Any pointers (with many examples, please) would be much appreciated.
$BOOST_ROOT/libs/thread/tutorial/helloworld4.cpp illustrates using Boost.Bind to pass data while creating a thread.
Sorry for the frustration. I need a full tutorial in the documentation, so this isn't something that's your fault, but mine. For now, all I can recommend is that you look at the numerous example programs included in the CVS archive.