|
Boost : |
From: Marcus Lindblom (macke_at_[hidden])
Date: 2006-09-22 16:06:35
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.
But small vector libs is such a matter of taste and convenience, just
like coding style. No solution will please everyone.
/Marcus
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk