Skip to content

Commit

Permalink
SafePtr: tiny
Browse files Browse the repository at this point in the history
  • Loading branch information
fchn289 committed Jul 1, 2024
1 parent 0cdb517 commit f43a078
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/safe_mem/SafePtr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class SafePtr
template<typename From> void init_(const SafePtr<From>&) noexcept;

// -------------------------------------------------------------------------------------------
shared_ptr<T> pT_;
shared_ptr<T> pT_; // core
type_index realType_ = typeid(T); // origin type
type_index lastType_ = typeid(T); // maybe last valid type than realType_ & void
};
Expand Down Expand Up @@ -113,7 +113,7 @@ shared_ptr<To> SafePtr<T>::cast() const noexcept
//HID("(SafePtr) cast to derived");
return dynamic_pointer_cast<To>(pT_);
}
else if constexpr(is_void_v<To>)
else if constexpr(is_void_v<To>)
{
//HID("(SafePtr) cast to void (for container to store diff types)");
return pT_;
Expand Down Expand Up @@ -152,7 +152,7 @@ void SafePtr<T>::init_(const SafePtr<From>& aSafeFrom) noexcept

realType_ = aSafeFrom.realType();
// save last useful type
if (type_index(typeid(T)) != realType_ && !is_same_v<T, void>)
if (!is_same_v<T, void> && type_index(typeid(T)) != realType_)
lastType_ = type_index(typeid(T));
else
lastType_ = aSafeFrom.lastType();
Expand Down Expand Up @@ -205,16 +205,16 @@ bool operator<(SafePtr<T> lhs, SafePtr<U> rhs)

// ***********************************************************************************************
template<typename To, typename From>
SafePtr<To> static_pointer_cast(const SafePtr<From>& aFromPtr) noexcept
SafePtr<To> static_pointer_cast(const SafePtr<From>& aSafeFrom) noexcept
{
return dynamic_pointer_cast<To>(aFromPtr);
return dynamic_pointer_cast<To>(aSafeFrom);
}
} // namespace

template<typename T>
struct std::hash<RLib::SafePtr<T>>
{
auto operator()(const RLib::SafePtr<T>& aSafeAdr) const { return hash<shared_ptr<T>>()(aSafeAdr.get()); }
auto operator()(const RLib::SafePtr<T>& aSafePtr) const { return hash<shared_ptr<T>>()(aSafePtr.get()); }
};

// ***********************************************************************************************
Expand Down

0 comments on commit f43a078

Please sign in to comment.