Boost logo

Boost :

From: William Kempf (sirwillard_at_[hidden])
Date: 2000-12-01 18:49:29


--- In boost_at_[hidden], "Giovanni Bavestrelli" <gibav_at_y...> wrote:
> --- In boost_at_[hidden], Kevlin Henney <kevlin_at_c...> wrote:
> > In message <906dth+ds3m_at_e...>, William Kempf <sirwillard_at_my-
> > deja.com> writes
> > >> Where X is an appropriate but short name we haven't yet
thought
> of
> > >that
> > >> indicates dimension :->
> > >
> > >Array<int, 3> A3(dim(10) + dim(20) + dim(30));
> >
> > I had been hoping to avoid the obvious BASIC reference, but I must
> > confess that it has a certain appeal.
> >
>
> 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 the syntax is alien to anything else. Why not:

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

where 'dimensions' is a factory function that creates the same type
that 'dim(10)(20)(30)' did?

> Besides, not overloading operator + would
> probably make it less open to abuse.

A little less, yes, but not by enough to mean much to me.

> And, using your approach, what
> about:

Well, it wasn't my approach, I just suggested the name 'dim'.
 
> Array<int, 3> A3((dim(10) + dim(20)) + dim(30));
>
> Should that work?

You've got a missing ')' in the above. Fix the syntax and yes, it
should.

> It certainly does not look nice to me. Another
> consideration: we are not adding dimensions, if anything, we are
> multiplying them, so should we overload operator *? All in all, I'm
> not convinced.

It's not really multiplication either. More like concatenation,
though even that's not accurate.
 
> > >Or even:
> > >
> > >Array<int, 3> A3(dim(10), dim(20), dim(30));
> > >
> > >by overloading the comma operator?
> >
>
> This looks better, but it's still not as concise.

It's a lot more intuitive when reading the code, however.
 
> > It would have to be
> >
> > Array<int, 3> A3((dim(10), dim(20), dim(30));
> >
>
> I don't like those extra brackets.

Neither do I, but I think they're required to make the compiler
behave as we want. That's what I feared when I suggested the comma
operator. It's not an easy operator to overload and use correctly.
 
> > And even then, I feel a little uncomfortable overloading the comma
> > operator in public :-}
> >
>
> I agree.

So do I, I just was attempting to make the code easier to understand.

Bill Kempf


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