8 #ifndef MOD_SERVLET_ANY_MAP_H
9 #define MOD_SERVLET_ANY_MAP_H
18 #include <unordered_map>
19 #include <experimental/any>
26 using std::experimental::any;
27 using std::experimental::any_cast;
83 template<
typename _MapType>
160 template<
typename... Args>
175 template<
typename... Args>
176 any_map&
operator=(Args &&... args) { map_type::operator=(std::forward<Args>(args)...);
return *
this; }
185 template<
typename KeyType>
186 bool contains_key(
const KeyType &key)
const {
return this->find(key) != this->end(); }
202 template<
typename T,
typename KeyType>
205 auto it = this->find(key);
222 template<
typename T,
typename KeyType>
225 auto it = this->find(key);
243 template<
typename T,
typename... Args>
246 std::pair<iterator, bool> res = this->try_emplace(std::move(key));
247 if (res.second) res.first->second = T{std::forward<Args>(args)...};
248 return any_cast<T&>(res.first->second);
264 template<
typename T,
typename... Args>
267 std::pair<iterator, bool> res = this->try_emplace(key);
268 if (res.second) res.first->second = T{std::forward<Args>(args)...};
269 return any_cast<T&>(res.first->second);
282 template<
typename T,
typename... Args>
285 std::pair<iterator, bool> res = this->try_emplace(std::move(key));
286 res.first->second = T{std::forward<Args>(args)...};
299 template<
typename T,
typename... Args>
302 std::pair<iterator, bool> res = this->try_emplace(key);
303 res.first->second = T{std::forward<Args>(args)...};
311 template <
typename _Key = std::
string,
typename _Compare = std::less<>,
312 typename _Alloc = std::allocator<std::pair<const _Key, any>>>
324 template <
typename _Key = std::
string,
typename _Hash = std::hash<_Key>,
325 typename _Pred = std::equal_to<_Key>,
typename _Alloc = std::allocator<std::pair<const _Key, any>>>
336 #endif // MOD_SERVLET_ANY_MAP_H
_MapType map_type
Type definition for this map implementation.
Definition: any_map.h:90
map_type::allocator_type allocator_type
Container's allocator type.
Definition: any_map.h:107
~any_map()=default
Destroys the object.
bool put(key_type &&key, Args &&...args)
Associates a value of specified type created with a given arguments with the specified key in this ma...
Definition: any_map.h:283
Defines optional container objects and related methods.
map_type::size_type size_type
An unsigned integral type to represent the size of this container.
Definition: any_map.h:127
map_type::const_pointer const_pointer
Constant pointer type to value_type.
Definition: any_map.h:123
bool put(const key_type &key, Args &&...args)
Associates a value of specified type created with a given arguments with the specified key in this ma...
Definition: any_map.h:300
map_type::const_iterator const_iterator
Bidirectional constant iterator type.
Definition: any_map.h:140
Optional reference implementation.
Definition: optional.h:221
bool contains_key(const KeyType &key) const
Tests whether value with a given key exists in this container.
Definition: any_map.h:186
const value_type & const_reference
const value_type&
Definition: any_map.h:115
Covenience class on top of associative container to facilitate work with value type std::any...
Definition: any_map.h:84
map_type::mapped_type mapped_type
Container's mapped type.
Definition: any_map.h:99
map_type::iterator iterator
Bidirectional iterator type.
Definition: any_map.h:136
any_map()=default
Constructs an empty container, with no elements.
map_type::difference_type difference_type
A signed integral type to represent distance between iterators.
Definition: any_map.h:131
T & ensure_get(const key_type &key, Args &&...args)
Returns reference to a value with a specified type, if that value exists and can be casted to the req...
Definition: any_map.h:265
map_type::key_type key_type
Container's key type.
Definition: any_map.h:95
T & ensure_get(key_type &&key, Args &&...args)
Returns reference to a value with a specified type, if that value exists and can be casted to the req...
Definition: any_map.h:244
map_type::pointer pointer
Pointer type to value_type.
Definition: any_map.h:119
map_type::reverse_iterator reverse_iterator
Reverse iterator type.
Definition: any_map.h:144
value_type & reference
value_type&
Definition: any_map.h:111
map_type::value_type value_type
Container's value type: std::pair<const key_type, mapped_type>
Definition: any_map.h:103
any_map & operator=(Args &&...args)
Forwarding assignment.
Definition: any_map.h:176
any_map(Args &&...args)
Forwarding constructor.
Definition: any_map.h:161
map_type::const_reverse_iterator const_reverse_iterator
Constant reverse iterator type.
Definition: any_map.h:148