summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-01-09 19:43:23 +0100
committerMichael Stahl <michael.stahl@allotropia.de>2022-03-03 13:38:05 +0100
commita4f877d1d42dd8bb2c9fe50d1fbdbbbe15a160b8 (patch)
tree7bfa35efd89c95b9ebfb96d9be100f0bfeb62a72 /include
parent38b0f36eef3a48a2b1ecbca91cb8fc396e2e4ad3 (diff)
Introduce o3tl::make_unsigned to cast from signed to unsigned type
...without having to spell out a specific type to cast to (and also making it more obvious what the intend of such a cast is) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86502 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com> (cherry picked from commit 6417668b3e12d9659ac5dc4a2f60aa8ad3bca675) Change-Id: Id9c68b856a4ee52e5a40d15dc9d83e95d1c231cd
Diffstat (limited to 'include')
-rw-r--r--include/o3tl/safeint.hxx8
1 files changed, 8 insertions, 0 deletions
diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx
index fa08b6dfc899..b65b93e0a541 100644
--- a/include/o3tl/safeint.hxx
+++ b/include/o3tl/safeint.hxx
@@ -12,6 +12,7 @@
#include <sal/config.h>
+#include <cassert>
#include <limits>
#include <type_traits>
@@ -226,6 +227,13 @@ template<typename T> inline typename std::enable_if<std::is_unsigned<T>::value,
#endif
+template<typename T> constexpr std::enable_if_t<std::is_signed_v<T>, std::make_unsigned_t<T>>
+make_unsigned(T value)
+{
+ assert(value >= 0);
+ return value;
+}
+
}
#endif