Does std::make_shared<POD>()
value initialize my POD?
If yes, is this a guaranteed by the standard?
If no (as I suspect), is there a way to do this? I guess std::make_shared<POD>(POD())
would do but is that what I should be doing?
Yes, it's value intialized, and this is guaranteed by the standard:
§20.7.2.2.6,2: (about make_shared
)
Effects: Allocates memory suitable for an object of type
T
and constructs an object in that memory via the placement new expression::new (pv) T(std::forward<Args>(args)...)
.
And §5.3.4,15:
A new-expression that creates an object of type T initializes that object as follows:
— If the new-initializer is omitted, the object is default-initialized (8.5); if no initialization is performed, the object has indeterminate value.
— Otherwise, the new-initializer is interpreted according to the initialization rules of 8.5 for directinitialization.
So it's direct-initialized as in new POD()
.
§8.5,16:
The semantics of initializers are as follows. [...]
— If the initializer is (), the object is value-initialized.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With