Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
is_accessor_policy.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_IS_ACCESSOR_POLICY_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_IS_ACCESSOR_POLICY_HPP_
7
8#include "arene/base/constraints/constraints.hpp"
9#include "arene/base/stdlib_choice/cstddef.hpp"
10#include "arene/base/stdlib_choice/declval.hpp"
11#include "arene/base/stdlib_choice/enable_if.hpp"
12#include "arene/base/stdlib_choice/is_abstract.hpp"
13#include "arene/base/stdlib_choice/is_constructible.hpp"
14#include "arene/base/stdlib_choice/is_move_assignable.hpp"
15#include "arene/base/stdlib_choice/is_move_constructible.hpp"
16#include "arene/base/stdlib_choice/is_object.hpp"
17#include "arene/base/stdlib_choice/is_same.hpp"
18#include "arene/base/type_traits/is_copyable.hpp"
19#include "arene/base/type_traits/is_swappable.hpp"
20
21namespace arene {
22namespace base {
23
24namespace is_accessor_policy_detail {
25
26/// @brief Check if a type has the required accessor policy typedefs
27/// @tparam AccessorPolicy The policy to check
28template <typename AccessorPolicy, typename = arene::base::constraints<>>
29extern constexpr bool has_typedefs_v = false;
30
31/// @brief Check if a type has the required accessor policy typedefs
32/// @tparam AccessorPolicy The policy to check
33template <typename AccessorPolicy>
34extern constexpr bool has_typedefs_v<
35 AccessorPolicy,
36 arene::base::constraints<
37 typename AccessorPolicy::element_type,
38 typename AccessorPolicy::data_handle_type,
39 typename AccessorPolicy::reference,
40 typename AccessorPolicy::offset_policy,
41 typename AccessorPolicy::offset_policy::element_type>> =
42 std::is_object<typename AccessorPolicy::element_type>::value &&
43 !std::is_abstract<typename AccessorPolicy::element_type>::value &&
44 is_copyable_v<typename AccessorPolicy::data_handle_type> &&
45 std::is_nothrow_move_constructible<typename AccessorPolicy::data_handle_type>::value &&
46 std::is_nothrow_move_assignable<typename AccessorPolicy::data_handle_type>::value &&
47 is_nothrow_swappable_v<typename AccessorPolicy::data_handle_type> &&
48 std::is_constructible<typename AccessorPolicy::offset_policy, AccessorPolicy const&>::value &&
49 std::is_same<typename AccessorPolicy::offset_policy::element_type, typename AccessorPolicy::element_type>::value;
50
51/// @brief Try to call the @c access() member function with the required arguments
52/// @tparam AccessorPolicy The policy to check
53template <typename AccessorPolicy>
54using access_t = decltype(std::declval<AccessorPolicy const&>()
55 .access(std::declval<typename AccessorPolicy::data_handle_type const&>(), std::size_t{}));
56
57/// @brief Try to call the @c offest() member function with the required arguments
58/// @tparam AccessorPolicy The policy to check
59template <typename AccessorPolicy>
60using offset_t = decltype(std::declval<AccessorPolicy const&>()
61 .offset(std::declval<typename AccessorPolicy::data_handle_type const&>(), std::size_t{}));
62
63/// @brief Check if a type has the required accessor policy typedefs and member functions
64/// @tparam AccessorPolicy The policy to check
65template <typename AccessorPolicy, typename = arene::base::constraints<>>
66extern constexpr bool has_typedefs_and_functions_v = false;
67
68/// @brief Check if a type has the required accessor policy typedefs and member functions
69/// @tparam AccessorPolicy The policy to check
70template <typename AccessorPolicy>
71extern constexpr bool has_typedefs_and_functions_v<
72 AccessorPolicy,
73 arene::base::constraints<
74 std::enable_if_t<has_typedefs_v<AccessorPolicy>>,
75 access_t<AccessorPolicy>,
76 offset_t<AccessorPolicy>>> =
77 std::is_same<access_t<AccessorPolicy>, typename AccessorPolicy::reference>::value &&
78 std::is_same<offset_t<AccessorPolicy>, typename AccessorPolicy::offset_policy::data_handle_type>::value;
79
80} // namespace is_accessor_policy_detail
81
82/// @brief Check if a type is a valid accessor policy
83/// @tparam AccessorPolicy The policy to check
84///
85/// A type A meets the accessor policy requirements if
86/// * A has a type alias named @c element_type
87/// * A has a type alias named @c data_handle_type
88/// * A has a type alias named @c reference
89/// * A has a type alias named @c offset_policy
90/// * A has a member function named @c access that takes a @c data_handle_type and a @c std::size_t
91/// * A has a member function named @c offest that takes a @c data_handle_type and a @c std::size_t
92/// * @c arene::base::is_copyable_v<A> is true
93/// * @c is_nothrow_move_constructible_v<A> is true
94/// * @c is_nothrow_move_assignable_v<A> is true
95/// * @c is_nothrow_swappable_v<A> is true
96template <class AccessorPolicy>
97extern constexpr bool is_accessor_policy_v =
101
102} // namespace base
103} // namespace arene
104
105#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MDSPAN_IS_ACCESSOR_POLICY_HPP_
Definition array_exceptions_disabled.cpp:11
constexpr bool is_accessor_policy_v
Check if a type is a valid accessor policy.
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10