From 109d1d21fdc425213e54993a75123afb6549ba4d Mon Sep 17 00:00:00 2001 From: Pharap <2933055+Pharap@users.noreply.github.com> Date: Fri, 26 Mar 2021 12:43:15 +0000 Subject: [PATCH] Add postincrement and postdecrement operators (#86) --- src/FixedPoints/SFixedFreeFunctions.h | 20 ++++++++++++++++++++ src/FixedPoints/UFixedFreeFunctions.h | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/FixedPoints/SFixedFreeFunctions.h b/src/FixedPoints/SFixedFreeFunctions.h index fcf8d71..1fc3fe2 100644 --- a/src/FixedPoints/SFixedFreeFunctions.h +++ b/src/FixedPoints/SFixedFreeFunctions.h @@ -28,6 +28,26 @@ constexpr SFixed multiply(const SFixed(static_cast(left.getInternal()) * static_cast(right.getInternal()))); } +// +// Postincrement and Postdecrement +// + +template< unsigned Integer, unsigned Fraction > +SFixed operator ++(SFixed & value, int) +{ + const auto oldValue = value; + ++value; + return oldValue; +} + +template< unsigned Integer, unsigned Fraction > +SFixed operator --(SFixed & value, int) +{ + const auto oldValue = value; + --value; + return oldValue; +} + // // Basic Logic Operations // diff --git a/src/FixedPoints/UFixedFreeFunctions.h b/src/FixedPoints/UFixedFreeFunctions.h index a424bec..0bfca01 100644 --- a/src/FixedPoints/UFixedFreeFunctions.h +++ b/src/FixedPoints/UFixedFreeFunctions.h @@ -28,6 +28,26 @@ constexpr UFixed multiply(const UFixed(static_cast(left.getInternal()) * static_cast(right.getInternal()))); } +// +// Postincrement and Postdecrement +// + +template< unsigned Integer, unsigned Fraction > +UFixed operator ++(UFixed & value, int) +{ + const auto oldValue = value; + ++value; + return oldValue; +} + +template< unsigned Integer, unsigned Fraction > +UFixed operator --(UFixed & value, int) +{ + const auto oldValue = value; + --value; + return oldValue; +} + // // Basic Logic Operations //