From 9a94c4a415179377197f02580ea8fbcb0c5ce517 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 17 May 2021 12:51:26 +0200 Subject: Long live qToUnderlying "Cherry-pick" of C++2b's std::to_underlying. [ChangeLog][QtCore][QtGlobal] The qToUnderlying function has been added, to convert an value of enumeration type to its underlying value. Change-Id: Ia46bd8e4496e55174171ac2f0799eacbcca02cf9 Reviewed-by: Thiago Macieira --- tests/auto/corelib/global/qglobal/tst_qglobal.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/auto/corelib/global/qglobal/tst_qglobal.cpp') diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index 5547f832ff..3d8759fba5 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -60,6 +60,7 @@ private slots: void qRoundDoubles_data(); void qRoundDoubles(); void PRImacros(); + void testqToUnderlying(); }; extern "C" { // functions in qglobal.c @@ -698,5 +699,24 @@ void tst_QGlobal::PRImacros() } } +void tst_QGlobal::testqToUnderlying() +{ + enum class E { + E1 = 123, + E2 = 456, + }; + static_assert(std::is_same_v); + QCOMPARE(qToUnderlying(E::E1), 123); + QCOMPARE(qToUnderlying(E::E2), 456); + + enum EE : unsigned long { + EE1 = 123, + EE2 = 456, + }; + static_assert(std::is_same_v); + QCOMPARE(qToUnderlying(EE1), 123UL); + QCOMPARE(qToUnderlying(EE2), 456UL); +} + QTEST_APPLESS_MAIN(tst_QGlobal) #include "tst_qglobal.moc" -- cgit v1.2.3