Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
arithmetic_traits.hpp
Go to the documentation of this file.
1// Copyright 2024, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_TRAITS_ARITHMETIC_TRAITS_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_TRAITS_ARITHMETIC_TRAITS_HPP_
7
8// IWYU pragma: private, include "arene/base/type_traits.hpp"
9// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11#include "arene/base/constraints/constraints.hpp"
12#include "arene/base/stdlib_choice/declval.hpp"
13#include "arene/base/stdlib_choice/enable_if.hpp"
14
15namespace arene {
16namespace base {
17
18namespace arithmetic_traits_detail {
19
20/// @brief Check if instances of @c Lhs can be added to instances of @c Rhs
21/// @tparam Lhs The type of the left-hand operand
22/// @tparam Rhs The type of the right-hand operand
23template <typename Lhs, typename Rhs, typename = constraints<>>
24extern constexpr bool is_addable_v = false;
25
26/// @brief Check if instances of @c Lhs can be added to instances of @c Rhs --- this specialization is for the case
27/// where they can be added
28/// @tparam Lhs The type of the left-hand operand
29/// @tparam Rhs The type of the right-hand operand
30template <typename Lhs, typename Rhs>
31extern constexpr bool is_addable_v<Lhs, Rhs, constraints<decltype(std::declval<Lhs>() + std::declval<Rhs>())>> = true;
32
33} // namespace arithmetic_traits_detail
34
35/// @brief Check if instances of @c Lhs can be added to instances of @c Rhs. The value is @c true if they can be added,
36/// @c false otherwise.
37/// @tparam Lhs The type of the left-hand operand
38/// @tparam Rhs The type of the right-hand operand, defaults to @c Lhs
39template <typename Lhs, typename Rhs = Lhs>
41
42namespace arithmetic_traits_detail {
43
44/// @brief Check if instances of @c Lhs can be added to instances of @c Rhs without throwing an exception
45/// @tparam Lhs The type of the left-hand operand
46/// @tparam Rhs The type of the right-hand operand
47template <typename Lhs, typename Rhs, typename = constraints<>>
48extern constexpr bool is_nothrow_addable_v = false;
49
50/// @brief Check if instances of @c Lhs can be added to instances of @c Rhs without throwing an exception --- this
51/// specialization is for the case where they can be added
52/// @tparam Lhs The type of the left-hand operand
53/// @tparam Rhs The type of the right-hand operand
54template <typename Lhs, typename Rhs>
55extern constexpr bool is_nothrow_addable_v<Lhs, Rhs, constraints<std::enable_if_t<is_addable_v<Lhs, Rhs>>>> =
56 noexcept(std::declval<Lhs>() + std::declval<Rhs>());
57
58} // namespace arithmetic_traits_detail
59
60/// @brief Check if instances of @c Lhs can be added to instances of @c Rhs without throwing an exception. The value is
61/// @c true if they can be added without throwing, @c false otherwise.
62/// @tparam Lhs The type of the left-hand operand
63/// @tparam Rhs The type of the right-hand operand, defaults to @c Lhs
64template <typename Lhs, typename Rhs = Lhs>
66
67namespace arithmetic_traits_detail {
68
69/// @brief Check if instances of @c Rhs can be subtracted from an instance of @c Lhs
70/// @tparam Lhs The type of the left-hand operand
71/// @tparam Rhs The type of the right-hand operand
72template <typename Lhs, typename Rhs, typename = constraints<>>
73extern constexpr bool is_subtractable_v = false;
74
75/// @brief Check if instances of @c Rhs can be subtracted from an instance of @c Lhs --- this specialization is for the
76/// case where they can be added
77/// @tparam Lhs The type of the left-hand operand
78/// @tparam Rhs The type of the right-hand operand
79template <typename Lhs, typename Rhs>
80extern constexpr bool is_subtractable_v<Lhs, Rhs, constraints<decltype(std::declval<Lhs>() - std::declval<Rhs>())>> =
81 true;
82
83} // namespace arithmetic_traits_detail
84
85/// @brief Check if instances of @c Rhs can be subtracted from an instance of @c Lhs. The value is @c true if they can
86/// be added, @c false otherwise.
87/// @tparam Lhs The type of the left-hand operand
88/// @tparam Rhs The type of the right-hand operand, defaults to @c Lhs
89template <typename Lhs, typename Rhs = Lhs>
91
92namespace arithmetic_traits_detail {
93
94/// @brief Check if instances of @c Rhs can be subtracted from an instance of @c Lhs without throwing an exception
95/// @tparam Lhs The type of the left-hand operand
96/// @tparam Rhs The type of the right-hand operand
97template <typename Lhs, typename Rhs, typename = constraints<>>
98extern constexpr bool is_nothrow_subtractable_v = false;
99
100/// @brief Check if instances of @c Rhs can be subtracted from an instance of @c Lhs without throwing an exception ---
101/// this specialization is for the case where they can be added
102/// @tparam Lhs The type of the left-hand operand
103/// @tparam Rhs The type of the right-hand operand
104template <typename Lhs, typename Rhs>
105extern constexpr bool is_nothrow_subtractable_v<Lhs, Rhs, constraints<std::enable_if_t<is_subtractable_v<Lhs, Rhs>>>> =
106 noexcept(std::declval<Lhs>() - std::declval<Rhs>());
107
108} // namespace arithmetic_traits_detail
109
110/// @brief Check if instances of @c Rhs can be subtracted from an instance of @c Lhs without throwing an exception. The
111/// value is @c true if they can be added without throwing, @c false otherwise.
112/// @tparam Lhs The type of the left-hand operand
113/// @tparam Rhs The type of the right-hand operand, defaults to @c Lhs
114template <typename Lhs, typename Rhs = Lhs>
116
117} // namespace base
118} // namespace arene
119
120#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_TRAITS_ARITHMETIC_TRAITS_HPP_
Definition array_exceptions_disabled.cpp:11
constexpr bool is_addable_v
Check if instances of Lhs can be added to instances of Rhs. The value is true if they can be added,...
constexpr bool is_nothrow_addable_v
Check if instances of Lhs can be added to instances of Rhs without throwing an exception....
constexpr bool is_nothrow_subtractable_v
Check if instances of Rhs can be subtracted from an instance of Lhs without throwing an exception....
constexpr bool is_subtractable_v
Check if instances of Rhs can be subtracted from an instance of Lhs. The value is true if they can be...
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10