#pragma once #include "RBTree.hpp" namespace Lenyiin { template class Map { struct MapKeyOfT { const K &operator()(const std::pair &kv) { return kv.first; } }; public: typedef typename RBTree, MapKeyOfT>::iterator iterator; typedef typename RBTree, MapKeyOfT>::const_iterator const_iterator; iterator begin() { return _tree.begin(); } iterator end() { return _tree.end(); } const_iterator begin() const { return _tree.begin(); } const_iterator end() const { return _tree.end(); } std::pair Insert(const std::pair &kv) { return _tree.Insert(kv); } bool Erase(const K &key) { return _tree.Erase(key); } V &operator[](const K &key) { std::pair ret = _tree.Insert(std::make_pair(key, V())); return ret.first->second; } bool IsRBTree() { return _tree.IsRBTree(); } private: RBTree, MapKeyOfT> _tree; }; }