15 Jun
2017
15 Jun
'17
8:46 a.m.
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
(storage); } private: std::aligned_storage_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