Skip to content

Commit 109d1d2

Browse files
authored
Add postincrement and postdecrement operators (#86)
1 parent d8c2300 commit 109d1d2

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/FixedPoints/SFixedFreeFunctions.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ constexpr SFixed<Integer * 2, Fraction * 2> multiply(const SFixed<Integer, Fract
2828
return ResultType::fromInternal(static_cast<InternalType>(static_cast<InternalType>(left.getInternal()) * static_cast<InternalType>(right.getInternal())));
2929
}
3030

31+
//
32+
// Postincrement and Postdecrement
33+
//
34+
35+
template< unsigned Integer, unsigned Fraction >
36+
SFixed<Integer, Fraction> operator ++(SFixed<Integer, Fraction> & value, int)
37+
{
38+
const auto oldValue = value;
39+
++value;
40+
return oldValue;
41+
}
42+
43+
template< unsigned Integer, unsigned Fraction >
44+
SFixed<Integer, Fraction> operator --(SFixed<Integer, Fraction> & value, int)
45+
{
46+
const auto oldValue = value;
47+
--value;
48+
return oldValue;
49+
}
50+
3151
//
3252
// Basic Logic Operations
3353
//

src/FixedPoints/UFixedFreeFunctions.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ constexpr UFixed<Integer * 2, Fraction * 2> multiply(const UFixed<Integer, Fract
2828
return ResultType::fromInternal(static_cast<InternalType>(static_cast<InternalType>(left.getInternal()) * static_cast<InternalType>(right.getInternal())));
2929
}
3030

31+
//
32+
// Postincrement and Postdecrement
33+
//
34+
35+
template< unsigned Integer, unsigned Fraction >
36+
UFixed<Integer, Fraction> operator ++(UFixed<Integer, Fraction> & value, int)
37+
{
38+
const auto oldValue = value;
39+
++value;
40+
return oldValue;
41+
}
42+
43+
template< unsigned Integer, unsigned Fraction >
44+
UFixed<Integer, Fraction> operator --(UFixed<Integer, Fraction> & value, int)
45+
{
46+
const auto oldValue = value;
47+
--value;
48+
return oldValue;
49+
}
50+
3151
//
3252
// Basic Logic Operations
3353
//

0 commit comments

Comments
 (0)