Boost logo

Boost :

Subject: Re: [boost] AllocatorAwareContainers
From: Joaquin M López Muñoz (joaquinlopezmunoz_at_[hidden])
Date: 2017-06-15 08:46:23


El 15/06/2017 a las 10:17, Gavin Lambert via Boost escribió:
> [...]
>
> Granted it's easy enough to make this safe once you're aware of it,
> but it seems like a way-too-easy trap to fall into. eg. this would be
> a "safe" node:
>
> struct node
> {
> explicit node(node* n = nullptr) : next(n) {}
>
> node* next;
> T& value() { return reinterpret_cast<T&>(storage); }
>
> private:
> std::aligned_storage_t<sizeof(T), alignof(T)> storage;
> };
>
> But of course now it's not a POD.

It's not a POD, but it has a trvial default ctor. My reading of 3.8
Object lifetime [basic.life]
implies that you can omit construction and begin using a just-allocated
object when
its default ctor is trivial. Maybe some language lawyer can shed some
light here.

Joaquín M López Muñoz


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk