summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qglobal.h
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-05-17 12:51:26 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-05-18 02:09:11 +0200
commit9a94c4a415179377197f02580ea8fbcb0c5ce517 (patch)
treeba9cb9bf07668dccd922d9474b008714240d9892 /src/corelib/global/qglobal.h
parent8b8ff64be273d9e74ac64d7efd1d5f6b2c70d362 (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 'src/corelib/global/qglobal.h')
-rw-r--r--src/corelib/global/qglobal.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index 52accb8031..481ee695ca 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -1177,6 +1177,13 @@ constexpr T qExchange(T &t, U &&newValue)
return old;
}
+// like std::to_underlying
+template <typename Enum>
+constexpr std::underlying_type_t<Enum> qToUnderlying(Enum e) noexcept
+{
+ return static_cast<std::underlying_type_t<Enum>>(e);
+}
+
#ifdef __cpp_conditional_explicit
#define Q_IMPLICIT explicit(false)
#else