Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
arithmetic_identities.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_MATH_ARITHMETIC_IDENTITIES_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MATH_ARITHMETIC_IDENTITIES_HPP_
7
8// IWYU pragma: private, include "arene/base/math.hpp"
9// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11namespace arene {
12namespace base {
13namespace numbers {
14
15/// @brief The additive identity of @c T
16/// @tparam T numeric type
17///
18/// <c> a + zero_v<T> == a </c> and <c> zero_v<T> + a == a </c> are @c true for valid values
19/// of @c a of type @c T.
20///
21/// Users may specialize @c zero_v for cv-unqualified program-defined types.
22/// A specialization is required if any of the following cases are true for
23/// the expression @c T{}:
24/// * is not well formed
25/// * does not match the required semantics
26/// * is not invocable within a constant expression
27///
28/// A specialization may be non-@c constexpr; such specializations may not
29/// be used in contexts that require a constant expression.
30///
31/// Example of a non-@c constexpr specialization (for a type whose
32/// default constructor is not @c constexpr but does have the correct semantics):
33///
34/// ~~~{.cpp}
35/// template <>
36/// my_type const arene::base::numbers::zero_v<my_type>{};
37/// ~~~
38template <typename T>
39extern constexpr T zero_v{};
40
41/// @brief The multiplicative identity of @c T
42/// @tparam T numeric type
43///
44/// <c> a * one_v<T> == a </c> and <c> one_v<T> * a == a </c> are @c true for valid values
45/// of @c a of type @c T.
46///
47/// Users may specialize @c one_v for cv-unqualified program-defined types.
48/// A specialization is required if any of the following cases are true for
49/// the expression @c T{1}:
50/// * is not well formed
51/// * does not match the required semantics
52/// * is not invocable within a constant expression
53///
54/// @see zero_v
55///
56template <typename T>
57extern constexpr T one_v{1};
58
59} // namespace numbers
60} // namespace base
61} // namespace arene
62
63#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MATH_ARITHMETIC_IDENTITIES_HPP_
Definition arithmetic_identities.hpp:13
constexpr T one_v
The multiplicative identity of T.
constexpr T zero_v
The additive identity of T.
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10