Samchon Framework for CPP  1.0.0
Map.hpp
1 #pragma once
2 
3 #include <map>
4 
5 namespace samchon
6 {
87  template <typename _Kty, typename _Ty, typename _Pr = std::less<_Kty>, typename _Alloc = std::allocator<std::pair<const _Kty, _Ty>>>
88  class Map
89  : public std::map<_Kty, _Ty, _Pr, _Alloc>
90  {
91  private:
92  typedef std::map<_Kty, _Ty, _Pr, _Alloc> super;
93 
94  //PROHIBIT ACCESS TO AT
95  auto at(const _Kty &) -> _Ty& = delete;
96  auto at(const _Kty &) const -> const _Ty& = delete;
97 
98  public:
99  using super::super;
100 
110  auto has(const _Kty &key) const -> bool
111  {
112  return count(key) != 0;
113  };
114 
129  auto get(const _Kty &key) -> _Ty&
130  {
131  return find(key)->second;
132  };
133  auto get(const _Kty &key) const -> const _Ty&
134  {
135  return find(key)->second;
136  };
137 
150  void set(const _Kty &key, const _Ty &val)
151  {
152  iterator it = find(key);
153  if (it != end())
154  erase(it);
155 
156  insert({ key, val });
157  };
158  void set(const _Kty &key, const _Ty &&val)
159  {
160  iterator it = find(key);
161  if (it != end())
162  erase(it);
163 
164  insert({ key, val });
165  };
166 
173  auto pop(const _Kty &key) -> _Ty
174  {
175  iterator it = find(key);
176  _Ty val = it->second;
177 
178  erase(it);
179 
180  return std::move(val);
181  };
182  };
183 };
Customized std::map.
Definition: Map.hpp:88
auto has(const _Kty &key) const -> bool
Whether have the item or not.
Definition: Map.hpp:110
auto pop(const _Kty &key) -> _Ty
Pop item.
Definition: Map.hpp:173
Top level namespace of products built from samchon.
Definition: ByteArray.hpp:7