Skip to content

Commit 26af412

Browse files
author
jparisu
committed
Refs #15831: Fix fragile ==operator
Signed-off-by: jparisu <[email protected]>
1 parent 44687c5 commit 26af412

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/cpp/types/fragile_ptr.hpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,26 @@ class fragile_ptr
7373
/////////////////////
7474
// OPERATOR METHODS
7575

76-
template <typename U>
77-
bool operator==(const std::shared_ptr<T>& other) const noexcept
78-
{
79-
static_assert(std::is_base_of<U, T>::value, "U must inherit from T");
80-
return std::dynamic_pointer_cast<U>(this->safety_lock_()) == other;
81-
}
76+
// template <typename U>
77+
// bool operator==(const std::shared_ptr<T>& other) const noexcept
78+
// {
79+
// static_assert(std::is_base_of<U, T>::value, "U must inherit from T");
80+
// return std::dynamic_pointer_cast<U>(this->safety_lock_()) == other;
81+
// }
8282

8383
// TODO: use if_enabled or somehow limit this cast to only those U that are coherent
8484
template <typename U>
8585
bool operator==(const std::shared_ptr<U>& other) const noexcept
8686
{
87-
return this->safety_lock_() == other;
87+
static_assert(std::is_base_of<U, T>::value, "U must inherit from T");
88+
if (other == nullptr)
89+
{
90+
return this->expired();
91+
}
92+
else
93+
{
94+
return this->safety_lock_() == other;
95+
}
8896
}
8997

9098
/////////////////////
@@ -237,7 +245,15 @@ std::ostream& operator <<(
237245
std::ostream& o,
238246
const fragile_ptr<T>& f)
239247
{
240-
return o << f.lock();
248+
if (f.expired())
249+
{
250+
o << "{nullptr}";
251+
}
252+
else
253+
{
254+
o << f.lock();
255+
}
256+
return o;
241257
}
242258

243259
} // namespace details

0 commit comments

Comments
 (0)