11#include <initializer_list>
37template <
typename K,
typename V>
45 using Data = std::map<K, V>;
85 d = std::move(
other.d);
176 auto it = d.find(key);
177 if(
it != d.end())
return it->second;
182 bool contains(
const K &key)
const {
return d.find(key) != d.end(); }
202 d.insert_or_assign(key,
val);
212 d.insert_or_assign(key, std::move(
val));
222 return d.erase(key) > 0;
272 template <
typename Func>
274 for(
const auto &[
k, v] : d) func(
k, v);
Dynamic array container wrapping std::vector.
Definition list.h:40
void reserve(size_t newCapacity)
Pre-allocates storage for at least newCapacity elements.
Definition list.h:314
void pushToBack(const T &value)
Pushes an item onto the back of the list.
Definition list.h:455
Ordered associative container wrapping std::map.
Definition map.h:38
ConstRevIterator crend() const noexcept
Returns a const reverse iterator to one before the first entry.
Definition map.h:134
Iterator find(const K &key)
Finds the entry for key.
Definition map.h:189
ConstIterator constEnd() const noexcept
Returns a const iterator to one past the last entry.
Definition map.h:113
bool contains(const K &key) const
Returns true if key exists in the map.
Definition map.h:182
List< V > values() const
Returns a list of all values.
Definition map.h:260
Map & operator=(Map &&other) noexcept
Move assignment operator.
Definition map.h:84
friend bool operator==(const Map &lhs, const Map &rhs)
Returns true if both maps have identical contents.
Definition map.h:281
Map(std::initializer_list< std::pair< const K, V > > initList)
Constructs a map from an initializer list of key-value pairs.
Definition map.h:72
void insert(const K &key, V &&val)
Inserts or assigns a key-value pair (move overload).
Definition map.h:211
std::map< K, V > Data
Underlying std::map storage type.
Definition map.h:45
ConstIterator end() const noexcept
Returns a const iterator to one past the last entry.
Definition map.h:107
ConstIterator constBegin() const noexcept
Returns a const iterator to the first entry.
Definition map.h:101
ConstIterator cbegin() const noexcept
Returns a const iterator to the first entry.
Definition map.h:98
Map(const Map &other)
Copy constructor.
Definition map.h:63
void insert(const K &key, const V &val)
Inserts or assigns a key-value pair.
Definition map.h:201
typename Data::iterator Iterator
Mutable forward iterator.
Definition map.h:48
V & operator[](const K &key)
Returns a reference to the value for key, inserting a default-constructed value if it does not exist.
Definition map.h:155
Map(Map &&other) noexcept
Move constructor.
Definition map.h:66
ConstRevIterator constRevEnd() const noexcept
Returns a const reverse iterator to one before the first entry.
Definition map.h:137
RevIterator rend() noexcept
Returns a mutable reverse iterator to one before the first entry.
Definition map.h:128
V value(const K &key, const V &defaultValue=V{}) const
Returns the value for key, or defaultValue if the key is not present.
Definition map.h:175
RevIterator rbegin() noexcept
Returns a mutable reverse iterator to the last entry.
Definition map.h:116
Iterator begin() noexcept
Returns a mutable iterator to the first entry.
Definition map.h:92
size_t size() const noexcept
Returns the number of key-value pairs.
Definition map.h:145
List< K > keys() const
Returns a list of all keys.
Definition map.h:252
bool isEmpty() const noexcept
Returns true if the map has no entries.
Definition map.h:142
typename Data::const_iterator ConstIterator
Const forward iterator.
Definition map.h:51
void clear() noexcept
Removes all entries.
Definition map.h:235
Map & operator=(const Map &other)
Copy assignment operator.
Definition map.h:78
typename Data::const_reverse_iterator ConstRevIterator
Const reverse iterator.
Definition map.h:57
ConstRevIterator crbegin() const noexcept
Returns a const reverse iterator to the last entry.
Definition map.h:122
RevIterator revEnd() noexcept
Returns a mutable reverse iterator to one before the first entry.
Definition map.h:131
Iterator remove(Iterator pos)
Removes the entry at pos.
Definition map.h:230
ConstRevIterator constRevBegin() const noexcept
Returns a const reverse iterator to the last entry.
Definition map.h:125
ConstIterator cend() const noexcept
Returns a const iterator to one past the last entry.
Definition map.h:110
ConstIterator find(const K &key) const
Const overload of find().
Definition map.h:192
void swap(Map &other) noexcept
Swaps contents with another map.
Definition map.h:244
RevIterator revBegin() noexcept
Returns a mutable reverse iterator to the last entry.
Definition map.h:119
Map()=default
Default constructor. Creates an empty map.
bool remove(const K &key)
Removes the entry for key.
Definition map.h:221
~Map()=default
Destructor.
void forEach(Func &&func) const
Calls func for every key-value pair.
Definition map.h:273
friend bool operator!=(const Map &lhs, const Map &rhs)
Returns true if the maps differ.
Definition map.h:284
ConstIterator begin() const noexcept
Returns a const iterator to the first entry.
Definition map.h:95
const V & operator[](const K &key) const
Returns a const reference to the value for key.
Definition map.h:166
Iterator end() noexcept
Returns a mutable iterator to one past the last entry.
Definition map.h:104
typename Data::reverse_iterator RevIterator
Mutable reverse iterator.
Definition map.h:54
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19
#define PROMEKI_SHARED_FINAL(TYPE)
Macro for non-polymorphic native shared objects.
Definition sharedptr.h:88