Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
negate.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_NEGATE_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_NEGATE_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
20
namespace
std
{
21
22
/// @brief Function object for performing negation.
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.
26
template
<
class
T =
void
>
27
class
negate
{
28
public
:
29
/// @brief Result type of invoking this object
30
using
result_type = T;
31
/// @brief Type of the value to negate
32
using
argument_type = T;
33
34
/// @brief Returns the negation of the value
35
/// @tparam U Template parameter to enable constraints.
36
/// @param value The value to negate
37
/// @return Returns the result of invoking @c operator- on @c value
38
template
<
class
U
=
T
,
arene
::
base
::
constraints
<
std
::
enable_if_t
<!
is_integral_v
<
U
>>> =
nullptr
>
39
constexpr
auto
operator
()(
T
const
&
value
)
const
noexcept
(
noexcept
(-
std
::
declval
<
T
>())) ->
T
{
40
return
-
value
;
41
}
42
43
/// @brief Returns the negation of the value
44
/// @tparam U Template parameter to enable constraints.
45
/// @param value The value to negate
46
/// @return Returns the result of invoking @c operator- on @c value
47
///
48
/// @note This overload explicitly casts the result of the computation to the type @c T. This avoids any warning for
49
/// implicit conversion (present on gcc8).
50
template
<
class
U
=
T
,
arene
::
base
::
constraints
<
std
::
enable_if_t
<
is_integral_v
<
U
>>> =
nullptr
>
51
constexpr
auto
operator
()(
T
const
&
value
)
const
noexcept
(
noexcept
(-
std
::
declval
<
T
>())) ->
T
{
52
return
static_cast
<
T
>(-
value
);
53
}
54
};
55
56
/// @brief Function object that can be invoked for negate, specialized for type deduction
57
template
<>
58
class
negate
<
void
> {
59
public
:
60
/// @brief Denotes that this is a transparent function object type
61
using
is_transparent =
void
;
62
63
// parasoft-begin-suppress AUTOSAR-M5_0_4-a "Function return type is specified by the C++ Standard"
64
/// @brief Returns the negation of the value
65
/// @tparam T The value type
66
/// @param value The value to negate
67
/// @return Returns the result of invoking @c operator- on @c value
68
template
<
class
T>
69
constexpr
auto
operator
()(T&& value)
const
noexcept
(
noexcept
(-
std
::
forward
<
T
>(
std
::
declval
<
T
>())))
70
->
decltype
(-
std
::
forward
<
T
>(
value
)) {
71
return
-std::forward<T>(value);
72
}
73
// parasoft-end-suppress AUTOSAR-M5_0_4-a
74
};
75
76
}
// namespace std
77
78
#
endif
// INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_NEGATE_HPP_
std::negate< void >::operator()
constexpr auto operator()(T &&value) const noexcept(noexcept(-std::forward< T >(std::declval< T >()))) ->
Returns the negation of the value.
Definition
negate.hpp:69
std::negate
Function object for performing negation.
Definition
negate.hpp:27
std::hash<::arene::base::result< void, E > >::operator()
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
stdlib
include
stdlib_detail
negate.hpp
Generated by
1.13.2