|
constexpr | IntMap (const std::initializer_list< std::pair< KeyType, ValueType > > &init) |
|
constexpr bool | operator== (const IntMap &other) const |
|
constexpr bool | operator!= (const IntMap &other) const |
|
constexpr ValueType & | operator[] (KeyType i) |
|
constexpr const ValueType & | operator[] (KeyType i) const |
|
constexpr ValueType & | at (KeyType i) |
|
constexpr const ValueType & | at (KeyType i) const |
|
constexpr iterator | begin () |
|
constexpr iterator | end () |
|
constexpr const_iterator | begin () const |
|
constexpr const_iterator | end () const |
|
constexpr iterator | lower_bound (KeyType i) |
|
constexpr iterator | upper_bound (KeyType i) |
|
constexpr const_iterator | lower_bound (KeyType i) const |
|
constexpr const_iterator | upper_bound (KeyType i) const |
|
constexpr uint64_t | empty () const |
|
constexpr uint64_t | size () const |
|
constexpr int | count (KeyType i) const |
|
constexpr bool | contains (KeyType i) const |
|
constexpr void | insert (sp::Pair< KeyType, ValueType > p) |
|
constexpr void | erase (KeyType i) |
|
template<typename Fn > |
constexpr void | map (const Fn &fn) |
| Apply a map function to the values in the IntMap . More...
|
|
template<typename Result , typename Fn > |
constexpr Result | reduce (const Fn &fn, Result initialResult={}) |
| Apply a reduce function to the values in the IntMap . More...
|
|
constexpr const IntSet< KeyType, KeyBits > & | keySet () |
|
template<typename KeyType, typename ValueType, int KeyBits = sizeof(KeyType) * 8>
class sp::c::IntMap< KeyType, ValueType, KeyBits >
Like std::map
, but for compile-time use.
Unlike std::map, access and update operations are constant-time.
- Note
- Like all structures in the
sp::c
namespace, this cannot be used at runtime.
- Template Parameters
-
KeyType | The key type of the map. This must be a fundamental integer type. |
ValueType | The value type of the map. Must be default constexpr constructible and constexpr copyable, or a fundamental data type. |
KeyBits | The number of bits in the key to use. The default is the size needed to store any value of KeyType. This template parameter is useful to limit the address space used by the container (e.g: to nest containers). For unsigned integers, the minimum value is 0 and the maximum value is 2^KeyBits - 1 . For signed integers, the minimum value is -2^(KeyBits - 1) and the maximum is 2^(KeyBits - 1) - 1 . This must be at least 0 , and at most sizeof(KeyType) * 8 . |
template<typename KeyType , typename ValueType , int KeyBits = sizeof(KeyType) * 8>
template<typename Result , typename Fn >
constexpr Result sp::c::IntMap< KeyType, ValueType, KeyBits >::reduce |
( |
const Fn & |
fn, |
|
|
Result |
initialResult = {} |
|
) |
| |
|
constexpr |
Apply a reduce function to the values in the IntMap
.
- Template Parameters
-
Result | The type of the result (also used as the accumulator). |
Fn | The type of the function. The function must accept three arguments: (Result &, KeyType, ValueType). The third argument is the accumulator to write to. |
- Parameters
-
fn | The function object. This can be a function pointer, or an object with operator(). |
initialResult | The result to use before any elements of the IntMap have been processed. |
- Returns
- The result of the reduction.