ChoreoLib
Choreo support library.
Loading...
Searching...
No Matches
Map.h
1
// Copyright (c) Choreo contributors
2
3
#pragma once
4
5
#include <algorithm>
6
#include <array>
7
#include <stdexcept>
8
#include <utility>
9
10
namespace
choreo::util {
11
17
template
<
typename
Key,
typename
Value,
size_t
Size>
18
class
Map
{
19
public
:
23
explicit
constexpr
Map
(
const
std::array<std::pair<Key, Value>, Size>& data)
24
: data{data} {}
25
31
[[nodiscard]]
32
constexpr
const
Value&
at
(
const
Key& key)
const
{
33
if
(
const
auto
it =
34
std::find_if(std::begin(data), std::end(data),
35
[&key](
const
auto
& v) {
return
v.first == key; });
36
it != std::end(data)) {
37
return
it->second;
38
}
else
{
39
throw
std::range_error(
"Key not found"
);
40
}
41
}
42
43
private
:
44
std::array<std::pair<Key, Value>, Size> data;
45
};
46
47
template
<
typename
Key,
typename
Value,
size_t
Size>
48
Map(
const
std::array<std::pair<Key, Value>, Size>&) -> Map<Key, Value, Size>;
49
50
}
// namespace choreo::util
choreo::util::Map
Definition
Map.h:18
choreo::util::Map::Map
constexpr Map(const std::array< std::pair< Key, Value >, Size > &data)
Definition
Map.h:23
choreo::util::Map::at
constexpr const Value & at(const Key &key) const
Definition
Map.h:32
src
main
native
include
choreo
util
Map.h
Generated on Tue Dec 9 2025 22:15:30 for ChoreoLib by
1.9.8