Boost logo

Boost :

From: Marco Costalba (mcostalba_at_[hidden])
Date: 2008-03-05 07:53:07

On Wed, Mar 5, 2008 at 12:19 PM, Neal Becker <ndbecker2_at_[hidden]> wrote:
> Do you have any design doc I can read?

A struct overload it's a hierarchy of many overload_function template classes.

Each overload_function template it's instantiated on given signature.
One overload_function per signature.

The overload_function template defines one operator() that forwards
its calling arguments to a function wrapper called 'functor'.

This functor it's a very simple home made replacement of boost.function.

Each overload_function defines also a couple of set() member functions
that are used to link one of our simplified 'functor' with a specific
function/function object the user passes in as the set() argument.

At calling time, according to the passed in arguments the correct
overload_function::operator() will be linked by the compiler, but how
to invoke the correct overload_function::set() among all the ones that
are instantiated by our struct overload ?

To achieve this a SFINAE tecnique is used on an (hidden) second
argument of set().

Indeed one signature of set() is:

        template<typename Fun>
        void set(Fun* fun, typename enable_if<is_compatible<Fun,
Sig>::value>::type = 0);

When, as example, a pointer to a function 'fun' is passed in the
signature Fun of the pointer is tested against Sig that is the
signature on which this overload_function is instantiated.

Value of is_compatible<Fun, Sig>::value is true only for types F that
are functions with signature Sig or functors whose operator() has
signature Sig. So, given that all the signatures on which is defined
an overload struct are unique, only one of the set() member functions
will be enabled.

More or less that's all.


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