Boost logo

Boost :

From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2007-10-11 05:29:38


Hi,

Marco Costalba <mcostalba <at> gmail.com> writes:
> Ok I have pushed the (final ?) implementation of overload called
> "slim" overload because it's much more light and less feature packed
> then Marco Cecchetti's one.

> boost::overload
> < int(char)
> , double(int, char)
> , char(std::string)
> , void(std::string, std::string, std::string)
> , int()
> > f;
>
> // assign functions in any order, as pointers or plain types
> std::cout << f.set(&foo4) << std::endl;
> std::cout << f.set(&foo2) << std::endl;
> std::cout << f.set( foo1) << std::endl;
> std::cout << f.set( foo5) << std::endl;
> std::cout << f.set( foo3) << std::endl;

Here's a completely different idea.

struct overload_set
{
   int overload(int_<1>, char a) const { return foo1(a); }
   double overload(int_<2>, int a, char b) const { return foo2(a, b); }
   char overload(int_<3>, std::string a) const { return foo3(a); }
   // ...
};

This struct can be wrapped into a fusion sequence. Once it's done,
transforming it into a tuple of boost::functions is an exercise for
a fusion user.

Code is here
http://cpp-experiment.cvs.sourceforge.net/cpp-experiment/overloads/

I don't remember if the last version can be compiled at all
but I remember I couldn't compile in on VC 7.1 (not sure about 8.0).

--
Alexander

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