Spicy
Public Types | Public Member Functions | Public Attributes | Friends | List of all members
hilti::rt::Map< K, V > Class Template Reference

#include <map.h>

Inheritance diagram for hilti::rt::Map< K, V >:

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 = integer::safe< 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

_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)
 

Detailed Description

template<typename K, typename V>
class hilti::rt::Map< K, V >

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 dereferenceable iterators.
map.insert({1, 1});

*it; // Iterator now invalid, throws.

If not otherwise specified, member functions have the semantics of std::map member functions.

Member Function Documentation

◆ clear()

template<typename K, typename V>
auto hilti::rt::Map< K, V >::clear ( )
inline

Erases all elements from the map.

This function invalidates all iterators into the map.

◆ contains()

template<typename K, typename V>
bool hilti::rt::Map< K, V >::contains ( const K &  k) const
inline

Checks whether a key is set in the map.

Parameters
<tt>k</tt>the key to check for
Returns
true if the key is set in the map

◆ erase()

template<typename K, typename V>
auto hilti::rt::Map< K, V >::erase ( const key_type &  key)
inline

Removes an element from the map.

This function invalidates all iterators into the map iff an element was removed.

Parameters
keykey of the element to remove
Returns
1 if the element was in the set, 0 otherwise

◆ get() [1/2]

template<typename K, typename V>
const V& hilti::rt::Map< K, V >::get ( const K &  k) const &
inline

Attempts to get the value for a key.

Parameters
kkey to retrieve
Returns
the value
Exceptions
<tt>IndexError</tt>if k is not set in the map

◆ get() [2/2]

template<typename K, typename V>
V& hilti::rt::Map< K, V >::get ( const K &  k) &
inline

Attempts to get the value for a key.

Parameters
kkey to retrieve
Returns
the value
Exceptions
<tt>IndexError</tt>if k is not set in the map

◆ operator[]() [1/3]

template<typename K, typename V>
auto& hilti::rt::Map< K, V >::operator[] ( const K &  k) &
inline

Access an element by key

Parameters
kkey of the element
Returns
a reference to the element
Exceptions
<tt>IndexError</tt>if k is not set in the map

◆ operator[]() [2/3]

template<typename K, typename V>
const auto& hilti::rt::Map< K, V >::operator[] ( const K &  k) const &
inline

Access an element by key

Parameters
kkey of the element
Returns
a reference to the element
Exceptions
<tt>IndexError</tt>if k is not set in the map

◆ operator[]() [3/3]

template<typename K, typename V>
auto hilti::rt::Map< K, V >::operator[] ( const K &  k) &&
inline

Access an element by key

This function invalidates all iterators into the map iff k was not present in the map.

Parameters
kkey of the element
Returns
a reference to the element
Exceptions
<tt>IndexError</tt>if k is not set in the map

The documentation for this class was generated from the following file: