Hacker News new | ask | show | jobs
by cherryteastain 339 days ago
Why not just use constexpr in the second case?
1 comments

What if the object is to be mutable?
You use constinit. But this means constexpr constructor (easy with 2-phase init, not too much of a problem for singleton objects), and trivial destruction
Does that guarantee that the static object is constructed before the first execution of the block?
Yes, it will be constructed at compile time. Not everything can be constinit.