Boost logo

Boost :

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

 <Oliver.Kowalke <at>> 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 ( 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:


while I expect a single functor supporting all overloads:

_1 + 1;


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


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