Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-11-09 10:01:28

On Saturday 09 November 2002 04:10 am, Aleksey Gurtovoy wrote:
> A crazy thought - how about enabling something like this:
[snip code]
> In other words, can we allow a zero-arity 'function<...>' to treat ordinary
> values as first-class function objects?

Do we want to? I think not, because boost::function will lose its ability to
safely replace function pointers. At present, boost::function function
objects either support the same syntax and (nearly) the same semantics as
function pointers, or the syntax will fail to compile on boost::function. I'm
worried about this case:

  typedef bool (*when_to_stop_callback)();

  bool stop_if_user_intervention();

  // ...
  expensive_action.when_to_stop = &stop_if_user_intervention;
  expensive_action.when_to_stop = 0;

If when_to_stop_callback is changed to a have type function<bool()>, we have a
problem: the code still compiles, but now the final line (assignment to zero)
has different semantics: it assigns a function object that always returns

#include your friendly local lambda header and you can do this:

  boost::function<int ()> f1 = constant(-1);

Aside from that, I'm not sure it's implementable. We would need a way to tell
if an arbitrary class type is a function object or not. If we can do this,
we will have solved the is_callable problem and Boost.Function will become
very useful indeed :)


Boost list run by bdawes at, gregod at, cpdaniel at, john at