
Dave Harris wrote:
In-Reply-To: <1191527843170@dmwebmail.japan.chezphil.org> spam_from_boost_dev@chezphil.org (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