Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
is_predicate.hpp
Go to the documentation of this file.
1// parasoft-begin-suppress AUTOSAR-A2_8_1-a "False positive: also defines arene::base::type_traits::is_predicate"
2
3// Copyright 2026, Toyota Motor Corporation
4//
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
7#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_TRAITS_IS_PREDICATE_HPP_
8#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_TRAITS_IS_PREDICATE_HPP_
9
10// IWYU pragma: private, include "arene/base/type_traits.hpp"
11// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
12
13#include "arene/base/stdlib_choice/declval.hpp"
14#include "arene/base/stdlib_choice/enable_if.hpp"
15#include "arene/base/stdlib_choice/integral_constant.hpp"
16#include "arene/base/stdlib_choice/is_convertible.hpp"
17#include "arene/base/type_list/type_list.hpp"
18#include "arene/base/type_traits/is_invocable.hpp"
19
20namespace arene {
21namespace base {
22namespace is_predicate_detail {
23
24/// @brief implementation trait for @c is_predicate
25/// @tparam F the possible predicate
26/// @tparam Args argument types
27///
28/// Primary template which is always @c false_type.
29///
30template <class F, class Args, class = void>
31class is_predicate_impl : public std::false_type {};
32
33/// @brief implementation trait for @c is_predicate
34/// @tparam F the possible predicate
35/// @tparam Args argument types
36///
37/// Template specialization selected if @c F is invocable with @c Args ... and
38/// the result is convertible to @c bool.
39///
40template <class F, class... Args>
41class is_predicate_impl<
42 F,
43 type_list<Args...>,
44 std::enable_if_t< //
45 is_invocable_v<F, Args...> && //
46 std::is_convertible<invoke_result_t<F, Args...>, bool>::value && //
47 std::is_convertible<decltype(!std::declval<invoke_result_t<F, Args...>>()), bool>::value>>
48 : public std::true_type {};
49
50} // namespace is_predicate_detail
51
52/// @brief backport for the C++20 predicate concept
53/// @tparam F the possible predicate
54/// @tparam Args the argument types that the predicate is invoked with
55///
56/// The concept @c predicate<F, Args...> specifies that @c F is a predicate that
57/// accepts arguments whose types and value categories are encoded by Args...,
58/// i.e., it can be invoked with these arguments to produce a boolean-testable
59/// result.
60///
61/// @{
62template <class F, class... Args>
64/// @}
65
66} // namespace base
67} // namespace arene
68#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_TRAITS_IS_PREDICATE_HPP_
Definition array_exceptions_disabled.cpp:11
constexpr bool is_predicate_v
backport for the C++20 predicate concept
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10