Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
object_traits.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_LINALG_OBJECT_TRAITS_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_LINALG_OBJECT_TRAITS_HPP_
7
8// IWYU pragma: private, include "arene/base/linalg.hpp"
9// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11#include "arene/base/mdspan/mdspan.hpp"
12#include "arene/base/stdlib_choice/is_assignable.hpp"
13#include "arene/base/stdlib_choice/is_default_constructible.hpp"
14#include "arene/base/stdlib_choice/remove_cv.hpp"
15#include "arene/base/type_traits/is_copyable.hpp"
16
17namespace arene {
18namespace base {
19namespace linalg {
20
21/// @brief Determine if the given type is a scalar for the purposes of linalg algorithms
22/// @tparam T The type to check
23/// @note To be a scalar for this purpose, the type must be semiregular (having all special member functions) and not
24/// be an mdspan. The <c>value_type</c>s of vectors and matrices used in linalg must be scalars in this sense.
25/// @note C++26 also requires @c !std::is_execution_policy_v<T> but there are no execution policies in C++14.
26template <typename T>
27extern constexpr bool is_scalar_v{
30 !is_mdspan_v<T> //
31};
32
33namespace linalg_traits_detail {
34/// @brief Determine if the given type is an in-vector, usable as an input vector for linalg algorithms
35/// @tparam T The type to check
36template <typename T>
37extern constexpr bool is_in_vector_v{false};
38
39/// @brief Determine if the given type is an in-vector, usable as an input vector for linalg algorithms
40/// @tparam ElementType The element type of an @c mdspan being checked
41/// @tparam Extents The extents type of an @c mdspan being checked
42/// @tparam LayoutPolicy The layout policy type (note: not the layout mapping) of an @c mdspan being checked
43/// @tparam AccessorPolicy The accessor policy type of an @c mdspan being checked
44template <typename ElementType, typename Extents, typename LayoutPolicy, typename AccessorPolicy>
45extern constexpr bool is_in_vector_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>>{
46 mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>::rank() == 1U && //
47 is_scalar_v<typename mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>::value_type> //
48};
49
50/// @brief Determine if the given type is an out-vector, usable as an output vector for linalg algorithms
51/// @tparam T The type to check
52template <typename T>
53extern constexpr bool is_out_vector_v{false};
54
55/// @brief Determine if the given type is an out-vector, usable as an output vector for linalg algorithms
56/// @tparam ElementType The element type of an @c mdspan being checked
57/// @tparam Extents The extents type of an @c mdspan being checked
58/// @tparam LayoutPolicy The layout policy type (note: not the layout mapping) of an @c mdspan being checked
59/// @tparam AccessorPolicy The accessor policy type of an @c mdspan being checked
60template <typename ElementType, typename Extents, typename LayoutPolicy, typename AccessorPolicy>
61extern constexpr bool is_out_vector_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>>{
62 is_in_vector_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>> &&
63 std::is_assignable<
64 typename mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>::reference,
65 typename mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>::element_type>::value &&
66 mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>::is_always_unique()
67};
68
69/// @brief Determine if the given type is an in-matrix, usable as an input matrix for linalg algorithms
70/// @tparam T The type to check
71template <typename T>
72extern constexpr bool is_in_matrix_v{false};
73
74/// @brief Determine if the given type is an in-matrix, usable as an input matrix for linalg algorithms
75/// @tparam ElementType The element type of an @c mdspan being checked
76/// @tparam Extents The extents type of an @c mdspan being checked
77/// @tparam LayoutPolicy The layout policy type (note: not the layout mapping) of an @c mdspan being checked
78/// @tparam AccessorPolicy The accessor policy type of an @c mdspan being checked
79template <typename ElementType, typename Extents, typename LayoutPolicy, typename AccessorPolicy>
80extern constexpr bool is_in_matrix_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>>{
81 mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>::rank() == 2U && //
82 is_scalar_v<typename mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>::value_type> //
83};
84
85/// @brief Determine if the given type is an out-matrix, usable as an output matrix for linalg algorithms
86/// @tparam T The type to check
87template <typename T>
88extern constexpr bool is_out_matrix_v{false};
89
90/// @brief Determine if the given type is an out-matrix, usable as an output matrix for linalg algorithms
91/// @tparam ElementType The element type of an @c mdspan being checked
92/// @tparam Extents The extents type of an @c mdspan being checked
93/// @tparam LayoutPolicy The layout policy type (note: not the layout mapping) of an @c mdspan being checked
94/// @tparam AccessorPolicy The accessor policy type of an @c mdspan being checked
95template <typename ElementType, typename Extents, typename LayoutPolicy, typename AccessorPolicy>
96extern constexpr bool is_out_matrix_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>>{
97 is_in_matrix_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>> &&
98 std::is_assignable<
99 typename mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>::reference,
100 typename mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>::element_type>::value &&
101 mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>::is_always_unique()
102};
103} // namespace linalg_traits_detail
104
105/// @brief Determine if the given type is an in-vector, usable as an input vector for linalg algorithms
106/// @tparam T The type to check
107template <typename T>
109
110/// @brief Determine if the given type is an out-vector, usable as an output vector for linalg algorithms
111/// @tparam T The type to check
112template <typename T>
114
115/// @brief Determine if the given type is an inout-vector, usable as both input and output vector for linalg algorithms
116/// @tparam T The type to check
117template <typename T>
118extern constexpr bool is_inout_vector_v{is_out_vector_v<T>};
119
120/// @brief Determine if the given type is an in-matrix, usable as an input matrix for linalg algorithms
121/// @tparam T The type to check
122template <typename T>
124
125/// @brief Determine if the given type is an out-matrix, usable as an output matrix for linalg algorithms
126/// @tparam T The type to check
127template <typename T>
129
130/// @brief Determine if the given type is an inout-matrix, usable as both input and output matrix for linalg algorithms
131/// @tparam T The type to check
132template <typename T>
133extern constexpr bool is_inout_matrix_v{is_out_matrix_v<T>};
134
135/// @brief Determine if the given type is an in-object, i.e. an in-vector or in-matrix
136/// @tparam T The type to check
137template <typename T>
138extern constexpr bool is_in_object_v{is_in_vector_v<T> || is_in_matrix_v<T>};
139
140/// @brief Determine if the given type is an out-object, i.e. an out-vector or out-matrix
141/// @tparam T The type to check
142template <typename T>
143extern constexpr bool is_out_object_v{is_out_vector_v<T> || is_out_matrix_v<T>};
144
145/// @brief Determine if the given type is an inout-object, i.e. an inout-vector or inout-matrix
146/// @tparam T The type to check
147template <typename T>
148extern constexpr bool is_inout_object_v{is_inout_vector_v<T> || is_inout_matrix_v<T>};
149
150} // namespace linalg
151} // namespace base
152} // namespace arene
153
154#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_LINALG_OBJECT_TRAITS_HPP_
Definition math_traits.hpp:17
constexpr bool is_out_vector_v
Determine if the given type is an out-vector, usable as an output vector for linalg algorithms.
constexpr bool is_in_matrix_v
Determine if the given type is an in-matrix, usable as an input matrix for linalg algorithms.
constexpr bool is_inout_object_v
Determine if the given type is an inout-object, i.e. an inout-vector or inout-matrix.
constexpr bool is_in_object_v
Determine if the given type is an in-object, i.e. an in-vector or in-matrix.
constexpr bool is_inout_vector_v
Determine if the given type is an inout-vector, usable as both input and output vector for linalg alg...
constexpr bool is_inout_matrix_v
Determine if the given type is an inout-matrix, usable as both input and output matrix for linalg alg...
constexpr bool is_out_matrix_v
Determine if the given type is an out-matrix, usable as an output matrix for linalg algorithms.
constexpr bool is_in_vector_v
Determine if the given type is an in-vector, usable as an input vector for linalg algorithms.
constexpr bool is_scalar_v
Determine if the given type is a scalar for the purposes of linalg algorithms.
constexpr bool is_out_object_v
Determine if the given type is an out-object, i.e. an out-vector or out-matrix.
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10