Skip to content

Commit 1ab9a17

Browse files
N-Dekkerhjmjohnson
authored andcommitted
STYLE: Add in-class default member initializer to SmartPointer m_Pointer
Defaulted the default-constructor of `SmartPointer`. Slightly simplified the implementation of `SmartPointer(std::nullptr_t)` and its destructor.
1 parent 03ce742 commit 1ab9a17

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

Modules/Core/Common/include/itkSmartPointer.h

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ class SmartPointer
5656
template <typename T>
5757
using EnableIfConvertible = typename std::enable_if<std::is_convertible<T *, TObjectType *>::value>;
5858

59-
/** Constructor */
60-
constexpr SmartPointer() noexcept
61-
: m_Pointer(nullptr)
62-
{}
59+
/** Default-constructor */
60+
constexpr SmartPointer() noexcept = default;
6361

6462
/** Copy constructor */
6563
SmartPointer(const SmartPointer & p) noexcept
@@ -68,9 +66,8 @@ class SmartPointer
6866
this->Register();
6967
}
7068

71-
constexpr SmartPointer(std::nullptr_t p) noexcept
72-
: m_Pointer(p)
73-
{}
69+
/** Constructor for implicit conversion from nullptr */
70+
constexpr SmartPointer(std::nullptr_t) noexcept {}
7471

7572
/** constructor with implicit conversion of pointer type */
7673
template <typename T, typename = typename EnableIfConvertible<T>::type>
@@ -103,11 +100,7 @@ class SmartPointer
103100
}
104101

105102
/** Destructor */
106-
~SmartPointer()
107-
{
108-
this->UnRegister();
109-
m_Pointer = nullptr;
110-
}
103+
~SmartPointer() { this->UnRegister(); }
111104

112105
/** Overload operator -> */
113106
ObjectType * operator->() const noexcept { return m_Pointer; }
@@ -199,7 +192,7 @@ class SmartPointer
199192

200193
private:
201194
/** The pointer to the object referred to by this smart pointer. */
202-
ObjectType * m_Pointer;
195+
ObjectType * m_Pointer{ nullptr };
203196

204197
template <typename T>
205198
friend class SmartPointer;

0 commit comments

Comments
 (0)