Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
constant_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_CONSTANT_ACCESSOR_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_CONSTANT_ACCESSOR_HPP_
7
8#include "arene/base/stdlib_choice/cstddef.hpp"
9#include "arene/base/stdlib_choice/is_abstract.hpp"
10#include "arene/base/stdlib_choice/is_object.hpp"
11
12// parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
13
14namespace arene {
15namespace base {
16/// @brief Accessor policy for @c mdspan which always returns the same value
17/// @tparam ElementType the type of the element
18template <typename ElementType>
20 public:
21 static_assert(!std::is_abstract<ElementType>::value, "ElementType must not be abstract");
22 static_assert(std::is_object<ElementType>::value, "ElementType must be an object type");
23
24 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False positive: type aliases do not hide identifiers from class
25 // 'constant_accessor'"
26 /// @brief The type of the element
27 using element_type = ElementType;
28 /// @brief The type of the data handle --- this is the same as the element type, so no backing data is required, the
29 /// fixed value is passed in as the handle
30 using data_handle_type = ElementType;
31 /// @brief The type of a "reference" to the element --- this is the same as the element type, so no backing data is
32 /// required, the value is returned by value
33 using reference = ElementType;
34 /// @brief The type of the accessor policy for accessing data with an offset --- this is @c constant_accessor , since
35 /// the value is constant, so the offset doesn't matter
37 // parasoft-end-suppress AUTOSAR-A2_10_1-e
38
39 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False positive: 'access' does not hide an identifier from class
40 // 'constant_accessor'"
41 /// @brief Return the value for the given data handle and index. The index is ignored as the value is always constant
42 /// @param data_handle The fixed value to return
43 /// @return The fixed value supplied as @c data_handle
44 static constexpr auto access(data_handle_type data_handle, std::size_t) noexcept -> reference { return data_handle; }
45 // parasoft-end-suppress AUTOSAR-A2_10_1-e
46
47 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False positive: 'offset' does not hide an identifier from class
48 // 'constant_accessor'"
49 /// @brief Return the data handle value to use with the offset policy for the given data handle and index. The index
50 /// is ignored as the value is always constant
51 /// @param data_handle The fixed value to return
52 /// @return The fixed value supplied as @c data_handle
53 static constexpr auto offset(data_handle_type data_handle, std::size_t) noexcept -> reference { return data_handle; }
54 // parasoft-end-suppress AUTOSAR-A2_10_1-e
55};
56} // namespace base
57} // namespace arene
58
59#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_CONSTANT_ACCESSOR_HPP_
Accessor policy for mdspan which always returns the same value.
Definition constant_accessor.hpp:19
constant_accessor offset_policy
The type of the accessor policy for accessing data with an offset — this is constant_accessor ,...
Definition constant_accessor.hpp:36
ElementType element_type
The type of the element.
Definition constant_accessor.hpp:27
ElementType data_handle_type
The type of the data handle — this is the same as the element type, so no backing data is required,...
Definition constant_accessor.hpp:30
static constexpr auto access(data_handle_type data_handle, std::size_t) noexcept -> reference
Return the value for the given data handle and index. The index is ignored as the value is always con...
Definition constant_accessor.hpp:44
static constexpr auto offset(data_handle_type data_handle, std::size_t) noexcept -> reference
Return the data handle value to use with the offset policy for the given data handle and index....
Definition constant_accessor.hpp:53
ElementType reference
The type of a "reference" to the element — this is the same as the element type, so no backing data i...
Definition constant_accessor.hpp:33
static constexpr value_type value
Definition integral_constant.hpp:34
Definition accumulate.hpp:37
Definition accumulate.hpp:36
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29