| 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 | |
| 17 | static_assert(std::predicate<bool()>); |
| 18 | static_assert(std::predicate<bool (*)()>); |
| 19 | static_assert(std::predicate<bool (&)()>); |
| 20 | |
| 21 | static_assert(!std::predicate<void()>); |
| 22 | static_assert(!std::predicate<void (*)()>); |
| 23 | static_assert(!std::predicate<void (&)()>); |
| 24 | |
| 25 | struct S {}; |
| 26 | |
| 27 | static_assert(!std::predicate<S(int), int>); |
| 28 | static_assert(!std::predicate<S(double), double>); |
| 29 | static_assert(std::predicate<int S::*, S*>); |
| 30 | static_assert(std::predicate<int (S::*)(), S*>); |
| 31 | static_assert(std::predicate<int (S::*)(), S&>); |
| 32 | static_assert(!std::predicate<void (S::*)(), S*>); |
| 33 | static_assert(!std::predicate<void (S::*)(), S&>); |
| 34 | |
| 35 | static_assert(!std::predicate<bool(S)>); |
| 36 | static_assert(!std::predicate<bool(S&), S>); |
| 37 | static_assert(!std::predicate<bool(S&), S const&>); |
| 38 | static_assert(std::predicate<bool(S&), S&>); |
| 39 | |
| 40 | struct Predicate { |
| 41 | bool operator()(int, double, char); |
| 42 | }; |
| 43 | static_assert(std::predicate<Predicate, int, double, char>); |
| 44 | static_assert(std::predicate<Predicate&, int, double, char>); |
| 45 | static_assert(!std::predicate<const Predicate, int, double, char>); |
| 46 | static_assert(!std::predicate<const Predicate&, int, double, char>); |
| 47 | |
| 48 | constexpr bool check_lambda(auto) { return false; } |
| 49 | |
| 50 | constexpr bool check_lambda(std::predicate auto) { return true; } |
| 51 | |
| 52 | static_assert(check_lambda([] { return std::true_type(); })); |
| 53 | static_assert(check_lambda([]() -> int* { return nullptr; })); |
| 54 | |
| 55 | struct boolean { |
| 56 | operator bool() const noexcept; |
| 57 | }; |
| 58 | static_assert(check_lambda([] { return boolean(); })); |
| 59 | |
| 60 | struct explicit_bool { |
| 61 | explicit operator bool() const noexcept; |
| 62 | }; |
| 63 | static_assert(!check_lambda([] { return explicit_bool(); })); |
| 64 | |