Boost logo

Boost :

Subject: Re: [boost] [optional] layout
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2009-10-28 10:31:55

On Tue, Oct 27, 2009 at 7:13 PM, Domagoj Saric <dsaritz_at_[hidden]> wrote:
> ...because that is what i was whishing for to be extracted from optional<> -
> the placement new/in-place construction + aligned storage + reference
> workarounds&co. wrapped up machinery...
> ...for example:
> 1....
> 2....
> 3....

4. An in-place fast pimpl. see Herb Sutter's for why not to do this. Yet I've done
it anyhow. I templatized it and it probably turns out to be the same
as most of the internals of optional<>. I also managed to mitigate
most of the list of his concerns for why not to do this. Still not
something to do without good reason, but manageable.


// just forward declare CRITICAL_SECTION,
// instead of including <windows.h>
// and polluting everything with its macros:


class CriticalSection // windows version of cross-platform CS
   in_place_pimpl<CRITICAL_SECTION, 16> pCS; // 16 is sizeof(CRITICAL_SECTION)

In the cpp file for CriticalSection, we check that sizeof(pCS) really
is 16, properly aligned, etc.
The in_place_pimpl<> also forwards constructor args, implements operator=, etc.

But it is not just for in_place_pimpl, it is for any time you need
finer control over construction/destruction/storage. In fact, each of
those is a policy to the underlying reinterpret_bytes<> or whatever I
called it.

I probably should have looked at the internals of optional<>, would
have made my life easier...


Boost list run by bdawes at, gregod at, cpdaniel at, john at