Boost logo

Boost :

From: Alexander Nasonov (alnsn-mycop_at_[hidden])
Date: 2003-05-08 05:15:36


Alexander Nasonov wrote:
> I agree that a->move(10, 10) is clearer then move()(a, 10, 10). One big
> plus of it is ability to overload move member-function: a->move(Point(10,
> 10)). You can't do that with move operation:
> move()(a, 10, 10);
> move()(a, Point(10, 10)); // error
> You have to implement two operations move_to_xy and move_to_point:
> move_to_xy()(a, 10, 10);
> move_to_point()(a, Point(10, 10)); // ok
>
> But, looking at the single interface bottleneck and less clear
> implementation of supported operations, I prefer to use my-own move()(a,
> 10, 10).

One addition.
I always thought about dynamic_any as a concrete class and I never
considered deriving from it. But you can:

struct moveable
  : dynamic_any::any<mpl::list<move_to_xy, move_to_point> >
{
    void move(int x, int y)
    {
        move_to_xy()(*this, x, y);
    }

    void move(const Point & point)
    {
        move_to_point()(*this, point);
    }
};

int main()
{
    moveable a = get_moveable();
    a.move(10, 10);
    a.move(Point(10, 10));
}

The problem is closed.

-- 
Alexander Nasonov
Remove minus and all between minus and at from my e-mail for timely response

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