Can C++20 `constinit` waive the need for nifty counter idiom?

238 views Asked by At

C++20 introduced constinit to avoid static initialization order fiasco.

Can constinit waive the need for the nifty counter idiom (e.g. for initialization of std::cout)?

1

There are 1 answers

3
eerorika On BEST ANSWER

Can C++20 constinit waive the need for nifty counter idiom?

No.

Static initialisation order fiasco is only a problem with dynamic initialisation phase of static objects. Sure, if you don't do dynamic initialisation, then there is no problem, and constinit enforces that. But that doesn't solve anything when you need dynamic initialisation.