|
Boost : |
From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2007-10-07 15:11:52
François Duranleau wrote:
> On Sun, 7 Oct 2007, Dave Harris wrote:
>
>> 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]; }
>> };
>>
>> which in my view is the only way to fly. It has no run-time overhead
>> (provided the trivial functions are inlined). It does not rely on
>> non-standard or non-portable features. It's simple and easy to
>> understand. It has the added benefit that the underlying
>> representation is kept private, and all access done via member
>> functions.
>>
>> The main drawback is the extra brackets.
>> cout << p.x();
>>
>> rather than:
>> cout << p.x;
>>
>> Which is a pain, but I think the benefits are worth it.
>
> I was beginning to wonder when finally someone would bring this one. I
> totally agree that this is the best option, and I personnaly don't
> understand what is the big fuss about adding the extra parenthesis.
>
FWIW I also totally agree with you both. On both accounts.
Fernando Cacciola
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk