Y
Hacker News
new
|
ask
|
show
|
jobs
by
cherryteastain
339 days ago
Why not just use constexpr in the second case?
1 comments
kazinator
339 days ago
What if the object is to be mutable?
link
TuxSH
339 days ago
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
link
kazinator
339 days ago
Does that guarantee that the static object is constructed before the first execution of the block?
link
TuxSH
339 days ago
Yes, it will be constructed at compile time. Not everything can be constinit.
link