Boost logo

Boost :

From: Brad King (brad.king_at_[hidden])
Date: 2001-05-01 10:50:13

> I see two options for making it const, each with its semantic problems:
> 1) Just make function::operator() const, but constness won't be passed
> through to underlying function objects, so we're dealing with a semantic grey
> area.
I would argue that this is actually correct semantic behavior. Isn't
boost::function supposed to be a generalized function pointer that can
bind to both free functions and function objects? Consider this class:

template <typename TFunctionPointer>
struct my_caller {
  typedef TFunctionPointer FunctionPointer;

  my_caller(FunctionPointer in_f): f(in_f) {}

  void invoke() const { f(); }

  FunctionPointer f;

If TFunctionPointer is a real function pointer type, then the constness of
the invoke() method would not affect the call to "f". This is because the
top-level cv-qualifiers of a pointer type do not affect the cv-qualifiers
of the "pointed-to" type. Since boost::function is supposed to act like a
function pointer, it should be consistent with this behavior. If it is
pointing at a function object, then the top-level cv-qualifiers of the
boost::function instance should not affect the target object.

If, however, boost::function is supposed to act like a function, not a
function pointer, then this argument is invalid.


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