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