1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03, c++11, c++14, c++17
10
11// template<class F, class... Args>
12// concept predicate;
13
14#include <concepts>
15#include <type_traits>
16
17static_assert(std::predicate<bool()>);
18static_assert(std::predicate<bool (*)()>);
19static_assert(std::predicate<bool (&)()>);
20
21static_assert(!std::predicate<void()>);
22static_assert(!std::predicate<void (*)()>);
23static_assert(!std::predicate<void (&)()>);
24
25struct S {};
26
27static_assert(!std::predicate<S(int), int>);
28static_assert(!std::predicate<S(double), double>);
29static_assert(std::predicate<int S::*, S*>);
30static_assert(std::predicate<int (S::*)(), S*>);
31static_assert(std::predicate<int (S::*)(), S&>);
32static_assert(!std::predicate<void (S::*)(), S*>);
33static_assert(!std::predicate<void (S::*)(), S&>);
34
35static_assert(!std::predicate<bool(S)>);
36static_assert(!std::predicate<bool(S&), S>);
37static_assert(!std::predicate<bool(S&), S const&>);
38static_assert(std::predicate<bool(S&), S&>);
39
40struct Predicate {
41 bool operator()(int, double, char);
42};
43static_assert(std::predicate<Predicate, int, double, char>);
44static_assert(std::predicate<Predicate&, int, double, char>);
45static_assert(!std::predicate<const Predicate, int, double, char>);
46static_assert(!std::predicate<const Predicate&, int, double, char>);
47
48constexpr bool check_lambda(auto) { return false; }
49
50constexpr bool check_lambda(std::predicate auto) { return true; }
51
52static_assert(check_lambda([] { return std::true_type(); }));
53static_assert(check_lambda([]() -> int* { return nullptr; }));
54
55struct boolean {
56 operator bool() const noexcept;
57};
58static_assert(check_lambda([] { return boolean(); }));
59
60struct explicit_bool {
61 explicit operator bool() const noexcept;
62};
63static_assert(!check_lambda([] { return explicit_bool(); }));
64

source code of libcxx/test/std/concepts/concepts.callable/concept.predicate/predicate.compile.pass.cpp