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
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"
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{
31};
32
33namespace linalg_traits_detail {
34/// @brief Determine if the given type is an in-object, usable as an input object for linalg algorithms
35/// @tparam T The type to check
36template <typename T>
37extern constexpr bool is_in_object_v{false};
38
39/// @brief Determine if the given type is an in-object, usable as an input object 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_object_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>>{is_scalar_v<
47
48/// @brief Determine if the given type is an out-object, usable as an output object for linalg algorithms
49/// @tparam T The type to check
50template <typename T>
51extern constexpr bool is_out_object_v{false};
52
53/// @brief Determine if the given type is an out-object, usable as an output object for linalg algorithms
54/// @tparam ElementType The element type of an @c mdspan being checked
55/// @tparam Extents The extents type of an @c mdspan being checked
56/// @tparam LayoutPolicy The layout policy type (note: not the layout mapping) of an @c mdspan being checked
57/// @tparam AccessorPolicy The accessor policy type of an @c mdspan being checked
58template <typename ElementType, typename Extents, typename LayoutPolicy, typename AccessorPolicy>
59extern constexpr bool is_out_object_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>>{
60 is_in_object_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>> &&
61 std::is_assignable<
64 mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>::is_always_unique()
65};
66
67/// @brief Determine if the given type is an in-vector, usable as an input vector for linalg algorithms
68/// @tparam T The type to check
69template <typename T>
70extern constexpr bool is_in_vector_v{false};
71
72/// @brief Determine if the given type is an in-vector, usable as an input vector for linalg algorithms
73/// @tparam ElementType The element type of an @c mdspan being checked
74/// @tparam Extents The extents type of an @c mdspan being checked
75/// @tparam LayoutPolicy The layout policy type (note: not the layout mapping) of an @c mdspan being checked
76/// @tparam AccessorPolicy The accessor policy type of an @c mdspan being checked
77template <typename ElementType, typename Extents, typename LayoutPolicy, typename AccessorPolicy>
78extern constexpr bool is_in_vector_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>>{
80 is_in_object_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>> //
81};
82
83/// @brief Determine if the given type is an out-vector, usable as an output vector for linalg algorithms
84/// @tparam T The type to check
85template <typename T>
86extern constexpr bool is_out_vector_v{false};
87
88/// @brief Determine if the given type is an out-vector, usable as an output vector for linalg algorithms
89/// @tparam ElementType The element type of an @c mdspan being checked
90/// @tparam Extents The extents type of an @c mdspan being checked
91/// @tparam LayoutPolicy The layout policy type (note: not the layout mapping) of an @c mdspan being checked
92/// @tparam AccessorPolicy The accessor policy type of an @c mdspan being checked
93template <typename ElementType, typename Extents, typename LayoutPolicy, typename AccessorPolicy>
94extern constexpr bool is_out_vector_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>>{
95 is_in_vector_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>> && //
96 is_out_object_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>> //
97};
98
99/// @brief Determine if the given type is an in-matrix, usable as an input matrix for linalg algorithms
100/// @tparam T The type to check
101template <typename T>
102extern constexpr bool is_in_matrix_v{false};
103
104/// @brief Determine if the given type is an in-matrix, usable as an input matrix for linalg algorithms
105/// @tparam ElementType The element type of an @c mdspan being checked
106/// @tparam Extents The extents type of an @c mdspan being checked
107/// @tparam LayoutPolicy The layout policy type (note: not the layout mapping) of an @c mdspan being checked
108/// @tparam AccessorPolicy The accessor policy type of an @c mdspan being checked
109template <typename ElementType, typename Extents, typename LayoutPolicy, typename AccessorPolicy>
110extern constexpr bool is_in_matrix_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>>{
112 is_in_object_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>> //
113};
114
115/// @brief Determine if the given type is an out-matrix, usable as an output matrix for linalg algorithms
116/// @tparam T The type to check
117template <typename T>
118extern constexpr bool is_out_matrix_v{false};
119
120/// @brief Determine if the given type is an out-matrix, usable as an output matrix for linalg algorithms
121/// @tparam ElementType The element type of an @c mdspan being checked
122/// @tparam Extents The extents type of an @c mdspan being checked
123/// @tparam LayoutPolicy The layout policy type (note: not the layout mapping) of an @c mdspan being checked
124/// @tparam AccessorPolicy The accessor policy type of an @c mdspan being checked
125template <typename ElementType, typename Extents, typename LayoutPolicy, typename AccessorPolicy>
126extern constexpr bool is_out_matrix_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>>{
127 is_in_matrix_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>> && //
128 is_out_object_v<mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>>
129};
130} // namespace linalg_traits_detail
131
132/// @brief Determine if the given type is an in-vector, usable as an input vector for linalg algorithms
133/// @tparam T The type to check
134template <typename T>
135extern constexpr bool is_in_vector_v{linalg_traits_detail::is_in_vector_v<std::remove_cv_t<T>>};
136
137/// @brief Determine if the given type is an out-vector, usable as an output vector for linalg algorithms
138/// @tparam T The type to check
139template <typename T>
140extern constexpr bool is_out_vector_v{linalg_traits_detail::is_out_vector_v<std::remove_cv_t<T>>};
141
142/// @brief Determine if the given type is an inout-vector, usable as both input and output vector for linalg algorithms
143/// @tparam T The type to check
144template <typename T>
145extern constexpr bool is_inout_vector_v{is_out_vector_v<T>};
146
147/// @brief Determine if the given type is an in-matrix, usable as an input matrix for linalg algorithms
148/// @tparam T The type to check
149template <typename T>
150extern constexpr bool is_in_matrix_v{linalg_traits_detail::is_in_matrix_v<std::remove_cv_t<T>>};
151
152/// @brief Determine if the given type is an out-matrix, usable as an output matrix for linalg algorithms
153/// @tparam T The type to check
154template <typename T>
155extern constexpr bool is_out_matrix_v{linalg_traits_detail::is_out_matrix_v<std::remove_cv_t<T>>};
156
157/// @brief Determine if the given type is an inout-matrix, usable as both input and output matrix for linalg algorithms
158/// @tparam T The type to check
159template <typename T>
160extern constexpr bool is_inout_matrix_v{is_out_matrix_v<T>};
161
162/// @brief Determine if the given type is an in-object, e.g. an in-vector or in-matrix
163/// @tparam T The type to check
164template <typename T>
165extern constexpr bool is_in_object_v{linalg_traits_detail::is_in_object_v<std::remove_cv_t<T>>};
166
167/// @brief Determine if the given type is an out-object, e.g. an out-vector or out-matrix
168/// @tparam T The type to check
169template <typename T>
170extern constexpr bool is_out_object_v{linalg_traits_detail::is_out_object_v<std::remove_cv_t<T>>};
171
172/// @brief Determine if the given type is an inout-object, e.g. an inout-vector or inout-matrix
173/// @tparam T The type to check
174template <typename T>
175extern constexpr bool is_inout_object_v{is_out_object_v<T>};
176
177} // namespace linalg
178} // namespace base
179} // namespace arene
180
181#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_LINALG_OBJECT_TRAITS_HPP_
ElementType element_type
The element type.
Definition mdspan.hpp:183
static constexpr std::integral_constant< rank_type, Extents::rank()> rank
Get the number of dimensions.
Definition mdspan.hpp:206
std::remove_cv_t< element_type > value_type
The value type.
Definition mdspan.hpp:188
typename accessor_type::reference reference
The reference type.
Definition mdspan.hpp:200
static constexpr value_type value
Definition integral_constant.hpp:34
Definition add.hpp:20
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, e.g. an inout-vector or inout-matrix.
constexpr bool is_in_object_v
Determine if the given type is an in-object, e.g. 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, e.g. an out-vector or out-matrix.
Definition accumulate.hpp:37
constexpr bool is_mdspan_v
Type trait to determine if the given type is an mdspan of some kind.
constexpr bool is_copyable_v
Backport for the C++20 copyable concept.
Definition accumulate.hpp:36