Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-104153

Impact of C++20 designated initializers on our code

XMLWordPrintable

    • Icon: Epic Epic
    • Resolution: Unresolved
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • None
    • Core: Other
    • None
    • C++20 designated initializers @ Qt

      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.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            cnn Qt Core & Network
            mmutz Marc Mutz
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes