Boost logo

Boost :

From: Michael Fawcett (michael.fawcett_at_[hidden])
Date: 2007-10-04 16:15:33


On 10/4/07, Phil Endecott <spam_from_boost_dev_at_[hidden]> wrote:
> Michael Marcin wrote:
> >
> > Have a look at:
> >
> > http://www.gamedev.net/community/forums/topic.asp?topic_id=261920
>
> Yes, a very good page showing several solutions:
>
> 1. A vector of member pointers (may have some overhead).
> 2. Anonymous structs and unions (may be non-standard).
> 3. x, y and z implemented as references (makes object bigger).
> 4. Relying on (&x)[1] pointing to y.

For actual asm output, see
http://www.gamedev.net/community/forums/topic.asp?topic_id=230443&PageSize=25&WhichPage=2

for the "overhead" of option 1.

> _IF_ 4 really is guaranteed to work portably (as its author claims), it
> would get my vote:
>
> template <typename T>
> struct point2d {
> T x, y;
> T& operator[](int i) { return (&x)[i]; }
> };
>
> ...what's the catch?

I'm almost positive the author was wrong in claiming that it is
portable. Here's an old thread about the issue:

http://groups.google.com/group/comp.lang.c++.moderated/browse_frm/thread/df5bc148a994d511/36c133bbb606bece?lnk=gst&q=point+operator%5B%5D+x+y+z&rnum=6#36c133bbb606bece

--Michael Fawcett


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