1 // Copyright 2020 Peter Dimov
2 // Distributed under the Boost Software License, Version 1.0.
3 // https://www.boost.org/LICENSE_1_0.txt
4
5 #include <boost/smart_ptr/owner_less.hpp>
6 #include <boost/smart_ptr/local_shared_ptr.hpp>
7 #include <boost/core/lightweight_test.hpp>
8
main()9 int main()
10 {
11 boost::owner_less<> const lt = {};
12
13 {
14 boost::local_shared_ptr<int> p1( new int );
15 boost::local_shared_ptr<int> p2( p1 );
16
17 BOOST_TEST( !lt( p1, p2 ) );
18 BOOST_TEST( !lt( p2, p1 ) );
19
20 boost::local_shared_ptr<int> p3( new int );
21
22 BOOST_TEST( lt( p1, p3 ) || lt( p3, p1 ) );
23
24 boost::local_shared_ptr<int> p4;
25 boost::local_shared_ptr<int> p5;
26
27 BOOST_TEST( !lt( p4, p5 ) );
28 BOOST_TEST( !lt( p5, p4 ) );
29
30 BOOST_TEST( lt( p4, p3 ) || lt( p3, p4 ) );
31
32 boost::local_shared_ptr<int> p6( static_cast<int*>(0) );
33
34 BOOST_TEST( lt( p4, p6 ) || lt( p6, p4 ) );
35
36 boost::local_shared_ptr<void> p7( p1 );
37
38 BOOST_TEST( !lt( p1, p7 ) );
39 BOOST_TEST( !lt( p7, p1 ) );
40
41 boost::local_shared_ptr<void> p8;
42
43 BOOST_TEST( lt( p1, p8 ) || lt( p8, p1 ) );
44
45 BOOST_TEST( !lt( p4, p8 ) );
46 BOOST_TEST( !lt( p8, p4 ) );
47 /*
48 boost::local_weak_ptr<int> q1( p1 );
49
50 BOOST_TEST( !lt( p1, q1 ) );
51 BOOST_TEST( !lt( q1, p1 ) );
52
53 boost::local_weak_ptr<int> q2( p1 );
54
55 BOOST_TEST( !lt( q1, q2 ) );
56 BOOST_TEST( !lt( q2, q1 ) );
57
58 boost::local_weak_ptr<int> q3( p3 );
59
60 BOOST_TEST( lt( p1, q3 ) || lt( q3, p1 ) );
61 BOOST_TEST( lt( q1, q3 ) || lt( q3, q1 ) );
62
63 boost::local_weak_ptr<int> q4;
64
65 BOOST_TEST( !lt( p4, q4 ) );
66 BOOST_TEST( !lt( q4, p4 ) );
67
68 BOOST_TEST( lt( q1, q4 ) || lt( q4, q1 ) );
69
70 boost::local_weak_ptr<void> q5;
71
72 BOOST_TEST( !lt( q4, q5 ) );
73 BOOST_TEST( !lt( q5, q4 ) );
74
75 boost::local_weak_ptr<void> q7( p7 );
76
77 BOOST_TEST( !lt( p1, q7 ) );
78 BOOST_TEST( !lt( q7, p1 ) );
79
80 BOOST_TEST( !lt( q1, q7 ) );
81 BOOST_TEST( !lt( q7, q1 ) );
82
83 p1.reset();
84 p2.reset();
85 p3.reset();
86 p7.reset();
87
88 BOOST_TEST( q1.expired() );
89 BOOST_TEST( q2.expired() );
90 BOOST_TEST( q3.expired() );
91 BOOST_TEST( q7.expired() );
92
93 BOOST_TEST( !lt( q1, q2 ) );
94 BOOST_TEST( !lt( q2, q1 ) );
95
96 BOOST_TEST( !lt( q1, q7 ) );
97 BOOST_TEST( !lt( q7, q1 ) );
98
99 BOOST_TEST( lt( q1, q3 ) || lt( q3, q1 ) );
100
101 BOOST_TEST( lt( q1, q4 ) || lt( q4, q1 ) );
102 */
103 }
104
105 return boost::report_errors();
106 }
107