Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
plus.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_PLUS_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_PLUS_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
19
20namespace std {
21
22/// @brief Function object for performing addition.
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 plus {
28 public:
29 /// @brief Result type of invoking this object
30 using result_type = T;
31 /// @brief Type of the first value to add
33 /// @brief Type of the second value to add
35
36 /// @brief Returns the first value plus the second value
37 /// @tparam U Template parameter to enable constraints.
38 /// @param lhs The first value to add
39 /// @param rhs The second value to add
40 /// Produces 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 plus the second value
48 /// @tparam U Template parameter to enable constraints.
49 /// @param lhs The first value to add
50 /// @param rhs The second value to add
51 /// Produces 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 noexcept(noexcept(std::declval<T>() + std::declval<T&>()))
57 -> T {
58 return static_cast<T>(lhs + rhs);
59 }
60};
61
62/// @brief Function object that can be invoked for addition, specialized for type deduction
63template <>
64class plus<void> {
65 public:
66 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False positive: 'is_transparent' does not hide an identifier in 'plus'"
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 plus the second value
73 /// @tparam T The first type
74 /// @tparam U The second type
75 /// @param lhs The first value to add
76 /// @param rhs The second value to add
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
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_PLUS_HPP_
void is_transparent
Denotes that this is a transparent function object type.
Definition plus.hpp:68
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 plus the second value.
Definition plus.hpp:79
Function object for performing addition.
Definition plus.hpp:27
constexpr auto operator()(T const &lhs, T const &rhs) const noexcept(noexcept(std::declval< T >()+std::declval< T & >())) -> T
Returns the first value plus the second value.
Definition plus.hpp:56
T result_type
Result type of invoking this object.
Definition plus.hpp:30
T first_argument_type
Type of the first value to add.
Definition plus.hpp:32
T second_argument_type
Type of the second value to add.
Definition plus.hpp:34
constexpr auto operator()(T const &lhs, T const &rhs) const noexcept(noexcept(std::declval< T & >()+std::declval< T & >())) -> T
Returns the first value plus the second value.
Definition plus.hpp:42
Public export header for the constraints subpackage.
STL namespace.
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...
constexpr auto forward(remove_reference_t< T > &value) noexcept -> T &&
Cast a value to an rvalue if T is an rvalue or rvalue reference, otherwise forward an lvalue referenc...
Definition forward.hpp:24