Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
minus.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_STDLIB_INCLUDE_STDLIB_DETAIL_MINUS_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_MINUS_HPP_
7
8// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
9// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
10
11// IWYU pragma: private, include <functional>
12// IWYU pragma: friend "stdlib_detail/.*"
13
14#include "arene/base/constraints.hpp"
15#include "stdlib/include/stdlib_detail/declval.hpp"
16#include "stdlib/include/stdlib_detail/enable_if.hpp"
17#include "stdlib/include/stdlib_detail/forward.hpp"
18#include "stdlib/include/stdlib_detail/is_integral.hpp"
19
20namespace std {
21
22/// @brief Function object for performing subtraction.
23/// @tparam T The type of the values
24/// @note This class contains the member types @c result_type, @c first_argument type, and @c second_argument type.
25/// These aliases have been deprecated in C++17 and removed in C++20.
26template <class T = void>
27class minus {
28 public:
29 /// @brief Result type of invoking this object
30 using result_type = T;
31 /// @brief Type of the first value to subtract
32 using first_argument_type = T;
33 /// @brief Type of the second value to subtract
34 using second_argument_type = T;
35
36 /// @brief Returns the first value minus the second value
37 /// @tparam U Template parameter to enable constraints.
38 /// @param lhs The first value to subtract
39 /// @param rhs The second value to subtract
40 /// @return Returns the result of invoking @c operator- on @c lhs and @c rhs
41 template <class U = T, arene::base::constraints<std::enable_if_t<!is_integral_v<U>>> = nullptr>
42 constexpr auto operator()(T const& lhs, T const& rhs) const
43 noexcept(noexcept(std::declval<T&>() - std::declval<T&>())) -> T {
44 return lhs - rhs;
45 }
46
47 /// @brief Returns the first value minus the second value
48 /// @tparam U Template parameter to enable constraints.
49 /// @param lhs The first value to subtract
50 /// @param rhs The second value to subtract
51 /// @return Returns the result of invoking @c operator- on @c lhs and @c rhs
52 ///
53 /// @note This overload explicitly casts the result of the computation to the type @c T. This avoids any warning for
54 /// implicit conversion (present on gcc8).
55 template <class U = T, arene::base::constraints<std::enable_if_t<is_integral_v<U>>> = nullptr>
56 constexpr auto operator()(T const& lhs, T const& rhs) const
57 noexcept(noexcept(std::declval<T&>() - std::declval<T&>())) -> T {
58 return static_cast<T>(lhs - rhs);
59 }
60};
61
62/// @brief Function object that can be invoked for subtraction, specialized for type deduction
63template <>
64class minus<void> {
65 public:
66 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False positive: 'is_transparent' does not hide an identifier in 'minus'"
67 /// @brief Denotes that this is a transparent function object type
68 using is_transparent = void;
69 // parasoft-end-suppress AUTOSAR-A2_10_1-e
70
71 // parasoft-begin-suppress AUTOSAR-M5_0_4-a "Function return type is specified by the C++ Standard"
72 /// @brief Returns the first value minus the second value
73 /// @tparam T The first type
74 /// @tparam U The second type
75 /// @param lhs The first value to subtract
76 /// @param rhs The second value to subtract
77 /// @return Returns the result of invoking @c operator- on @c lhs and @c rhs
78 template <class T, class U>
79 constexpr auto operator()(T&& lhs, U&& rhs) const
80 noexcept(noexcept(std::forward<T>(std::declval<T&>()) - std::forward<U>(std::declval<U&>())))
81 -> decltype(std::forward<T>(lhs) - std::forward<U>(rhs)) {
82 return std::forward<T>(lhs) - std::forward<U>(rhs);
83 }
84 // parasoft-end-suppress AUTOSAR-M5_0_4-a
85};
86
87} // namespace std
88
89#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_MINUS_HPP_
constexpr auto operator()(T &&lhs, U &&rhs) const noexcept(noexcept(std::forward< T >(std::declval< T & >()) - std::forward< U >(std::declval< U & >()))) ->
Returns the first value minus the second value.
Definition minus.hpp:79
Function object for performing subtraction.
Definition minus.hpp:27
constexpr auto operator()(::arene::base::result< void, E > const &value) const noexcept(noexcept(hash< E >{}(std::declval< E const & >()))) -> std::size_t
Calculate the hash of a result.
Definition result.hpp:1827