Skip to content

Commit 67f295f

Browse files
committed
Added converting assignment operators to sfl::test::fancy_ptr
1 parent 8616335 commit 67f295f

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

test/include/fancy_ptr.hpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ class fancy_ptr
9898
: ptr_(static_cast<T*>(ptr))
9999
{}
100100

101-
// Construct from other fancy_ptr.
101+
// Converting constructor from other fancy_ptr.
102102
// Participates in overload resolution if U* is convertible to T*.
103103
template <typename U,
104104
typename std::enable_if<std::is_convertible<U*, T*>::value>::type* = nullptr>
105105
fancy_ptr(const fancy_ptr<U>& other) noexcept
106106
: ptr_(static_cast<T*>(other.ptr_))
107107
{}
108108

109-
// Construct from other fancy_ptr.
109+
// Converting constructor from other fancy_ptr.
110110
// Participates in overload resolution if U* is constructible from T*.
111111
template <typename U,
112112
typename std::enable_if<!std::is_convertible<U*, T*>::value && std::is_constructible<U*, T*>::value>::type* = nullptr>
@@ -115,12 +115,29 @@ class fancy_ptr
115115
: ptr_(static_cast<T*>(other.ptr_))
116116
{}
117117

118-
#if 0 // Old code.
119-
template <typename U = T, typename std::enable_if<std::is_const<U>::value>::type* = nullptr>
120-
fancy_ptr(const fancy_ptr<typename std::remove_const<T>::type>& other) noexcept
121-
: ptr_(other.operator->() /* std::to_address(other) in C++20 */)
122-
{}
123-
#endif
118+
//
119+
// ---- ASSIGNMENT --------------------------------------------------------
120+
//
121+
122+
// Converting assignment operator from other fancy_ptr
123+
// Participates in overload resolution if U* is convertible to T*.
124+
template <typename U,
125+
typename std::enable_if<std::is_convertible<U*, T*>::value>::type* = nullptr>
126+
fancy_ptr& operator=(const fancy_ptr<U>& other) noexcept
127+
{
128+
ptr_ = static_cast<T*>(other.ptr_);
129+
return *this;
130+
}
131+
132+
// Converting assignment operator from other fancy_ptr
133+
// Participates in overload resolution if U* is constructible from T*.
134+
template <typename U,
135+
typename std::enable_if<!std::is_convertible<U*, T*>::value && std::is_constructible<U*, T*>::value>::type* = nullptr>
136+
fancy_ptr& operator=(const fancy_ptr<U>& other) noexcept
137+
{
138+
ptr_ = static_cast<T*>(other.ptr_);
139+
return *this;
140+
}
124141

125142
//
126143
// ---- OBSERVERS ---------------------------------------------------------

0 commit comments

Comments
 (0)