xref: /llvm-project/libcxx/test/std/utilities/function.objects/range.cmp/equal_to.pass.cpp (revision a224bf8ec423b42eea251407e7a6cc8398a5edf4)
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::equal_to
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 NotEqualityComparable {
27   friend bool operator==(const NotEqualityComparable&, const NotEqualityComparable&);
28   friend bool operator!=(const NotEqualityComparable&, const NotEqualityComparable&) = delete;
29 };
30 
31 static_assert(!std::is_invocable_v<std::ranges::equal_to, NotEqualityComparable, NotEqualityComparable>);
32 static_assert(!std::is_invocable_v<std::ranges::equal_to, int, MoveOnly>);
33 static_assert(std::is_invocable_v<std::ranges::equal_to, explicit_operators, explicit_operators>);
34 
35 static_assert(requires { typename std::ranges::equal_to::is_transparent; });
36 
37 constexpr bool test() {
38   auto fn = std::ranges::equal_to();
39 
40   assert(fn(MoveOnly(42), MoveOnly(42)));
41 
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, 1));
49   assert(fn(2, 2));
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 equal_to<int*> and equal_to<void>.
62   do_pointer_comparison_test(std::ranges::equal_to());
63 
64   return 0;
65 }
66