From 470369a871791b610e0c42212558e83baeb83409 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 17 Dec 2018 00:20:19 -0500 Subject: [PATCH] [array] Add arithmetic operators --- src/hb-array.hh | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/hb-array.hh b/src/hb-array.hh index ae8d2d794..959f10307 100644 --- a/src/hb-array.hh +++ b/src/hb-array.hh @@ -60,12 +60,9 @@ struct hb_array_t } explicit_operator bool (void) const { return len; } - - template operator T * (void) const { return arrayZ; } - Type * operator & (void) const { return arrayZ; } - Type & operator * (void) { return (this->operator [])[0]; } + template operator T * (void) const { return arrayZ; } hb_array_t & operator += (unsigned int count) { @@ -75,6 +72,23 @@ struct hb_array_t arrayZ += count; return *this; } + hb_array_t & operator -= (unsigned int count) + { + if (unlikely (count > len)) + count = len; + len -= count; + return *this; + } + hb_array_t & operator ++ (void) { *this += 1; } + hb_array_t & operator -- (void) { *this -= 1; } + hb_array_t operator + (unsigned int count) + { hb_array_t copy (*this); *this += count; return copy; } + hb_array_t operator - (unsigned int count) + { hb_array_t copy (*this); *this -= count; return copy; } + hb_array_t operator ++ (int) + { hb_array_t copy (*this); ++*this; return copy; } + hb_array_t operator -- (int) + { hb_array_t copy (*this); --*this; return copy; } /* * Compare, Sort, and Search.