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 // <memory> 10 11 // shared_ptr 12 13 // template <class T, class D> 14 // bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept; 15 // template <class T, class D> 16 // bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept; 17 // template <class T, class D> 18 // bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept; 19 // template <class T, class D> 20 // bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept; 21 // template <class T, class D> 22 // bool operator<(const unique_ptr<T, D>& x, nullptr_t); 23 // template <class T, class D> 24 // bool operator<(nullptr_t, const unique_ptr<T, D>& y); 25 // template <class T, class D> 26 // bool operator<=(const unique_ptr<T, D>& x, nullptr_t); 27 // template <class T, class D> 28 // bool operator<=(nullptr_t, const unique_ptr<T, D>& y); 29 // template <class T, class D> 30 // bool operator>(const unique_ptr<T, D>& x, nullptr_t); 31 // template <class T, class D> 32 // bool operator>(nullptr_t, const unique_ptr<T, D>& y); 33 // template <class T, class D> 34 // bool operator>=(const unique_ptr<T, D>& x, nullptr_t); 35 // template <class T, class D> 36 // bool operator>=(nullptr_t, const unique_ptr<T, D>& y); 37 // template<class T, class D> 38 // requires three_way_comparable<typename unique_ptr<T, D>::pointer> 39 // constexpr compare_three_way_result_t<typename unique_ptr<T, D>::pointer> 40 // operator<=>(const unique_ptr<T, D>& x, nullptr_t); // C++20 41 42 #include <memory> 43 #include <cassert> 44 45 #include "test_macros.h" 46 #include "test_comparisons.h" 47 48 int main(int, char**) 49 { 50 AssertEqualityAreNoexcept<std::unique_ptr<int>, nullptr_t>(); 51 AssertEqualityAreNoexcept<nullptr_t, std::unique_ptr<int> >(); 52 AssertComparisonsReturnBool<std::unique_ptr<int>, nullptr_t>(); 53 AssertComparisonsReturnBool<nullptr_t, std::unique_ptr<int> >(); 54 #if TEST_STD_VER > 17 55 AssertOrderReturn<std::strong_ordering, std::unique_ptr<int>, nullptr_t>(); 56 AssertOrderReturn<std::strong_ordering, nullptr_t, std::unique_ptr<int>>(); 57 #endif 58 59 const std::unique_ptr<int> p1(new int(1)); 60 assert(!(p1 == nullptr)); 61 assert(!(nullptr == p1)); 62 assert(!(p1 < nullptr)); 63 assert((nullptr < p1)); 64 assert(!(p1 <= nullptr)); 65 assert((nullptr <= p1)); 66 assert((p1 > nullptr)); 67 assert(!(nullptr > p1)); 68 assert((p1 >= nullptr)); 69 assert(!(nullptr >= p1)); 70 #if TEST_STD_VER > 17 71 assert((nullptr <=> p1) == std::strong_ordering::less); 72 assert((p1 <=> nullptr) == std::strong_ordering::greater); 73 #endif 74 75 const std::unique_ptr<int> p2; 76 assert((p2 == nullptr)); 77 assert((nullptr == p2)); 78 assert(!(p2 < nullptr)); 79 assert(!(nullptr < p2)); 80 assert((p2 <= nullptr)); 81 assert((nullptr <= p2)); 82 assert(!(p2 > nullptr)); 83 assert(!(nullptr > p2)); 84 assert((p2 >= nullptr)); 85 assert((nullptr >= p2)); 86 #if TEST_STD_VER > 17 87 assert((nullptr <=> p2) == std::strong_ordering::equivalent); 88 #endif 89 90 return 0; 91 } 92