From: Marco Costalba Date: Wed, 28 Dec 2011 23:13:49 +0000 (+0100) Subject: Use for_each() in Endgames d'tor X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=4a8c1b24702ddf577853d72962cee6735a0235da Use for_each() in Endgames d'tor And fix some comments while there. No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/endgame.cpp b/src/endgame.cpp index d2877227..cf38009f 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -17,8 +17,8 @@ along with this program. If not, see . */ -#include #include +#include #include "bitcount.h" #include "endgame.h" @@ -90,6 +90,9 @@ namespace { return Position(fen, false, 0).material_key(); } + template + void delete_endgame(const typename M::value_type& p) { delete p.second; } + } // namespace @@ -119,11 +122,8 @@ Endgames::Endgames() { Endgames::~Endgames() { - for (M1::const_iterator it = m1.begin(); it != m1.end(); ++it) - delete it->second; - - for (M2::const_iterator it = m2.begin(); it != m2.end(); ++it) - delete it->second; + for_each(m1.begin(), m1.end(), delete_endgame); + for_each(m2.begin(), m2.end(), delete_endgame); } template diff --git a/src/endgame.h b/src/endgame.h index ca29c0b9..e350022c 100644 --- a/src/endgame.h +++ b/src/endgame.h @@ -93,9 +93,9 @@ private: /// Endgames class stores in two std::map the pointers to endgame evaluation /// and scaling base objects. Then we use polymorphism to invoke the actual -/// endgame function calling its apply() method that is virtual. +/// endgame function calling its operator() method that is virtual. -struct Endgames { +class Endgames { template struct Map { typedef std::map*> type; }; @@ -103,6 +103,7 @@ struct Endgames { typedef Map::type M1; typedef Map::type M2; +public: Endgames(); ~Endgames(); diff --git a/src/ucioption.cpp b/src/ucioption.cpp index aad801b8..8ea4c5f6 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -38,7 +38,7 @@ bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const /// OptionsMap c'tor initializes the UCI options to their hard coded default -/// values and initializes the default value of "Threads" and "Minimum Split Depth" +/// values and initializes the default value of "Threads" and "Min Split Depth" /// parameters according to the number of CPU cores detected. OptionsMap::OptionsMap() {