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
19
template
<
typename
Key,
typename
Value,
size_t
Size>
20
class
Map
{
21
public
:
27
explicit
constexpr
Map
(
const
std::array<std::pair<Key, Value>, Size>& data)
28
: data{data} {}
29
37
[[nodiscard]]
38
constexpr
const
Value&
at
(
const
Key& key)
const
{
39
if
(
const
auto
it =
40
std::find_if(std::begin(data), std::end(data),
41
[&key](
const
auto
& v) {
return
v.first == key; });
42
it != std::end(data)) {
43
return
it->second;
44
}
else
{
45
throw
std::range_error(
"Key not found"
);
46
}
47
}
48
49
private
:
50
std::array<std::pair<Key, Value>, Size> data;
51
};
52
53
template
<
typename
Key,
typename
Value,
size_t
Size>
54
Map(
const
std::array<std::pair<Key, Value>, Size>&) -> Map<Key, Value, Size>;
55
56
}
// namespace choreo::util
choreo::util::Map
Definition
Map.h:20
choreo::util::Map::Map
constexpr Map(const std::array< std::pair< Key, Value >, Size > &data)
Definition
Map.h:27
choreo::util::Map::at
constexpr const Value & at(const Key &key) const
Definition
Map.h:38
src
main
native
include
choreo
util
Map.h
Generated on Mon Mar 3 2025 05:51:12 for ChoreoLib by
1.9.8