Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
copy_elements.hpp
Go to the documentation of this file.
1// parasoft-suppress AUTOSAR-A2_8_1-a "False positive: also defines arene::base::linalg::copy_elements"
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_COPY_ELEMENTS_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_LINALG_COPY_ELEMENTS_HPP_
7
11#include "arene/base/linalg/detail/mandates.hpp"
13#include "arene/base/stdlib_choice/enable_if.hpp"
15
16// parasoft-begin-suppress AUTOSAR-M2_10_1-a-2 "Similar names permitted by M2-10-1 Permit #1"
17// parasoft-begin-suppress AUTOSAR-A7_1_5-a "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
18
19namespace arene {
20namespace base {
21namespace linalg {
22
23namespace copy_elements_detail {
24
25/// @brief Class to implement @c copy_elements
26class copy_elements_fn {
27 public:
28 /// @brief Copy the elements of one @c mdspan into another
29 /// @tparam InSpan The type of the source (input) @c mdspan, must be the same rank as @c OutSpan
30 /// @tparam OutSpan The type of the destination (output) @c mdspan, must be the same rank as @c InSpan
31 /// @param source The @c mdspan to copy elements from
32 /// @param dest The @c mdspan to copy elements into
33 /// @note This corresponds to the SCOPY and DCOPY functions from BLAS 1 (xCOPY).
34 /// @pre <c>source.extents() == dest.extents()</c>, otherwise precondition violation
35 template <
36 typename InSpan,
37 typename OutSpan,
39 linalg_detail::possibly_comparable_constraints<InSpan, OutSpan>,
40 std::enable_if_t<is_invocable_v<decltype(elementwise_unary_transform), InSpan, OutSpan, arene::base::identity>>
41 > = nullptr>
42 // parasoft-begin-suppress AUTOSAR-A0_1_4-a "False positive: All parameters are used"
43 constexpr auto operator()(InSpan const source, OutSpan const dest) const noexcept( //
44 is_nothrow_invocable_v<decltype(elementwise_unary_transform), InSpan, OutSpan, arene::base::identity>
45 ) -> void {
46 // parasoft-end-suppress AUTOSAR-A0_1_4-a
47 return elementwise_unary_transform(source, dest, ::arene::base::identity{});
48 }
49};
50} // namespace copy_elements_detail
51
52/// @brief Copy corresponding elements from one multidimensional view to another.
53// parasoft-begin-suppress AUTOSAR-M7_3_3-a "An unnamed namespace is used to create a per-TU reference to a global
54// object used in multiple TUs."
55// parasoft-begin-suppress CERT_CPP-DCL59-a "An unnamed namespace is used to create a per-TU reference to a global
56// object used in multiple TUs."
57ARENE_CPP14_INLINE_VARIABLE(copy_elements_detail::copy_elements_fn, copy_elements);
58// parasoft-end-suppress AUTOSAR-M7_3_3-a
59// parasoft-end-suppress CERT_CPP-DCL59-a
60
61} // namespace linalg
62} // namespace base
63} // namespace arene
64
65#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_LINALG_COPY_ELEMENTS_HPP_
#define ARENE_CPP14_INLINE_VARIABLE(type, name)
Emulates C++17's inline variable declarations for function objects.
Definition cpp14_inline.hpp:69
Definition add.hpp:20
Definition accumulate.hpp:37
constexpr bool is_invocable_v
Determine if a functor type is invocable with the specified argument types.
constexpr bool is_nothrow_invocable_v
Determine if a functor type is no-throw invocable with the specified argument types.
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