| 46 | |
| 47 | template <class K, class V> |
| 48 | mapped_type* insert(K&& key, V&& value) { |
| 49 | auto iter = _map.find(key); |
| 50 | if (iter != _map.end()) { |
| 51 | return &iter->second.first; |
| 52 | } |
| 53 | if (size() == capacity()) { |
| 54 | auto i = --_list.end(); |
| 55 | _map.erase(*i); |
| 56 | _list.erase(i); |
| 57 | } |
| 58 | _list.push_front(std::forward<K>(key)); |
| 59 | std::tie(iter, std::ignore) = |
| 60 | _map.insert(std::make_pair(*_list.begin(), std::make_pair(std::forward<V>(value), _list.begin()))); |
| 61 | return &iter->second.first; |
| 62 | } |
| 63 | |
| 64 | private: |
| 65 | const size_type _capacity; |
no test coverage detected