Boost logo

Boost Users :

From: Mark Sizer (yg-boost-users_at_[hidden])
Date: 2003-05-16 23:27:39


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.

I get, I think, that it can't be a member function, because there is no
'this' attached.

However, I'm having trouble with two things:

#1 from: function.tutorial.html
<quote>
   boost::function2<float, int, int> 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;)

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.

Thanks,
  - Mark


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net