SimpleCxxLib
packageclass Map<KeyType,ValueType>
Constructor | |
Initializes a new empty map that associates keys and values of the specified types. | |
Methods | |
Removes all entries from this map. | |
Returns true if there is an entry for key in this map. | |
Returns the value associated with key in this map. | |
Returns true if this map contains no entries. | |
Iterates through the map entries and calls fn(key, value) for each one. | |
Associates key with value in this map. | |
Removes any entry for key from this map. | |
Returns the number of entries in this map. | |
Converts the map to a printable string representation. | |
Operator | |
Selects the value associated with key . |
Map();
Usage:
Map<KeyType,ValueType> map; Map<KeyType,ValueType> map = {{ k1, v1}, { k2, v2 }};
int size() const;
Usage:
int nEntries = map.size();
bool isEmpty() const;
true
if this map contains no entries.
Usage:
if (map.isEmpty()) ...
void put(const KeyType & key, const ValueType & value);
key
with value
in this map.
Any previous value associated with key
is replaced
by the new value.
Usage:
map.put(key, value);
ValueType get(const KeyType & key) const;
key
in this map.
If key
is not found, get
returns the
default value for ValueType
.
Usage:
ValueType value = map.get(key);
bool containsKey(const KeyType & key) const;
true
if there is an entry for key
in this map.
Usage:
if (map.containsKey(key)) ...
void remove(const KeyType & key);
key
from this map.
Usage:
map.remove(key);
void clear();
Usage:
map.clear();
string toString();
Usage:
string str = map.toString();
void mapAll(void (*fn)(KeyType, ValueType)) const; void mapAll(void (*fn)(const KeyType &, const ValueType &)) const; void mapAll(FunctorType fn) const;
fn(key, value)
for each one. The keys are processed in ascending order, as defined
by the comparison function.
Usage:
map.mapAll(fn);
ValueType & operator[](const KeyType & key); ValueType operator[](const KeyType & key) const;
key
. This syntax
makes it easy to think of a map as an "associative array"
indexed by the key type. If key
is already present
in the map, this function returns a reference to its associated
value. If key is not present in the map, a new entry is created
whose value is set to the default for the value type.
Usage:
map[key]