diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2020-01-09 19:43:23 +0100 |
---|---|---|
committer | Thorsten Behrens <thorsten.behrens@allotropia.de> | 2022-03-04 15:02:50 +0100 |
commit | ddd16156c040a97619929c31a310308688211b95 (patch) | |
tree | e7ddd66445e0e95d5211d053370422d63601c2d5 | |
parent | 8a4e271ab5baec3a7b3d43cab3d13cc7bd34b462 (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
-rw-r--r-- | include/o3tl/safeint.hxx | 8 |
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 |