diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-11-24 00:00:21 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-11-24 05:30:53 +0100 |
commit | e41024bc9a693164ffc64048046469aaa81a07d4 (patch) | |
tree | 11d599f808095f535f00fb0cb818b25875f517a8 /include | |
parent | ef37f8b9208d7e4f386afbac02cb3efaf283d6e1 (diff) |
Rename o3tl::underlyingEnumValue to o3tl::to_underlying to match C++23
Change-Id: I1597a8e77199445bf377dbe54adc3134bb04fd51
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125748
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/o3tl/typed_flags_set.hxx | 96 | ||||
-rw-r--r-- | include/o3tl/underlyingenumvalue.hxx | 3 |
2 files changed, 50 insertions, 49 deletions
diff --git a/include/o3tl/typed_flags_set.hxx b/include/o3tl/typed_flags_set.hxx index 7c9053bcd4f0..413ee9579d4d 100644 --- a/include/o3tl/typed_flags_set.hxx +++ b/include/o3tl/typed_flags_set.hxx @@ -104,10 +104,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ~(E rhs) { assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(rhs))); + o3tl::to_underlying(rhs))); return static_cast<typename o3tl::typed_flags<E>::Wrap>( o3tl::typed_flags<E>::mask - & ~o3tl::underlyingEnumValue(rhs)); + & ~o3tl::to_underlying(rhs)); } template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ~( @@ -115,7 +115,7 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ~( { return static_cast<typename o3tl::typed_flags<E>::Wrap>( o3tl::typed_flags<E>::mask - & ~o3tl::underlyingEnumValue<E>(rhs)); + & ~o3tl::to_underlying<E>(rhs)); } template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^( @@ -123,13 +123,13 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^( { assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(lhs))); + o3tl::to_underlying(lhs))); assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(rhs))); + o3tl::to_underlying(rhs))); return static_cast<typename o3tl::typed_flags<E>::Wrap>( - o3tl::underlyingEnumValue(lhs) - ^ o3tl::underlyingEnumValue(rhs)); + o3tl::to_underlying(lhs) + ^ o3tl::to_underlying(rhs)); } template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^( @@ -137,10 +137,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^( { assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(lhs))); + o3tl::to_underlying(lhs))); return static_cast<typename o3tl::typed_flags<E>::Wrap>( - o3tl::underlyingEnumValue(lhs) - ^ o3tl::underlyingEnumValue<E>(rhs)); + o3tl::to_underlying(lhs) + ^ o3tl::to_underlying<E>(rhs)); } template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^( @@ -148,10 +148,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^( { assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(rhs))); + o3tl::to_underlying(rhs))); return static_cast<typename o3tl::typed_flags<E>::Wrap>( - o3tl::underlyingEnumValue<E>(lhs) - ^ o3tl::underlyingEnumValue(rhs)); + o3tl::to_underlying<E>(lhs) + ^ o3tl::to_underlying(rhs)); } template<typename W> constexpr @@ -159,21 +159,21 @@ typename o3tl::typed_flags<typename W::Unwrapped::Self>::Wrap operator ^( W lhs, W rhs) { return static_cast<W>( - o3tl::underlyingEnumValue<typename W::Unwrapped::Self>(lhs) - ^ o3tl::underlyingEnumValue<typename W::Unwrapped::Self>(rhs)); + o3tl::to_underlying<typename W::Unwrapped::Self>(lhs) + ^ o3tl::to_underlying<typename W::Unwrapped::Self>(rhs)); } template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator &(E lhs, E rhs) { assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(lhs))); + o3tl::to_underlying(lhs))); assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(rhs))); + o3tl::to_underlying(rhs))); return static_cast<typename o3tl::typed_flags<E>::Wrap>( - o3tl::underlyingEnumValue(lhs) - & o3tl::underlyingEnumValue(rhs)); + o3tl::to_underlying(lhs) + & o3tl::to_underlying(rhs)); } template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator &( @@ -181,10 +181,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator &( { assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(lhs))); + o3tl::to_underlying(lhs))); return static_cast<typename o3tl::typed_flags<E>::Wrap>( - o3tl::underlyingEnumValue(lhs) - & o3tl::underlyingEnumValue<E>(rhs)); + o3tl::to_underlying(lhs) + & o3tl::to_underlying<E>(rhs)); } template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator &( @@ -192,10 +192,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator &( { assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(rhs))); + o3tl::to_underlying(rhs))); return static_cast<typename o3tl::typed_flags<E>::Wrap>( - o3tl::underlyingEnumValue<E>(lhs) - & o3tl::underlyingEnumValue(rhs)); + o3tl::to_underlying<E>(lhs) + & o3tl::to_underlying(rhs)); } template<typename W> constexpr @@ -203,21 +203,21 @@ typename o3tl::typed_flags<typename W::Unwrapped::Self>::Wrap operator &( W lhs, W rhs) { return static_cast<W>( - o3tl::underlyingEnumValue<typename W::Unwrapped::Self>(lhs) - & o3tl::underlyingEnumValue<typename W::Unwrapped::Self>(rhs)); + o3tl::to_underlying<typename W::Unwrapped::Self>(lhs) + & o3tl::to_underlying<typename W::Unwrapped::Self>(rhs)); } template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator |(E lhs, E rhs) { assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(lhs))); + o3tl::to_underlying(lhs))); assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(rhs))); + o3tl::to_underlying(rhs))); return static_cast<typename o3tl::typed_flags<E>::Wrap>( - o3tl::underlyingEnumValue(lhs) - | o3tl::underlyingEnumValue(rhs)); + o3tl::to_underlying(lhs) + | o3tl::to_underlying(rhs)); } template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator |( @@ -225,10 +225,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator |( { assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(lhs))); + o3tl::to_underlying(lhs))); return static_cast<typename o3tl::typed_flags<E>::Wrap>( - o3tl::underlyingEnumValue(lhs) - | o3tl::underlyingEnumValue<E>(rhs)); + o3tl::to_underlying(lhs) + | o3tl::to_underlying<E>(rhs)); } template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator |( @@ -236,10 +236,10 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator |( { assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(rhs))); + o3tl::to_underlying(rhs))); return static_cast<typename o3tl::typed_flags<E>::Wrap>( - o3tl::underlyingEnumValue<E>(lhs) - | o3tl::underlyingEnumValue(rhs)); + o3tl::to_underlying<E>(lhs) + | o3tl::to_underlying(rhs)); } template<typename W> constexpr @@ -247,18 +247,18 @@ typename o3tl::typed_flags<typename W::Unwrapped::Self>::Wrap operator |( W lhs, W rhs) { return static_cast<W>( - o3tl::underlyingEnumValue<typename W::Unwrapped::Self>(lhs) - | o3tl::underlyingEnumValue<typename W::Unwrapped::Self>(rhs)); + o3tl::to_underlying<typename W::Unwrapped::Self>(lhs) + | o3tl::to_underlying<typename W::Unwrapped::Self>(rhs)); } template<typename E> inline typename o3tl::typed_flags<E>::Self operator &=(E & lhs, E rhs) { assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(lhs))); + o3tl::to_underlying(lhs))); assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(rhs))); + o3tl::to_underlying(rhs))); lhs = lhs & rhs; return lhs; } @@ -269,7 +269,7 @@ inline typename o3tl::typed_flags<E>::Self operator &=( { assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(lhs))); + o3tl::to_underlying(lhs))); lhs = lhs & rhs; return lhs; } @@ -278,10 +278,10 @@ template<typename E> inline typename o3tl::typed_flags<E>::Self operator |=(E & lhs, E rhs) { assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(lhs))); + o3tl::to_underlying(lhs))); assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(rhs))); + o3tl::to_underlying(rhs))); lhs = lhs | rhs; return lhs; } @@ -292,7 +292,7 @@ inline typename o3tl::typed_flags<E>::Self operator |=( { assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(lhs))); + o3tl::to_underlying(lhs))); lhs = lhs | rhs; return lhs; } @@ -301,10 +301,10 @@ template<typename E> inline typename o3tl::typed_flags<E>::Self operator ^=(E & lhs, E rhs) { assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(lhs))); + o3tl::to_underlying(lhs))); assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(rhs))); + o3tl::to_underlying(rhs))); lhs = lhs ^ rhs; return lhs; } @@ -315,7 +315,7 @@ inline typename o3tl::typed_flags<E>::Self operator ^=( { assert( o3tl::detail::isNonNegative( - o3tl::underlyingEnumValue(lhs))); + o3tl::to_underlying(lhs))); lhs = lhs ^ rhs; return lhs; } diff --git a/include/o3tl/underlyingenumvalue.hxx b/include/o3tl/underlyingenumvalue.hxx index 1684b2da17d9..a913ab385381 100644 --- a/include/o3tl/underlyingenumvalue.hxx +++ b/include/o3tl/underlyingenumvalue.hxx @@ -16,8 +16,9 @@ namespace o3tl { +// An implementation of C++23 std::to_underlying // For a value e of an enumeration type T, return the corresponding value of T's underlying type: -template <typename T> constexpr std::underlying_type_t<T> underlyingEnumValue(T e) +template <typename T> constexpr std::underlying_type_t<T> to_underlying(T e) { return static_cast<std::underlying_type_t<T>>(e); } |