![]() |
Spicy
|
#include <map.h>
Public Types | |
using | M = std::map< K, V > |
using | C = std::shared_ptr< Map< K, V > * > |
using | key_type = typename M::key_type |
using | value_type = typename M::value_type |
using | size_type = uint64_t |
using | iterator = typename map::Iterator< K, V > |
using | const_iterator = typename map::ConstIterator< K, V > |
Public Member Functions | |
Map (std::initializer_list< value_type > init) | |
bool | contains (const K &k) const |
const V & | get (const K &k) const & |
V & | get (const K &k) & |
auto & | operator[] (const K &k) & |
const auto & | operator[] (const K &k) const & |
auto | operator[] (const K &k) && |
void | index_assign (const K &key, V value) |
auto | begin () const |
auto | end () const |
auto | begin () |
auto | end () |
auto | cbegin () const |
auto | cend () const |
size_type | size () const |
auto | clear () |
auto | erase (const key_type &key) |
Public Attributes | |
C | _control = std::make_shared<Map<K, V>*>(this) |
Friends | |
bool | operator== (const Map &a, const Map &b) |
bool | operator!= (const Map &a, const Map &b) |
HILTI's Map
is a std::map
-like type with additional safety guarantees.
In particular it guarantees that iterators are either valid, or throw an exception when accessed.
If not otherwise specified, we follow the semantics on iterator invalidation of std::map
with the caveat that iterators which cannot be dereferenced can become invalid through mutating Map
operations. We still validate invalid dereferencing of such iterators.
rt::Map<int, int> map; auto it = map.begin(); // Valid iterator which cannot be dereferenced. // Mutating the map invalidates not dereferencable iterators. map.insert({1, 1}); *it; // Iterator now invalid, throws.
If not otherwise specified, member functions have the semantics of std::map
member functions.
|
inline |
Erases all elements from the map.
This function invalidates all iterators into the map.
|
inline |
Checks whether a key is set in the map.
<tt>k</tt> | the key to check for |
true
if the key is set in the map
|
inline |
Removes an element from the map.
This function invalidates all iterators into the map iff an element was removed.
key | key of the element to remove |
|
inline |
Attempts to get the value for a key.
k | key to retrieve |
<tt>IndexError</tt> | if k is not set in the map |
|
inline |
Attempts to get the value for a key.
k | key to retrieve |
<tt>IndexError</tt> | if k is not set in the map |
|
inline |
Access an element by key
k | key of the element |
<tt>IndexError</tt> | if k is not set in the map |
|
inline |
Access an element by key
k | key of the element |
<tt>IndexError</tt> | if k is not set in the map |
|
inline |
Access an element by key
This function invalidates all iterators into the map iff k
was not present in the map.
k | key of the element |
<tt>IndexError</tt> | if k is not set in the map |