Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
slice.hpp
Go to the documentation of this file.
1// Copyright 2026, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_SLICE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_SLICE_HPP_
7
8#include "arene/base/stdlib_choice/cstddef.hpp"
9#include "arene/base/stdlib_choice/integral_constant.hpp"
10#include "arene/base/stdlib_choice/is_integral.hpp"
11#include "arene/base/type_traits/is_integral_constant_like.hpp"
12
13namespace arene {
14namespace base {
15
16// parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this class is POD"
17
18/// @brief represents a set of @c extent regularly spaced integer indices
19/// @tparam OffsetType type used to specify the offset
20/// @tparam ExtentType type used to specify the extent
21/// @tparam StrideType type used to specify the stride
22///
23/// <c> extent_slice<int>{1, 4, 3} </c> indicates the indices 1, 4,
24/// 7, and 10. The slice contains 4 indices, starting from 1, with a stride of 3.
25template < //
26 class OffsetType,
27 class ExtentType = OffsetType,
28 class StrideType = std::integral_constant<std::size_t, 1>>
30 public:
31 static_assert( //
33 "'OffsetType' must be an integer type or model integral-constant-like"
34 );
35 static_assert( //
37 "'ExtentType' must be an integer type or model integral-constant-like"
38 );
39 static_assert( //
41 "'StrideType' must be an integer type or model integral-constant-like"
42 );
43
44 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False positive: these identifiers do not hide identifiers in
45 // 'extent_slice'"
46 /// @brief offset type
47 using offset_type = OffsetType;
48 /// @brief extent type
49 using extent_type = ExtentType;
50 /// @brief stride type
51 using stride_type = StrideType;
52 // parasoft-end-suppress AUTOSAR-A2_10_1-e
53
54 /// @brief start of indices
55 /// First index in this slice, i.e. offset from zero.
56 /// @attention This value must be non-negative to represent a valid slice.
57 offset_type offset{};
58 /// @brief extent of indices
59 /// Number of indices in this slice.
60 /// @attention This value must be non-negative to represent a valid slice.
61 extent_type extent{};
62 /// @brief stride of indices
63 /// Stride (or step) between indices in this slice.
64 /// @attention This value must be positive to represent a valid slice.
65 stride_type stride{};
66};
67
68// parasoft-end-suppress AUTOSAR-M11_0_1-a-2
69
70// parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this class is POD"
71
72/// @brief represents a slice of integer indices given the first and last
73/// @tparam FirstType type used to specify the first index
74/// @tparam LastType type used to specify the last index
75/// @tparam StrideType type used to specify the stride
76///
77/// <c> range_slice<int>{1, 11, 3} </c> indicates the indices 1, 4,
78/// 7, and 10. Indices are selected from the half-open interval [1, 11) with a
79/// stride of 3.
80template < //
81 class FirstType,
82 class LastType = FirstType,
83 class StrideType = std::integral_constant<std::size_t, 1>>
85 public:
86 static_assert( //
88 "'FirstType' must be an integer type or model integral-constant-like"
89 );
90 static_assert( //
92 "'LastType' must be an integer type or model integral-constant-like"
93 );
94 static_assert( //
96 "'StrideType' must be an integer type or model integral-constant-like"
97 );
98
99 /// @brief first index type
100 using first_type = FirstType;
101 /// @brief last index type
102 using last_type = LastType;
103 /// @brief stride type
104 using stride_type = StrideType;
105
106 /// @brief start index
107 /// First index (inclusive) in this slice.
108 /// @attention This value must be non-negative to represent a valid slice.
109 first_type first{};
110 /// @brief last index
111 /// Last index (exclusive) in this slice.
112 last_type last{};
113 /// @brief stride of indices
114 /// Stride (or step) between indices in this slice.
115 /// @attention This value must be positive to represent a valid slice.
116 stride_type stride{};
117};
118
119// parasoft-end-suppress AUTOSAR-M11_0_1-a-2
120
121} // namespace base
122} // namespace arene
123
124#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_SLICE_HPP_
represents a set of extent regularly spaced integer indices
Definition slice.hpp:29
stride_type stride
stride of indices Stride (or step) between indices in this slice.
Definition slice.hpp:65
extent_type extent
extent of indices Number of indices in this slice.
Definition slice.hpp:61
offset_type offset
start of indices First index in this slice, i.e. offset from zero.
Definition slice.hpp:57
represents a slice of integer indices given the first and last
Definition slice.hpp:84
stride_type stride
stride of indices Stride (or step) between indices in this slice.
Definition slice.hpp:116
last_type last
last index Last index (exclusive) in this slice.
Definition slice.hpp:112
first_type first
start index First index (inclusive) in this slice.
Definition slice.hpp:109
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10