Coverage Report

Created: 2026-10-28 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/poco/Foundation/include/Poco/AutoPtr.h
Line
Count
Source
1
//
2
// AutoPtr.h
3
//
4
// Library: Foundation
5
// Package: Core
6
// Module:  AutoPtr
7
//
8
// Definition of the AutoPtr template class.
9
//
10
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
11
// and Contributors.
12
//
13
// SPDX-License-Identifier: BSL-1.0
14
//
15
16
17
#ifndef Foundation_AutoPtr_INCLUDED
18
#define Foundation_AutoPtr_INCLUDED
19
20
21
#include "Poco/Foundation.h"
22
#include "Poco/Exception.h"
23
#include <algorithm>
24
#include <cstddef>
25
26
27
namespace Poco {
28
29
30
template <class C>
31
class AutoPtr
32
  /// AutoPtr is a "smart" pointer for classes implementing
33
  /// reference counting based garbage collection.
34
  /// To be usable with the AutoPtr template, a class must
35
  /// implement the following behaviour:
36
  /// A class must maintain a reference count.
37
  /// The constructors of the object initialize the reference
38
  /// count to one.
39
  /// The class must implement a public duplicate() method:
40
  ///     void duplicate();
41
  /// that increments the reference count by one.
42
  /// The class must implement a public release() method:
43
  ///     void release()
44
  /// that decrements the reference count by one, and,
45
  /// if the reference count reaches zero, deletes the
46
  /// object.
47
  ///
48
  /// AutoPtr works in the following way:
49
  /// If an AutoPtr is assigned an ordinary pointer to
50
  /// an object (via the constructor or the assignment operator),
51
  /// it takes ownership of the object and the object's reference
52
  /// count remains unchanged.
53
  /// If the AutoPtr is assigned another AutoPtr, the
54
  /// object's reference count is incremented by one by
55
  /// calling duplicate() on its object.
56
  /// The destructor of AutoPtr calls release() on its
57
  /// object.
58
  /// AutoPtr supports dereferencing with both the ->
59
  /// and the * operator. An attempt to dereference a null
60
  /// AutoPtr results in a NullPointerException being thrown.
61
  /// AutoPtr also implements all relational operators.
62
  /// Note that AutoPtr allows casting of its encapsulated data types.
63
{
64
public:
65
0
  AutoPtr(): _ptr(nullptr)
66
0
  {
67
0
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::IPAddressImpl>::AutoPtr()
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::SocketAddressImpl>::AutoPtr()
68
69
1.22M
  AutoPtr(C* ptr): _ptr(ptr)
70
1.22M
  {
71
1.22M
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::IPAddressImpl>::AutoPtr(Poco::Net::Impl::IPAddressImpl*)
Poco::AutoPtr<Poco::XML::Document>::AutoPtr(Poco::XML::Document*)
Line
Count
Source
69
172
  AutoPtr(C* ptr): _ptr(ptr)
70
172
  {
71
172
  }
Poco::AutoPtr<Poco::XML::Notation>::AutoPtr(Poco::XML::Notation*)
Line
Count
Source
69
7.68k
  AutoPtr(C* ptr): _ptr(ptr)
70
7.68k
  {
71
7.68k
  }
Poco::AutoPtr<Poco::XML::Entity>::AutoPtr(Poco::XML::Entity*)
Line
Count
Source
69
303
  AutoPtr(C* ptr): _ptr(ptr)
70
303
  {
71
303
  }
Poco::AutoPtr<Poco::XML::Element>::AutoPtr(Poco::XML::Element*)
Line
Count
Source
69
359k
  AutoPtr(C* ptr): _ptr(ptr)
70
359k
  {
71
359k
  }
Poco::AutoPtr<Poco::XML::Attr>::AutoPtr(Poco::XML::Attr*)
Line
Count
Source
69
121k
  AutoPtr(C* ptr): _ptr(ptr)
70
121k
  {
71
121k
  }
Poco::AutoPtr<Poco::XML::CDATASection>::AutoPtr(Poco::XML::CDATASection*)
Line
Count
Source
69
4.53k
  AutoPtr(C* ptr): _ptr(ptr)
70
4.53k
  {
71
4.53k
  }
Poco::AutoPtr<Poco::XML::Text>::AutoPtr(Poco::XML::Text*)
Line
Count
Source
69
100k
  AutoPtr(C* ptr): _ptr(ptr)
70
100k
  {
71
100k
  }
Poco::AutoPtr<Poco::XML::ProcessingInstruction>::AutoPtr(Poco::XML::ProcessingInstruction*)
Line
Count
Source
69
166k
  AutoPtr(C* ptr): _ptr(ptr)
70
166k
  {
71
166k
  }
Poco::AutoPtr<Poco::XML::EntityReference>::AutoPtr(Poco::XML::EntityReference*)
Line
Count
Source
69
55.4k
  AutoPtr(C* ptr): _ptr(ptr)
70
55.4k
  {
71
55.4k
  }
Poco::AutoPtr<Poco::XML::DocumentType>::AutoPtr(Poco::XML::DocumentType*)
Line
Count
Source
69
10.9k
  AutoPtr(C* ptr): _ptr(ptr)
70
10.9k
  {
71
10.9k
  }
Poco::AutoPtr<Poco::XML::Comment>::AutoPtr(Poco::XML::Comment*)
Line
Count
Source
69
371k
  AutoPtr(C* ptr): _ptr(ptr)
70
371k
  {
71
371k
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::XML::ElementsByTagNameList>::AutoPtr(Poco::XML::ElementsByTagNameList*)
Unexecuted instantiation: Poco::AutoPtr<Poco::XML::ElementsByTagNameListNS>::AutoPtr(Poco::XML::ElementsByTagNameListNS*)
Unexecuted instantiation: Poco::AutoPtr<Poco::XML::MutationEvent>::AutoPtr(Poco::XML::MutationEvent*)
Poco::AutoPtr<Poco::JWT::Algorithm>::AutoPtr(Poco::JWT::Algorithm*)
Line
Count
Source
69
25.7k
  AutoPtr(C* ptr): _ptr(ptr)
70
25.7k
  {
71
25.7k
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::Crypto::KeyPairImpl>::AutoPtr(Poco::Crypto::KeyPairImpl*)
72
73
0
  AutoPtr(C* ptr, bool shared): _ptr(ptr)
74
0
  {
75
0
    if (shared && _ptr) _ptr->duplicate();
76
0
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::Crypto::ECKeyImpl>::AutoPtr(Poco::Crypto::ECKeyImpl*, bool)
Unexecuted instantiation: Poco::AutoPtr<Poco::Crypto::RSAKeyImpl>::AutoPtr(Poco::Crypto::RSAKeyImpl*, bool)
77
78
0
  AutoPtr(const AutoPtr& ptr): _ptr(ptr._ptr)
79
0
  {
80
0
    if (_ptr) _ptr->duplicate();
81
0
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::IPAddressImpl>::AutoPtr(Poco::AutoPtr<Poco::Net::Impl::IPAddressImpl> const&)
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::SocketAddressImpl>::AutoPtr(Poco::AutoPtr<Poco::Net::Impl::SocketAddressImpl> const&)
Unexecuted instantiation: Poco::AutoPtr<Poco::Crypto::KeyPairImpl>::AutoPtr(Poco::AutoPtr<Poco::Crypto::KeyPairImpl> const&)
82
83
0
  AutoPtr(AutoPtr&& ptr) noexcept: _ptr(std::move(ptr._ptr))
84
0
  {
85
0
    ptr._ptr = nullptr;
86
0
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::IPAddressImpl>::AutoPtr(Poco::AutoPtr<Poco::Net::Impl::IPAddressImpl>&&)
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::SocketAddressImpl>::AutoPtr(Poco::AutoPtr<Poco::Net::Impl::SocketAddressImpl>&&)
Unexecuted instantiation: Poco::AutoPtr<Poco::Crypto::KeyPairImpl>::AutoPtr(Poco::AutoPtr<Poco::Crypto::KeyPairImpl>&&)
87
88
  template <class Other>
89
  AutoPtr(const AutoPtr<Other>& ptr): _ptr(const_cast<Other*>(ptr.get()))
90
  {
91
    if (_ptr) _ptr->duplicate();
92
  }
93
94
  ~AutoPtr()
95
1.22M
  {
96
1.22M
    if (_ptr) _ptr->release();
97
1.22M
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::IPAddressImpl>::~AutoPtr()
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::SocketAddressImpl>::~AutoPtr()
Poco::AutoPtr<Poco::XML::Document>::~AutoPtr()
Line
Count
Source
95
172
  {
96
172
    if (_ptr) _ptr->release();
97
172
  }
Poco::AutoPtr<Poco::XML::Notation>::~AutoPtr()
Line
Count
Source
95
7.68k
  {
96
7.68k
    if (_ptr) _ptr->release();
97
7.68k
  }
Poco::AutoPtr<Poco::XML::Entity>::~AutoPtr()
Line
Count
Source
95
303
  {
96
303
    if (_ptr) _ptr->release();
97
303
  }
Poco::AutoPtr<Poco::XML::Element>::~AutoPtr()
Line
Count
Source
95
359k
  {
96
359k
    if (_ptr) _ptr->release();
97
359k
  }
Poco::AutoPtr<Poco::XML::Attr>::~AutoPtr()
Line
Count
Source
95
121k
  {
96
121k
    if (_ptr) _ptr->release();
97
121k
  }
Poco::AutoPtr<Poco::XML::CDATASection>::~AutoPtr()
Line
Count
Source
95
4.53k
  {
96
4.53k
    if (_ptr) _ptr->release();
97
4.53k
  }
Poco::AutoPtr<Poco::XML::Text>::~AutoPtr()
Line
Count
Source
95
100k
  {
96
100k
    if (_ptr) _ptr->release();
97
100k
  }
Poco::AutoPtr<Poco::XML::ProcessingInstruction>::~AutoPtr()
Line
Count
Source
95
166k
  {
96
166k
    if (_ptr) _ptr->release();
97
166k
  }
Poco::AutoPtr<Poco::XML::EntityReference>::~AutoPtr()
Line
Count
Source
95
55.4k
  {
96
55.4k
    if (_ptr) _ptr->release();
97
55.4k
  }
Poco::AutoPtr<Poco::XML::DocumentType>::~AutoPtr()
Line
Count
Source
95
10.9k
  {
96
10.9k
    if (_ptr) _ptr->release();
97
10.9k
  }
Poco::AutoPtr<Poco::XML::Comment>::~AutoPtr()
Line
Count
Source
95
371k
  {
96
371k
    if (_ptr) _ptr->release();
97
371k
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::XML::ElementsByTagNameList>::~AutoPtr()
Unexecuted instantiation: Poco::AutoPtr<Poco::XML::ElementsByTagNameListNS>::~AutoPtr()
Unexecuted instantiation: Poco::AutoPtr<Poco::XML::MutationEvent>::~AutoPtr()
Poco::AutoPtr<Poco::JWT::Algorithm>::~AutoPtr()
Line
Count
Source
95
25.7k
  {
96
25.7k
    if (_ptr) _ptr->release();
97
25.7k
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::Crypto::KeyPairImpl>::~AutoPtr()
Unexecuted instantiation: Poco::AutoPtr<Poco::Crypto::ECKeyImpl>::~AutoPtr()
Unexecuted instantiation: Poco::AutoPtr<Poco::Crypto::RSAKeyImpl>::~AutoPtr()
98
99
  AutoPtr& assign(C* ptr)
100
0
  {
101
0
    if (_ptr != ptr)
102
0
    {
103
0
      if (_ptr) _ptr->release();
104
0
      _ptr = ptr;
105
0
    }
106
0
    return *this;
107
0
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::IPAddressImpl>::assign(Poco::Net::Impl::IPAddressImpl*)
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::SocketAddressImpl>::assign(Poco::Net::Impl::SocketAddressImpl*)
108
109
  AutoPtr& assign(C* ptr, bool shared)
110
0
  {
111
0
    if (_ptr != ptr)
112
0
    {
113
0
      if (shared && ptr) ptr->duplicate();
114
0
      std::swap(_ptr, ptr);
115
0
      if (ptr) ptr->release();
116
0
    }
117
0
    return *this;
118
0
  }
119
120
  AutoPtr& assign(const AutoPtr& ptr)
121
0
  {
122
0
    return assign(ptr._ptr, true);
123
0
  }
124
125
  template <class Other>
126
  AutoPtr& assign(const AutoPtr<Other>& ptr)
127
  {
128
    C* nptr = const_cast<Other*>(ptr.get());
129
    return assign(nptr, true);
130
  }
131
132
  void reset()
133
  {
134
    if (_ptr)
135
    {
136
      _ptr->release();
137
      _ptr = nullptr;
138
    }
139
  }
140
141
  void reset(C* ptr)
142
  {
143
    assign(ptr);
144
  }
145
146
  void reset(C* ptr, bool shared)
147
  {
148
    assign(ptr, shared);
149
  }
150
151
  void reset(const AutoPtr& ptr)
152
  {
153
    assign(ptr);
154
  }
155
156
  template <class Other>
157
  void reset(const AutoPtr<Other>& ptr)
158
  {
159
    assign<Other>(ptr);
160
  }
161
162
  AutoPtr& operator = (C* ptr)
163
0
  {
164
0
    return assign(ptr);
165
0
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::IPAddressImpl>::operator=(Poco::Net::Impl::IPAddressImpl*)
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::SocketAddressImpl>::operator=(Poco::Net::Impl::SocketAddressImpl*)
166
167
  AutoPtr& operator = (const AutoPtr& ptr)
168
0
  {
169
0
    return assign(ptr);
170
0
  }
171
172
  AutoPtr& operator = (AutoPtr&& ptr) noexcept
173
0
  {
174
0
    if (_ptr) _ptr->release();
175
0
    _ptr = ptr._ptr;
176
0
    ptr._ptr = nullptr;
177
0
    return *this;
178
0
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::IPAddressImpl>::operator=(Poco::AutoPtr<Poco::Net::Impl::IPAddressImpl>&&)
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::SocketAddressImpl>::operator=(Poco::AutoPtr<Poco::Net::Impl::SocketAddressImpl>&&)
Unexecuted instantiation: Poco::AutoPtr<Poco::Crypto::KeyPairImpl>::operator=(Poco::AutoPtr<Poco::Crypto::KeyPairImpl>&&)
179
180
  template <class Other>
181
  AutoPtr& operator = (const AutoPtr<Other>& ptr)
182
  {
183
    return assign<Other>(ptr);
184
  }
185
186
  void swap(AutoPtr& ptr) noexcept
187
  {
188
    std::swap(_ptr, ptr._ptr);
189
  }
190
191
  template <class Other>
192
  [[nodiscard]] AutoPtr<Other> cast() const
193
    /// Casts the AutoPtr via a dynamic cast to the given type.
194
    /// Returns an AutoPtr containing nullptr if the cast fails.
195
    /// Example: (assume class Sub: public Super)
196
    ///    AutoPtr<Super> super(new Sub());
197
    ///    AutoPtr<Sub> sub = super.cast<Sub>();
198
    ///    poco_assert (sub.get());
199
0
  {
200
0
    Other* pOther = dynamic_cast<Other*>(_ptr);
201
0
    return AutoPtr<Other>(pOther, true);
202
0
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::Crypto::RSAKeyImpl> Poco::AutoPtr<Poco::Crypto::KeyPairImpl>::cast<Poco::Crypto::RSAKeyImpl>() const
Unexecuted instantiation: Poco::AutoPtr<Poco::Crypto::ECKeyImpl> Poco::AutoPtr<Poco::Crypto::KeyPairImpl>::cast<Poco::Crypto::ECKeyImpl>() const
203
204
  template <class Other>
205
  [[nodiscard]] AutoPtr<Other> unsafeCast() const
206
    /// Casts the AutoPtr via a static cast to the given type.
207
    /// Example: (assume class Sub: public Super)
208
    ///    AutoPtr<Super> super(new Sub());
209
    ///    AutoPtr<Sub> sub = super.unsafeCast<Sub>();
210
    ///    poco_assert (sub.get());
211
  {
212
    Other* pOther = static_cast<Other*>(_ptr);
213
    return AutoPtr<Other>(pOther, true);
214
  }
215
216
  C* operator -> ()
217
147k
  {
218
147k
    if (_ptr)
219
147k
      return _ptr;
220
0
    else
221
0
      throw NullPointerException();
222
147k
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::IPAddressImpl>::operator->()
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::SocketAddressImpl>::operator->()
Poco::AutoPtr<Poco::XML::Element>::operator->()
Line
Count
Source
217
121k
  {
218
121k
    if (_ptr)
219
121k
      return _ptr;
220
0
    else
221
0
      throw NullPointerException();
222
121k
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::XML::ElementsByTagNameList>::operator->()
Unexecuted instantiation: Poco::AutoPtr<Poco::XML::ElementsByTagNameListNS>::operator->()
Unexecuted instantiation: Poco::AutoPtr<Poco::Crypto::KeyPairImpl>::operator->()
Poco::AutoPtr<Poco::JWT::Algorithm>::operator->()
Line
Count
Source
217
25.7k
  {
218
25.7k
    if (_ptr)
219
25.7k
      return _ptr;
220
0
    else
221
0
      throw NullPointerException();
222
25.7k
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::Crypto::ECKeyImpl>::operator->()
Unexecuted instantiation: Poco::AutoPtr<Poco::Crypto::RSAKeyImpl>::operator->()
223
224
  const C* operator -> () const
225
0
  {
226
0
    if (_ptr)
227
0
      return _ptr;
228
0
    else
229
0
      throw NullPointerException();
230
0
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::ThreadImpl::ThreadData>::operator->() const
Unexecuted instantiation: Poco::AutoPtr<Poco::Crypto::KeyPairImpl>::operator->() const
231
232
  C& operator * ()
233
  {
234
    if (_ptr)
235
      return *_ptr;
236
    else
237
      throw NullPointerException();
238
  }
239
240
  const C& operator * () const
241
  {
242
    if (_ptr)
243
      return *_ptr;
244
    else
245
      throw NullPointerException();
246
  }
247
248
  [[nodiscard]] C* get()
249
0
  {
250
0
    return _ptr;
251
0
  }
252
253
  [[nodiscard]] const C* get() const
254
  {
255
    return _ptr;
256
  }
257
258
  [[nodiscard]] operator C* ()
259
1.55M
  {
260
1.55M
    return _ptr;
261
1.55M
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::IPAddressImpl>::operator Poco::Net::Impl::IPAddressImpl*()
Poco::AutoPtr<Poco::XML::Notation>::operator Poco::XML::Notation*()
Line
Count
Source
259
7.68k
  {
260
7.68k
    return _ptr;
261
7.68k
  }
Poco::AutoPtr<Poco::XML::Entity>::operator Poco::XML::Entity*()
Line
Count
Source
259
303
  {
260
303
    return _ptr;
261
303
  }
Poco::AutoPtr<Poco::XML::Attr>::operator Poco::XML::Attr*()
Line
Count
Source
259
121k
  {
260
121k
    return _ptr;
261
121k
  }
Poco::AutoPtr<Poco::XML::Element>::operator Poco::XML::Element*()
Line
Count
Source
259
719k
  {
260
719k
    return _ptr;
261
719k
  }
Poco::AutoPtr<Poco::XML::CDATASection>::operator Poco::XML::CDATASection*()
Line
Count
Source
259
4.53k
  {
260
4.53k
    return _ptr;
261
4.53k
  }
Poco::AutoPtr<Poco::XML::Text>::operator Poco::XML::Text*()
Line
Count
Source
259
100k
  {
260
100k
    return _ptr;
261
100k
  }
Poco::AutoPtr<Poco::XML::ProcessingInstruction>::operator Poco::XML::ProcessingInstruction*()
Line
Count
Source
259
166k
  {
260
166k
    return _ptr;
261
166k
  }
Poco::AutoPtr<Poco::XML::EntityReference>::operator Poco::XML::EntityReference*()
Line
Count
Source
259
55.4k
  {
260
55.4k
    return _ptr;
261
55.4k
  }
Poco::AutoPtr<Poco::XML::DocumentType>::operator Poco::XML::DocumentType*()
Line
Count
Source
259
10.9k
  {
260
10.9k
    return _ptr;
261
10.9k
  }
Poco::AutoPtr<Poco::XML::Comment>::operator Poco::XML::Comment*()
Line
Count
Source
259
371k
  {
260
371k
    return _ptr;
261
371k
  }
262
263
  [[nodiscard]] operator const C* () const
264
0
  {
265
0
    return _ptr;
266
0
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::IPAddressImpl>::operator Poco::Net::Impl::IPAddressImpl const*() const
Unexecuted instantiation: Poco::AutoPtr<Poco::Net::Impl::SocketAddressImpl>::operator Poco::Net::Impl::SocketAddressImpl const*() const
267
268
  [[nodiscard]] bool operator ! () const
269
0
  {
270
0
    return _ptr == nullptr;
271
0
  }
Unexecuted instantiation: Poco::AutoPtr<Poco::Crypto::ECKeyImpl>::operator!() const
Unexecuted instantiation: Poco::AutoPtr<Poco::Crypto::RSAKeyImpl>::operator!() const
272
273
  [[nodiscard]] bool isNull() const
274
  {
275
    return _ptr == nullptr;
276
  }
277
278
  [[nodiscard]] C* duplicate()
279
  {
280
    if (_ptr) _ptr->duplicate();
281
    return _ptr;
282
  }
283
284
  [[nodiscard]] bool operator == (const AutoPtr& ptr) const
285
  {
286
    return _ptr == ptr._ptr;
287
  }
288
289
  [[nodiscard]] bool operator == (const C* ptr) const
290
  {
291
    return _ptr == ptr;
292
  }
293
294
  [[nodiscard]] bool operator == (C* ptr) const
295
  {
296
    return _ptr == ptr;
297
  }
298
299
  [[nodiscard]] bool operator == (std::nullptr_t ptr) const
300
  {
301
    return _ptr == ptr;
302
  }
303
304
  [[nodiscard]] bool operator != (const AutoPtr& ptr) const
305
  {
306
    return _ptr != ptr._ptr;
307
  }
308
309
  [[nodiscard]] bool operator != (const C* ptr) const
310
  {
311
    return _ptr != ptr;
312
  }
313
314
  [[nodiscard]] bool operator != (C* ptr) const
315
  {
316
    return _ptr != ptr;
317
  }
318
319
  [[nodiscard]] bool operator != (std::nullptr_t ptr) const
320
  {
321
    return _ptr != ptr;
322
  }
323
324
  [[nodiscard]] bool operator < (const AutoPtr& ptr) const
325
  {
326
    return _ptr < ptr._ptr;
327
  }
328
329
  [[nodiscard]] bool operator < (const C* ptr) const
330
  {
331
    return _ptr < ptr;
332
  }
333
334
  [[nodiscard]] bool operator < (C* ptr) const
335
  {
336
    return _ptr < ptr;
337
  }
338
339
  [[nodiscard]] bool operator <= (const AutoPtr& ptr) const
340
  {
341
    return _ptr <= ptr._ptr;
342
  }
343
344
  [[nodiscard]] bool operator <= (const C* ptr) const
345
  {
346
    return _ptr <= ptr;
347
  }
348
349
  [[nodiscard]] bool operator <= (C* ptr) const
350
  {
351
    return _ptr <= ptr;
352
  }
353
354
  [[nodiscard]] bool operator > (const AutoPtr& ptr) const
355
  {
356
    return _ptr > ptr._ptr;
357
  }
358
359
  [[nodiscard]] bool operator > (const C* ptr) const
360
  {
361
    return _ptr > ptr;
362
  }
363
364
  [[nodiscard]] bool operator > (C* ptr) const
365
  {
366
    return _ptr > ptr;
367
  }
368
369
  [[nodiscard]] bool operator >= (const AutoPtr& ptr) const
370
  {
371
    return _ptr >= ptr._ptr;
372
  }
373
374
  [[nodiscard]] bool operator >= (const C* ptr) const
375
  {
376
    return _ptr >= ptr;
377
  }
378
379
  [[nodiscard]] bool operator >= (C* ptr) const
380
  {
381
    return _ptr >= ptr;
382
  }
383
384
private:
385
  C* _ptr;
386
};
387
388
389
template <class C>
390
inline void swap(AutoPtr<C>& p1, AutoPtr<C>& p2) noexcept
391
{
392
  p1.swap(p2);
393
}
394
395
396
template <typename T, typename... Args>
397
[[nodiscard]] AutoPtr<T> makeAuto(Args&&... args)
398
{
399
  return AutoPtr<T>(new T(std::forward<Args>(args)...));
400
}
401
402
403
} // namespace Poco
404
405
406
#endif // Foundation_AutoPtr_INCLUDED