#if !defined(my_map_ptr_h_) #define my_map_ptr_h_ #include template class my_ptr_map { typedef std::map storage_type; public: template struct proxy { proxy(const Key& key, ValueType& value) : first(key), second(value) { } proxy* operator->() { return this; } const Key& first; ValueType& second; }; class iterator { friend my_ptr_map; friend class const_iterator; typename storage_type::iterator i; iterator(typename storage_type::iterator i) : i(i) { } public: proxy operator->() const { return proxy(i->first, *i->second); } proxy operator*() const { return proxy(i->first, *i->second); } }; class const_iterator { friend my_ptr_map; typename storage_type::const_iterator i; const_iterator(typename storage_type::const_iterator i) : i(i) { } public: const_iterator(const iterator &i) : i(i.i) { } proxy operator->() const { return proxy(i->first, *i->second); } proxy operator*() const { return proxy(i->first, *i->second); } }; void insert(Key& k, Value * v) { storage_.insert(std::make_pair(k, v)); } iterator begin() { return iterator(storage_.begin()); } const_iterator begin() const { return const_iterator(storage_.begin()); } private: storage_type storage_; }; #endif