Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
default_accessor.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_DEFAULT_ACCESSOR_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_DEFAULT_ACCESSOR_HPP_
7
8
// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
9
10
#
include
"arene/base/constraints/constraints.hpp"
11
#
include
"arene/base/stdlib_choice/cstddef.hpp"
12
#
include
"arene/base/stdlib_choice/enable_if.hpp"
13
#
include
"arene/base/stdlib_choice/is_abstract.hpp"
14
#
include
"arene/base/stdlib_choice/is_array.hpp"
15
#
include
"arene/base/stdlib_choice/is_convertible.hpp"
16
#
include
"arene/base/stdlib_choice/is_object.hpp"
17
// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
18
19
namespace
arene
{
20
namespace
base
{
21
22
/// @brief accesses a single element from a pointer and an index
23
/// @tparam ElementType complete object type that is accessed by @c default_accessor
24
///
25
/// Backport of @c std::default_accessor from C++23. The @c default_accessor
26
/// class template is the default AccessorPolicy of @c mdspan if no
27
/// user-specified accessor policy is provided. It defines the @c
28
/// data_handle_type as a pointer to the @c ElementType and access will return a
29
/// reference to the @c ElementType.
30
///
31
template
<
class
ElementType>
32
class
default_accessor
{
33
public
:
34
static_assert
(
std
::
is_object
<
ElementType
>::
value
,
"'ElementType' must be an object"
);
35
static_assert
(!
std
::
is_abstract
<
ElementType
>::
value
,
"'ElementType' must not be an abstract class"
);
36
static_assert
(!
std
::
is_array
<
ElementType
>::
value
,
"'ElementType' must not be an array"
);
37
38
// parasoft-begin-suppress AUTOSAR-A2_10_1-e "False positive: Identifiers do not hide anything"
39
/// @brief offset policy type
40
using
offset_policy =
default_accessor
;
41
/// @brief element type to access
42
using
element_type = ElementType;
43
/// @brief reference type
44
/// Returned on element to access. In this case, an lvalue reference.
45
using
reference = ElementType&;
46
/// @brief data handle type
47
/// Refers to a group of elements. In this case, a pointer.
48
using
data_handle_type = ElementType*;
49
// parasoft-end-suppress AUTOSAR-A2_10_1-e
50
51
/// @brief default constructor
52
/// @note This constructor has no visible effect
53
constexpr
default_accessor
()
noexcept
=
default
;
54
55
/// @brief converting constructor
56
/// @tparam OtherElementType element type of the other @c default_accessor
57
/// @note This constructor has no visible effect
58
template
<
59
class
OtherElementType
,
60
// NOLINTNEXTLINE(hicpp-avoid-c-arrays)
61
constraints
<
std
::
enable_if_t
<
std
::
is_convertible
<
OtherElementType
(*)[],
element_type
(*)[]>::
value
>> =
nullptr
>
62
// NOLINTNEXTLINE(hicpp-explicit-conversions)
63
constexpr
default_accessor
(
default_accessor
<
OtherElementType
>)
noexcept
{}
64
65
// parasoft-begin-suppress AUTOSAR-M5_0_15-a "[mdspan.accessor.default] specifies indexing and incrementing a pointer"
66
// parasoft-begin-suppress AUTOSAR-M9_3_3-a "[mdspan.accessor.default] specifies these functions to be non-static"
67
/// @brief obtain the element at the specified index
68
/// @param ptr pointer to an element
69
/// @param index offset from the first element
70
/// @return reference to the element at the specified index
71
constexpr
auto
access
(
data_handle_type
ptr
,
std
::
size_t
index
)
const
noexcept
->
reference
{
return
ptr
[
index
]; }
72
73
/// @brief apply an offset to a pointer
74
/// @param ptr pointer to an element
75
/// @param index offset to apply
76
/// @return data handle after applying the offset
77
constexpr
auto
offset
(
data_handle_type
ptr
,
std
::
size_t
index
)
const
noexcept
->
data_handle_type
{
78
return
ptr
+
index
;
79
}
80
// parasoft-end-suppress AUTOSAR-M5_0_15-a
81
// parasoft-end-suppress AUTOSAR-M9_3_3-a
82
};
83
84
}
// namespace base
85
}
// namespace arene
86
87
#
endif
// INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_DEFAULT_ACCESSOR_HPP_
arene::base::default_accessor
accesses a single element from a pointer and an index
Definition
default_accessor.hpp:32
arene::base::default_accessor::default_accessor
constexpr default_accessor() noexcept=default
default constructor
arene::base
Definition
array_exceptions_disabled.cpp:11
arene
Copyright 2026, Toyota Motor Corporation.
Definition
array_exceptions_disabled.cpp:10
arene
base
mdspan
default_accessor.hpp
Generated by
1.13.2