qt5base-lts/tests/auto/corelib
Marc Mutz de3e970889 Implement [variant.get] for QVariant [1/2]: get_if()
QVariant supports non-default-constructible payloads, in principle
(QTBUG-105140). And fromValue() works with such types, but value()
insists on providing a wide contract and therefore accidentally
requires default-constructible.

We can now invent other "Qt-ish" API like optional::value_or() or a
value() that returns optional<T>, but we should first get the
interface in that generic code must use, and which at the same time is
the most versatile, because it gives write access to the element
stored in the variant: [variant.get], consisting of get_if(), get(),
and holds_alternative(). The latter is the same as get_if() !=
nullptr, so we won't provide it.

This first patch implements get_if(), adds test for it.

As a Hidden Friend supposed to be called with explicit template
arguments, we run into the problem that wg21.link/P0846 solved for
C++20. Add the usual work-around, and check it works.

The ChangeLog will be on the last patch.

Task-number: QTBUG-111598
Change-Id: I23f57ea2de3946944810c5552c68a7a3060a44f2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-03-24 06:40:11 +01:00
..
animation tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
global tst_qmessagehandler: fix QtTest warnings about duplicate row names 2023-02-23 10:33:39 -08:00
io Corelib: s/Q_OS_MAC/Q_OS_DARWIN/wg except for doc and definition 2023-03-20 19:18:52 +01:00
ipc tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
itemmodels QAbstractItemModel: fix match() with Qt::MatchWildcard 2023-03-09 18:26:59 +01:00
kernel Implement [variant.get] for QVariant [1/2]: get_if() 2023-03-24 06:40:11 +01:00
mimetypes QMimeDatabase: cleanup unittest 2023-03-11 12:39:56 +02:00
platform tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
plugin Corelib: s/Q_OS_MAC/Q_OS_DARWIN/wg except for doc and definition 2023-03-20 19:18:52 +01:00
serialization tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
text Corelib: s/Q_OS_MAC/Q_OS_DARWIN/wg except for doc and definition 2023-03-20 19:18:52 +01:00
thread Corelib: s/Q_OS_MAC/Q_OS_DARWIN/wg except for doc and definition 2023-03-20 19:18:52 +01:00
time Corelib: s/Q_OS_MAC/Q_OS_DARWIN/wg except for doc and definition 2023-03-20 19:18:52 +01:00
tools Short live QT_ENABLE_P0846_SEMANTICS_FOR! 2023-03-22 15:59:10 +00:00
CMakeLists.txt tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00