diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2021-05-17 12:51:26 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2021-05-18 02:09:11 +0200 |
commit | 9a94c4a415179377197f02580ea8fbcb0c5ce517 (patch) | |
tree | ba9cb9bf07668dccd922d9474b008714240d9892 /tests/auto/corelib/global | |
parent | 8b8ff64be273d9e74ac64d7efd1d5f6b2c70d362 (diff) |
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 <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/global')
-rw-r--r-- | tests/auto/corelib/global/qglobal/tst_qglobal.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
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<decltype(qToUnderlying(E::E1)), int>); + QCOMPARE(qToUnderlying(E::E1), 123); + QCOMPARE(qToUnderlying(E::E2), 456); + + enum EE : unsigned long { + EE1 = 123, + EE2 = 456, + }; + static_assert(std::is_same_v<decltype(qToUnderlying(EE1)), unsigned long>); + QCOMPARE(qToUnderlying(EE1), 123UL); + QCOMPARE(qToUnderlying(EE2), 456UL); +} + QTEST_APPLESS_MAIN(tst_QGlobal) #include "tst_qglobal.moc" |