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