Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches
CMap< Key, Value, Size > Class Template Reference

This class is designed to implement a constexpr version of std::map. The standard library std::map doesn't allow constexpr (and it doesn't look like it will be implemented in the future). This class utilizes std::array and std::pair as they allow constexpr. More...

#include <Map.h>

Public Member Functions

template<typename Iterable >
constexpr CMap (Iterable begin, Iterable end)
 
 ~CMap ()=default
 
constexpr const Value & at (const Key &key) const
 
constexpr auto find (const Key &key) const
 
constexpr size_t size () const
 
constexpr auto cbegin () const
 
constexpr auto cend () const
 

Detailed Description

template<typename Key, typename Value, size_t Size>
class CMap< Key, Value, Size >

This class is designed to implement a constexpr version of std::map. The standard library std::map doesn't allow constexpr (and it doesn't look like it will be implemented in the future). This class utilizes std::array and std::pair as they allow constexpr.

When using this class you should use the helper make_map instead of constructing this class directly. For example: constexpr auto myMap = make_map<int, std::string_view>({{1, "one"}});

This class is useful for mapping enum values to strings that can be compile time checked. This also helps with heap usage.

Lookups have linear complexity, so should not be used for "big" maps.

Constructor & Destructor Documentation

◆ CMap()

template<typename Key , typename Value , size_t Size>
template<typename Iterable >
constexpr CMap< Key, Value, Size >::CMap ( Iterable begin,
Iterable end )
inlineconstexpr
Todo
: c++20 can use constexpr assignment operator instead

◆ ~CMap()

template<typename Key , typename Value , size_t Size>
CMap< Key, Value, Size >::~CMap ( )
default

Member Function Documentation

◆ at()

template<typename Key , typename Value , size_t Size>
constexpr const Value & CMap< Key, Value, Size >::at ( const Key & key) const
inlineconstexpr

◆ cbegin()

template<typename Key , typename Value , size_t Size>
constexpr auto CMap< Key, Value, Size >::cbegin ( ) const
inlineconstexpr

◆ cend()

template<typename Key , typename Value , size_t Size>
constexpr auto CMap< Key, Value, Size >::cend ( ) const
inlineconstexpr

◆ find()

template<typename Key , typename Value , size_t Size>
constexpr auto CMap< Key, Value, Size >::find ( const Key & key) const
inlineconstexpr

◆ size()

template<typename Key , typename Value , size_t Size>
constexpr size_t CMap< Key, Value, Size >::size ( ) const
inlineconstexpr

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