map.hpp

A drop-in wrapper for std::map and std:multimap; makes sure we create vars on access.

This class is a drop-in wrapper for std::map, adding on debbing where the indexing operator [square brackets] returns a proxy. That proxy can either be assigned to OR convert an existing value ONLY if it exists. This mechanism ensures that we don’t accidentally write a default value to a map when all we meant to do was read from it, but had a typo. If EMP_NDEBUG is set then it reverts back to std::map.

Note

Status: ALPHA

template<class Key, class T, class ...Ts>
class map : public std::map<Key, T, Ts...>
#include <map.hpp>

Public Types

using key_type = Key
using mapped_type = T
using value_type = std::pair<const key_type, mapped_type>
using key_compare = typename base_t::key_compare
using value_compare = typename base_t::value_compare
using allocator_type = typename base_t::allocator_type
using reference = typename base_t::reference
using const_reference = typename base_t::const_reference
using pointer = typename base_t::pointer
using const_pointer = typename base_t::const_pointer
using iterator = typename base_t::iterator
using const_iterator = typename base_t::const_iterator
using reverse_iterator = typename base_t::reverse_iterator
using const_reverse_iterator = typename base_t::const_reverse_iterator
using difference_type = typename base_t::difference_type
using size_type = typename base_t::size_type

Public Functions

inline explicit map(const key_compare &comp = key_compare(), const allocator_type &alloc = allocator_type())
inline explicit map(const allocator_type &alloc)
template<class InputIterator>
inline map(InputIterator first, InputIterator last, const key_compare &comp = key_compare(), const allocator_type &alloc = allocator_type())
inline map(const this_t &x)
inline map(const this_t &x, const allocator_type &alloc)
inline map(this_t &&x)
inline map(this_t &&x, const allocator_type &alloc)
inline map(std::initializer_list<value_type> il, const key_compare &comp = key_compare(), const allocator_type &alloc = allocator_type())
this_t &operator=(const this_t&) = default
this_t &operator=(this_t&&) = default
inline proxy_t operator[](const Key &k)

Private Types

using this_t = map<Key, T, Ts...>
using base_t = std::map<Key, T, Ts...>
using proxy_t = MapProxy<std::decay_t<T>>
template<class Key, class T, class ...Ts>
class multimap : public std::multimap<Key, T, Ts...>
#include <map.hpp>

Public Types

using key_type = Key
using mapped_type = T
using value_type = std::pair<const key_type, mapped_type>
using key_compare = typename base_t::key_compare
using value_compare = typename base_t::value_compare
using allocator_type = typename base_t::allocator_type
using reference = typename base_t::reference
using const_reference = typename base_t::const_reference
using pointer = typename base_t::pointer
using const_pointer = typename base_t::const_pointer
using iterator = typename base_t::iterator
using const_iterator = typename base_t::const_iterator
using reverse_iterator = typename base_t::reverse_iterator
using const_reverse_iterator = typename base_t::const_reverse_iterator
using difference_type = typename base_t::difference_type
using size_type = typename base_t::size_type

Public Functions

inline explicit multimap(const key_compare &comp = key_compare(), const allocator_type &alloc = allocator_type())
inline explicit multimap(const allocator_type &alloc)
template<class InputIterator>
inline multimap(InputIterator first, InputIterator last, const key_compare &comp = key_compare(), const allocator_type &alloc = allocator_type())
inline multimap(const this_t &x)
inline multimap(const this_t &x, const allocator_type &alloc)
inline multimap(this_t &&x)
inline multimap(this_t &&x, const allocator_type &alloc)
inline multimap(std::initializer_list<value_type> il, const key_compare &comp = key_compare(), const allocator_type &alloc = allocator_type())
this_t &operator=(const this_t&) = default
this_t &operator=(this_t&&) = default
inline proxy_t operator[](const Key &k)

Private Types

using this_t = multimap<Key, T, Ts...>
using base_t = std::multimap<Key, T, Ts...>
using proxy_t = MapProxy<std::decay_t<T>>