An ordered key–value container with unique keys and convenient lookup and merging.
Standard-style names retain their familiar container meaning. The notes below explain lookup results, mutation, ownership, and Catalyst conveniences; only entirely obvious operations are left as declarations.
Exceptions escaping container operations are translated to CError. Direct iterator operations, element references, and calls through .std() follow the underlying type’s contracts.
CMap
template<class K, class V, class Cmp = std::less<K>, class Alloc = std::allocator<std::pair<const K, V>>> class CMap
Types, constants & data
using Map = std::map<K, V, Cmp, Alloc>;
using key_type = typename Map::key_type;
using value_type = typename Map::value_type;
using allocator_type = typename Map::allocator_type;
using reference = typename Map::reference;
using const_reference = typename Map::const_reference;
using pointer = typename Map::pointer;
using const_pointer = typename Map::const_pointer;
using size_type = typename Map::size_type;
using difference_type = typename Map::difference_type;
using iterator = typename Map::iterator;
using const_iterator = typename Map::const_iterator;
using node_type = typename Map::node_type;
using insert_return_type = typename Map::insert_return_type;
using mapped_type = typename Map::mapped_type;
using key_compare = typename Map::key_compare;
using value_compare = typename Map::value_compare;
using reverse_iterator = typename Map::reverse_iterator;
using const_reverse_iterator = typename Map::const_reverse_iterator;
Methods
CMap() noexcept(std::is_nothrow_default_constructible_v<Map>);
explicit CMap(const key_compare& comp, const allocator_type& a = cContainerDefault<allocator_type>());
explicit CMap(const allocator_type& a);
template<CInputIterator I> CMap(I first, I last, const key_compare& comp = cContainerDefault<key_compare>(), const allocator_type& a = cContainerDefault<allocator_type>());
template<CInputIterator I> CMap(I first, I last, const allocator_type& a);
template<CContainerRange<value_type> R> CMap(std::from_range_t, R&& range, const key_compare& comp = cContainerDefault<key_compare>(), const allocator_type& a = cContainerDefault<allocator_type>());
template<CContainerRange<value_type> R> CMap(std::from_range_t, R&& range, const allocator_type& a);
CMap(std::initializer_list<value_type> values, const key_compare& comp = cContainerDefault<key_compare>(), const allocator_type& a = cContainerDefault<allocator_type>());
CMap(std::initializer_list<value_type> values, const allocator_type& a);
CMap(const CMap& other);
CMap(CMap&& other) noexcept(std::is_nothrow_move_constructible_v<Map>);
CMap(const CMap& other, const allocator_type& a);
CMap(CMap&& other, const allocator_type& a);
CMap(CBuffer& b);
Creates an empty container or copies entries from a range, initializer list, or compatible container. Equivalent keys are stored once. The CBuffer overload restores the corresponding typed container format.
CMap& operator=(const CMap& x);
CMap& operator=(CMap&& x) noexcept(std::is_nothrow_move_assignable_v<Map>);
CMap& operator=(std::initializer_list<value_type> il);
iterator begin() noexcept;
const_iterator begin() const noexcept;
const_iterator cbegin() const noexcept;
iterator end() noexcept;
const_iterator end() const noexcept;
const_iterator cend() const noexcept;
reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;
const_reverse_iterator crbegin() const noexcept;
reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
const_reverse_iterator crend() const noexcept;
cspan span() const noexcept;
cspan span(size_t start) const noexcept;
cspan span(size_t start, size_t endOffset) const noexcept;
Returns numeric indices from zero to size(), optionally excluding an initial or trailing portion. It does not return key/value pairs or an element view.
bool empty() const noexcept;
size_type size() const noexcept;
size_type max_size() const noexcept;
V& operator[](const key_type& x);
V& operator[](key_type&& k);
Returns the mapped value by reference, inserting a value-initialized value when the key is missing. Use at() or get() for lookup without insertion.
V& at(const key_type& k);
const V& at(const key_type& k) const;
Returns the mapped value by reference without insertion. A missing key raises COutOfRangeError.
V get(const key_type& x, const V& def) const;
V& get(const key_type& x, V& def);
Looks up a key without inserting it. The const overload returns a value copy or fallback; the mutable overload returns a reference to the stored value or the supplied fallback.
Returns a new vector containing keys in this map’s iteration order. Hash-map order is unspecified.
iterator find(const key_type& x);
const_iterator find(const key_type& x) const;
template<class Q> requires(CTransparent<key_compare>) iterator find(const Q& key);
template<class Q> requires(CTransparent<key_compare>) const_iterator find(const Q& key) const;
Returns an iterator to an equivalent key or element, or end() when none is present. This lookup does not insert a missing entry.
bool has(const key_type& x) const;
Reports whether an equivalent key or element is present, without inserting anything.
bool contains(const key_type& x) const;
template<class Q> requires(CTransparent<key_compare>) bool contains(const Q& key) const;
Reports whether an equivalent key is present. This is the standard-style spelling of a membership lookup.
size_type count(const key_type& x) const;
template<class Q> requires(CTransparent<key_compare>) size_type count(const Q& key) const;
Returns the number of elements equivalent to the key. A unique-key container returns either zero or one.
iterator lower_bound(const key_type& x);
const_iterator lower_bound(const key_type& x) const;
template<class Q> requires(CTransparent<key_compare>) iterator lower_bound(const Q& key);
template<class Q> requires(CTransparent<key_compare>) const_iterator lower_bound(const Q& key) const;
Returns the first position whose key is not less than the requested key according to the ordering policy, or end().
iterator upper_bound(const key_type& x);
const_iterator upper_bound(const key_type& x) const;
template<class Q> requires(CTransparent<key_compare>) iterator upper_bound(const Q& key);
template<class Q> requires(CTransparent<key_compare>) const_iterator upper_bound(const Q& key) const;
Returns the first position whose key is greater than the requested key according to the ordering policy, or end().
std::pair<iterator, iterator> equal_range(const key_type& x);
std::pair<const_iterator, const_iterator> equal_range(const key_type& x) const;
template<class Q> requires(CTransparent<key_compare>) std::pair<iterator, iterator> equal_range(const Q& key);
template<class Q> requires(CTransparent<key_compare>) std::pair<const_iterator, const_iterator> equal_range(const Q& key) const;
Returns the half-open iterator range of equivalent keys. A missing key produces an empty range.
K keyForValue(const V& value);
Scans values and returns the key of the first equal value in iteration order. Raises CError if no value matches.
std::pair<iterator, bool> insert(const value_type& x);
iterator insert(const_iterator position, const value_type& x);
template<class P> requires std::is_constructible_v<value_type, P&&> std::pair<iterator, bool> insert(P&& p);
template<CInputIterator InputIterator> void insert(InputIterator first, InputIterator last);
std::pair<iterator, bool> insert(value_type&& value);
iterator insert(const_iterator hint, value_type&& value);
template<class P> requires std::is_constructible_v<value_type, P&&> iterator insert(const_iterator hint, P&& value);
void insert(std::initializer_list<value_type> values);
insert_return_type insert(node_type&& node);
iterator insert(const_iterator hint, node_type&& node);
Inserts entries without replacing an equivalent existing key. For a single value, the pair-returning overload gives an iterator to the existing or inserted entry and a boolean indicating insertion.
Inserts elements from a C++ range using the container’s duplicate-key policy. It does not clear the existing contents.
template<class... Args> std::pair<iterator, bool> emplace(Args&&... args);
Constructs an entry from forwarded arguments and attempts insertion. For unique keys, the pair-returning overload reports whether insertion took place; construction may occur even when the key already exists.
template<class... Args> iterator emplace_hint(const_iterator position, Args&&... args);
Attempts emplacement using the supplied position as a lookup hint and returns an iterator to the result. The hint does not change the key ordering or duplicate policy.
template<class... Args> std::pair<iterator, bool> try_emplace(const key_type& key, Args&&... args);
template<class... Args> iterator try_emplace(const_iterator hint, const key_type& key, Args&&... args);
template<class... Args> std::pair<iterator, bool> try_emplace(key_type&& key, Args&&... args);
template<class... Args> iterator try_emplace(const_iterator hint, key_type&& key, Args&&... args);
Constructs the mapped value only if the key is absent. An existing entry is preserved and forwarded value arguments are not moved from in that case.
template<class M> std::pair<iterator, bool> insert_or_assign(const key_type& key, M&& value);
template<class M> iterator insert_or_assign(const_iterator hint, const key_type& key, M&& value);
template<class M> std::pair<iterator, bool> insert_or_assign(key_type&& key, M&& value);
template<class M> iterator insert_or_assign(const_iterator hint, key_type&& key, M&& value);
Inserts a missing key or replaces the value of an existing key. The pair-returning overload reports insertion with true and replacement with false.
CMap& add(const K& k, const V& t);
Inserts or replaces a mapped value and returns this map for chaining. Unlike insert(), it overwrites an existing value.
template<class K2, class V2> V& init(K2&& k, V2&& dv);
Returns the existing mapped value by reference, or inserts dv for a missing key and returns the new value. Existing entries are left unchanged.
iterator erase(iterator position);
size_type erase(const key_type& x);
iterator erase(const_iterator first, const_iterator last);
iterator erase(const_iterator position);
template<class Q> requires(CTransparent<key_compare> && !std::is_convertible_v<Q, iterator> && !std::is_convertible_v<Q, const_iterator>) size_type erase(Q&& key);
Erases an iterator, a half-open iterator range, or all entries equivalent to a key. Iterator forms return the following iterator; key forms return the number removed.
V take(const key_type& k);
V take(const key_type& k, V def);
Moves out the mapped value and erases its key. A missing key raises CError, or returns the fallback when that overload is used.
template<class S> void clearExcept(const S& s);
Removes entries whose keys are not present in s, as tested by s.has(key).
void swap(CMap& m) noexcept(noexcept(m_.swap(m.m_)));
template<class C2> void merge(CMap<K, V, C2, Alloc>& source);
template<class C2> void merge(CMap<K, V, C2, Alloc>&& source);
template<class C2> void merge(CMultimap<K, V, C2, Alloc>& source);
template<class C2> void merge(CMultimap<K, V, C2, Alloc>&& source);
template<class C2> void merge(std::map<K, V, C2, Alloc>& source);
template<class C2> void merge(std::map<K, V, C2, Alloc>&& source);
template<class C2> void merge(std::multimap<K, V, C2, Alloc>& source);
template<class C2> void merge(std::multimap<K, V, C2, Alloc>&& source);
Transfers entries whose keys are absent here from the source. Conflicting entries stay in the source; existing mapped values are preserved.
void innerMerge(const CMap& m);
Adds entries whose keys are absent, preserving values already present.
void outerMerge(const CMap& m);
Copies incoming entries into this map, replacing values for keys that already exist. The source is unchanged; mapped values are assigned as whole values.
const Map& std() const noexcept;
Map& std() noexcept;
Returns a reference to the underlying container for interoperation. Changes affect this object directly; operations through that reference bypass Catalyst exception translation.
operator const Map&() const noexcept;
Borrows the underlying container for interoperability. This does not copy storage; references and iterators follow that container’s lifetime and invalidation rules.
operator Map&() noexcept;
Borrows the underlying container for interoperability. This does not copy storage; references and iterators follow that container’s lifetime and invalidation rules.
allocator_type get_allocator() const noexcept;
key_compare key_comp() const;
value_compare value_comp() const;
Appends the container to a CBuffer; restore it with the buffer-taking constructor.
Returns the stream-formatted contents as a cstr. Use store() for binary serialization.