| 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 U> bool operator==(const shared_ptr<T>& a, const shared_ptr<U>& b); |
| 14 |
// template<class T, class U> bool operator!=(const shared_ptr<T>& a, const shared_ptr<U>& b); |
| 15 |
// template<class T, class U> bool operator< (const shared_ptr<T>& a, const shared_ptr<U>& b); |
| 16 |
// template<class T, class U> bool operator<=(const shared_ptr<T>& a, const shared_ptr<U>& b); |
| 17 |
// template<class T, class U> bool operator> (const shared_ptr<T>& a, const shared_ptr<U>& b); |
| 18 |
// template<class T, class U> bool operator>=(const shared_ptr<T>& a, const shared_ptr<U>& b); |
| 19 |
// template<class T1, class D1, class T2, class D2> |
| 20 |
// requires three_way_comparable_with<typename unique_ptr<T1, D1>::pointer, |
| 21 |
// typename unique_ptr<T2, D2>::pointer> |
| 22 |
// compare_three_way_result_t<typename unique_ptr<T1, D1>::pointer, |
| 23 |
// typename unique_ptr<T2, D2>::pointer> |
| 24 |
// operator<=>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); |
| 25 |
|
| 26 |
#include <memory> |
| 27 |
#include <cassert> |
| 28 |
|
| 29 |
#include "test_macros.h" |
| 30 |
#include "test_comparisons.h" |
| 31 |
|
| 32 |
void do_nothing(int*) {} |
| 33 |
|
| 34 |
int main(int, char**) { |
| 35 |
AssertComparisonsAreNoexcept<std::shared_ptr<int> >(); |
| 36 |
AssertComparisonsReturnBool<std::shared_ptr<int> >(); |
| 37 |
#if TEST_STD_VER > 17 |
| 38 |
AssertOrderAreNoexcept<std::shared_ptr<int>>(); |
| 39 |
AssertOrderReturn<std::strong_ordering, std::shared_ptr<int>>(); |
| 40 |
#endif |
| 41 |
|
| 42 |
int* ptr1(new int); |
| 43 |
int* ptr2(new int); |
| 44 |
const std::shared_ptr<int> p1(ptr1); |
| 45 |
const std::shared_ptr<int> p2(ptr2); |
| 46 |
|
| 47 |
assert(!(p1 == p2)); |
| 48 |
assert(p1 != p2); |
| 49 |
assert((p1 < p2) == (ptr1 < ptr2)); |
| 50 |
assert((p1 <= p2) == (ptr1 <= ptr2)); |
| 51 |
assert((p1 > p2) == (ptr1 > ptr2)); |
| 52 |
assert((p1 >= p2) == (ptr1 >= ptr2)); |
| 53 |
#if TEST_STD_VER > 17 |
| 54 |
assert((p1 <=> p2) != std::strong_ordering::equal); |
| 55 |
assert((p1 <=> p2) == (ptr1 <=> ptr2)); |
| 56 |
#endif |
| 57 |
|
| 58 |
// The deleter does not influence the comparisons |
| 59 |
// of the `shared_ptr` |
| 60 |
const std::shared_ptr<int> p3(ptr2, do_nothing); |
| 61 |
assert(p2 == p3); |
| 62 |
assert(!(p1 == p3)); |
| 63 |
assert(!(p2 != p3)); |
| 64 |
assert(p1 != p3); |
| 65 |
assert((p1 < p3) == (ptr1 < ptr2)); |
| 66 |
assert((p1 <= p3) == (ptr1 <= ptr2)); |
| 67 |
assert((p1 > p3) == (ptr1 > ptr2)); |
| 68 |
assert((p1 >= p3) == (ptr1 >= ptr2)); |
| 69 |
#if TEST_STD_VER > 17 |
| 70 |
assert((p2 <=> p3) == std::strong_ordering::equal); |
| 71 |
assert((p1 <=> p3) != std::strong_ordering::equal); |
| 72 |
assert((p1 <=> p3) == (ptr1 <=> ptr2)); |
| 73 |
#endif |
| 74 |
|
| 75 |
return 0; |
| 76 |
} |