Boost logo

Boost :

From: vicente.botet (vicente.botet_at_[hidden])
Date: 2008-03-05 16:40:28

----- Original Message -----
From: "Marco Costalba" <mcostalba_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, March 05, 2008 1:53 PM
Subject: Re: [boost] [announce] Multi-signature overload of any function
orfunction object

> 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.
> Marco


I have take a lock to the code. Could you tell us if there is a deep raison
to not use boost::function, boost::enable_if, boost::mpl::list ...?

I have no doubt of the usefulness of such a overload class.
What happens if we forget to initialize one of the signatures? crash ?
What can you do to improbe this aspect.

Do you think that is possible to have a version ensuring a default function
for each signature? Somting like

 overload_ns::overload <
          , int(char),
          , double(int, char),
          , char(string),
          , string(string, string, string)
      default_functions<foo1, &foo2, foo3, &foo4, foo5_ptr>
> f;


 overload_ns::overload <
          , fct<int(char), &foo2>,
          , fct<double(int, char), foo3>,
          , fct<char(string), &foo4>,
          , fct<string(string, string, string), foo5_ptr>
> f;

Could you give a practical example? Which is the context you have used it?

Vicente Juan Botet Escriba

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