Go to the documentation of this file.
9 #ifndef EAGINE_KEY_VAL_LIST_HPP
10 #define EAGINE_KEY_VAL_LIST_HPP
14 #include <type_traits>
20 template <
typename Traits, std::
size_t N = 0>
26 template <
typename Traits>
42 template <
typename Traits, std::
size_t N>
43 struct key_value_list_base;
45 template <
typename Traits>
46 struct key_value_list_base<Traits, 0> {
49 key_value_list_base() =
default;
51 static auto data() noexcept -> const
value_type* {
52 static const value_type term = Traits::terminator();
57 template <
typename Traits>
58 struct key_value_list_base<Traits, 2> {
59 std::array<typename Traits::value_type, 3> _elements;
61 using key_type =
typename Traits::key_type;
62 using conv_type =
typename Traits::conv_type;
65 constexpr key_value_list_base(key_type key,
value_type value) noexcept
66 : _elements{{
value_type(conv_type(key)), value, Traits::terminator()}} {}
68 constexpr key_value_list_base(
69 const key_value_list_base<Traits, 0>&,
72 std::index_sequence<>) noexcept
73 : _elements{{
value_type(conv_type(key)), value, Traits::terminator()}} {}
75 auto data() const noexcept -> const
value_type* {
76 return _elements.data();
80 template <
typename Traits, std::
size_t N>
81 struct key_value_list_base {
82 std::array<typename Traits::value_type, N + 1> _elements;
84 using key_type =
typename Traits::key_type;
85 using conv_type =
typename Traits::conv_type;
91 typename = std::enable_if_t<(M + 2 == N) && (
sizeof...(I) == M)>>
92 constexpr key_value_list_base(
93 const key_value_list_base<Traits, M>&
head,
96 std::index_sequence<I...>) noexcept
98 {
head._elements[I]...,
101 Traits::terminator()}} {}
103 auto data() const noexcept -> const
value_type* {
104 return _elements.data();
112 template <
typename Traits, std::
size_t N>
113 class key_value_list {
124 template <std::
size_t M,
typename = std::enable_if_t<M + 2 == N>>
126 const key_value_list_base<Traits, M>&
head,
129 : _base(
head, key, value, std::make_index_sequence<M>()) {}
149 return {data(), data() + size()};
155 return {data(), size()};
162 return {_base, key_val._key, key_val._value};
166 key_value_list_base<Traits, N> _base;
173 template <
typename Traits>
185 template <
typename Traits, std::
size_t N>
195 #endif // EAGINE_KEY_VAL_LIST_HPP
value_type
Value tree value element data type enumeration.
Definition: interface.hpp:27
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
static constexpr auto span_size(T v) noexcept
Converts argument to span size type.
Definition: types.hpp:59
A single key/value pair for a key/value list.
Definition: key_val_list.hpp:27
Common code is placed in this namespace.
Definition: eagine.hpp:21
typename Traits::key_type key_type
Alias for the key type.
Definition: key_val_list.hpp:116
static constexpr auto head(basic_span< T, P, S > s, L l) noexcept -> basic_span< T, P, S >
Returns the first l elements from the front of a span.
Definition: span_algo.hpp:99
basic_span< T, T *, S > span
Default alias for basic memory spans with native pointer type.
Definition: span.hpp:415
typename Traits::key_type key_type
Alias for the key type.
Definition: key_val_list.hpp:29
Basic N-dimensional vector implementation template.
Definition: fwd.hpp:19
constexpr key_value_list_element(key_type key, value_type value) noexcept
Construction from the key and the value.
Definition: key_val_list.hpp:37
typename Traits::value_type value_type
Alias for the value type.
Definition: key_val_list.hpp:119
typename Traits::value_type value_type
Alias for the value type.
Definition: key_val_list.hpp:31
static constexpr auto operator+(const key_value_list< Traits, N > &l, const key_value_list_element< Traits > &r) noexcept -> key_value_list< Traits, N+2 >
Adds a key/value pair into a key/value list, returns a new list.
Definition: key_val_list.hpp:186
auto get() const noexcept -> span< const value_type >
A const view of the internal element array.
Definition: key_val_list.hpp:154
static constexpr auto size() noexcept -> span_size_t
Returns the size of the element array (including the terminating zero).
Definition: key_val_list.hpp:136
Template for classes wrapping static key/value typically attribute lists.
Definition: key_val_list.hpp:21
constexpr auto append(const key_value_list_element< Traits > &key_val) const noexcept -> key_value_list< Traits, N+2 >
Appends a key/value pair and returns a new extended list.
Definition: key_val_list.hpp:160
static constexpr auto operator+(const key_value_list_element< Traits > &l, const key_value_list_element< Traits > &r) noexcept -> key_value_list< Traits, 4 >
Concatenates two individual key/value elements into a key/value list.
Definition: key_val_list.hpp:174
auto copy() const noexcept -> std::vector< value_type >
Copies the internal element array into a vector.
Definition: key_val_list.hpp:148
auto data() const noexcept -> const value_type *
Returns a pointer to the internal element array.
Definition: key_val_list.hpp:142