X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Ftypes.h;h=d81e7e80a33f3c391c9bf530996a3a61c2d40e71;hp=0c12d930490bb6c4516c817fe2950d67f4c45ec7;hb=0e800c527a9773ab986e185dae291695a4ca83ee;hpb=85559cc5972f93a2e7618d29b4b2cdcb79c55f98 diff --git a/src/types.h b/src/types.h index 0c12d930..d81e7e80 100644 --- a/src/types.h +++ b/src/types.h @@ -109,4 +109,41 @@ inline void __cpuid(int CPUInfo[4], int) } #endif + +// Templetized enum operations, we avoid to repeat the same inlines for each +// different enum. + +template +inline T operator+ (const T d1, const T d2) { return T(int(d1) + int(d2)); } + +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); } + +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 +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); } + #endif // !defined(TYPES_H_INCLUDED)