Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
constant.hpp
Go to the documentation of this file.
1// parasoft-suppress AUTOSAR-A2_8_1-a "False positive: also defines arene::base::linalg::constant"
2// Copyright 2026, Toyota Motor Corporation
3//
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_LINALG_CONSTANT_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_LINALG_CONSTANT_HPP_
7
8// IWYU pragma: private, include "arene/base/linalg.hpp"
9// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
19#include "arene/base/stdlib_choice/enable_if.hpp"
20#include "arene/base/stdlib_choice/is_copy_constructible.hpp"
21// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
22
23// parasoft-begin-suppress AUTOSAR-M2_10_1-a-2 "Similar names permitted by M2-10-1 Permit #1"
24// parasoft-begin-suppress AUTOSAR-A7_1_5-a "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
25
26namespace arene {
27namespace base {
28namespace linalg {
29
30namespace constant_detail {
31/// @brief function object to return a constant tensorlet
32class constant_fn {
33 public:
34 /// @brief returns a constant tensorlet
35 /// @tparam T numeric type
36 /// @tparam Extents constant tensorlet extents type
37 /// @param value constant tensorlet value
38 /// @param extents constant tensorlet extents
39 ///
40 /// Provides a tensorlet (i.e. a vector for rank-1 and a matrix for rank-2)
41 /// where the value at all indexes is the same constant @c value. The tensorlet
42 /// stores a single copy of the constant @c value
43 /// and access always returns a copy of the stored @c value.
44 ///
45 /// @return @c mdspan with value of @c value for all entries
46 ///
47 /// @note The layout of the returned @c mdspan is unspecified.
48 template <
49 class T,
50 class Extents,
51 constraints< //
54 constexpr auto operator()(T const& value, Extents const& extents) const
55 noexcept(std::is_nothrow_copy_constructible<T>::value) -> mdspan<T, Extents, layout_right, constant_accessor<T>> {
56 return {value, extents};
57 }
58};
59} // namespace constant_detail
60
61/// @brief Construct a constant-valued expression for a linear algebra operation.
62// parasoft-begin-suppress AUTOSAR-M7_3_3-a "An unnamed namespace is used to create a per-TU reference to a global
63// object used in multiple TUs."
64// parasoft-begin-suppress CERT_CPP-DCL59-a "An unnamed namespace is used to create a per-TU reference to a global
65// object used in multiple TUs."
66ARENE_CPP14_INLINE_VARIABLE(constant_detail::constant_fn, constant);
67// parasoft-end-suppress AUTOSAR-M7_3_3-a
68// parasoft-end-suppress CERT_CPP-DCL59-a
69
70} // namespace linalg
71} // namespace base
72} // namespace arene
73#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_LINALG_CONSTANT_HPP_
#define ARENE_CPP14_INLINE_VARIABLE(type, name)
Emulates C++17's inline variable declarations for function objects.
Definition cpp14_inline.hpp:69
static constexpr value_type value
Definition integral_constant.hpp:34
Definition add.hpp:20
Definition accumulate.hpp:37
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
Definition accumulate.hpp:36
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