#include #include #include #include // insert [] at template class vecMap { std::vector> container; public: Value at(const Key &key) { for(std::pair p : container){ if(p.first == key) return p.second; } // throw exception throw } // U& operator[](T key) { // auto it = find(v_key.begin(), v_key.end(), key); // if (it != v_key.end()) { // int index = it - v_key.begin(); // return v_value[index]; // } // v_key.push_back(key); // v_value.push_back(default_value); // return v_value.back(); // } Value &operator[](Key &key){ for(std::pair p : container){ if(p.first == key) return p.second; } container.push_back(std::make_pair(key, 0)); return container.back().second; } void insert(Key k, Value v){ container.push_back(std::make_pair(k, v)); } }; int main(){ vecMap map; map.insert(1,'a'); map[1] = 'e'; std::cout << map[1]; map.at(2); }