Boost logo

Boost :

From: Yitzhak Sapir (ysapir_at_[hidden])
Date: 2002-02-18 15:34:06

> While we're at it, why not allow the same thing for function pointers?
> void f(int = 5);
> void (*p)() = f;
> This could be implemented by having the definition of 'f' create a
> forwarding function:
> void __forwarding_f() { f(5); }
> The original 'f' could be implicitly convertable to type 'void (*)()'
> by substituting the address of '__forwarding_f'. ('__forwarding_f'
> cannot be an overload of 'f' because of backwards compatability.)

For that matter, this should be implemented also for overloaded
functions and member functions. That is, if the address of an
overloaded function is taken, then a forwarding function will be created
that takes the types, arguments, cv qualifiers, and throw
specifications, of the left-hand-side of the initialization/assignment
"void (*p)()" and forwards the arguments to f. This combined with
default value forwarding (done when supplied with less than the number
of total default + nondefault arguments), would allow such things as
passing map's find member function, as an argument to std::mem_fun.
Even other member functions which have only one specification would
benefit given

Also, allowing operator() to be static, such as its use in std::less.
In my opinion, since this causes use of less<> to produce code with
different semantics than might be a use with a function pointer, it
makes use of std::less worse had it not been for its reliability and
conciseness. But I am probably just not aware of the issues that
brought this restriction about.

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