Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-10-17 16:01:49

On Thursday 17 October 2002 11:28 am, Alexander Nasonov wrote:
> I implemented unary and binary function calls for dynamic_any.
> New version can be download from:
>r.gz?download There is no documentation yet, only examples.

This is excellent. I can almost feel the run-time/compile-time type barrier
dissolving. I haven't yet dug through the code, but I will when I get a
chance (post-Santa Cruz, unfortunately, I should have some free time).

I like the syntax for introducing new operations: it's about as concise as we
can possibly expect given what we are doing. I expect that a final version of
the library would contain quite a few prefabricated operation mixins (e.g.,
for most C++ operators), probably scattered amongst a few different headers
to keep the size of each down.

boost::call seems a little unwieldy, and I'm wondering what we can do about
that. It would be nice if, along with the prefabricated operation mixins, we
could provide the actual operator and function overloads for
appropriately-constructed dynamic_any's. For instance, say we have
dynamic_any_less from the example. Then we'd really like this to work:

dynamic_any<mpl::list<dynamic_any_less> > a1, a2;
if (a1 < a2) {
  // ...

But, we don't want something like this to work:

dynamic_any<mpl::list<something_that_isn't_less> > a3, a4;
if (a3 < a4) { // should be an error
  // ...

For binary functions, at least, something like this wouldn't be very hard to
implement. A general scheme is:

template<typename OperationList>
bool operator<(const dynamic_any<OperationList>& x,
               const dynamic_any<
                       typename select_type<
                       void>::type>& y);

i.e., given objects a1 and a2 of type dynamic_any<T>, operator<(a1, a2) only
unifies if T (the list of supported operations) contains dynamic_any_less.
The unary function analogue to this would probably need to use the has_member


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