Boost logo

Boost :

From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2005-02-03 16:12:30


Joel de Guzman wrote:
> I'm quite sure that the common ground is the low level (dynamic)
> 'object' mechanism. There's fine detail going on here such as
> dealing with type promotion (e.g. int to real), multiple dispatch
> (e.g. how to deal with, say int+real, bignum+int), etc.

When I finish implementing overloads library, I'm going to add multimethods
to dynamic_any. My current vision of it is below:

struct plus : operation<plus, anyT(anyT const&, anyT const&)>
{
    template<class OperationList>
    struct definition
    {
        definition(plus) {}

        int operator()(id<1>, int a, int b) const { return a + b; }
        float operator()(id<2>, int a, float b) const { return a + b; }

        // ...

        any<OperationList> operator()(id<100>, any<OperationList> const& a,
any<OperationList> const& b) const
        {
            // Default case. Use other dispatch mechanisms or throw
exception.
            // ...
        }
    };
};

// Other operations
// ...

typedef any<vector<plus,minus,integral_promotion,/*...*/> > object;

--
Alexander Nasonov

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