HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
tagged_map.hpp
1// Copyright Take Vos 2019, 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "tag.hpp"
8#include "utility/module.hpp"
9#include <typeinfo>
10#include <typeindex>
11#include <array>
12
13namespace hi::inline v1 {
14
15template<typename T, fixed_string... Tags>
17private:
18 std::array<T, sizeof...(Tags)> data;
19
20public:
21 static constexpr std::size_t size() noexcept
22 {
23 return sizeof...(Tags);
24 }
25
26 static std::string get_tag(std::size_t i) noexcept
27 {
28 return tag_at_index<Tags...>(i);
29 }
30
31 static bool has(std::string tag) noexcept
32 {
33 return has_tag<Tags...>(tag);
34 }
35
36 constexpr auto begin() noexcept
37 {
38 return data.begin();
39 }
40
41 constexpr auto end() noexcept
42 {
43 return data.end();
44 }
45
46 constexpr auto begin() const noexcept
47 {
48 return data.begin();
49 }
50
51 constexpr auto end() const noexcept
52 {
53 return data.end();
54 }
55
56 constexpr T &operator[](std::size_t i) noexcept
57 {
58 return data[i];
59 }
60
61 constexpr T const &operator[](std::size_t i) const noexcept
62 {
63 return data[i];
64 }
65
66 T &get(std::string tag) noexcept
67 {
68 return data[index_of_tag<Tags...>(tag)];
69 }
70
71 T const &get(std::string tag) const noexcept
72 {
73 return data[index_of_tag<Tags...>(tag)];
74 }
75
76 template<fixed_string Tag>
77 constexpr T &get() noexcept
78 {
79 return data[index_of_tag<Tag, Tags...>()];
80 }
81
82 template<fixed_string Tag>
83 constexpr T const &get() const noexcept
84 {
85 return data[index_of_tag<Tag, Tags...>()];
86 }
87};
88
89} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:13
std::size_t index_of_tag(std::string tag) noexcept
Definition tag.hpp:55
std::string tag_at_index(std::size_t index) noexcept
Definition tag.hpp:32
Definition tagged_map.hpp:16