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