2 ms·
> though as of C++20 we now have C99's designated initializers C++20 only supports a thin imitation of C99's designated initializers. In C99 you can a) mix def
by wahern 6y ago
> though as of C++20 we now have C99's designated initializers
C++20 only supports a thin imitation of C99's designated initializers. In C99 you can a) mix definition forms (designated and non-designated), b) define members out of order, and c) override earlier definitions. C++20 doesn't support any of these. I've often relied on a and c in initializer macros that provide default, non-0 values that can be overridden (using vararg parameters) by the user, but many might see that as unclean. The lack of b, however, significantly diminishes the value of designated initializers: by reordering struct members you invalidate all uses of designated initializers for that type in C++20, which means they're useless to minimize the burden of refactoring.
Also, C++20 doesn't permit designated array initializers, which I've found very useful for arrays that map, e.g., enums to strings.