1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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);
29 #include "test_macros.h"
30 #include "test_comparisons.h"
32 void do_nothing(int*) {}
34 int main(int, char**) {
35 AssertComparisonsAreNoexcept
<std::shared_ptr
<int> >();
36 AssertComparisonsReturnBool
<std::shared_ptr
<int> >();
38 AssertOrderAreNoexcept
<std::shared_ptr
<int>>();
39 AssertOrderReturn
<std::strong_ordering
, std::shared_ptr
<int>>();
44 const std::shared_ptr
<int> p1(ptr1
);
45 const std::shared_ptr
<int> p2(ptr2
);
49 assert((p1
< p2
) == (ptr1
< ptr2
));
50 assert((p1
<= p2
) == (ptr1
<= ptr2
));
51 assert((p1
> p2
) == (ptr1
> ptr2
));
52 assert((p1
>= p2
) == (ptr1
>= ptr2
));
54 assert((p1
<=> p2
) != std::strong_ordering::equal
);
55 assert((p1
<=> p2
) == (ptr1
<=> ptr2
));
58 // The deleter does not influence the comparisons
59 // of the `shared_ptr`
60 const std::shared_ptr
<int> p3(ptr2
, do_nothing
);
65 assert((p1
< p3
) == (ptr1
< ptr2
));
66 assert((p1
<= p3
) == (ptr1
<= ptr2
));
67 assert((p1
> p3
) == (ptr1
> ptr2
));
68 assert((p1
>= p3
) == (ptr1
>= ptr2
));
70 assert((p2
<=> p3
) == std::strong_ordering::equal
);
71 assert((p1
<=> p3
) != std::strong_ordering::equal
);
72 assert((p1
<=> p3
) == (ptr1
<=> ptr2
));