summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
48e39c5)
Push the template pedal a bit in our "showoff" endgame code ;-)
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
return Position(fen, false, 0).get_material_key();
}
return Position(fen, false, 0).get_material_key();
}
- typedef EndgameBase<Value> EF;
- typedef EndgameBase<ScaleFactor> SF;
+ typedef Endgames::EMap<Value>::type EFMap;
+ typedef Endgames::EMap<ScaleFactor>::type SFMap;
} // namespace
/// Endgames member definitions
} // namespace
/// Endgames member definitions
-template<> const Endgames::EFMap& Endgames::map<EF>() const { return maps.first; }
-template<> const Endgames::SFMap& Endgames::map<SF>() const { return maps.second; }
+template<> const EFMap& Endgames::map<Value>() const { return maps.first; }
+template<> const SFMap& Endgames::map<ScaleFactor>() const { return maps.second; }
- for (EFMap::const_iterator it = map<EF>().begin(); it != map<EF>().end(); ++it)
+ for (EFMap::const_iterator it = map<Value>().begin(); it != map<Value>().end(); ++it)
- for (SFMap::const_iterator it = map<SF>().begin(); it != map<SF>().end(); ++it)
+ for (SFMap::const_iterator it = map<ScaleFactor>().begin(); it != map<ScaleFactor>().end(); ++it)
typedef Endgame<T, E> EG;
typedef typename EG::Base B;
typedef Endgame<T, E> EG;
typedef typename EG::Base B;
- typedef std::map<Key, B*> M;
+ typedef typename EMap<T>::type M;
- const_cast<M&>(map<B>()).insert(std::pair<Key, B*>(mat_key(keyCode), new EG(WHITE)));
- const_cast<M&>(map<B>()).insert(std::pair<Key, B*>(mat_key(swap_colors(keyCode)), new EG(BLACK)));
+ const_cast<M&>(map<T>()).insert(std::pair<Key, B*>(mat_key(keyCode), new EG(WHITE)));
+ const_cast<M&>(map<T>()).insert(std::pair<Key, B*>(mat_key(swap_colors(keyCode)), new EG(BLACK)));
}
template<typename T>
EndgameBase<T>* Endgames::get(Key key) const {
}
template<typename T>
EndgameBase<T>* Endgames::get(Key key) const {
- typedef EndgameBase<T> E;
- typename std::map<Key, E*>::const_iterator it = map<E>().find(key);
- return it != map<E>().end() ? it->second : NULL;
+ typename EMap<T>::type::const_iterator it = map<T>().find(key);
+ return it != map<T>().end() ? it->second : NULL;
}
// Explicit template instantiations
}
// Explicit template instantiations
-template EF* Endgames::get<Value>(Key key) const;
-template SF* Endgames::get<ScaleFactor>(Key key) const;
+template EndgameBase<Value>* Endgames::get<Value>(Key key) const;
+template EndgameBase<ScaleFactor>* Endgames::get<ScaleFactor>(Key key) const;
/// Mate with KX vs K. This function is used to evaluate positions with
/// Mate with KX vs K. This function is used to evaluate positions with
/// and scaling base objects. Then we use polymorphism to invoke the actual
/// endgame function calling its apply() method that is virtual.
/// and scaling base objects. Then we use polymorphism to invoke the actual
/// endgame function calling its apply() method that is virtual.
- typedef std::map<Key, EndgameBase<Value>* > EFMap;
- typedef std::map<Key, EndgameBase<ScaleFactor>* > SFMap;
+ template<typename T>
+ struct EMap { typedef std::map<Key, EndgameBase<T>*> type; };
Endgames();
~Endgames();
template<typename T> EndgameBase<T>* get(Key key) const;
Endgames();
~Endgames();
template<typename T> EndgameBase<T>* get(Key key) const;
template<typename T, EndgameType E> void add(const std::string& keyCode);
// Here we store two maps, for evaluate and scaling functions...
template<typename T, EndgameType E> void add(const std::string& keyCode);
// Here we store two maps, for evaluate and scaling functions...
- std::pair<EFMap, SFMap> maps;
+ std::pair<EMap<Value>::type, EMap<ScaleFactor>::type> maps;
// ...and here is the accessing template function
// ...and here is the accessing template function
- template<typename T> const std::map<Key, T*>& map() const;
+ template<typename T> const typename EMap<T>::type& map() const;
};
#endif // !defined(ENDGAME_H_INCLUDED)
};
#endif // !defined(ENDGAME_H_INCLUDED)