Subject: Re: [boost] [optional] generates unnessesary code for trivial types
From: Domagoj Saric (domagoj.saric_at_[hidden])
Date: 2012-02-02 09:45:37
On 28.1.2012. 13:34, Olaf van der Spek wrote:
> On Fri, Jan 27, 2012 at 5:32 PM, Domagoj Saric
> <domagoj.saric_at_[hidden]> wrote:
>> a) the lifetime management bool was changed into a properly typed pointer
>> actually takes the same amount of space while it provides a no-op
> AFAIK bool and pointer aren't the same size. How can it still take the
> same amount of space?
A "language lawyer" might be more precise but, for optional<T>:
- if the bool member is before the T member the compiler has to add
alignment_of<T>::value - sizeof( bool ) bytes of padding after the bool so that
the T member would be properly aligned
- if the bool member is after the T member the compiler has to add the same
amount of padding after the bool member to satisfy the requirement that there
are no "holes" between individual (properly aligned) instances of optional<T> in
arrays of optional<T>...
IOW, my statement in (a) does not for example hold for chars or shorts...
-- "What Huxley teaches is that in the age of advanced technology, spiritual devastation is more likely to come from an enemy with a smiling face than from one whose countenance exudes suspicion and hate." Neil Postman
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk