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 // XFAIL: msvc && clang 12 13 // <functional> 14 15 // ranges::less_equal 16 17 #include <functional> 18 #include <type_traits> 19 #include <cassert> 20 21 #include "test_macros.h" 22 #include "compare_types.h" 23 #include "MoveOnly.h" 24 #include "pointer_comparison_test_helper.h" 25 26 struct NotTotallyOrdered { 27 friend bool operator<(const NotTotallyOrdered&, const NotTotallyOrdered&); 28 }; 29 30 static_assert(!std::is_invocable_v<std::ranges::less_equal, NotTotallyOrdered, NotTotallyOrdered>); 31 static_assert(!std::is_invocable_v<std::ranges::less_equal, int, MoveOnly>); 32 static_assert(std::is_invocable_v<std::ranges::less_equal, explicit_operators, explicit_operators>); 33 34 static_assert(requires { typename std::ranges::less_equal::is_transparent; }); 35 36 constexpr bool test() { 37 auto fn = std::ranges::less_equal(); 38 39 assert(fn(MoveOnly(41), MoveOnly(42))); 40 41 // These are the opposite of other tests. 42 ForwardingTestObject a; 43 ForwardingTestObject b; 44 assert(fn(a, b)); 45 assert(!fn(std::move(a), std::move(b))); 46 47 assert(fn(1, 2)); 48 assert(fn(2, 2)); 49 assert(!fn(2, 1)); 50 51 assert(!fn(2, 1L)); 52 53 return true; 54 } 55 56 int main(int, char**) { 57 58 test(); 59 static_assert(test()); 60 61 // test total ordering of int* for less_equal<int*> and less_equal<void>. 62 do_pointer_comparison_test(std::ranges::less_equal()); 63 64 return 0; 65 } 66