xref: /llvm-project/libcxx/test/std/utilities/function.objects/range.cmp/equal_to.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::equal_to
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 NotEqualityComparable {
25   friend bool operator==(const NotEqualityComparable&, const NotEqualityComparable&);
26   friend bool operator!=(const NotEqualityComparable&, const NotEqualityComparable&) = delete;
27 };
28 
29 static_assert(!std::is_invocable_v<std::ranges::equal_to, NotEqualityComparable, NotEqualityComparable>);
30 static_assert(!std::is_invocable_v<std::ranges::equal_to, int, MoveOnly>);
31 static_assert(std::is_invocable_v<std::ranges::equal_to, explicit_operators, explicit_operators>);
32 
33 static_assert(requires { typename std::ranges::equal_to::is_transparent; });
34 
35 constexpr bool test() {
36   auto fn = std::ranges::equal_to();
37 
38   assert(fn(MoveOnly(42), MoveOnly(42)));
39 
40   ForwardingTestObject a;
41   ForwardingTestObject b;
42   assert(!fn(a, b));
43   assert(fn(std::move(a), std::move(b)));
44 
45   assert(!fn(1, 2));
46   assert(!fn(2, 1));
47   assert(fn(2, 2));
48 
49   assert(!fn(2, 1L));
50 
51   return true;
52 }
53 
54 int main(int, char**) {
55 
56   test();
57   static_assert(test());
58 
59   // test total ordering of int* for equal_to<int*> and equal_to<void>.
60   do_pointer_comparison_test(std::ranges::equal_to());
61 
62   return 0;
63 }
64