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::not_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::not_equal_to::is_transparent; }); 34 35 struct PtrAndNotEqOperator { 36 constexpr operator void*() const { return nullptr; } 37 // We *don't* want operator!= to be picked here. 38 friend constexpr bool operator!=(PtrAndNotEqOperator, PtrAndNotEqOperator) { return true; } 39 }; 40 41 constexpr bool test() { 42 auto fn = std::ranges::not_equal_to(); 43 44 assert(fn(MoveOnly(41), MoveOnly(42))); 45 46 // These are the opposite of other tests. 47 ForwardingTestObject a; 48 ForwardingTestObject b; 49 assert(fn(a, b)); 50 assert(!fn(std::move(a), std::move(b))); 51 52 assert(fn(1, 2)); 53 assert(!fn(2, 2)); 54 assert(fn(2, 1)); 55 56 assert(fn(2, 1L)); 57 58 // Make sure that "ranges::equal_to(x, y) == !ranges::not_equal_to(x, y)", even here. 59 assert(!fn(PtrAndNotEqOperator(), PtrAndNotEqOperator())); 60 assert(std::ranges::equal_to()(PtrAndNotEqOperator(), PtrAndNotEqOperator())); 61 62 return true; 63 } 64 65 int main(int, char**) { 66 67 test(); 68 static_assert(test()); 69 70 // test total ordering of int* for not_equal_to<int*> and not_equal_to<void>. 71 do_pointer_comparison_test(std::ranges::not_equal_to()); 72 73 return 0; 74 } 75