1 #ifndef PROTON_MAP_HEADER
2 #define PROTON_MAP_HEADER
8 #include <proton/pool.hpp>
11 #include "_mapped_type.hpp"
24 template <
typename _Key,
typename _Tp,
typename _Cmp,
typename _Alloc>
25 std::map<_Key, _Tp, _Cmp, _Alloc>& operator<<(std::map<_Key, _Tp, _Cmp, _Alloc>& x,
26 const std::pair<const _Key, _Tp>& item)
32 template <
typename _Key,
typename _Tp,
typename _Cmp,
typename _Alloc>
33 std::map<_Key, _Tp, _Cmp, _Alloc>& operator<<(std::map<_Key, _Tp, _Cmp, _Alloc>& x,
34 std::initializer_list<std::pair<const _Key, _Tp> > item)
45 template <
typename _Key,
typename _Tp,
typename _Cmp,
typename _Alloc>
46 std::ostream& operator<<(std::ostream& s, const std::map<_Key, _Tp, _Cmp, _Alloc>& x)
55 s << t.first <<
" : "<<t.second;
61 template <
typename _Key,
typename _Tp,
typename _Cmp,
typename _Alloc>
62 std::wostream& operator<<(std::wostream& s, const std::map<_Key, _Tp, _Cmp, _Alloc>& x)
71 s << t.first << L
" : "<<t.second;
79 template <
typename K,
typename T,
typename C=std::less<K>,
typename A=smart_allocator<std::pair<const K,T> > >
80 class map_ :
public std::map<K,T,C,A>{
82 typedef std::map<K,T,C,A> baseT;
83 typedef std::pair<const K,T> itemT;
88 template<
typename ...argT>
map_(argT&& ...a):baseT(a...)
93 map_(std::initializer_list<itemT> a):baseT(a)
106 explicit map_(
const baseT& x):baseT(x)
109 map_(baseT&& x)noexcept:baseT(x)
154 return reinterpret_cast<baseT&
>(*this);
165 auto end=this->end();
166 auto it=this->find(key);
168 throw std::out_of_range(
"The given key doesn't exist in this map.");
177 T
get(
const K& key)
const
179 return this->
at[key];
187 template<
typename ...D>
188 T
get(
const K& key, D&& ...dft)
const
190 auto it=this->find(key);
202 return this->find(key)!=this->end();
212 auto it=this->find(key);
224 template<
typename ...D>
225 T
pop(
const K& key, D&& ...dft)
227 auto it=this->find(key);
240 PROTON_THROW_IF(this->empty(),
"try to pop an item from an empty map");
241 auto it=this->begin();
249 template<
typename ...D>
252 auto it=this->find(key);
255 return this->insert(std::make_pair(key, T(dft...))).first->second;
260 template<
typename oT>
264 (*this)[i->first]=i->second;
276 template<
typename K,
typename T,
typename C,
typename A>
282 template<
typename K,
typename T,
typename C,
typename A>
283 const map_<K,T,C,A>&
cast_(
const std::map<K,T,C,A>& x)
285 return reinterpret_cast<const map_<K,T,C,A>&
>(x);
288 template<
typename K,
typename T,
typename C,
typename A>
289 map_<K,T,C,A>&&
cast_(std::map<K,T,C,A>&& x)
291 return reinterpret_cast<map_<K,T,C,A>&&
>(x);
294 template<
typename K,
typename T,
typename C,
typename A>
295 const map_<K,T,C,A>&&
cast_(
const std::map<K,T,C,A>&& x)
297 return reinterpret_cast<const map_<K,T,C,A>&&
>(x);
306 template<
typename _Key,
typename _Tp,
typename _Cmp,
typename _Alloc>
307 struct has_t<std::map<_Key, _Tp, _Cmp, _Alloc> >{
308 template<
typename V>
static bool result(
const std::map<_Key, _Tp, _Cmp, _Alloc>& x, V&& v)
310 return x.find(v)!=x.end();
314 template<
typename _Key,
typename _Tp,
typename _Cmp,
typename _Alloc>
315 struct has_t<map_<_Key, _Tp, _Cmp, _Alloc> >{
316 template<
typename V>
static bool result(
const map_<_Key, _Tp, _Cmp, _Alloc>& x, V&& v)
318 return x.find(v)!=x.end();
326 #endif // PROTON_MAP_HEADER