]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/unique_ptr/comparison/compare.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / unique_ptr / comparison / compare.cc
1 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-do run { target c++11 } }
19
20 #include <memory>
21 #include <testsuite_hooks.h>
22
23 void
24 test01()
25 {
26 std::unique_ptr<int> p0, p00;
27 VERIFY( p0 == p00 );
28 VERIFY( !(p0 < p00) );
29 VERIFY( !(p0 > p00) );
30 VERIFY( p0 <= p00 );
31 VERIFY( p0 >= p00 );
32
33 std::unique_ptr<int> p1(new int(1));
34 VERIFY( p1 == p1 );
35 VERIFY( !(p1 < p1) );
36 VERIFY( !(p1 > p1) );
37 VERIFY( p1 <= p1 );
38 VERIFY( p1 >= p1 );
39
40 std::unique_ptr<const int> p2(new int(1));
41 VERIFY( p1 >= p1 );
42 VERIFY( p1 != p2 );
43 VERIFY( (p1 < p2) || (p1 > p2) );
44 VERIFY( (p1 <= p2) || (p1 >= p2) );
45
46 VERIFY( p1 != p0 );
47 VERIFY( !(p1 < p0) );
48 VERIFY( p1 > p0 );
49 VERIFY( !(p1 <= p0) );
50 VERIFY( p1 >= p0 );
51 }
52
53 void
54 test02()
55 {
56 std::unique_ptr<int> p0;
57 VERIFY( p0 == nullptr );
58 VERIFY( !(p0 < nullptr) );
59 VERIFY( !(p0 > nullptr) );
60 VERIFY( p0 <= nullptr );
61 VERIFY( p0 >= nullptr );
62
63 VERIFY( nullptr == p0 );
64 VERIFY( !(nullptr < p0) );
65 VERIFY( !(nullptr > p0) );
66 VERIFY( nullptr <= p0 );
67 VERIFY( nullptr >= p0 );
68
69 std::unique_ptr<int> p1(new int(1));
70 VERIFY( p1 != nullptr );
71 VERIFY( !(p1 < nullptr) );
72 VERIFY( p1 > nullptr );
73 VERIFY( !(p1 <= nullptr) );
74 VERIFY( p1 >= nullptr );
75
76 VERIFY( nullptr != p1 );
77 VERIFY( nullptr < p1 );
78 VERIFY( !(nullptr > p1) );
79 VERIFY( nullptr <= p1 );
80 VERIFY( !(nullptr >= p1) );
81 }
82
83 int
84 main()
85 {
86 test01();
87 test02();
88 }