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

Impact of C++20 explicit(bool) on our code

    XMLWordPrintable

Details

    • Epic
    • Resolution: Unresolved
    • P2: Important
    • None
    • None
    • Core: Other
    • None
    • C++20 explicit(bool) @ Qt

    Description

      C++20 added support for an optional argument to explicit, similar to noexcept, which can evaluate to true or false.

      This is mainly useful in implementation of wrapper types such as pair, tuple, variant and optional to "copy" the explicit'ness of the wapped-type's constructors to the wrapper's constructors.

      There are two immediate effects:

      1. you can use explicit(false) as a moniker for /* implicit */, and, indeed, we already have Q_IMPLICIT, which does exactly that, which leads to the obvious coding rule that each ctor you define should be either explicit or Q_IMPLICIT.
      2. it should prompt us to inspect our own wrapper types (do we have any?) for consistent explicit copying. The effect of explicit(bool) can be emulated in C++17 by defining the same ctor twice, one with explicit and once without and SFINAE'ing out one or the other, depending on the same condition you'd put into explicit(bool).

      Both of these can be done already.

      Attachments

        Issue Links

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

          Activity

            People

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

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes