From: Marco Costalba Date: Wed, 18 Aug 2010 15:40:26 +0000 (+0100) Subject: Use templetized operations for Square X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=8e31764c49149cd73cdbfd8a251bb31f068bf799;p=fairystockfish.git Use templetized operations for Square This is tricky because there are some special binary fnctions with SquareDelta that we should leave as they are. Also note that we needed to add Unary minus template to fix a comile error in SERIALIZE_MOVES_D macro that was triggered because now we don't allow conversion to int. No fuctional change. Signed-off-by: Marco Costalba --- diff --git a/src/square.h b/src/square.h index 8de3f55..d539e00 100644 --- a/src/square.h +++ b/src/square.h @@ -77,20 +77,10 @@ const int FlopMask = 07; //// Inline functions //// -inline Square operator+ (Square x, int i) { return Square(int(x) + i); } -inline void operator++ (Square &x, int) { x = Square(int(x) + 1); } -inline void operator+= (Square &x, int i) { x = Square(int(x) + i); } -inline Square operator- (Square x, int i) { return Square(int(x) - i); } -inline void operator-- (Square &x, int) { x = Square(int(x) - 1); } -inline void operator-= (Square &x, int i) { x = Square(int(x) - i); } -inline Square operator+ (Square x, SquareDelta i) { return Square(int(x) + i); } -inline void operator+= (Square &x, SquareDelta i) { x = Square(int(x) + i); } -inline Square operator- (Square x, SquareDelta i) { return Square(int(x) - i); } -inline void operator-= (Square &x, SquareDelta i) { x = Square(int(x) - i); } - -inline SquareDelta operator- (Square x, Square y) { - return SquareDelta(int(x) - int(y)); -} +inline Square operator+ (Square x, SquareDelta i) { return x + Square(i); } +inline void operator+= (Square& x, SquareDelta i) { x = x + Square(i); } +inline Square operator- (Square x, SquareDelta i) { return x - Square(i); } +inline void operator-= (Square& x, SquareDelta i) { x = x - Square(i); } inline Square make_square(File f, Rank r) { return Square(int(f) | (int(r) << 3)); diff --git a/src/types.h b/src/types.h index f018311..ec9f9bb 100644 --- a/src/types.h +++ b/src/types.h @@ -126,6 +126,9 @@ template inline T operator/ (const T d, int i) { return T(int(d) / i); } template +inline T operator- (const T d) { return T(-int(d)); } + +template inline void operator++ (T& d, int) { d = T(int(d) + 1); } template