koutil
Loading...
Searching...
No Matches
koutil::container::ComptimeMap< Key, Value, Size > Class Template Reference

A compile-time map implementation. More...

#include <comptime_map.h>

Public Types

using pair_t = std::pair<Key, Value>
 
using pairs_t = std::array<pair_t, Size>
 

Public Member Functions

consteval ComptimeMap (pairs_t pairs)
 Constructs a compile-time map from an array of pairs.
 
consteval bool contains_duplicate_key () const
 Checks if there are duplicate keys in the map.
 
constexpr std::size_t find (const Key &key) const
 Finds the index of a key in the map.
 
constexpr const Value & operator[] (const Key &key) const
 Retrieves the value associated with a key.
 
constexpr const Value & at (const Key &key) const
 Retrieves the value associated with a key.
 
constexpr const Value & safe_at (const Key &key, const Value &default_value) const
 Retrieves the value associated with a key or a default value if not found.
 
constexpr const Value & unsafe_get (std::size_t index) const
 Retrieves the value at a specific index.
 
constexpr const pair_tget_pair (const Key &key) const
 Retrieves the key-value pair associated with a key.
 
constexpr bool contains (const Key &key) const
 Checks if the map contains a key.
 
consteval bool test_value (const Value &value) const
 Checks if a specific value exists in the map.
 
consteval bool test_no_value (const Value &value) const
 Checks if a specific value does not exist in the map.
 

Static Public Attributes

static constexpr auto npos = std::numeric_limits<std::size_t>::max()
 

Private Attributes

pairs_t m_data
 

Detailed Description

template<typename Key, typename Value, std::size_t Size>
class koutil::container::ComptimeMap< Key, Value, Size >

A compile-time map implementation.

Template Parameters
KeyThe key type.
ValueThe value type.
SizeThe size of the map.

Member Typedef Documentation

◆ pair_t

template<typename Key , typename Value , std::size_t Size>
using koutil::container::ComptimeMap< Key, Value, Size >::pair_t = std::pair<Key, Value>

◆ pairs_t

template<typename Key , typename Value , std::size_t Size>
using koutil::container::ComptimeMap< Key, Value, Size >::pairs_t = std::array<pair_t, Size>

Constructor & Destructor Documentation

◆ ComptimeMap()

template<typename Key , typename Value , std::size_t Size>
koutil::container::ComptimeMap< Key, Value, Size >::ComptimeMap ( pairs_t pairs)
inlineconsteval

Constructs a compile-time map from an array of pairs.

Parameters
pairsThe array of key-value pairs.

Member Function Documentation

◆ at()

template<typename Key , typename Value , std::size_t Size>
const Value & koutil::container::ComptimeMap< Key, Value, Size >::at ( const Key & key) const
inlinenodiscardconstexpr

Retrieves the value associated with a key.

Parameters
keyThe key.
Returns
The value associated with the key.

◆ contains()

template<typename Key , typename Value , std::size_t Size>
bool koutil::container::ComptimeMap< Key, Value, Size >::contains ( const Key & key) const
inlinenodiscardconstexpr

Checks if the map contains a key.

Parameters
keyThe key to check.
Returns
True if the map contains the key, false otherwise.

◆ contains_duplicate_key()

template<typename Key , typename Value , std::size_t Size>
bool koutil::container::ComptimeMap< Key, Value, Size >::contains_duplicate_key ( ) const
inlinenodiscardconsteval

Checks if there are duplicate keys in the map.

Returns
True if duplicate keys are found, false otherwise.

◆ find()

template<typename Key , typename Value , std::size_t Size>
std::size_t koutil::container::ComptimeMap< Key, Value, Size >::find ( const Key & key) const
inlinenodiscardconstexpr

Finds the index of a key in the map.

Parameters
keyThe key to find.
Returns
The index of the key if found, npos otherwise.

◆ get_pair()

template<typename Key , typename Value , std::size_t Size>
const pair_t & koutil::container::ComptimeMap< Key, Value, Size >::get_pair ( const Key & key) const
inlinenodiscardconstexpr

Retrieves the key-value pair associated with a key.

Parameters
keyThe key.
Returns
The key-value pair.

◆ operator[]()

template<typename Key , typename Value , std::size_t Size>
const Value & koutil::container::ComptimeMap< Key, Value, Size >::operator[] ( const Key & key) const
inlinenodiscardconstexpr

Retrieves the value associated with a key.

Parameters
keyThe key.
Returns
The value associated with the key.

◆ safe_at()

template<typename Key , typename Value , std::size_t Size>
const Value & koutil::container::ComptimeMap< Key, Value, Size >::safe_at ( const Key & key,
const Value & default_value ) const
inlinenodiscardconstexpr

Retrieves the value associated with a key or a default value if not found.

Parameters
keyThe key.
default_valueThe default value.
Returns
The value associated with the key if found, default_value otherwise.

◆ test_no_value()

template<typename Key , typename Value , std::size_t Size>
bool koutil::container::ComptimeMap< Key, Value, Size >::test_no_value ( const Value & value) const
inlinenodiscardconsteval

Checks if a specific value does not exist in the map.

Parameters
valueThe value to check.
Returns
True if the value does not exist, false otherwise.

◆ test_value()

template<typename Key , typename Value , std::size_t Size>
bool koutil::container::ComptimeMap< Key, Value, Size >::test_value ( const Value & value) const
inlinenodiscardconsteval

Checks if a specific value exists in the map.

Parameters
valueThe value to check.
Returns
True if the value exists, false otherwise.

◆ unsafe_get()

template<typename Key , typename Value , std::size_t Size>
const Value & koutil::container::ComptimeMap< Key, Value, Size >::unsafe_get ( std::size_t index) const
inlinenodiscardconstexpr

Retrieves the value at a specific index.

Parameters
indexThe index.
Returns
The value at the specified index.

Member Data Documentation

◆ m_data

template<typename Key , typename Value , std::size_t Size>
pairs_t koutil::container::ComptimeMap< Key, Value, Size >::m_data
private

◆ npos

template<typename Key , typename Value , std::size_t Size>
auto koutil::container::ComptimeMap< Key, Value, Size >::npos = std::numeric_limits<std::size_t>::max()
staticconstexpr

The documentation for this class was generated from the following file: