IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
container_concepts.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <ice/hash.hxx>
6#include <ice/stringid.hxx>
10
12{
13
14 template<typename T>
15 concept ContainerType = requires(T t) {
16 typename std::remove_reference_t<T>::SizeType;
17 typename std::remove_reference_t<T>::ValueType;
18 typename std::remove_reference_t<T>::ConstContainerValueType;
19 };
20
21 template<typename T>
22 concept AssociativeContainerType = ContainerType<T> && requires(T t) {
23 typename std::remove_reference_t<T>::KeyType;
24 typename std::remove_reference_t<T>::EntryType;
25 };
26
27 template<typename T>
28 concept Container = ContainerType<T> && requires(T t) {
29 { t.size() } -> std::convertible_to<ice::ncount>;
30 };
31
32 template<typename T>
34 && requires(T t, typename std::remove_reference_t<T>::KeyType key, typename std::remove_reference_t<T>::ValueType&& val) {
35 { t.size() } -> std::convertible_to<ice::ncount>;
36 { t.find(key) } -> std::convertible_to<typename std::remove_reference_t<T>::ValueType const*>;
37 };
38
39 template<typename T>
40 concept ResizableContainer = Container<T> && requires(T t, ice::ncount size) {
41 { t.capacity() } -> std::convertible_to<ice::ncount>;
42 { t.set_capacity(size) } -> std::convertible_to<void>;
43 { t.clear() } -> std::convertible_to<void>;
44 };
45
46 template<typename T>
48 T t,
49 typename std::remove_reference_t<T>::KeyType key,
50 typename std::remove_reference_t<T>::ValueType&& val)
51 {
52 { t.store(key, val) } -> std::convertible_to<typename std::remove_reference_t<T>::ValueType&>;
53 { t.remove(key) } -> std::convertible_to<bool>;
54 };
55
57
58 template<typename T>
59 concept ContiguousContainer = Container<T> && requires(T t) {
60 typename std::remove_reference_t<T>::Iterator;
61 typename std::remove_reference_t<T>::ReverseIterator;
62 typename std::remove_reference_t<T>::ConstIterator;
63 typename std::remove_reference_t<T>::ConstReverseIterator;
64 std::is_same_v<typename std::remove_reference_t<T>::ContainerTag, ContiguousContainerTag>;
65 { t.data() } -> std::convertible_to<typename std::remove_reference_t<T>::ValueType const*>;
66 { t.data_view() } -> std::convertible_to<ice::Data>;
67 };
68
69 template<typename T>
71 { t.memory_view() } -> std::convertible_to<ice::Memory>;
72 };
73
74 template<typename T>
77
78 template<typename T>
81
82 template<typename T>
83 concept HashableKeyType = requires(T t) {
84 { ice::hash(t) } -> std::convertible_to<ice::u64>;
85 };
86
87 template<typename Node>
88 concept LinkedListNode = requires(Node node) {
89 { node._next } -> std::convertible_to<void*>;
90 { node._next->_next } -> std::convertible_to<void*>;
91 };
92
93 template<typename T>
94 concept LinkedList = requires(T list) {
95 typename std::remove_reference_t<T>::ValueType;
96 { list._head } -> std::convertible_to<typename std::remove_reference_t<T>::ValueType>;
97 { list._tail } -> std::convertible_to<typename std::remove_reference_t<T>::ValueType>;
98 };
99
100} // namespace ice::concepts
101
102namespace ice
103{
104
105 template<typename T>
106 struct Span;
107
108} // namespace ice
109
110namespace ice::container
111{
112
113 template<ice::concepts::ContainerType ContainerT>
114 using ConstCorrectContainerValueType = std::conditional_t<
115 std::is_const_v<typename std::remove_reference_t<ContainerT>>,
116 typename std::remove_reference_t<ContainerT>::ConstContainerValueType,
117 typename std::remove_reference_t<ContainerT>::ValueType
118 >;
119
120 template<ice::concepts::ContainerType ContainerT>
121 using ConstCorrectContainerIterator = std::conditional_t<
122 std::is_const_v<typename std::remove_reference_t<ContainerT>>,
123 typename std::remove_reference_t<ContainerT>::ConstIterator,
124 typename std::remove_reference_t<ContainerT>::Iterator
125 >;
126
127 template<ice::concepts::ContainerType ContainerT>
128 using ConstCorrectContainerReverseIterator = std::conditional_t<
129 std::is_const_v<typename std::remove_reference_t<ContainerT>>,
130 typename std::remove_reference_t<ContainerT>::ConstReverseIterator,
131 typename std::remove_reference_t<ContainerT>::ReverseIterator
132 >;
133
134 template<ice::concepts::ContainerType ContainerT>
135 using KeyType = typename std::remove_reference_t<ContainerT>::KeyType;
136
137 template<ice::concepts::ContainerType ContainerT>
138 using KeyTypeArg = std::conditional_t<
139 sizeof(ice::container::KeyType<ContainerT>) <= 16 && std::is_trivially_copyable_v<ice::container::KeyType<ContainerT>>,
142 >;
143
144
145 template<ice::concepts::ContainerType ContainerT>
147
148 template<ice::concepts::ContainerType ContainerT>
150
151 template<ice::concepts::ContainerType ContainerT>
153
154 template<ice::concepts::ContainerType ContainerT>
156
157 template<ice::concepts::ContainerType ContainerT>
159
160 template<ice::concepts::ContainerType ContainerT>
162
163 template<ice::concepts::ContainerType ContainerT>
164 using ContainerType = typename std::remove_reference_t<ContainerT>;
165
166 template<ice::concepts::ContainerType ContainerT>
168
169} // namespace ice::container
170
171namespace ice::concepts
172{
173
174 template<typename TargetT, typename SourceContainerT>
175 concept CompatibleContainer = std::convertible_to<
177 TargetT
178 >;// && std::is_constructible_v<Type, ice::container::ValueType<ContainerT>>)
179
180
181 template<typename T>
183 { t.begin() } -> std::convertible_to<ice::container::Iterator<T>>;
184 { t.end() } -> std::convertible_to<ice::container::Iterator<T>>;
185 };
186
187 template<typename T>
188 concept ReverseIterableContainer = requires(T t) {
189 { t.rbegin() } -> std::convertible_to<ice::container::ReverseIterator<T>>;
190 { t.rend() } -> std::convertible_to<ice::container::ReverseIterator<T>>;
191 };
192
193} // namespace ice::concepts
A concept that ensures only types that can be trivially copyable can be 'forced' to use trifial Logic...
Definition container_logic.hxx:25
Definition container_concepts.hxx:33
Definition container_concepts.hxx:22
Definition container_concepts.hxx:47
Definition container_concepts.hxx:175
Definition container_concepts.hxx:28
Definition container_concepts.hxx:15
Definition container_concepts.hxx:59
Definition container_concepts.hxx:70
Definition container_concepts.hxx:83
Definition container_concepts.hxx:182
Definition container_concepts.hxx:94
Definition container_concepts.hxx:88
Definition container_concepts.hxx:79
Definition container_concepts.hxx:40
Definition container_concepts.hxx:188
Definition container_concepts.hxx:75
Definition container_concepts.hxx:12
Definition associative_container.hxx:8
std::conditional_t< std::is_const_v< typename std::remove_reference_t< ContainerT > >, typename std::remove_reference_t< ContainerT >::ConstContainerValueType, typename std::remove_reference_t< ContainerT >::ValueType > ConstCorrectContainerValueType
Definition container_concepts.hxx:114
ice::Span< ice::container::ConstCorrectContainerValueType< ContainerT > > SpanType
Definition container_concepts.hxx:167
ValueType< ContainerT > && ValueRVal
Definition container_concepts.hxx:152
ValueType< ContainerT > * ValuePtr
Definition container_concepts.hxx:155
typename std::remove_reference_t< ContainerT >::KeyType KeyType
Definition container_concepts.hxx:135
std::conditional_t< sizeof(ice::container::KeyType< ContainerT >)<=16 &&std::is_trivially_copyable_v< ice::container::KeyType< ContainerT > >, ice::container::KeyType< ContainerT >, ice::container::KeyType< ContainerT > const & > KeyTypeArg
Definition container_concepts.hxx:138
typename std::remove_reference_t< ContainerT > ContainerType
Definition container_concepts.hxx:164
ConstCorrectContainerReverseIterator< ContainerT > ReverseIterator
Definition container_concepts.hxx:161
std::conditional_t< std::is_const_v< typename std::remove_reference_t< ContainerT > >, typename std::remove_reference_t< ContainerT >::ConstIterator, typename std::remove_reference_t< ContainerT >::Iterator > ConstCorrectContainerIterator
Definition container_concepts.hxx:121
ConstCorrectContainerValueType< ContainerT > ValueType
Definition container_concepts.hxx:146
std::conditional_t< std::is_const_v< typename std::remove_reference_t< ContainerT > >, typename std::remove_reference_t< ContainerT >::ConstReverseIterator, typename std::remove_reference_t< ContainerT >::ReverseIterator > ConstCorrectContainerReverseIterator
Definition container_concepts.hxx:128
ConstCorrectContainerIterator< ContainerT > Iterator
Definition container_concepts.hxx:158
ValueType< ContainerT > & ValueRef
Definition container_concepts.hxx:149
SPDX-License-Identifier: MIT.
Definition array.hxx:12
constexpr auto hash(ice::HeapString<> const &value) noexcept -> ice::u64
Definition heap_string.hxx:251
A view into an array of objects laid out in contiguous memory.
Definition span.hxx:17
Definition container_concepts.hxx:56
Definition ncount.hxx:14