X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fendgame.h;h=7ff70373752fe85264caa2b82c14270b97ed403b;hb=3c07603dac03f0da20194097cf4eb1a396fea60d;hp=8a42eda29d1393891415af23f2e22d919c316955;hpb=c73f33f37e56048f4e137dd5e5118367eb072a05;p=stockfish diff --git a/src/endgame.h b/src/endgame.h index 8a42eda2..7ff70373 100644 --- a/src/endgame.h +++ b/src/endgame.h @@ -21,7 +21,10 @@ #define ENDGAME_H_INCLUDED #include +#include #include +#include +#include #include "position.h" #include "types.h" @@ -63,11 +66,9 @@ enum EndgameType { /// Endgame functions can be of two types depending on whether they return a -/// Value or a ScaleFactor. Type eg_fun::type returns either ScaleFactor -/// or Value depending on whether the template parameter is 0 or 1. - -template struct eg_fun { typedef Value type; }; -template<> struct eg_fun<1> { typedef ScaleFactor type; }; +/// Value or a ScaleFactor. +template +using eg_fun = std::conditional<(E < SCALING_FUNCTIONS), Value, ScaleFactor>; /// Base and derived templates for endgame evaluation and scaling functions @@ -81,7 +82,7 @@ struct EndgameBase { }; -template SCALING_FUNCTIONS)>::type> +template::type> struct Endgame : public EndgameBase { explicit Endgame(Color c) : strongSide(c), weakSide(~c) {} @@ -99,24 +100,21 @@ private: class Endgames { - typedef std::map::type>*> M1; - typedef std::map::type>*> M2; + template using Map = std::map>; - M1 m1; - M2 m2; + template::type>> + void add(const std::string& code); - M1& map(M1::mapped_type) { return m1; } - M2& map(M2::mapped_type) { return m2; } + template>::value> + Map& map() { return std::get(maps); } - template void add(const std::string& code); + std::pair>, Map>> maps; public: Endgames(); - ~Endgames(); - template T probe(Key key, T& eg) { - return eg = map(eg).count(key) ? map(eg)[key] : NULL; - } + template T* probe(Key key, T** eg) + { return *eg = map().count(key) ? map()[key].get() : nullptr; } }; #endif // #ifndef ENDGAME_H_INCLUDED