+Endgames::~Endgames() {
+
+ for (EFMap::const_iterator it = map<Value>().begin(); it != map<Value>().end(); ++it)
+ delete it->second;
+
+ for (SFMap::const_iterator it = map<ScaleFactor>().begin(); it != map<ScaleFactor>().end(); ++it)
+ delete it->second;
+}
+
+template<EndgameType E>
+void Endgames::add(const string& keyCode) {
+
+ typedef typename eg_family<E>::type T;
+ typedef typename EMap<T>::type M;
+
+ const_cast<M&>(map<T>()).insert(std::make_pair(mat_key(keyCode), new Endgame<E>(WHITE)));
+ const_cast<M&>(map<T>()).insert(std::make_pair(mat_key(swap_colors(keyCode)), new Endgame<E>(BLACK)));
+}
+
+template<typename T>
+EndgameBase<T>* Endgames::get(Key key) const {
+
+ typename EMap<T>::type::const_iterator it = map<T>().find(key);
+ return it != map<T>().end() ? it->second : NULL;
+}
+
+// Explicit template instantiations
+template EndgameBase<Value>* Endgames::get<Value>(Key key) const;
+template EndgameBase<ScaleFactor>* Endgames::get<ScaleFactor>(Key key) const;
+