Boost logo

Boost :

From: Geoffrey Irving (irving_at_[hidden])
Date: 2006-09-22 16:10:42


On Fri, Sep 22, 2006 at 10:06:35PM +0200, Marcus Lindblom wrote:
> Sohail Somani wrote:
> >> -----Original Message-----
> >> From: boost-bounces_at_[hidden]
> >> [mailto:boost-bounces_at_[hidden]] On Behalf Of Martin Bonner
> >> Sent: Friday, September 22, 2006 6:52 AM
> >> To: boost_at_[hidden]
> >> Subject: Re: [boost] Geometry/Vector Lib
> >>
> >> ----Original Message----
> >> From: Sohail Somani
> >>
> >>> Marcus Lindblom wrote:
> >>>> I've sometimes done just:
> >>>>
> >>>> class vector3d
> >>>> {
> >>>> public:
> >>>> float x, y, z;
> >>>>
> >>>> float operator[]( int index ) const
> >>>> { return (&x)[index]; }
> >>>>
> >>>> /* ... */
> >>>> };
> >>> Won't that not work in the presence of padding?
> >> In theory, yes. In practice, I can't see why any compiler
> >> would bother
> >> adding such padding.
> >
> > Theory is what holds the C++ world together! I wouldn't want to
> > knowingly invoke UB unless I can prove its worth my while (for example,
> > in the case of hardware specific optimizations).
>
> You can add pretty easily some tests to see if it holds true for the
> compiler you're running on.

Or you can just encode the test into an assertion into the class, as in
the code I posted. Especially if you can make it a static assert (which
I'm not sure of). It isn't theory if the code only compiles if it works.

> But small vector libs is such a matter of taste and convenience, just
> like coding style. No solution will please everyone.

Geoffrey


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