Mercurial > hg > openttd
changeset 7838:13bb961dbc1b draft
(svn r11388) -Fix: postfix ++ returned new value, should (ofcourse) be old value (SmatZ)
-Fix: prefix ++ didn't exist, added it
author | truelight <truelight@openttd.org> |
---|---|
date | Wed, 07 Nov 2007 14:33:52 +0000 |
parents | f8e3e46dfbc4 |
children | dc96989488d7 |
files | src/helpers.hpp |
diffstat | 1 files changed, 13 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/helpers.hpp +++ b/src/helpers.hpp @@ -136,7 +136,15 @@ } /** postfix ++ operator on tiny type */ - FORCEINLINE TinyEnumT& operator ++ (int) + FORCEINLINE TinyEnumT operator ++ (int) + { + TinyEnumT org = *this; + if (++m_val >= end) m_val -= (storage_type)(end - begin); + return org; + } + + /** prefix ++ operator on tiny type */ + FORCEINLINE TinyEnumT& operator ++ () { if (++m_val >= end) m_val -= (storage_type)(end - begin); return *this; @@ -208,8 +216,10 @@ FORCEINLINE OverflowSafeInt operator - (const int other) const { OverflowSafeInt result = *this; result -= (int64)other; return result; } FORCEINLINE OverflowSafeInt operator - (const uint other) const { OverflowSafeInt result = *this; result -= (int64)other; return result; } - FORCEINLINE OverflowSafeInt& operator ++ (int) { return *this += 1; } - FORCEINLINE OverflowSafeInt& operator -- (int) { return *this += -1; } + FORCEINLINE OverflowSafeInt& operator ++ () { return *this += 1; } + FORCEINLINE OverflowSafeInt& operator -- () { return *this += -1; } + FORCEINLINE OverflowSafeInt operator ++ (int) { OverflowSafeInt org = *this; *this += 1; return org; } + FORCEINLINE OverflowSafeInt operator -- (int) { OverflowSafeInt org = *this; *this += -1; return org; } /** * Safe implementation of multiplication.