|
@@ -24,16 +24,24 @@ namespace ZeroTier {
|
|
|
*
|
|
|
* This is used in the core to avoid requiring C++11 and because auto_ptr is weird.
|
|
|
*/
|
|
|
-template<typename T>
|
|
|
+template< typename T >
|
|
|
class ScopedPtr : public TriviallyCopyable
|
|
|
{
|
|
|
public:
|
|
|
- explicit ZT_INLINE ScopedPtr(T *const p) noexcept : m_ptr(p) {}
|
|
|
- ZT_INLINE ~ScopedPtr() { delete m_ptr; }
|
|
|
+ explicit ZT_INLINE ScopedPtr(T *const p) noexcept: m_ptr(p)
|
|
|
+ {}
|
|
|
|
|
|
- ZT_INLINE T *operator->() const noexcept { return m_ptr; }
|
|
|
- ZT_INLINE T &operator*() const noexcept { return *m_ptr; }
|
|
|
- ZT_INLINE T *ptr() const noexcept { return m_ptr; }
|
|
|
+ ZT_INLINE ~ScopedPtr()
|
|
|
+ { delete m_ptr; }
|
|
|
+
|
|
|
+ ZT_INLINE T *operator->() const noexcept
|
|
|
+ { return m_ptr; }
|
|
|
+
|
|
|
+ ZT_INLINE T &operator*() const noexcept
|
|
|
+ { return *m_ptr; }
|
|
|
+
|
|
|
+ ZT_INLINE T *ptr() const noexcept
|
|
|
+ { return m_ptr; }
|
|
|
|
|
|
ZT_INLINE void swap(const ScopedPtr &p) noexcept
|
|
|
{
|
|
@@ -42,17 +50,30 @@ public:
|
|
|
p.m_ptr = tmp;
|
|
|
}
|
|
|
|
|
|
- explicit ZT_INLINE operator bool() const noexcept { return (m_ptr != (T *)0); }
|
|
|
+ explicit ZT_INLINE operator bool() const noexcept
|
|
|
+ { return (m_ptr != (T *)0); }
|
|
|
+
|
|
|
+ ZT_INLINE bool operator==(const ScopedPtr &p) const noexcept
|
|
|
+ { return (m_ptr == p.m_ptr); }
|
|
|
|
|
|
- ZT_INLINE bool operator==(const ScopedPtr &p) const noexcept { return (m_ptr == p.m_ptr); }
|
|
|
- ZT_INLINE bool operator!=(const ScopedPtr &p) const noexcept { return (m_ptr != p.m_ptr); }
|
|
|
- ZT_INLINE bool operator==(T *const p) const noexcept { return (m_ptr == p); }
|
|
|
- ZT_INLINE bool operator!=(T *const p) const noexcept { return (m_ptr != p); }
|
|
|
+ ZT_INLINE bool operator!=(const ScopedPtr &p) const noexcept
|
|
|
+ { return (m_ptr != p.m_ptr); }
|
|
|
+
|
|
|
+ ZT_INLINE bool operator==(T *const p) const noexcept
|
|
|
+ { return (m_ptr == p); }
|
|
|
+
|
|
|
+ ZT_INLINE bool operator!=(T *const p) const noexcept
|
|
|
+ { return (m_ptr != p); }
|
|
|
|
|
|
private:
|
|
|
- ZT_INLINE ScopedPtr() noexcept {}
|
|
|
- ZT_INLINE ScopedPtr(const ScopedPtr &p) noexcept : m_ptr(nullptr) {}
|
|
|
- ZT_INLINE ScopedPtr &operator=(const ScopedPtr &p) noexcept { return *this; }
|
|
|
+ ZT_INLINE ScopedPtr() noexcept
|
|
|
+ {}
|
|
|
+
|
|
|
+ ZT_INLINE ScopedPtr(const ScopedPtr &p) noexcept: m_ptr(nullptr)
|
|
|
+ {}
|
|
|
+
|
|
|
+ ZT_INLINE ScopedPtr &operator=(const ScopedPtr &p) noexcept
|
|
|
+ { return *this; }
|
|
|
|
|
|
T *const m_ptr;
|
|
|
};
|
|
@@ -60,8 +81,9 @@ private:
|
|
|
} // namespace ZeroTier
|
|
|
|
|
|
namespace std {
|
|
|
-template<typename T>
|
|
|
-ZT_INLINE void swap(ZeroTier::ScopedPtr<T> &a,ZeroTier::ScopedPtr<T> &b) noexcept { a.swap(b); }
|
|
|
+template< typename T >
|
|
|
+ZT_INLINE void swap(ZeroTier::ScopedPtr< T > &a, ZeroTier::ScopedPtr< T > &b) noexcept
|
|
|
+{ a.swap(b); }
|
|
|
}
|
|
|
|
|
|
#endif
|