Details
-
Epic
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
None
-
None
-
C++20 designated initializers @ Qt
Description
C++20 added support for C99 designated initializers (https://en.cppreference.com/w/cpp/language/aggregate_initialization#Designated_initializers).
Once we can depend on C++20, I expect more classes to become simple structs as a result of this change, CTAD for aggregates (QTBUG-104152) and __cpp_aggregate_paren_init (QTBUG-104154).
In particular, this feature enables a different kind of constructor for our property-based classes:
auto sl = new QSlider({.range={0, 100}, .value=50, .orientation=Qt::Vertical});
Whether we want to go there remains to be seen, particularly because, while you can omit fields, the ones you do specify, you need to provide in declaration order (think ctor-init-list in constructors).
One noteworthy thing is that it seems most compilers already support this feature (by way of it being C99) in C++17 (e.g. QtWayland uses it in quite some places for quite some time, incl., IIRC, in Qt 5). Looks like it's only MSVC which requires /std:latest or /std:c++20 for this, so this might be one of the first C++20 features we can actually rely on.
Attachments
Issue Links
- is required for
-
QTBUG-99243 Initiative: Qt and C++20
- Open
-
QTBUG-109361 C++20 is required for the development and building of Qt itself (Phase II)
- Open
- relates to
-
QTBUG-104152 Impact of C++20 CTAD on our code
- Open
-
QTBUG-104154 Impact of C++20 aggregate init with parentheses on our code
- Open