]> git.sesse.net Git - stockfish/commitdiff
Use for_each() in Endgames d'tor
authorMarco Costalba <mcostalba@gmail.com>
Wed, 28 Dec 2011 23:13:49 +0000 (00:13 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Thu, 29 Dec 2011 09:25:11 +0000 (10:25 +0100)
And fix some comments while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/endgame.cpp
src/endgame.h
src/ucioption.cpp

index d28772277f2f65af11451e2c6b3c203ee8774fa4..cf38009fa2a0f16baf69d017581c38d339085bcd 100644 (file)
@@ -17,8 +17,8 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <cassert>
 #include <algorithm>
+#include <cassert>
 
 #include "bitcount.h"
 #include "endgame.h"
@@ -90,6 +90,9 @@ namespace {
     return Position(fen, false, 0).material_key();
   }
 
+  template<typename M>
+  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<M1>);
+  for_each(m2.begin(), m2.end(), delete_endgame<M2>);
 }
 
 template<EndgameType E>
index ca29c0b9d5cf46e2ea9c039675da665498bef849..e350022cce7351178333bf9ee11dc2b0ee175a2a 100644 (file)
@@ -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<typename T>
   struct Map { typedef std::map<Key, EndgameBase<T>*> type; };
@@ -103,6 +103,7 @@ struct Endgames {
   typedef Map<Value>::type M1;
   typedef Map<ScaleFactor>::type M2;
 
+public:
   Endgames();
   ~Endgames();
 
index aad801b89e20238dfa79248076d0edffae188364..8ea4c5f62b3f2d45a47b1a33dbc0a624a318c9d9 100644 (file)
@@ -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() {