From 0fc06cc7edfe040f4ccb64b4093a4e0f53ce8569 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Fri, 9 Jun 2023 09:47:24 +0200 Subject: [PATCH] Add increment operators --- include/boost/charconv/detail/emulated128.hpp | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/include/boost/charconv/detail/emulated128.hpp b/include/boost/charconv/detail/emulated128.hpp index 77912b3..8551b6e 100644 --- a/include/boost/charconv/detail/emulated128.hpp +++ b/include/boost/charconv/detail/emulated128.hpp @@ -444,10 +444,16 @@ struct uint128 BOOST_CHARCONV_CXX14_CONSTEXPR uint128 &operator++() noexcept; + BOOST_CHARCONV_CXX14_CONSTEXPR uint128 &operator++(int) noexcept; + BOOST_CHARCONV_CXX14_CONSTEXPR friend uint128 operator-(uint128 lhs, uint128 rhs) noexcept; BOOST_CHARCONV_CXX14_CONSTEXPR uint128 &operator-=(uint128 v) noexcept; + BOOST_CHARCONV_CXX14_CONSTEXPR uint128 &operator--() noexcept; + + BOOST_CHARCONV_CXX14_CONSTEXPR uint128 &operator--(int) noexcept; + inline friend uint128 operator*(uint128 lhs, uint128 rhs) noexcept; inline uint128 &operator*=(uint128 v) noexcept; @@ -601,6 +607,11 @@ BOOST_CHARCONV_CXX14_CONSTEXPR uint128 &uint128::operator++() noexcept return *this; } +BOOST_CHARCONV_CXX14_CONSTEXPR uint128 &uint128::operator++(int) noexcept +{ + return ++(*this); +} + BOOST_CHARCONV_CXX14_CONSTEXPR uint128 operator-(uint128 lhs, uint128 rhs) noexcept { const uint128 temp {lhs.high - rhs.high, lhs.low - rhs.low}; @@ -620,6 +631,26 @@ BOOST_CHARCONV_CXX14_CONSTEXPR uint128 &uint128::operator-=(uint128 v) noexcept return *this; } +BOOST_CHARCONV_CXX14_CONSTEXPR uint128 &uint128::operator--() noexcept +{ + if (this->low == 0) + { + this->low = UINT64_MAX; + --this->high; + } + else + { + --this->low; + } + + return *this; +} + +BOOST_CHARCONV_CXX14_CONSTEXPR uint128 &uint128::operator--(int) noexcept +{ + return --(*this); +} + inline uint128 operator*(uint128 lhs, uint128 rhs) noexcept { #if defined(BOOST_CHARCONV_HAS_MSVC_64BIT_INTRINSICS) @@ -672,7 +703,7 @@ BOOST_CHARCONV_CXX14_CONSTEXPR int high_bit(uint128 v) noexcept // See: https://stackoverflow.com/questions/5386377/division-without-using BOOST_CHARCONV_CXX14_CONSTEXPR void div_impl(uint128 lhs, uint128 rhs, uint128& quotient, uint128& remainder) noexcept { - const uint128 one {0, 1}; + constexpr uint128 one {0, 1}; if (rhs > lhs) {