From: Michael Marcin (mmarcin_at_[hidden])
Date: 2007-10-08 15:20:50


Dave Harris wrote:
> In-Reply-To: <1191527843170_at_[hidden]>
> spam_from_boost_dev_at_[hidden] (Phil Endecott) wrote (abridged):
>>> 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.
>
> It misses this one:
>
> template <typename T>
> class Point3 {
> T v[3];
> public:
> T &operator[]( size_t i ) { return v[i]; }
> T &x() { return v[0]; }
> T &y() { return v[1]; }
> T &z() { return v[2]; }
> };
>

Doesn't work for a T without a default constructor and likely
inefficient for a T with a non-trivial default constructor.

Concepts are the answer, let the user pick what type works best for them.

Thanks,

Michael Marcin