X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Ftypes.h;h=226d76e44d63a3607a8c2e45452871522c2e0460;hp=ec9f9bb97f3a9a688bc6cd5d077579c9ffe3ea07;hb=94b9c65e09b5d396bebb29b62d9979139b5fbdfa;hpb=8e31764c49149cd73cdbfd8a251bb31f068bf799 diff --git a/src/types.h b/src/types.h index ec9f9bb9..226d76e4 100644 --- a/src/types.h +++ b/src/types.h @@ -110,8 +110,10 @@ inline void __cpuid(int CPUInfo[4], int) #endif -// Templetized enum operations, we avoid to repeat the same inlines for each -// different enum. +// Templetized operators used by enum types like Depth, Piece, Square and so on. +// We don't want to write the same inline for each different enum. Note that we +// pass by value (to silence scaring warnings on volatiles), so you really should +// use only enum types with these functions to avoid hidden copies. template inline T operator+ (const T d1, const T d2) { return T(int(d1) + int(d2)); } @@ -120,7 +122,10 @@ template inline T operator- (const T d1, const T d2) { return T(int(d1) - int(d2)); } template -inline T operator* (int i, const T d) { return T(int(d) * i); } +inline T operator* (int i, const T d) { return T(i * int(d)); } + +template +inline T operator* (const T d, int i) { return T(int(d) * i); } template inline T operator/ (const T d, int i) { return T(int(d) / i); } @@ -137,10 +142,13 @@ inline void operator-- (T& d, int) { d = T(int(d) - 1); } template inline void operator+= (T& d1, const T d2) { d1 = d1 + d2; } +template +inline void operator-= (T& d1, const T d2) { d1 = d1 - d2; } + template inline void operator*= (T& d, int i) { d = T(int(d) * i); } template -inline void operator/= (T &d, int i) { d = T(int(d) / i); } +inline void operator/= (T& d, int i) { d = T(int(d) / i); } #endif // !defined(TYPES_H_INCLUDED)