[v3] Add constexpr specifiers to std::shared_ptr, std::unique_ptr, etc

Jonathan Wakely jwakely.gcc@gmail.com
Tue Nov 9 23:20:00 GMT 2010


On 9 November 2010 17:25, Benjamin Kosnik wrote:
>
> The only use I see right now for a default-constructed constexpr
> unique_ptr is to have a non-dymamically-initialized check for a "null"
> unique_ptr. So I'm a bit curious about this design decision.

IIUC then a non-const, default-constructed, global unique_ptr should
be statically-initialized because it's ctor is constexpr.

This means I can put:

extern std::unique_ptr<EvilSingleton> global_evil;

in a header, define it in one TU, and avoid the static initialization
order fiasco.   It will be (value) initialized before the program
starts.



More information about the Libstdc++ mailing list