From: Marco Costalba Date: Wed, 18 Aug 2010 16:04:38 +0000 (+0100) Subject: Use Use templetized operations for Score and Value X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=0e800c527a9773ab986e185dae291695a4ca83ee Use Use templetized operations for Score and Value Note that in value we leave two specialized functions to allow adding an integer, we don't want to add this as a template becasue we want to control implicit conversions to integer of an enum. No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/types.h b/src/types.h index ec9f9bb9..d81e7e80 100644 --- a/src/types.h +++ b/src/types.h @@ -137,6 +137,9 @@ 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); } diff --git a/src/value.h b/src/value.h index a0cd066f..512cc2f9 100644 --- a/src/value.h +++ b/src/value.h @@ -81,13 +81,6 @@ inline Value eg_value(Score s) { return Value((int)(unsigned(s) & 0x7fffu) - (in inline Score make_score(int mg, int eg) { return Score((mg << 16) + eg); } -inline Score operator-(Score s) { return Score(-int(s)); } -inline Score operator+(Score s1, Score s2) { return Score(int(s1) + int(s2)); } -inline Score operator-(Score s1, Score s2) { return Score(int(s1) - int(s2)); } -inline void operator+=(Score& s1, Score s2) { s1 = Score(int(s1) + int(s2)); } -inline void operator-=(Score& s1, Score s2) { s1 = Score(int(s1) - int(s2)); } -inline Score operator*(int i, Score s) { return Score(i * int(s)); } - // Division must be handled separately for each term inline Score operator/(Score s, int i) { return make_score(mg_value(s) / i, eg_value(s) / i); } @@ -149,29 +142,15 @@ const Score TempoValue = make_score(48, 22); //// inline Value operator+ (Value v, int i) { return Value(int(v) + i); } -inline Value operator+ (Value v1, Value v2) { return Value(int(v1) + int(v2)); } -inline void operator+= (Value &v1, Value v2) { - v1 = Value(int(v1) + int(v2)); -} inline Value operator- (Value v, int i) { return Value(int(v) - i); } -inline Value operator- (Value v) { return Value(-int(v)); } -inline Value operator- (Value v1, Value v2) { return Value(int(v1) - int(v2)); } -inline void operator-= (Value &v1, Value v2) { - v1 = Value(int(v1) - int(v2)); -} -inline Value operator* (Value v, int i) { return Value(int(v) * i); } -inline void operator*= (Value &v, int i) { v = Value(int(v) * i); } -inline Value operator* (int i, Value v) { return Value(int(v) * i); } -inline Value operator/ (Value v, int i) { return Value(int(v) / i); } -inline void operator/= (Value &v, int i) { v = Value(int(v) / i); } inline Value value_mate_in(int ply) { - return Value(VALUE_MATE - Value(ply)); + return VALUE_MATE - ply; } inline Value value_mated_in(int ply) { - return Value(-VALUE_MATE + Value(ply)); + return -VALUE_MATE + ply; } inline bool is_upper_bound(ValueType vt) {