summaryrefslogtreecommitdiff
path: root/include/o3tl
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-01-09 19:43:23 +0100
committerStephan Bergmann <sbergman@redhat.com>2020-01-09 20:34:01 +0100
commit6417668b3e12d9659ac5dc4a2f60aa8ad3bca675 (patch)
treef5e33e736054c0027d48fc40a207401de6d1e715 /include/o3tl
parent6efffbbfce9c27439f54970f7a569b069ce46eba (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) Change-Id: Id9c68b856a4ee52e5a40d15dc9d83e95d1c231cd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86502 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include/o3tl')
-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 ae28ca4b6570..6d8d1304fdf3 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