Boost logo

Boost :

From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2007-10-01 05:19:27


 <Oliver.Kowalke <at> qimonda.com> writes:
> Hmm - what are the benefits/disadvantages of the two implementations -
> or which should you use?

[ I'm talking past because I abandoned the library
  when I was unable to implement multimethods. ]

dynamic_any's goal was to mimic values of scripting languages.
For example, one could subtract a number from a string containing
numeric value and print the result:

dynamic_any< /* list of supported operations */ > a("2"), b(1);
cout << a - b;

Function calls is one particular case of "operation".

calls.cpp (http://tinyurl.com/373wkx) defines a list of operations
as follow:

typedef mpl::list<
  dynamic_any::function_call<int (int)>,
  dynamic_any::function_call<double (double)>
> ops;

At construction time, a single value functor is created.
It must be a functor that can accept one argument of type
int or double:

dynamic_any<ops> f(_1 + 1); // lambda expression

cout << f(136) << '\n';
cout << f(2.1459) << '\n';

This means that any dynamic_any value which supports these
operations is callable. You can pass either int or double
to such dynamic_any values.

Key difference between my interface and Joel's is that
Joel sets overloads individually:

    f.set<0>(&foo1);
    f.set<1>(&foo2);
    f.set<2>(&foo3);
    f.set<3>(&foo4);

while I expect a single functor supporting all overloads:

_1 + 1;

or

struct f {
   int operator(int) const;
   double operator(double) const;
};

--
Alexander

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