Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
logical_and.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_LOGICAL_AND_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_LOGICAL_AND_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/compiler_support/diagnostics.hpp"
15#include "stdlib/include/stdlib_detail/declval.hpp"
16#include "stdlib/include/stdlib_detail/forward.hpp"
17
18namespace std {
19
20/// @brief Function object for performing logical AND (logical conjunction). Effectively calls @c operator&& on type @c
21/// T.
22/// @tparam T The type of the values.
23/// @note This class contains the member types @c result_type, @c first_argument type, and @c second_argument type.
24/// These aliases have been deprecated in C++17 and removed in C++20.
25template <class T = void>
27 public:
28 /// @brief Result type of invoking this object (deprecated in C++17)(removed in C++20)
29 using result_type = bool;
30 /// @brief Type of the first value to logically AND (deprecated in C++17)(removed in C++20)
31 using first_argument_type = T;
32 /// @brief Type of the second value to logically AND (deprecated in C++17)(removed in C++20)
33 using second_argument_type = T;
34
36 ARENE_IGNORE_ARMCLANG("-Wnull-conversion", "The standard expects the conversions here");
37 /// @brief Returns the logical AND of @c lhs and @c rhs.
38 /// @tparam U Template parameter to enable constraints.
39 /// @param lhs The first value to compute logical AND of
40 /// @param rhs The second value to compute logical AND of
41 /// @return Returns the result of invoking <c>lhs && rhs</c>.
42 constexpr auto operator()(T const& lhs, T const& rhs) const
43 noexcept(noexcept(std::declval<T const&>() && std::declval<T const&>())) -> bool {
44 // parasoft-begin-suppress AUTOSAR-M5_3_1-a "False positive: operator&& accepts non-bool types in std::logical_and"
45 return lhs && rhs;
46 // parasoft-end-suppress AUTOSAR-M5_3_1-a
47 }
49};
50
51/// @brief Function object for performing logical AND (logical conjunction), specialized for deduction of parameter and
52/// return type.
53template <>
54class logical_and<void> {
55 public:
56 /// @brief Denotes that this is a transparent function object type
57 using is_transparent = void;
58
60 ARENE_IGNORE_ARMCLANG("-Wnull-conversion", "The standard expects the conversions here");
61 // parasoft-begin-suppress AUTOSAR-M5_0_4-a "Function return type is specified by the C++ Standard"
62 /// @brief Returns the logical AND of @c lhs and @c rhs.
63 /// @tparam T The type of @c lhs
64 /// @tparam U The type of @c rhs
65 /// @param lhs The first value to compute logical AND of
66 /// @param rhs The second value to compute logical AND of
67 /// @return Returns the result of invoking <c>lhs && rhs</c>.
68 template <class T, class U>
69 constexpr auto operator()(T&& lhs, U&& rhs) const
70 noexcept(noexcept(std::forward<T>(std::declval<T&&>()) && std::forward<U>(std::declval<U&&>())))
71 -> decltype(std::forward<T>(lhs) && std::forward<U>(rhs)) {
72 // parasoft-begin-suppress AUTOSAR-M5_3_1-a "False positive: operator&& accepts non-bool types in std::logical_and"
73 return std::forward<T>(lhs) && std::forward<U>(rhs);
74 // parasoft-end-suppress AUTOSAR-M5_3_1-a
75 }
76 // parasoft-end-suppress AUTOSAR-M5_0_4-a
78};
79
80} // namespace std
81
82#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_LOGICAL_AND_HPP_
ARENE_IGNORE_ARMCLANG("-Wnull-conversion", "The standard expects the conversions here")
constexpr auto operator()(T &&lhs, U &&rhs) const noexcept(noexcept(std::forward< T >(std::declval< T && >()) &&std::forward< U >(std::declval< U && >()))) ->
Returns the logical AND of lhs and rhs.
Definition logical_and.hpp:69
Function object for performing logical AND (logical conjunction). Effectively calls operator&& on typ...
Definition logical_and.hpp:26
constexpr auto operator()(T const &lhs, T const &rhs) const noexcept(noexcept(std::declval< T const & >() &&std::declval< T const & >())) -> bool
Returns the logical AND of lhs and rhs.
Definition logical_and.hpp:42
ARENE_IGNORE_ARMCLANG("-Wnull-conversion", "The standard expects the conversions here")
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