-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsynopsis.hpp
More file actions
267 lines (199 loc) · 10.4 KB
/
synopsis.hpp
File metadata and controls
267 lines (199 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#pragma once
#include "data_v1/private.hpp"
#include <array>
namespace data_v1 {
// array.hpp ===================================================================
/// Returns the number of elements in the given array.
template <class Value, size_t N> constexpr auto size(const Value (&array)[N]);
/// Returns a pointer (or iterator) to the beginning of the array.
template <class Value, size_t N> auto begin(Value (&array)[N]);
/// Returns a pointer (or iterator) to the beginning of the array.
template <class Value, size_t N> auto begin(const Value (&array)[N]);
/// Returns a pointer (or iterator) to the end of the array.
template <class Value, size_t N> auto end(Value (&array)[N]);
/// Returns a pointer (or iterator) to the end of the array.
template <class Value, size_t N> auto end(const Value (&array)[N]);
/// Returns a reference to the first element of the array.
template <class Value, size_t N> auto &front(Value (&array)[N]);
/// Returns a reference to the first element of the array.
template <class Value, size_t N> const auto &front(const Value (&array)[N]);
/// Returns a reference to the last element of the array.
template <class Value, size_t N> auto &back(Value (&array)[N]);
/// Returns a reference to the last element of the array.
template <class Value, size_t N> const auto &back(const Value (&array)[N]);
// lazy.hpp ====================================================================
/// `lazy_t<Thunk>` represents a lazily computed result. WARNING: This is
/// currently not thread safe.
template <class Thunk> struct lazy_t : Private::lazy<Thunk> {
using result_type = std::invoke_result_t<Thunk>;
/// Constructs a lazily computed result.
template <class ThatThunk> lazy_t(ThatThunk &&thunk);
/// Computes and stores the result if that hasn't yet been done and returns a
/// reference to it.
operator result_type &();
/// Computes and stores the result if that hasn't yet been done and returns a
/// const reference to it.
operator const result_type &() const;
};
/// Constructs a lazily computed result.
template <class Thunk> auto lazy(Thunk &&thunk);
// strided_iterator.hpp ========================================================
/// `strided_iterator_t<Value, Stride> is the iterator type of `strided_t<Value,
/// Stride, *>`. The stride in bytes between elements can be given either
/// statically or dynamically.
template <class Value, ptrdiff_t Stride = dynamic_stride>
struct strided_iterator_t : Private::strided_iterator<Value, Stride> {
using value_type = Value;
/// The static value of stride in bytes or `dynamic_stride` in which case
/// the step is only known dynamically.
static constexpr ptrdiff_t stride = Stride;
/// Constructs a strided iterator from a raw pointer and stride in bytes.
strided_iterator_t(Value *pointer, ptrdiff_t step);
/// Returns the stride in bytes between elements.
auto step() const;
/// Returns a reference to the current element. The result is undefined in
/// case the iterator does not point to an actual element in a strided array.
auto &operator*() const;
/// Compares `lhs` and `rhs` for equality. Both iterators must originate from
/// the same strided array.
static auto equals(const strided_iterator_t &lhs,
const strided_iterator_t &rhs);
/// Moves to next element. The result is undefined in case the iterator
/// points to beyond the last element of the underlying sequence.
auto increment();
/// Moves to previous element. The result is undefined in case the iterator
/// points to the first element of the underlying sequence.
auto decrement();
};
/// Compares `lhs` and `rhs` for equality. Both iterators must originate from
/// the same strided array.
template <class Value, ptrdiff_t Stride>
auto operator==(const strided_iterator_t<Value, Stride> &lhs,
const strided_iterator_t<Value, Stride> &rhs);
/// Compares `lhs` and `rhs` for inequality. Both iterators must originate from
/// the same strided array.
template <class Value, ptrdiff_t Stride>
auto operator!=(const strided_iterator_t<Value, Stride> &lhs,
const strided_iterator_t<Value, Stride> &rhs);
/// Moves to next element. The result is undefined in case the iterator
/// points to beyond the last element of the underlying sequence.
template <class Value, ptrdiff_t Stride>
auto &operator++(strided_iterator_t<Value, Stride> &i);
/// Moves to next element. The result is undefined in case the iterator
/// points to beyond the last element of the underlying sequence.
template <class Value, ptrdiff_t Stride>
auto &&operator++(strided_iterator_t<Value, Stride> &&i);
/// Moves to next element and returns a copy of the given iterator before
/// moving. The effect is undefined in case the iterator points to beyond the
/// last element of the underlying sequence.
template <class Value, ptrdiff_t Stride>
auto operator++(strided_iterator_t<Value, Stride> &i, int);
/// Moves to previous element. The result is undefined in case the iterator
/// points to the first element of the underlying sequence.
template <class Value, ptrdiff_t Stride>
auto &operator--(strided_iterator_t<Value, Stride> &i);
/// Moves to previous element. The result is undefined in case the iterator
/// points to the first element of the underlying sequence.
template <class Value, ptrdiff_t Stride>
auto &&operator--(strided_iterator_t<Value, Stride> &&i);
/// Moves to previous element and returns a copy of the given iterator before
/// moving. The effect is undefined in case the iterator points to the first
/// element of the underlying sequence.
template <class Value, ptrdiff_t Stride>
auto operator--(strided_iterator_t<Value, Stride> &i, int);
// strided.hpp =================================================================
/// A `strided_t<Value, Stride, Extent>` is basically a generalization of both
/// `std::span<Value, Extent>` and `std::array<Value, Extent>` and is a view of
/// or a reference to a subsequence of elements of an array. Both the stride in
/// bytes between elements and the extent or number of elements can be given
/// either statically or dynamically. In case the stride is given statically,
/// and is `sizeof(Value)`, then the array is contiguous.
template <class Value,
ptrdiff_t Stride = dynamic_stride,
size_t Extent = dynamic_extent>
struct strided_t : Private::strided<Value, Stride, Extent> {
using element_type = Value;
using iterator_type = strided_iterator_t<Value, Stride>;
/// The static value of stride in bytes or `dynamic_stride` in which case
/// the step is only known dynamically.
static constexpr ptrdiff_t stride = Stride;
/// The static value of extent or `dynamic_extent` in which case
/// the size is only known dynamically.
static constexpr size_t extent = Extent;
/// Constructs a strided array from a raw pointer, stride in bytes, and number
/// of elements.
strided_t(Value *begin, ptrdiff_t step, size_t size);
/// Constructs a strided array from two raw pointers.
template <class ThatValue> strided_t(ThatValue *begin, ThatValue *end);
/// Constructs a strided array from specified array.
template <class ThatValue, size_t ThatExtent>
strided_t(ThatValue (&that)[ThatExtent]);
/// Constructs a strided array from given strided array (of different type).
template <class ThatValue, ptrdiff_t ThatStride, size_t ThatExtent>
strided_t(const strided_t<ThatValue, ThatStride, ThatExtent> &that);
/// Constructs a strided array from a given `std::array`.
template <class ThatValue, size_t ThatExtent>
strided_t(std::array<ThatValue, ThatExtent> &array);
/// Constructs a strided array from a given `std::array`.
template <class ThatValue, size_t ThatExtent>
strided_t(const std::array<ThatValue, ThatExtent> &array);
/// Checks if the sequence is empty.
auto empty() const;
/// Returns the number of elements in the sequence.
auto size() const;
/// Returns the stride in bytes between elements.
auto step() const;
/// Returns reference to the `i`th element in the sequence.
auto &operator[](size_t i) const;
/// Returns an iterator to the beginning of the sequence.
auto begin() const;
/// Returns an iterator to the end of the sequence.
auto end() const;
/// Returns an iterator to the beginning of the reversed sequence. See also:
/// `reversed`.
auto rbegin() const;
/// Returns an iterator to the end of the reversed sequence. See also:
/// `reversed`.
auto rend() const;
/// Returns a reference to the first element of the sequence. The result is
/// undefined in case the sequence is empty.
auto &front() const;
/// Returns a reference to the last element of the sequence. The result is
/// undefined in case the sequence is empty.
auto &back() const;
};
/// Type alias for a strided array whose elements are statically known to be
/// stored contiguously.
template <class Value, size_t Extent = dynamic_extent>
using contiguous_t = strided_t<Value, sizeof(Value), Extent>;
/// Constructs a strided array from a raw pointer, stride in bytes, and number
/// of elements.
template <class Value> auto strided(Value *begin, ptrdiff_t step, size_t size);
/// Constructs a strided array from two raw pointers.
template <class Value> auto strided(Value *begin, Value *end);
/// Constructs a strided array from specified array.
template <class Value, size_t N> auto strided(Value (&array)[N]);
/// Constructs a strided array from specified array.
template <class Value, size_t N> auto strided(const Value (&array)[N]);
/// Constructs a strided array from a `std::array`.
template <class Value, size_t Extent>
auto strided(std::array<Value, Extent> &array);
/// Constructs a strided array from a `std::array`.
template <class Value, size_t Extent>
auto strided(const std::array<Value, Extent> &array);
/// View of members of the given strided array of structures.
template <class SubtypeOfStruct,
ptrdiff_t Stride,
size_t Extent,
class Struct,
class Value>
auto focused_on(Value(Struct::*member),
const strided_t<SubtypeOfStruct, Stride, Extent> &array);
/// Reversed view of the given strided array.
template <class Value, ptrdiff_t Stride, size_t Extent>
auto reversed(const strided_t<Value, Stride, Extent> &array);
// struct.hpp ==================================================================
/// Returns a pointer to the specified member of the pointed structure.
template <class Struct, class Value>
auto *pointer_of(Value(Struct::*member), Struct *whole = nullptr);
} // namespace data_v1