13#if HX_USE_MACROS_WITH_MODULE
14#error Header does not provide macros alone.
23#if HX_CPLUSPLUS >= 202002L
26concept hxflat_map_concept_ =
requires(T_& x_) {
32#define hxflat_map_concept_ typename
38template<
typename key_t_,
typename mapped_t_>
64 template<hxflat_map_concept_, hxflat_map_concept_,
typename,
bool, hx
size_t>
friend class hxflat_map;
72template<
typename key_t_,
typename mapped_t_>
98 template<hxflat_map_concept_, hxflat_map_concept_,
typename,
bool, hx
size_t>
friend class hxflat_map;
131template<hxflat_map_concept_ key_t_,
132 hxflat_map_concept_ mapped_t_,
212#if HX_CPLUSPLUS < 202002L
220 const key_t_&
key(
void)
const;
230 : m_map_(map_), m_index_(index_) { }
331#if HX_CPLUSPLUS >= 202302L
337 template<
typename self_t_,
typename callable_t_>
339 this self_t_&& self_,
const key_t_& key_, callable_t_&& callable_)
347 template<
typename self_t_,
typename callable_t_>
349 this self_t_&& self_,
const_iterator it_, callable_t_&& callable_)
363 template<hx
size_t capacity_x_>
365 capacity_x_>& x_)
noexcept;
382 template<hx
size_t capacity_x_>
384 multi_t_, capacity_x_>& x_)
const;
389 template<hx
size_t capacity_x_>
391 multi_t_, capacity_x_>& x_)
const;
420 template<
typename... args_t_>
483#if HX_CPLUSPLUS >= 202302L
489 template<
typename self_t_,
typename callable_t_>
491 this self_t_&& self_,
const key_t_& key_, callable_t_&& callable_)
492 ->
decltype(self_.end());
498 template<
typename self_t_,
typename callable_t_>
500 this self_t_&& self_,
const_iterator it_, callable_t_&& callable_)
501 ->
decltype(self_.end());
529#if HX_CPLUSPLUS >= 202302L
534 template<
typename self_t_,
typename... args_t_>
536 this self_t_&& self_,
const key_t_& key_, args_t_&&... args_);
541 template<
typename self_t_,
typename... args_t_>
554 template<hxflat_map_concept_, hxflat_map_concept_,
typename,
bool, hx
size_t>
557 template<
typename mapped_u_>
558 iterator insert_at_(
hxsize_t index_,
const key_t_& key_, mapped_u_&& mapped_)
noexcept;
566#include "detail/hxflat_map.inl"
hxallocator<1+> - Provides static allocation when capacity is greater than zero.
Definition hxallocator.hpp:25
const_iterator - A random-access iterator over key-value pairs.
Definition hxflat_map.hpp:144
const_iterator operator+(hxsize_t n_) const
Returns an iterator advanced by n positions.
Definition hxflat_map.hpp:165
const_iterator & operator--(void)
Retreats the iterator to the previous element.
Definition hxflat_map.hpp:187
hxflat_map_const_value_t< key_t_, mapped_t_ > operator[](hxsize_t n_) const
Returns a hxflat_map_const_value_t proxy referencing the key and value n positions ahead of this one.
Definition hxflat_map.hpp:178
bool operator==(const const_iterator &x_) const
Compares two iterators for equality.
const_iterator & operator++(void)
Advances the iterator to the next element.
Definition hxflat_map.hpp:181
bool operator>=(const const_iterator &x_) const
Returns true when this iterator is not ordered before x.
Definition hxflat_map.hpp:210
bool operator>(const const_iterator &x_) const
Returns true when this iterator is ordered after x.
Definition hxflat_map.hpp:202
const_iterator & operator-=(hxsize_t n_)
Moves the iterator back by n positions.
Definition hxflat_map.hpp:161
bool operator<(const const_iterator &x_) const
Returns true when this iterator is ordered before x.
const_iterator operator--(int)
Retreats the iterator to the previous element (post-decrement).
Definition hxflat_map.hpp:190
const mapped_t_ & value(void) const
Returns the mapped value at the current position.
hxflat_map_const_value_t< key_t_, mapped_t_ > operator*(void) const
Returns a hxflat_map_const_value_t proxy referencing the key and value at the current position.
Definition hxflat_map.hpp:151
const_iterator operator-(hxsize_t n_) const
Returns an iterator retreated by n positions.
Definition hxflat_map.hpp:169
const_iterator operator++(int)
Advances the iterator to the next element (post-increment).
Definition hxflat_map.hpp:184
const key_t_ & key(void) const
Returns the key at the current position.
bool operator<=(const const_iterator &x_) const
Returns true when this iterator is not ordered after x.
Definition hxflat_map.hpp:206
hxsize_t operator-(const const_iterator &x_) const
Returns the signed distance between two iterators.
const_iterator & operator+=(hxsize_t n_)
Advances the iterator by n positions.
const_iterator(void)
Constructs an end iterator.
Definition hxflat_map.hpp:147
iterator - A mutable random-access iterator that allows modifying the mapped value.
Definition hxflat_map.hpp:238
iterator & operator+=(hxsize_t n_)
Advances the iterator by n positions.
Definition hxflat_map.hpp:251
hxflat_map_value_t< key_t_, mapped_t_ > operator*(void) const
Returns a hxflat_map_value_t proxy referencing the key and value at the current position,...
Definition hxflat_map.hpp:245
iterator operator++(int)
Advances the iterator to the next element (post-increment).
Definition hxflat_map.hpp:278
mapped_t_ & value(void) const
Returns the mapped value at the current position, allowing mutation.
iterator operator+(hxsize_t n_) const
Returns an iterator advanced by n positions.
Definition hxflat_map.hpp:259
iterator(void)
Constructs an end iterator.
Definition hxflat_map.hpp:241
iterator & operator-=(hxsize_t n_)
Moves the iterator back by n positions.
Definition hxflat_map.hpp:255
iterator & operator++(void)
Advances the iterator to the next element.
Definition hxflat_map.hpp:275
iterator & operator--(void)
Retreats the iterator to the previous element.
Definition hxflat_map.hpp:281
iterator operator--(int)
Retreats the iterator to the previous element (post-decrement).
Definition hxflat_map.hpp:284
hxsize_t operator-(const const_iterator &x_) const
Returns the signed distance from x to this position.
Definition hxflat_map.hpp:267
iterator operator-(hxsize_t n_) const
Returns an iterator retreated by n positions.
Definition hxflat_map.hpp:263
hxflat_map_value_t< key_t_, mapped_t_ > operator[](hxsize_t n_) const
Returns a hxflat_map_value_t proxy referencing the key and value n positions ahead of this one.
Definition hxflat_map.hpp:272
hxflat_map_const_value_t - A proxy referencing the key and mapped value at a fixed position,...
Definition hxflat_map.hpp:39
const key_t_ & key
The referenced key.
Definition hxflat_map.hpp:57
bool operator<(const hxflat_map_const_value_t &x_) const
Returns true when this element is ordered before x, comparing keys first and then values with hxkey_e...
Definition hxflat_map.hpp:51
const mapped_t_ & value
The referenced mapped value.
Definition hxflat_map.hpp:60
bool operator==(const hxflat_map_const_value_t &x_) const
Compares the referenced key and value for equality with x, using hxkey_equal on both.
Definition hxflat_map.hpp:44
hxflat_map_value_t - A proxy referencing the key and mapped value at a fixed position,...
Definition hxflat_map.hpp:73
mapped_t_ & value
The referenced mapped value, allowing mutation.
Definition hxflat_map.hpp:94
const key_t_ & key
The referenced key.
Definition hxflat_map.hpp:91
bool operator<(const hxflat_map_value_t &x_) const
Returns true when this element is ordered before x, comparing keys first and then values with hxkey_e...
Definition hxflat_map.hpp:85
bool operator==(const hxflat_map_value_t &x_) const
Compares the referenced key and value for equality with x, using hxkey_equal on both.
Definition hxflat_map.hpp:78
hxflat_map - A sorted associative container that stores keys and mapped values in two parallel arrays...
Definition hxflat_map.hpp:136
iterator upper_bound(const key_t_ &key_)
const_iterator end(void) const
Returns a const iterator pointing past the last element.
Definition hxflat_map.hpp:427
iterator emplace(const key_t_ &key_, args_t_ &&... args_) noexcept
Constructs and inserts a mapped value from args, returning an iterator to the new or existing element...
iterator begin(void)
Returns an iterator pointing to the first element.
Definition hxflat_map.hpp:397
auto and_then(this self_t_ &&self_, const key_t_ &key_, callable_t_ &&callable_) -> hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< mapped_t_ & >())))>
Returns the result of calling callable with the mapped value for the first key matching key,...
bool full(void) const
Returns true if the map has reached its capacity.
Definition hxflat_map.hpp:450
hxflat_map(hxflat_map &&x_) noexcept
Move constructs from a temporary hxflat_map.
hxsize_t capacity(void) const
Returns the number of elements the map can hold.
Definition hxflat_map.hpp:400
bool has_value(const key_t_ &key_) const
Returns true if an element matching key exists.
const_iterator begin(void) const
Returns a const iterator pointing to the first element.
Definition hxflat_map.hpp:394
iterator insert(const key_t_ &key_, const mapped_t_ &mapped_) noexcept
Inserts a key-value pair.
mapped_t_ value_or(this self_t_ &&self_, const_iterator it_, args_t_ &&... args_)
Iterator overload of value_or.
void reserve(hxsize_t cap_, hxsystem_allocator_t allocator_=hxsystem_allocator_current, hxalignment_t alignment_=hxalignment) noexcept
Allocates storage for cap keys and values.
key_t_ key_t
Definition hxflat_map.hpp:138
iterator erase(const_iterator it_) noexcept
Removes the element at the iterator position and destroys the key-value pair.
iterator end(void)
Returns an iterator pointing past the last element.
Definition hxflat_map.hpp:430
compare_t_ compare_t
Definition hxflat_map.hpp:140
const mapped_t_ * values(void) const noexcept
Returns a const pointer to the underlying mapped value storage.
auto or_else(this self_t_ &&self_, const key_t_ &key_, callable_t_ &&callable_) -> decltype(self_.end())
Returns an iterator to the first element matching key, or the result of calling callable when lookup ...
mapped_t_ mapped_t
Definition hxflat_map.hpp:139
hxflat_map(void)
Constructs an empty map.
void swap(hxflat_map &x_) noexcept
Swaps the contents with x.
iterator lower_bound(const key_t_ &key_)
hxsize_t max_size(void) const
Returns the capacity of the map.
Definition hxflat_map.hpp:481
bool operator==(const hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_x_ > &x_) const
Returns true if this map and x contain the same key-value pairs in the same order using hxkey_equal o...
mapped_t_ value_or(this self_t_ &&self_, const key_t_ &key_, args_t_ &&... args_)
Returns a copy of the mapped value for the first key matching key, or a mapped value constructed from...
hxsize_t count(const key_t_ &key_) const
Returns the number of elements with the given key.
const_iterator find(const key_t_ &key_) const
Returns a const iterator to key, or end() if the key is not found.
const key_t_ * keys(void) const noexcept
Returns a const pointer to the underlying key storage.
bool empty(void) const
Checks if the map contains no elements.
Definition hxflat_map.hpp:424
void operator=(const hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_x_ > &x_) noexcept
Cross-capacity copy assignment.
const_iterator lower_bound(const key_t_ &key_) const
Returns an iterator to the first element whose key is not ordered before key.
iterator insert(const key_t_ &key_, mapped_t_ &&mapped_) noexcept
Move-value overload of insert.
auto or_else(this self_t_ &&self_, const_iterator it_, callable_t_ &&callable_) -> decltype(self_.end())
Iterator overload of or_else.
const_iterator cbegin(void) const
Returns a const iterator pointing to the first element (alias for begin).
Definition hxflat_map.hpp:404
void operator=(hxflat_map &&x_) noexcept
Move assigns from a temporary map using swap.
hxsize_t erase(const key_t_ &key_) noexcept
Removes all elements with the given key and destroys their key-value pairs.
bool operator<(const hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_x_ > &x_) const
Returns true if this map compares less than x lexicographically, using hxkey_equal and hxkey_less on ...
hxsize_t size(void) const
Returns the number of elements in the map.
Definition hxflat_map.hpp:516
hxflat_map(std::initializer_list< pair_t_ > x_) noexcept
Constructs a map by inserting every key-value pair from x in order using insert.
hxflat_map(const hxflat_map &x_) noexcept
Copy constructs from another hxflat_map.
const_iterator operator[](hxsize_t index_) const
Returns a const iterator to the element at index.
auto and_then(this self_t_ &&self_, const_iterator it_, callable_t_ &&callable_) -> hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< const mapped_t_ & >())))>
Iterator overload of and_then.
iterator find(const key_t_ &key_)
~hxflat_map(void) noexcept
Destructs the map and destroys all key-value pairs.
iterator operator[](hxsize_t index_)
mapped_t_ * values(void) noexcept
void operator=(const hxflat_map &x_) noexcept
Assigns the contents of x to this map.
const_iterator cend(void) const
Returns a const iterator pointing past the last element.
Definition hxflat_map.hpp:407
void clear(void) noexcept
Removes all elements and destroys their key-value pairs.
const_iterator upper_bound(const key_t_ &key_) const
Returns an iterator to the first element whose key is ordered after key.
hxkey_less_t<T> - A constexpr callable that returns true if the first object is less than the second.
Definition hxkey.hpp:91
Similar to std::allocator.
HX_NS_BEGIN_ constexpr hxsize_t hxallocator_dynamic_capacity
hxallocator_dynamic_capacity - A capacity value that allows for dynamic allocation.
Definition hxallocator.hpp:20
Implements or includes std::initializer_list depending on HX_USE_LIBCXX.
constexpr bool hxkey_equal(const A_ &a_, const B_ &b_)
hxkey_equal - Returns true if a and b are equivalent, deducing A and invoking hxkey_equal_t<A>.
Definition hxkey.hpp:80
constexpr bool hxkey_less(const A_ &a_, const B_ &b_)
hxkey_less - Returns true if a is less than b, deducing A and invoking hxkey_less_t<A>.
Definition hxkey.hpp:115
@ hxsystem_allocator_current
hxsystem_allocator_current - Use current allocation scope.
Definition hxmemory_manager.h:80
HX_C_BEGIN_ typedef unsigned int hxalignment_t
hxalignment_t - A positive integer power of 2 for aligning allocations.
Definition hxmemory_manager.h:62
int hxsystem_allocator_t
hxsystem_allocator_t - This is extendable by the application.
Definition hxmemory_manager.h:75
hxattr_noexcept hxsystem_allocator_t allocator_
Definition hxmemory_manager.h:120
hxattr_noexcept hxsystem_allocator_t hxalignment_t alignment_
Definition hxmemory_manager.h:121
constexpr hxalignment_t hxalignment
hxalignment - The default alignment.
Definition hxmemory_manager.h:67
Read-only range utilities for libhatchet.
#define hxattr_nodiscard
hxattr_nodiscard - Indicates the caller should not discard the return value.
Definition hxsettings.h:98
constexpr T && hxforward(hxremove_reference_t< T > &&x_)
hxforward - Implements std::forward.
Definition hxutility.h:353
hxremove_cv_t< hxremove_reference_t< T > > hxremove_cvref_t
hxremove_cvref_t<T> - Returns T with const, volatile, and references removed.
Definition hxutility.h:103
T && hxdeclval(void) noexcept
hxdeclval - Implements std::declval.
constexpr hxforward_like_t_< like_t_, value_t_ > hxforward_like(value_t_ &value_)
hxforward_like<T> - Returns value with the constness and value category of T.
Definition hxutility.h:387
Provides core macros, memory management and feature detection.
#define hxnull
hxnull - The null pointer value for a given pointer type represented by the numeric literal 0.
Definition libhatchet.h:280
ptrdiff_t hxsize_t
hxsize_t - A signed size type, same as ssize_t or ptrdiff_t.
Definition libhatchet.h:207