Boost logo

Boost :

From: Marco Costalba (mcostalba_at_[hidden])
Date: 2008-05-16 07:10:34


On Fri, May 16, 2008 at 12:45 PM, Marco Costalba <mcostalba_at_[hidden]> wrote:
> On Fri, May 16, 2008 at 12:25 AM, Daniel Walker
> <daniel.j.walker_at_[hidden]> wrote:
>>
>> If the overload_set were instead based on polymorphic_function, then
>> after loading add_int for integers, you only need to specify plus once
>> to handle all other types.
>>
>> overload_set<
>> mpl::vector<int(int,int), plus(_1,_1)>
>>> add(add_ints, plus);
>>
>

This is fundamentally different from writing

overload_set<
    mpl::vector<"comma separated function signatures">
> add(add_ints, plus)

In the latter case you instantiate plus for each signature in the
overload_set (or multi signature function MSF, if you prefer).

In your example you pass typename T where T = plus as template parameter.

mpl::vector<int(int,int), plus(_1,_1)>

Is no more a vector of signatures, it'a a vector of signatures + a
class type. It is a vector of heterogeneous item types.

This is _really_ totally different also from an implementation point
of view. Indeed a MSF boils down to a hierarchy of operator=() each
one defined on a given signature and each one forwarding to a
corresponding boost::function

What you suggest is to have a fall back MSF defined as:

template<typename Signatures, class fall_back_poly_class>
class function : public fall_back_poly_class
{
  ......good old multi sig. function implementation .....
}

In other words MSF _derives_ from poly class so that when a call
matches some operator=() signature the normal path is choosen, when a
call does not mach compiler synthetizes a new operator=() from the
poly base class.

Indeed Signatures can be more flexible of poly because poly is arity
constrained, as example plus takes _only_ two arguments. While
signatures list can contain signatures of any and also different
arity.

A simple generalization to overcome this could be:

template<typename signatures_sequence, typename poly_sequence>
class fallback_function : public "derive vertically from all the poly
objects in poly_sequence"
{
  ......good old multi sig. function implementation .....
}

Is my interpretation correct?

If it is and you are interested in such an object I think I can tweak
multi-signature function to handle that.

Thanks
Marco


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk