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 // unique_ptr
12
13 // template <class T1, class D1, class T2, class D2>
14 // bool
15 // operator< (const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
16
17 // template <class T1, class D1, class T2, class D2>
18 // bool
19 // operator> (const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
20
21 // template <class T1, class D1, class T2, class D2>
22 // bool
23 // operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
24
25 // template <class T1, class D1, class T2, class D2>
26 // bool
27 // operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
28
29 #include <memory>
30 #include <cassert>
31
32 #include "test_macros.h"
33 #include "deleter_types.h"
34
35 struct A
36 {
37 static int count;
AA38 A() {++count;}
AA39 A(const A&) {++count;}
~AA40 virtual ~A() {--count;}
41 };
42
43 int A::count = 0;
44
45 struct B
46 : public A
47 {
48 static int count;
BB49 B() {++count;}
BB50 B(const B& other) : A(other) {++count;}
~BB51 virtual ~B() {--count;}
52 };
53
54 int B::count = 0;
55
main(int,char **)56 int main(int, char**)
57 {
58 {
59 const std::unique_ptr<A, Deleter<A> > p1(new A);
60 const std::unique_ptr<A, Deleter<A> > p2(new A);
61 assert((p1 < p2) == !(p1 > p2));
62 assert((p1 < p2) == (p1 <= p2));
63 assert((p1 < p2) == !(p1 >= p2));
64 }
65 {
66 const std::unique_ptr<A, Deleter<A> > p1(new A);
67 const std::unique_ptr<B, Deleter<B> > p2(new B);
68 assert((p1 < p2) == !(p1 > p2));
69 assert((p1 < p2) == (p1 <= p2));
70 assert((p1 < p2) == !(p1 >= p2));
71 }
72 {
73 const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]);
74 const std::unique_ptr<A[], Deleter<A[]> > p2(new A[3]);
75 assert((p1 < p2) == !(p1 > p2));
76 assert((p1 < p2) == (p1 <= p2));
77 assert((p1 < p2) == !(p1 >= p2));
78 }
79 {
80 const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]);
81 const std::unique_ptr<B[], Deleter<B[]> > p2(new B[3]);
82 assert((p1 < p2) == !(p1 > p2));
83 assert((p1 < p2) == (p1 <= p2));
84 assert((p1 < p2) == !(p1 >= p2));
85 }
86 {
87 const std::unique_ptr<A, Deleter<A> > p1;
88 const std::unique_ptr<A, Deleter<A> > p2;
89 assert((p1 < p2) == (p1 > p2));
90 assert((p1 < p2) == !(p1 <= p2));
91 assert((p1 < p2) == !(p1 >= p2));
92 }
93 {
94 const std::unique_ptr<A, Deleter<A> > p1;
95 const std::unique_ptr<B, Deleter<B> > p2;
96 assert((p1 < p2) == (p1 > p2));
97 assert((p1 < p2) == !(p1 <= p2));
98 assert((p1 < p2) == !(p1 >= p2));
99 }
100
101 return 0;
102 }
103