Boost logo

Boost :

From: Kevlin Henney (kevlin_at_[hidden])
Date: 2000-12-02 05:32:33


In message <909747+kmum_at_[hidden]>, Giovanni Bavestrelli
<gibav_at_[hidden]> writes
>This has a certain appeal to me, and at first sight it does not look
>difficult to implement, maintaining the type safety that would make
>it impossible to pass the wrong number of dimensions to the
>constructor. But, keeping the class name you suggested, my approach
>would become:
>
>Array<int, 3> A3(dim(10)(20)(30));
>
>Is it not more concise?

Yes, but it also looks quite strange.

>Besides, not overloading operator + would
>probably make it less open to abuse. And, using your approach, what
>about:
>
>Array<int, 3> A3((dim(10) + dim(20)) + dim(30));
>
>Should that work? It certainly does not look nice to me.

If someone wishes to write this I would not stand in their way, and it
does also make a certain amount of sense.

>Another
>consideration: we are not adding dimensions, if anything, we are
>multiplying them, so should we overload operator *?

I am not wedded to the idea of using +, but a binary operator feels more
intuitive -- *, <<, & and ^ all seem possibilities. Or perhaps we should
just go for chaining, ie

        Array<int, 3> A3(dim(10).dim(20).dim(30));

This seems to sidestep the flammable territory of operator style.
Thoughts?

Kevlin
____________________________________________________________

  Kevlin Henney phone: +44 117 942 2990
  Curbralan Limited mobile: +44 7801 073 508
  mailto:kevlin_at_[hidden] fax: +44 870 052 2289
  http://www.curbralan.com
____________________________________________________________


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