Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
span.hpp
Go to the documentation of this file.
1// Copyright 2024, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_SPAN_SPAN_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_SPAN_SPAN_HPP_
7
8// IWYU pragma: private, include "arene/base/span.hpp"
9// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11// parasoft-begin-suppress AUTOSAR-A7_1_5-a-2 "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
12
13// AUTOSAR exceptions:
14// A11-3-1: Friend declarations shall not be used
15// The span::iterator type declares the outer span type to be a friend so that
16// the constructor can be private, preventing user code constructing iterators
17// with pointers outside the span.
18// The span::iterator non-member operator overloads are declared to be friends
19// to allow them to be defined within the class. This ensures that they are only
20// considered for overload resolution and name lookup when at least one of the
21// parameters is an iterator, and avoids the namespace-scope template overloads
22// that would otherwise be required.
23//
24// M5-0-15: Array indexing shall be the only form of pointer arithmetic.
25// span inherently refers to an array of elements. Pointer arithmetic is only
26// used to adjust the pointer within that array, as covered by M5-0-16 and
27// M5-0-17, unless iterators are incremented unchecked.
28//
29// A5-0-4: Pointer arithmetic shall not be used with pointers to non-final
30// classes.
31// The span constructors do not allow constructing a span<Base> from a
32// Derived*, so pointer arithmetic is safe unless the user does an explicit
33// cast.
34
35// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers"
41#include "arene/base/detail/dynamic_extent.hpp"
42#include "arene/base/detail/wrapped_iterator.hpp" // IWYU pragma: keep
46#include "arene/base/stdlib_choice/conditional.hpp"
47#include "arene/base/stdlib_choice/cstddef.hpp"
48#include "arene/base/stdlib_choice/declval.hpp"
49#include "arene/base/stdlib_choice/enable_if.hpp"
50#include "arene/base/stdlib_choice/integral_constant.hpp"
51#include "arene/base/stdlib_choice/is_const.hpp"
52#include "arene/base/stdlib_choice/numeric_limits.hpp"
53#include "arene/base/stdlib_choice/remove_cv.hpp"
54#include "arene/base/stdlib_choice/remove_reference.hpp"
55#include "arene/base/stdlib_choice/tuple_size.hpp"
58// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
59
60// parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
61
62namespace arene {
63namespace base {
64
65// IWYU pragma: begin_keep
66template <typename T, std::size_t Extent = dynamic_extent>
67class span;
68// IWYU pragma: end_keep
69
70namespace span_detail {
71
72/// @brief Helper function for gcc8 to get @c dynamic_extent
73/// @return The value of @c dynamic_extent
74constexpr auto get_dynamic_extent() noexcept -> std::size_t { return dynamic_extent; }
75
76// parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "Passkey idiom permitted by A11-3-1 Permit #1"
77/// @brief A passkey type to restrict constructing span's iterator to span.
78class span_iter_passkey {
79 private:
80 /// @brief Default-ctor is explicit to prevent construction via {}.
81 explicit span_iter_passkey() noexcept = default;
82 template <typename T, std::size_t Extent>
83 friend class ::arene::base::span;
84};
85// parasoft-end-suppress AUTOSAR-A11_3_1-a-2
86
87/// @brief Validate the extent of a source span given a target span
88/// @param my_extent The extent of the source span
89/// @param target_extent The extent of the target span
90/// @return @c true If @c my_extent==dynamic_extent or if @c my_extent==target_extent .
91/// @c false Otherwise.
92constexpr auto is_valid_source_extent(std::size_t const my_extent, std::size_t const target_extent) noexcept -> bool {
93 return (my_extent == dynamic_extent) || (my_extent == target_extent);
94}
95
96/// @brief Validate the size of a dynamic span
97/// @param my_extent The extent of the source span
98/// @param target_size The target size to check.
99/// @param max_size The maximum size to allow.
100/// @return @c true If @c is_valid_source_extent(my_extent,target_size) and @c target_size<=max_size .
101/// @c false Otherwise.
102constexpr auto
103is_valid_runtime_size(std::size_t const my_extent, std::size_t const target_size, std::size_t const max_size) noexcept
104 -> bool {
105 return is_valid_source_extent(my_extent, target_size) && (target_size <= max_size);
106}
107
108/// @brief Check if an extent is dynamic
109/// @param my_extent The extent to check
110/// @return @c true If @c my_extent is @c dynamic_extent
111/// @c false Otherwise.
112constexpr auto is_dynamic_extent(std::size_t const my_extent) noexcept -> bool { return my_extent == dynamic_extent; }
113
114/// @brief Computes the extent for a subspan of an original span with a given extent.
115/// Specialization for @c Count!=dynamic_extent .
116/// @tparam Extent The extent of the original span.
117/// @tparam Offset The offset into the original span to slice.
118/// @tparam Count The number of elements in the subspan.
119/// @return std::size_t @c Count
120template <
121 std::size_t Extent,
122 std::size_t Offset,
123 std::size_t Count,
124 constraints<std::enable_if_t<!is_dynamic_extent(Count)>> = nullptr>
125constexpr auto extent_for_subspan() -> std::size_t {
126 return Count;
127}
128/// @brief Computes the extent for a subspan of an original span with a given extent.
129/// Specialization for @c Count==dynamic_extent and @c Extent!=dynamic_extent.
130/// @tparam Extent The extent of the original span.
131/// @tparam Offset The offset into the original span to slice.
132/// @tparam Count The number of elements in the subspan.
133/// @return std::size_t @c Extent-Offset .
134template <
135 std::size_t Extent,
136 std::size_t Offset,
137 std::size_t Count,
138 constraints<std::enable_if_t<!is_dynamic_extent(Extent)>, std::enable_if_t<is_dynamic_extent(Count)>> = nullptr>
139constexpr auto extent_for_subspan() -> std::size_t {
140 return Extent - Offset;
141}
142/// @brief Computes the extent for a subspan of an original span with a given extent.
143/// Specialization for @c Count==dynamic_extent and @c Extent==dynamic_extent.
144/// @tparam Extent The extent of the original span.
145/// @tparam Offset The offset into the original span to slice.
146/// @tparam Count The number of elements in the subspan.
147/// @return std::size_t @c dynamic_extent .
148template <
149 std::size_t Extent,
150 std::size_t Offset,
151 std::size_t Count,
152 constraints<std::enable_if_t<is_dynamic_extent(Extent)>, std::enable_if_t<is_dynamic_extent(Count)>> = nullptr>
153constexpr auto extent_for_subspan() -> std::size_t {
154 return dynamic_extent;
155}
156
157/// @brief Trait to determine if a type has a member function @c data()
158/// @tparam T The type to test against
159template <typename T>
160using use_member_data = decltype(std::declval<T>().data());
161
162/// @brief Trait to determine if a type has a member function @c data()
163/// @tparam T The type to test against
164/// @return true if @c T has a member function @c data(), false otherwise
165template <typename T>
166constexpr bool has_member_data_v = substitution_succeeds<use_member_data, T>;
167
168/// @brief Trait to determine if a type has a @c std::tuple_size specialization.
169/// @tparam T The type to test against
170template <typename T>
171using use_tuple_size = decltype(std::tuple_size<T>::value);
172
173/// @brief Trait to determine if a type has a @c std::tuple_size specialization.
174/// @tparam T The type to test against
175/// @return true if @c T has a @c std::tuple_size specialization, false otherwise
176template <typename T>
177constexpr bool has_tuple_size_v = substitution_succeeds<use_tuple_size, T>;
178
179/// @brief A constant that is true if and only if T is an instantiation of arene::base::span
180template <typename T>
181extern constexpr bool is_span = false;
182
183/// @brief A constant that is true if and only if T is an instantiation of arene::base::Span
184template <typename T, std::size_t Extent>
185extern constexpr bool is_span<span<T, Extent>> = true;
186
187/// @brief Special tag type to use for constructing Spans
188struct span_construction_tag {};
189
190/// @brief A base class for Span to prevent default construction for fixed-size non-empty Spans
191template <std::size_t Extent>
192class span_base_fixed_size_non_empty {
193 public:
194 /// @brief Construct with a given run-time size
195 constexpr explicit span_base_fixed_size_non_empty(span_construction_tag, std::size_t) noexcept {}
196
197 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property"
198 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'size' does not hide anything"
199 /// @brief Returns the number of elements in the span
200 /// The size is fixed to the Extent
201 /// @return The number of elements in the span
202 static constexpr std::integral_constant<std::size_t, Extent> size{};
203 // parasoft-end-suppress AUTOSAR-A2_10_1-d
204 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
205
206 protected:
207 /// @brief protected destructor
208 ~span_base_fixed_size_non_empty() = default;
209 /// @brief protected copy constructor
210 /// @param other The source object
211 span_base_fixed_size_non_empty(span_base_fixed_size_non_empty const& other) = default;
212 /// @brief protected move constructor
213 /// @param other The source object
214 span_base_fixed_size_non_empty(span_base_fixed_size_non_empty&& other) noexcept = default;
215 /// @brief protected copy assignment
216 /// @param other The source object
217 auto operator=(span_base_fixed_size_non_empty const& other) & -> span_base_fixed_size_non_empty& = default;
218 /// @brief protected move assignment
219 /// @param other The source object
220 auto operator=(span_base_fixed_size_non_empty&& other) & noexcept -> span_base_fixed_size_non_empty& = default;
221};
222
223template <std::size_t Extent>
224constexpr std::integral_constant<std::size_t, Extent> span_base_fixed_size_non_empty<Extent>::size;
225
226/// @brief A base class for Span for a fixed-sized Span with an Extent of 0
227class span_base_fixed_size_empty {
228 public:
229 /// @brief The default constructor is trivial
230 constexpr span_base_fixed_size_empty() noexcept = default;
231
232 /// @brief Construct with a given run-time size
233 constexpr explicit span_base_fixed_size_empty(span_construction_tag, std::size_t) noexcept {}
234
235 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property"
236 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'size' does not hide anything"
237 /// @brief Returns the number of elements in the span
238 /// The size is fixed at zero
239 /// @return 0
240 static constexpr std::integral_constant<std::size_t, 0> size{};
241 // parasoft-end-suppress AUTOSAR-A2_10_1-d
242 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
243
244 protected:
245 /// @brief protected destructor
246 ~span_base_fixed_size_empty() = default;
247 /// @brief protected copy constructor
248 /// @param other The source object
249 span_base_fixed_size_empty(span_base_fixed_size_empty const& other) = default;
250 /// @brief protected move constructor
251 /// @param other The source object
252 span_base_fixed_size_empty(span_base_fixed_size_empty&& other) = default;
253 /// @brief protected copy assignment
254 /// @param other The source object
255 auto operator=(span_base_fixed_size_empty const& other) & -> span_base_fixed_size_empty& = default;
256 /// @brief protected move assignment
257 /// @param other The source object
258 auto operator=(span_base_fixed_size_empty&& other) & -> span_base_fixed_size_empty& = default;
259};
260
261/// @brief A base class for Span for a dynamically-sized span
262class span_base_dynamic_size {
263 protected:
264 /// @brief The default constructor sets the size to 0
265 constexpr span_base_dynamic_size() noexcept = default;
266
267 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'size' does not hide anything"
268 /// @brief Construct with a given run-time size
269 /// @param span_size The size of the span
270 constexpr explicit span_base_dynamic_size(span_construction_tag, std::size_t const span_size) noexcept
271 : dynamic_size_(span_size) {}
272
273 /// @brief Returns the number of elements in the span
274 /// @return The number of elements in the span
275 ARENE_NODISCARD constexpr auto size() const noexcept -> std::size_t { return this->dynamic_size_; }
276 // parasoft-end-suppress AUTOSAR-A2_10_1-d
277
278 /// @brief protected destructor
279 ~span_base_dynamic_size() = default;
280 /// @brief protected copy constructor
281 /// @param other The source object
282 span_base_dynamic_size(span_base_dynamic_size const& other) = default;
283 /// @brief protected move constructor
284 /// @param other The source object
285 span_base_dynamic_size(span_base_dynamic_size&& other) = default;
286 /// @brief protected copy assignment
287 /// @param other The source object
288 auto operator=(span_base_dynamic_size const& other) & -> span_base_dynamic_size& = default;
289 /// @brief protected move assignment
290 /// @param other The source object
291 auto operator=(span_base_dynamic_size&& other) & -> span_base_dynamic_size& = default;
292
293 private:
294 /// @brief The size of the span
295 std::size_t dynamic_size_{0U};
296};
297
298/// @brief Select instantiation of span_base with/without default construction
299template <std::size_t Extent>
300using span_base = typename std::conditional<
301 is_dynamic_extent(Extent),
302 span_base_dynamic_size,
303 typename std::conditional<Extent == 0, span_base_fixed_size_empty, span_base_fixed_size_non_empty<Extent>>::type>::
304 type;
305
306} // namespace span_detail
307
308// parasoft-begin-suppress AUTOSAR-A13_5_1-a-2 "False positive: no non-const overload"
309/// @brief A backport of @c std::span for C++14. Provides a view over a contiguous range of elements of type T.
310///
311/// @tparam T The type of the element the span views
312/// @tparam Extent The size of the span. If set to @c arene::base::dynamic_extent , then the Size of the range is
313/// determined at runtime. Otherwise the range of elements is exactly @c Extent elements.
314template <typename T, std::size_t Extent>
315class span : span_detail::span_base<Extent> {
316 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False positive: These identifiers do not hide anything"
317 /// @brief The base class for default construction
318 using base = span_detail::span_base<Extent>;
319
320 // parasoft-begin-suppress AUTOSAR-M0_1_3-c "False positive: data_ptr_ and max_extent are both used"
321 /// @brief The start of the data
322 T* data_ptr_{nullptr};
323
324 /// @brief The max extent of the span
325 static constexpr std::size_t max_extent{
326 static_cast<std::size_t>(static_cast<std::size_t>(std::numeric_limits<std::ptrdiff_t>::max()) / sizeof(T))
327 };
328 // parasoft-end-suppress AUTOSAR-M0_1_3-c
329
330 /// @brief Check if Span is dynamic size or Extent is valid for fixed size span
331 static_assert((Extent == dynamic_extent) || Extent <= max_extent, "span extent exceeds its max value");
332
333 /// @brief Validate the extent of a source span given the target span
334 /// @tparam target_extent The extent of the source span
335 /// @return bool Equivalent to @c span_detail::is_valid_source_extent(Extent,TargetExtent) .
336 template <std::size_t TargetExtent>
337 static constexpr bool is_valid_source_extent_v{span_detail::is_valid_source_extent(Extent, TargetExtent)};
338
339 /// @brief Validate the size of a dynamic span
340 /// @param target_extent The size of the dynamic span
341 /// @return @c true The size is valid
342 /// @c false The size is invalid
343 static constexpr auto is_valid_runtime_size(std::size_t target_extent) noexcept -> bool {
344 return span_detail::is_valid_runtime_size(Extent, target_extent, max_extent);
345 }
346
347 /// @brief Tag type for a the pre-checked size constructor
348 class pre_checked_size {
349 public:
350 /// @brief Default construction requires naming the type
351 constexpr explicit pre_checked_size() noexcept = default;
352 };
353 // parasoft-end-suppress AUTOSAR-A2_10_1-e
354
355 /// @brief Construct with the specified data and size.
356 ///
357 /// @param data_pointer The data from which to construct the span.
358 /// @param data_size The size of the data span to construct.
359 /// @post @c size()==data_size .
360 /// @post @c data()=data_pointer .
361 /// @pre @c data_pointer+data_size must be in the valid range of @c data_pointer , else behavior is undefined.
362 /// @pre @c data_size must satisfy @c is_valid_runtime_size else @c ARENE_PRECONDITION violation.
363 // NOLINTNEXTLINE(readability-non-const-parameter)
364 constexpr span(pre_checked_size, T* data_pointer, std::size_t data_size) noexcept
365 : base(span_detail::span_construction_tag{}, data_size),
366 data_ptr_(data_pointer) {}
367
368 public:
369 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False positive: these type aliases do not hide anything"
370 // alias size from the base class into the public space.
371 using base::size;
372
373 /// @brief The type of the elements of the span
374 using element_type = T;
375 /// @brief The type of the elements of the span without @c const or @c volatile qualification
377 /// @brief The type of the size of the span
379 /// @brief The type of pointers to elements of the span
380 using pointer = T*;
381 /// @brief The type of pointers to @c const elements of the span
382 using const_pointer = T const*;
383 /// @brief The type of references to elements of the span
384 using reference = T&;
385 /// @brief The type of references to @c const elements of the span
386 using const_reference = T const&;
387 /// @brief The type of an iterator into the data viewed by the span.
388 using iterator = detail::wrapped_iterator<pointer, span_detail::span_iter_passkey>;
389 /// @brief The type of an iterator into a const view of the data viewed by the span.
390 using const_iterator = detail::wrapped_iterator<const_pointer, span_detail::span_iter_passkey>;
391 /// @brief The type of an iterator into a reversed view of the data viewed by the span.
393 /// @brief The type of an iterator into a const and reversed view of the data viewed by the span.
395 /// @brief The type used for obtaining differences between iterators of the span.
396 using difference_type = typename iterator::difference_type;
397
398 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property"
399 /// @brief The Extent of the span --- either dynamic_extent, or the fixed size
401 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
402 // parasoft-end-suppress AUTOSAR-A2_10_1-e
403
404 /// @brief The size of the span as a signed integer
405 /// @return The size
406 ARENE_NODISCARD constexpr auto ssize() const noexcept -> difference_type {
407 return static_cast<difference_type>(this->size());
408 }
409
410 /// @brief Default-constructs an empty span. Only exists if @c Extent==dynamic_extent or @c Extent==0
411 /// @post @c size()==0 .
412 constexpr span() noexcept = default;
413
414 // parasoft-begin-suppress AUTOSAR-A13_3_1-a-2 "False positive: Constrained via SFINAE"
415 /// @brief default copy constructor
416 /// @param other The span being copied
417 constexpr span(span const& other) = default;
418 /// @brief default move constructor
419 /// @param other The span being moved
420 constexpr span(span&& other) = default;
421 // parasoft-end-suppress AUTOSAR-A13_3_1-a-2
422
423 /// @brief default copy assignment operator
424 /// @param other The span being copied
425 constexpr auto operator=(span const& other) -> span& = default;
426 /// @brief default move assignment operator
427 /// @param other The span being moved
428 constexpr auto operator=(span&& other) -> span& = default;
429
430 /// @brief default destructor
431 ~span() = default;
432
433 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
434 // initialize the base class"
435 /// @brief Construct with the specified data and size. Prevents implicit derived-to-base pointer conversions on the
436 /// supplied data argument.
437 ///
438 /// @tparam U The type of the data to convert from.
439 /// @param data_pointer The data from which to construct the span.
440 /// @param data_size The size of the data span to construct.
441 /// @post @c size()==data_size .
442 /// @post @c data()=data_pointer .
443 /// @pre @c data_pointer+data_size must be in the valid range of @c data_pointer , else behavior is undefined.
444 /// @pre @c data_size must satisfy @c is_valid_runtime_size else @c ARENE_PRECONDITION violation.
445 template <typename U, constraints<std::enable_if_t<arene::base::is_array_convertible_v<U, T>>> = nullptr>
446 // NOLINTNEXTLINE(readability-non-const-parameter)
447 constexpr span(U* data_pointer, std::size_t data_size) noexcept
448 : span(pre_checked_size{}, data_pointer, data_size) {
449 ARENE_PRECONDITION(is_valid_runtime_size(data_size));
450 }
451 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
452
453 // parasoft-begin-suppress AUTOSAR-A13_3_1-a-2 "False positive: Constrained via SFINAE"
454 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
455 // initialize the base class"
456 /// @brief Constructor from a c-array.
457 ///
458 /// @tparam N The size of the c-array. Must satisfy @c is_valid_source_extent .
459 /// @param array The array to construct the span from
460 /// @post @c size()==N .
461 /// @post @c data()==&array[0] .
462 template <std::size_t N, constraints<std::enable_if_t<is_valid_source_extent_v<N>>> = nullptr>
463 // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions,cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
464 constexpr span(T (&array)[N]) noexcept
465 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay)
466 : span(pre_checked_size{}, array, N) {}
467 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
468
469 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
470 // initialize the base class"
471 /// @brief Constructor from a @c std::array.
472 ///
473 /// @tparam ArrayLikeT The template-template type of the array-like container. A container is array-like if it has a
474 /// member function @c data() and @c std::tuple_size<ArrayLikeType<U,N>> is defined.
475 /// @tparam U The @c value_type of the array. Must satisfy @c is_array_convertible_v<U,T>
476 /// @tparam N The size of the array, Must satisfy @c is_valid_source_extent
477 /// @param array The array to construct the span from
478 /// @post @c size()==N .
479 /// @post @c data()==array.data() .
480 template <
481 template <typename U, std::size_t N>
482 class ArrayLikeT,
483 typename U,
484 std::size_t N,
485 constraints<
491 // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
492 constexpr span(ArrayLikeT<U, N>& array) noexcept
493 : span(pre_checked_size{}, array.data(), N) {}
494 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
495
496 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
497 // initialize the base class"
498 /// @brief Constructor from a const @c std::array -like type.
499 ///
500 /// @tparam ArrayLikeT The template-template type of the array-like container. A container is array-like if it has a
501 /// member function @c data() and @c std::tuple_size<ArrayLikeType<U,N>> is defined.
502 /// @tparam U The @c value_type of the array. Must satisfy <c>is_array_convertible_v<const U, T> </c>
503 /// @tparam N The size of the array, Must satisfy @c is_valid_source_extent
504 /// @param array The array to construct the span from
505 /// @post @c size()==N .
506 /// @post @c data()==array.data() .
507 template <
508 template <typename U, std::size_t N>
509 class ArrayLikeT,
510 typename U,
511 std::size_t N,
512 constraints<
518 // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
519 constexpr span(ArrayLikeT<U, N> const& array) noexcept
520 : span(pre_checked_size{}, array.data(), N) {}
521 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
522
523 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
524 // initialize the base class"
525 // parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "Span has reference semantics: forwarding not appropriate"
526 // parasoft-begin-suppress AUTOSAR-A8_4_5-a-2 "Span has reference semantics: forwarding not appropriate"
527 // parasoft-begin-suppress AUTOSAR-A12_8_4-a-2 "Span has reference semantics: forwarding not appropriate"
528 /// @brief Constructor from an rvalue @c std::array -like type.
529 ///
530 /// @tparam ArrayLikeT The template-template type of the array-like container. A container is array-like if it has a
531 /// member function @c data() and @c std::tuple_size<ArrayLikeType<U,N>> is defined.
532 /// @tparam U The @c value_type of the array. Must satisfy <c>is_array_convertible_v<const U, T> </c>
533 /// @tparam N The size of the array, Must satisfy @c is_valid_source_extent
534 /// @param array The array to construct the span from
535 /// @post @c size()==N .
536 /// @post @c data()==array.data() .
537 template <
538 template <typename U, std::size_t N>
539 class ArrayLikeT,
540 typename U,
541 std::size_t N,
542 constraints<
548 // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
549 constexpr span(ArrayLikeT<U, N>&& array) noexcept
550 : span(pre_checked_size{}, array.data(), N) {}
551 // parasoft-end-suppress AUTOSAR-A8_4_6-a-2
552 // parasoft-end-suppress AUTOSAR-A8_4_5-a-2
553 // parasoft-end-suppress AUTOSAR-A12_8_4-a-2
554 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
555
556 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
557 // initialize the base class"
558 /// @brief Constructor from an const rvalue @c std::array -like type.
559 ///
560 /// @tparam ArrayLikeT The template-template type of the array-like container. A container is array-like if it has a
561 /// member function @c data() and @c std::tuple_size<ArrayLikeType<U,N>> is defined.
562 /// @tparam U The @c value_type of the array. Must satisfy <c>is_array_convertible_v<const U, T> </c>
563 /// @tparam N The size of the array, Must satisfy @c is_valid_source_extent
564 /// @param array The array to construct the span from
565 /// @post @c size()==N .
566 /// @post @c data()==array.data() .
567 template <
568 template <typename U, std::size_t N>
569 class ArrayLikeT,
570 typename U,
571 std::size_t N,
572 constraints<
578 // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
579 constexpr span(ArrayLikeT<U, N> const&& array) noexcept
580 : span(pre_checked_size{}, array.data(), N) {}
581 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
582
583 /// @brief Disable construction of fixed size spans from other spans of mismatched size.
584 /// @param other The source object
585 template <
586 typename U,
587 std::size_t OtherExtent,
588 constraints<std::enable_if_t<
589 !span_detail::is_dynamic_extent(Extent) && !span_detail::is_dynamic_extent(OtherExtent) &&
590 Extent != OtherExtent>> = nullptr>
591 constexpr span(span<U, OtherExtent>&& other) noexcept = delete;
592
593 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
594 // initialize the base class"
595 // parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "Span has reference semantics: forwarding not appropriate"
596 // parasoft-begin-suppress AUTOSAR-A8_4_5-a-2 "Span has reference semantics: forwarding not appropriate"
597 // parasoft-begin-suppress AUTOSAR-A12_8_4-a-2 "Span has reference semantics: forwarding not appropriate"
598 /// @brief Constructor from a container of T with contiguous elements.
599 /// @tparam Container the type of the container to construct from. A "container" is a type which has @c data() and
600 /// @c size() member functions, where @c data() returns a pointer (or equivalent) to contiguous memory
601 /// containing elements pointer-convertible to @c T .
602 /// @param source The container to construct the span from
603 /// @pre If @c Extent is not @c dynamic_extent , then @c source.size()==Extent must be true, else it is an
604 /// @c ARENE_PRECONDITION violation.
605 template <
606 typename Container,
609 !span_detail::has_tuple_size_v<arene::base::remove_cvref_t<Container>> &&
610 span_detail::is_dynamic_extent(Extent)>,
613 T>>> = nullptr>
614 // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions,bugprone-forwarding-reference-overload)
615 constexpr span(Container&& source) noexcept
616 : span(source.data(), source.size()) {}
617 // parasoft-end-suppress AUTOSAR-A8_4_6-a-2
618 // parasoft-end-suppress AUTOSAR-A8_4_5-a-2
619 // parasoft-end-suppress AUTOSAR-A12_8_4-a-2
620 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
621
622 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
623 // initialize the base class"
624 // parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "Span has reference semantics: forwarding not appropriate"
625 // parasoft-begin-suppress AUTOSAR-A8_4_5-a-2 "Span has reference semantics: forwarding not appropriate"
626 // parasoft-begin-suppress AUTOSAR-A12_8_4-a-2 "Span has reference semantics: forwarding not appropriate"
627 /// @brief Constructor from a container of T with contiguous elements.
628 /// @tparam Container the type of the container to construct from. A "container" is a type which has @c data() and
629 /// @c size() member functions, where @c data() returns a pointer (or equivalent) to contiguous memory
630 /// containing elements pointer-convertible to @c T .
631 /// @param source The container to construct the span from
632 /// @pre If @c Extent is not @c dynamic_extent , then @c source.size()==Extent must be true, else it is an
633 /// @c ARENE_PRECONDITION violation.
634 template <
635 typename Container,
638 !span_detail::has_tuple_size_v<arene::base::remove_cvref_t<Container>> &&
639 !span_detail::is_dynamic_extent(Extent)>,
642 T>>> = nullptr>
643 // NOLINTNEXTLINE(bugprone-forwarding-reference-overload)
644 explicit constexpr span(Container&& source) noexcept
645 : span(source.data(), source.size()) {
646 ARENE_PRECONDITION(source.size() == Extent);
647 }
648 // parasoft-end-suppress AUTOSAR-A8_4_6-a-2
649 // parasoft-end-suppress AUTOSAR-A8_4_5-a-2
650 // parasoft-end-suppress AUTOSAR-A12_8_4-a-2
651 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
652
653 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
654 // initialize the base class"
655 /// @brief Constructor from another @c span<U,OtherExtent> when @c Extent is "no more restrictive" then @c OtherExtent
656 /// @tparam U The type of the element in the other span. Must be pointer-convertible to @c T
657 /// @tparam OtherExten If @c Extent is not @c dynamic_extent , then must be equal to @c Extent .
658 /// @param other The @c span to construct from.
659 template <
660 typename U,
661 std::size_t OtherExtent,
665 // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
666 constexpr span(span<U, OtherExtent> const& other) noexcept
667 // parasoft-begin-suppress AUTOSAR-A5_16_1-2 "False positive: used as a constructor argument not a subexpression"
668 : span(other.data(), (!span_detail::is_dynamic_extent(Extent)) ? Extent : other.size()) {}
669 // parasoft-end-suppress AUTOSAR-A5_16_1-2
670 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
671
672 /// @brief Constructor from @c span<U,dynamic_extent> when @c Extent is not @c dynamic_extent .
673 /// @tparam U The type of the element in the other span. Must be pointer-convertible to @c T
674 /// @param other The @c span to construct from.
675 /// @pre @c span.size()==Extent , else @c ARENE_PRECONDITION violation.
676 template <
677 typename U,
678 std::size_t OtherExtent,
681 std::enable_if_t<(!span_detail::is_dynamic_extent(Extent)) && span_detail::is_dynamic_extent(OtherExtent)>> =
682 nullptr>
683 explicit constexpr span(span<U, OtherExtent> const& other) noexcept
684 : span(other.data(), Extent) {}
685 // parasoft-end-suppress AUTOSAR-A13_3_1-a-2
686
687 /// @brief Predicate to test if the span views onto non-zero elements.
688 ///
689 /// @return true if <c>size() == 0</c>.
690 /// @return false otherwise.
691 ARENE_NODISCARD constexpr auto empty() const noexcept -> bool { return this->size() == 0U; }
692
693 /// @brief Returns the total size in bytes of the elements in the span.
694 ///
695 /// @return The total size, in bytes, of the elements in the span.
696 ARENE_NODISCARD constexpr auto size_bytes() const noexcept -> std::size_t { return this->size() * sizeof(T); }
697
698 /// @brief Accessor to the underlying data as a raw pointer.
699 ///
700 /// @return A pointer to the start of the elements covered by the span.
701 ARENE_NODISCARD constexpr auto data() const noexcept -> T* { return data_ptr_; }
702
703 /// @brief Retrieve the element at the specified index into the span. index must be less than size()
704 ///
705 /// @param index The index of the element to access
706 /// @pre <c>index < size()</c> else @c ARENE_PRECONDITION violation.
707 /// @return A reference to the element at the specified index into the span.
708
709 constexpr auto operator[](std::size_t index) const noexcept -> T& {
710 ARENE_PRECONDITION(index < this->size());
711 return begin()[static_cast<difference_type>(index)];
712 }
713
714 /// @brief Access the first element in the span.
715 ///
716 /// @pre @c empty() must be false, else @c ARENE_PRECONDITION violation.
717 /// @return A reference to the first element in the span.
718 ARENE_NODISCARD constexpr auto front() const noexcept -> T& {
720 return *data_ptr_;
721 }
722
723 /// @brief Access the last element in the span.
724 ///
725 /// @pre @c empty() must be false, else @c ARENE_PRECONDITION violation.
726 /// @return A reference to the last element in the span.
727 ARENE_NODISCARD constexpr auto back() const noexcept -> T& {
729 return this->operator[](this->size() - 1U);
730 }
731
732 /// @brief Create a new fixed-size span from the beginning of the span.
733 ///
734 /// @tparam Count The number of elements to include.
735 /// @tparam UE dummy parameter for SFINAE.
736 /// @pre @c Count<=size() . else @c ARENE_PRECONDITION violation.
737 /// @return span<T, Count> containing the first @c Count elements from the span.
738 template <
739 std::size_t Count,
740 std::size_t UE = Extent,
741 constraints<std::enable_if_t<span_detail::is_dynamic_extent(UE)>> = nullptr>
742 ARENE_NODISCARD constexpr auto first() const noexcept -> span<T, Count> {
743 ARENE_PRECONDITION(Count <= this->size());
744 return {data_ptr_, Count};
745 }
746 /// @brief Create a new fixed-size span from the beginning of the span.
747 ///
748 /// @tparam Count The number of elements to include. Must be @c <=Extent .
749 /// @return span<T, Count> containing the first @c Count elements from the span.
750 template <
751 std::size_t Count,
752 std::size_t UE = Extent,
753 constraints<std::enable_if_t<!span_detail::is_dynamic_extent(UE)>, std::enable_if_t<Count <= Extent>> = nullptr>
754 ARENE_NODISCARD constexpr auto first() const noexcept -> span<T, Count> {
755 return {data_ptr_, Count};
756 }
757
758 // parasoft-begin-suppress AUTOSAR-A2_10_1-a "False positive: 'count' does not hide anything"
759
760 /// @brief Create a new dynamic-size span from the beginning of the span.
761 ///
762 /// @param count The number of elements to include.
763 /// @pre @c count must be <= @c size() . else @c ARENE_PRECONDITION violation.
764 /// @return span<T, Count> containing the first @c count elements from the span.
765 ARENE_NODISCARD constexpr auto first(std::size_t count) const noexcept -> span<T> {
766 ARENE_PRECONDITION(count <= this->size());
767 return {data_ptr_, count};
768 }
769
770 // parasoft-end-suppress AUTOSAR-A2_10_1-a
771
772 /// @brief Create a new fixed-size span for the last @c Count elements.
773 ///
774 /// @tparam Count The number of elements to include.
775 /// @pre @c Count<=size() , else @c ARENE_PRECONDITION violation.
776 /// @return span<T, Count> containing the last @c Count elements from the span.
777 template <
778 std::size_t Count,
779 std::size_t UE = Extent,
780 constraints<std::enable_if_t<span_detail::is_dynamic_extent(UE)>> = nullptr>
781 ARENE_NODISCARD constexpr auto last() const noexcept -> span<T, Count> {
782 ARENE_PRECONDITION(Count <= this->size());
783 std::size_t const offset{this->size() - Count};
784 return span<T, Count>{arene::base::next(data_ptr_, static_cast<std::ptrdiff_t>(offset)), Count};
785 }
786 /// @brief Create a new fixed-size span for the last @c Count elements.
787 ///
788 /// @tparam Count The number of elements to include. Must be @c <=Extent .
789 /// @return span<T, Count> containing the last @c Count elements from the span.
790 template <
791 std::size_t Count,
792 std::size_t UE = Extent,
793 constraints<std::enable_if_t<!span_detail::is_dynamic_extent(UE)>, std::enable_if_t<Count <= Extent>> = nullptr>
794 ARENE_NODISCARD constexpr auto last() const noexcept -> span<T, Count> {
795 std::size_t const offset{this->size() - Count};
796 return span<T, Count>{arene::base::next(data_ptr_, static_cast<std::ptrdiff_t>(offset)), Count};
797 }
798
799 // parasoft-begin-suppress AUTOSAR-A2_10_1-a "False positive: 'count' does not hide anything"
800
801 /// @brief Create a new dynamic-size span for the last @c count elements.
802 ///
803 /// @param count The number of elements to include.
804 /// @pre @c count must be <= @c size() . else @c ARENE_PRECONDITION violation.
805 /// @return span<T, Count> containing the last @c count elements from the span.
806 ARENE_NODISCARD constexpr auto last(std::size_t count) const noexcept -> span<T> {
807 ARENE_PRECONDITION(count <= this->size());
808 std::size_t const offset{this->size() - count};
809 return span<T>{arene::base::next(data_ptr_, static_cast<std::ptrdiff_t>(offset)), count};
810 }
811
812 // parasoft-end-suppress AUTOSAR-A2_10_1-a
813
814 /// @brief Creates a new fixed-size span which is a slice of this span
815 ///
816 /// @tparam Offset The index of the first element to contain in the subspan. Must be @c <=Extent
817 /// @tparam Count The number of elements to include in the subspan. Must satisfy @c Offset+Count<=Extent , or be
818 /// @c dynamic_extent .
819 /// @return span<T,Extent-Offset> Equivalent to @c last<Extent-Offset>() .
820 template <
821 std::size_t Offset,
822 std::size_t Count = span_detail::get_dynamic_extent(),
825 std::enable_if_t<span_detail::is_dynamic_extent(Count) && !span_detail::is_dynamic_extent(Extent)>> = nullptr>
826 ARENE_NODISCARD constexpr auto subspan() const noexcept
827 -> span<T, span_detail::extent_for_subspan<Extent, Offset, Count>()> {
828 return last<Extent - Offset>();
829 }
830 /// @brief Creates a new fixed-size span which is a slice of this span
831 ///
832 /// @tparam Offset The index of the first element to contain in the subspan. Must be @c <=Extent
833 /// @tparam Count The number of elements to include in the subspan. Must satisfy @c Offset+Count<=Extent , or be
834 /// @c dynamic_extent .
835 /// @return span<T,Count> Equivalent to @c last<Extent-Offset>().first<Count>() .
836 template <
837 std::size_t Offset,
838 std::size_t Count = span_detail::get_dynamic_extent(),
841 std::enable_if_t<!span_detail::is_dynamic_extent(Count) && !span_detail::is_dynamic_extent(Extent)>> =
842 nullptr>
843 ARENE_NODISCARD constexpr auto subspan() const noexcept
844 -> span<T, span_detail::extent_for_subspan<Extent, Offset, Count>()> {
845 return last<Extent - Offset>().template first<Count>();
846 }
847 /// @brief Creates a new dynamic-sized span which is a slice of this span
848 ///
849 /// @tparam Offset The index of the first element to contain in the subspan. Must be <= @c size()
850 /// @tparam Count The number of elements to include in the subspan. <c> offset + count </c> must be <= @c size()
851 /// @return span<T> equivalent to @c last(size()-Offset) .
852 /// @pre <c> Count<= size() && (Count+Offset <= size()) </c>, else @c ARENE_PRECONDITION violation.
853 template <
854 std::size_t Offset,
855 std::size_t Count = span_detail::get_dynamic_extent(),
858 std::enable_if_t<span_detail::is_dynamic_extent(Count) && span_detail::is_dynamic_extent(Extent)>> = nullptr>
859 ARENE_NODISCARD constexpr auto subspan() const noexcept
860 -> span<T, span_detail::extent_for_subspan<Extent, Offset, Count>()> {
861 ARENE_PRECONDITION(Offset <= this->size());
862 return last(this->size() - Offset);
863 }
864 /// @brief Creates a new fixed-size span which is a slice of this span
865 ///
866 /// @tparam Offset The index of the first element to contain in the subspan. Must be <= @c size()
867 /// @tparam Count The number of elements to include in the subspan. <c> offset + count </c> must be <= @c size()
868 /// @return span<T,Count> Equivalent to @c last(size()-Offset).first<Count>() .
869 /// @pre If @c Extent is @c dynamic_extent , then <c> Count<= size() && (Count+Offset <= size()) </c>, else
870 /// @c ARENE_PRECONDITION violation.
871 template <
872 std::size_t Offset,
873 std::size_t Count = span_detail::get_dynamic_extent(),
876 std::enable_if_t<!span_detail::is_dynamic_extent(Count) && span_detail::is_dynamic_extent(Extent)>> = nullptr>
877 ARENE_NODISCARD constexpr auto subspan() const noexcept
878 -> span<T, span_detail::extent_for_subspan<Extent, Offset, Count>()> {
879 ARENE_PRECONDITION(Offset <= this->size());
880 return last(this->size() - Offset).template first<Count>();
881 }
882
883 // parasoft-begin-suppress AUTOSAR-A2_10_1-a "False positive: 'count' does not hide anything"
884
885 /// @brief Creates a new dynamic-size span which is a slice of this span
886 ///
887 /// @param offset The index of the first element to contain in the subspan. Must be <= @c size()
888 /// @param count The number of elements to include in the subspan. <c> offset + count </c> must be <= @c size()
889 /// @return span<T> If @c count==dynamic_extent , equivalent to @c last(size()-offset) , else
890 /// @c last(size()-offset).first(count) .
891 /// @pre <c> count<= size() && (count+offset <= size()) </c>, else @c ARENE_PRECONDITION violation.
892 // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) this API is required by span's stdlib compatibility.
893 ARENE_NODISCARD constexpr auto subspan(std::size_t offset, std::size_t count = dynamic_extent) const noexcept
894 -> span<T> {
895 ARENE_PRECONDITION(offset <= this->size());
896 auto const last_start = this->size() - offset;
897 if (span_detail ::is_dynamic_extent(count)) {
898 return last(last_start);
899 }
900 return last(last_start).first(count);
901 }
902
903 // parasoft-end-suppress AUTOSAR-A2_10_1-a
904
905 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: these standard range API names do not hide anything"
906 /// @brief Obtain an iterator to the beginning of the data viewed by the span.
907 ///
908 /// @return iterator An iterator pointing to the first position in the span.
909 ARENE_NODISCARD constexpr auto begin() const noexcept -> iterator {
910 return iterator{span_detail::span_iter_passkey{}, data_ptr_};
911 }
912 // parasoft-end-suppress AUTOSAR-A2_10_1-d
913
914 /// @brief Obtain a const_iterator to the beginning of the data viewed by the span.
915 ///
916 /// @return const_iterator A const iterator pointing to the first position in the span.
917 ARENE_NODISCARD constexpr auto cbegin() const noexcept -> const_iterator {
918 return const_iterator{span_detail::span_iter_passkey{}, data_ptr_};
919 }
920
921 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: these standard range API names do not hide anything"
922 /// @brief Obtain an iterator to the one-past-the-end of the data viewed by the span
923 ///
924 /// @return iterator An iterator equivalent to @c begin()+size() .
925 ARENE_NODISCARD constexpr auto end() const noexcept -> iterator {
926 return iterator{span_detail::span_iter_passkey{}, arene::base::next(data_ptr_, ssize())};
927 }
928 // parasoft-end-suppress AUTOSAR-A2_10_1-d
929
930 /// @brief Obtain a const_iterator to the one-past-the-end of the data viewed by the span
931 ///
932 /// @return const_iterator A const iterator equivalent to @c cbegin()+size() .
933 ARENE_NODISCARD constexpr auto cend() const noexcept -> const_iterator {
934 return const_iterator{span_detail::span_iter_passkey{}, arene::base::next(data_ptr_, ssize())};
935 }
936
937 /// @brief Obtain an iterator to the beginning of a reversed view of the data in the span.
938 ///
939 /// @return iterator An iterator equivalent to @c reverse_iterator(end())
940 ARENE_NODISCARD constexpr auto rbegin() const noexcept -> reverse_iterator { return reverse_iterator(end()); }
941
942 /// @brief Obtain a const_iterator to the beginning of a reversed view of the data in the span.
943 ///
944 /// @return const_reverse_iterator An iterator equivalent to @c const_reverse_iterator(cend())
945 ARENE_NODISCARD constexpr auto crbegin() const noexcept -> const_reverse_iterator {
947 }
948
949 /// @brief Obtain an iterator to one-past-the-end of a reversed view of the data in the span.
950 ///
951 /// @return iterator An iterator equivalent to @c reverse_iterator(begin())
952 ARENE_NODISCARD constexpr auto rend() const noexcept -> reverse_iterator { return reverse_iterator(begin()); }
953
954 /// @brief Obtain a const iterator to one-past-the-end of a reversed view of the data in the span.
955 ///
956 /// @return const_reverse_iterator A const iterator equivalent to @c const_reverse_iterator(cbegin())
957 ARENE_NODISCARD constexpr auto crend() const noexcept -> const_reverse_iterator {
959 }
960};
961// parasoft-end-suppress AUTOSAR-A13_5_1-a-2
962
963/// @brief Obtain a const view to the object representation of the elements of the span @c spn.
964/// @param spn The span of elements to inspect.
965/// @return A <c>span<const Byte, Size></c> of the object representations of the elements of @c spn.
966template <typename T, std::size_t N>
967auto as_bytes(span<T, N> spn) noexcept
968 -> span<byte const, span_detail::is_dynamic_extent(N) ? dynamic_extent : (N * sizeof(T))> {
969 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
970 return {reinterpret_cast<byte const*>(spn.data()), spn.size_bytes()};
971}
972
973/// @brief Obtain a non-const view to the object representation of the elements of the span @c spn.
974/// @param spn The span of elements to inspect.
975/// @return A <c>span<byte, Size></c> of the object representations of the elements of @c spn.
976template <typename T, std::size_t N, constraints<std::enable_if_t<!std::is_const<T>::value>> = nullptr>
978 -> span<byte, span_detail::is_dynamic_extent(N) ? dynamic_extent : (N * sizeof(T))> {
979 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
980 return {reinterpret_cast<byte*>(spn.data()), spn.size_bytes()};
981}
982
983template <typename T, std::size_t Extent>
985
986namespace ranges {
987/// @brief Indicate that @c span is a borrowed range
988/// @tparam T The type of the elements in the span
989/// @tparam Extent The extent of the span
990template <typename T, std::size_t Extent>
991class enable_borrowed_range<span<T, Extent>> : public std::true_type {};
992} // namespace ranges
993
994} // namespace base
995} // namespace arene
996
997#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_SPAN_SPAN_HPP_
A fixed-size array of T objects.
Definition array.hpp:77
constexpr auto data() noexcept -> T *
Obtain a pointer to the first element of the array.
Definition array.hpp:145
An opt-in trait to indicate that a range type is a borrowed range.
Definition enable_borrowed_range.hpp:31
A backport of the constexpr std::reverse_iterator from C++17.
Definition reverse_iterator.hpp:188
A backport of std::span for C++14. Provides a view over a contiguous range of elements of type T.
Definition span.hpp:315
ARENE_NODISCARD constexpr auto crend() const noexcept -> const_reverse_iterator
Obtain a const iterator to one-past-the-end of a reversed view of the data in the span.
Definition span.hpp:957
static constexpr std::integral_constant< std::size_t, Extent > extent
Definition span.hpp:400
ARENE_NODISCARD constexpr auto first() const noexcept -> span< T, Count >
Create a new fixed-size span from the beginning of the span.
Definition span.hpp:742
::arene::base::reverse_iterator< iterator > reverse_iterator
The type of an iterator into a reversed view of the data viewed by the span.
Definition span.hpp:392
ARENE_NODISCARD constexpr auto last() const noexcept -> span< T, Count >
Create a new fixed-size span for the last Count elements.
Definition span.hpp:781
detail::wrapped_iterator< const_pointer, span_detail::span_iter_passkey > const_iterator
The type of an iterator into a const view of the data viewed by the span.
Definition span.hpp:390
detail::wrapped_iterator< pointer, span_detail::span_iter_passkey > iterator
The type of an iterator into the data viewed by the span.
Definition span.hpp:388
ARENE_NODISCARD constexpr auto crbegin() const noexcept -> const_reverse_iterator
Obtain a const_iterator to the beginning of a reversed view of the data in the span.
Definition span.hpp:945
ARENE_NODISCARD constexpr auto rend() const noexcept -> reverse_iterator
Obtain an iterator to one-past-the-end of a reversed view of the data in the span.
Definition span.hpp:952
constexpr span(Container &&source) noexcept
Constructor from a container of T with contiguous elements.
Definition span.hpp:615
typename iterator::difference_type difference_type
The type used for obtaining differences between iterators of the span.
Definition span.hpp:396
constexpr span(ArrayLikeT< U, N > &array) noexcept
Constructor from a std::array.
Definition span.hpp:492
ARENE_NODISCARD constexpr auto end() const noexcept -> iterator
Obtain an iterator to the one-past-the-end of the data viewed by the span.
Definition span.hpp:925
ARENE_NODISCARD constexpr auto front() const noexcept -> T &
Access the first element in the span.
Definition span.hpp:718
ARENE_NODISCARD constexpr auto last(std::size_t count) const noexcept -> span< T >
Create a new dynamic-size span for the last count elements.
Definition span.hpp:806
constexpr span(span< U, OtherExtent > const &other) noexcept
Constructor from another span<U,OtherExtent> when Extent is "no more restrictive" then OtherExtent.
Definition span.hpp:666
T & reference
The type of references to elements of the span.
Definition span.hpp:384
T element_type
The type of the elements of the span.
Definition span.hpp:374
ARENE_NODISCARD constexpr auto size_bytes() const noexcept -> std::size_t
Returns the total size in bytes of the elements in the span.
Definition span.hpp:696
constexpr auto operator[](std::size_t index) const noexcept -> T &
Retrieve the element at the specified index into the span. index must be less than size()
Definition span.hpp:709
ARENE_NODISCARD constexpr auto empty() const noexcept -> bool
Predicate to test if the span views onto non-zero elements.
Definition span.hpp:691
constexpr span(ArrayLikeT< U, N > const &array) noexcept
Constructor from a const std::array -like type.
Definition span.hpp:519
ARENE_NODISCARD constexpr auto back() const noexcept -> T &
Access the last element in the span.
Definition span.hpp:727
constexpr span(span< U, OtherExtent > &&other) noexcept=delete
Disable construction of fixed size spans from other spans of mismatched size.
arene::base::remove_cvref_t< T > value_type
The type of the elements of the span without const or volatile qualification.
Definition span.hpp:376
ARENE_NODISCARD constexpr auto ssize() const noexcept -> difference_type
The size of the span as a signed integer.
Definition span.hpp:406
ARENE_NODISCARD constexpr auto first(std::size_t count) const noexcept -> span< T >
Create a new dynamic-size span from the beginning of the span.
Definition span.hpp:765
ARENE_NODISCARD constexpr auto subspan(std::size_t offset, std::size_t count=dynamic_extent) const noexcept -> span< T >
Creates a new dynamic-size span which is a slice of this span.
Definition span.hpp:893
::arene::base::reverse_iterator< const_iterator > const_reverse_iterator
The type of an iterator into a const and reversed view of the data viewed by the span.
Definition span.hpp:394
ARENE_NODISCARD constexpr auto cend() const noexcept -> const_iterator
Obtain a const_iterator to the one-past-the-end of the data viewed by the span.
Definition span.hpp:933
constexpr span() noexcept=default
Default-constructs an empty span. Only exists if Extent==dynamic_extent or Extent==0.
ARENE_NODISCARD constexpr auto data() const noexcept -> T *
Accessor to the underlying data as a raw pointer.
Definition span.hpp:701
ARENE_NODISCARD constexpr auto rbegin() const noexcept -> reverse_iterator
Obtain an iterator to the beginning of a reversed view of the data in the span.
Definition span.hpp:940
ARENE_NODISCARD constexpr auto cbegin() const noexcept -> const_iterator
Obtain a const_iterator to the beginning of the data viewed by the span.
Definition span.hpp:917
T * pointer
The type of pointers to elements of the span.
Definition span.hpp:380
constexpr span(ArrayLikeT< U, N > &&array) noexcept
Constructor from an rvalue std::array -like type.
Definition span.hpp:549
constexpr span(T(&array)[N]) noexcept
Constructor from a c-array.
Definition span.hpp:464
constexpr span(ArrayLikeT< U, N > const &&array) noexcept
Constructor from an const rvalue std::array -like type.
Definition span.hpp:579
T const & const_reference
The type of references to const elements of the span.
Definition span.hpp:386
std::size_t size_type
The type of the size of the span.
Definition span.hpp:378
ARENE_NODISCARD constexpr auto first() const noexcept -> span< T, Count >
Create a new fixed-size span from the beginning of the span.
Definition span.hpp:754
ARENE_NODISCARD constexpr auto subspan() const noexcept -> span< T, span_detail::extent_for_subspan< Extent, Offset, Count >()>
Creates a new fixed-size span which is a slice of this span.
Definition span.hpp:826
ARENE_NODISCARD constexpr auto last() const noexcept -> span< T, Count >
Create a new fixed-size span for the last Count elements.
Definition span.hpp:794
T const * const_pointer
The type of pointers to const elements of the span.
Definition span.hpp:382
ARENE_NODISCARD constexpr auto begin() const noexcept -> iterator
Definition span.hpp:909
A helper class to represent a compile-time constant with the specified type and value....
Definition integral_constant.hpp:23
static constexpr auto max() noexcept -> T
The maximum finite value.
Definition numeric_limits.hpp:230
#define ARENE_PRECONDITION(condition)
Check that a precondition holds, and terminate the application if it does not.
Definition contract.hpp:150
Definition external_vector.hpp:803
Definition accumulate.hpp:37
constexpr bool is_array_convertible_v
Type trait to check if a pointer to an array of From is convertible to a pointer to an array of To.
Definition is_array_convertible.hpp:20
constexpr std::integral_constant< std::size_t, N > array< T, N >::size
Definition array.hpp:534
typename std::remove_reference< T >::type remove_reference_t
Backport of std::remove_reference_t.
Definition remove_cvref.hpp:28
constexpr std::integral_constant< std::size_t, N > array< T, N >::max_size
Definition array.hpp:537
ARENE_NODISCARD constexpr auto next(Iterator itr, typename std::iterator_traits< Iterator >::difference_type steps=1) noexcept(noexcept(::arene::base::advance(itr, steps))) -> Iterator
Produces the Nth successor (or predecessor if steps is negative) of an iterator.
Definition next.hpp:38
constexpr bool substitution_succeeds
Determines if a template can be instantiated successfully, similar to C++20's requires clause.
auto as_bytes(span< T, N > spn) noexcept -> span< byte const, span_detail::is_dynamic_extent(N) ? dynamic_extent :(N *sizeof(T))>
Obtain a const view to the object representation of the elements of the span spn.
Definition span.hpp:967
enum ARENE_MAY_ALIAS byte
A type that represents a byte of data.
Definition byte.hpp:39
auto as_writable_bytes(span< T, N > spn) noexcept -> span< byte, span_detail::is_dynamic_extent(N) ? dynamic_extent :(N *sizeof(T))>
Obtain a non-const view to the object representation of the elements of the span spn.
Definition span.hpp:977
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
remove_cv_t< remove_reference_t< T > > remove_cvref_t
Backport of std::remove_cvref_t.
Definition remove_cvref.hpp:35
Definition accumulate.hpp:36
STL namespace.
::ptrdiff_t ptrdiff_t
A type suitable for holding the difference between two pointers.
Definition cstddef.hpp:31
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41
bool_constant< true > true_type
An alias for bool_constant<true>
Definition integral_constant.hpp:76
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...
#define ARENE_NODISCARD
An alias for [[nodiscard]] , or a no-op if the attribute is not supported.
Definition nodiscard.hpp:26
Provides a backport of the constexpr implementation of std::reverse_iterator .