Skip to content

Commit 345ed20

Browse files
committed
ai min: SafePtr
1 parent c017538 commit 345ed20

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/safe_mem/SafePtr.hpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ SafePtr<T>::SafePtr(SafePtr<From>&& aSafeFrom) noexcept // mv - MtQ need
124124
// - for safe_cast; constructor is faster; private is safe
125125
template<typename T>
126126
constexpr SafePtr<T>::SafePtr(std::shared_ptr<T>&& aPtr, const std::type_index& aReal, const std::type_index& aLast) noexcept
127-
: pT_(aPtr) // mv
127+
: pT_(std::move(aPtr)) // mv
128128
, realType_(pT_ ? aReal : typeid(T))
129129
, lastType_(pT_ ? aLast : typeid(T))
130130
{}
@@ -175,18 +175,14 @@ template<typename T>
175175
template<typename To>
176176
std::type_index SafePtr<T>::genLastType_() const noexcept
177177
{
178-
if constexpr(std::is_same_v<To, void>) { // compile opt
179-
HID("T->void, recursive T.lastType_ is the most diff type before To=void");
180-
return lastType_; // eg Derive->Base->void = Base
181-
}
182-
else if (realType_ == typeid(To)) {
183-
HID("To->T->To, T.lastType is the most diff type");
184-
return lastType_; // eg Derive->Base->Derive = Base
185-
}
186-
else {
178+
if constexpr(!std::is_same_v<To, void>) {
179+
if (realType_ != typeid(To)) {
187180
HID("most diff type=" << typeid(To).name());
188181
return typeid(To); // eg Derive->Base = Base
182+
}
189183
}
184+
HID("T->void, or To->T->To, T.lastType_ is the most diff type");
185+
return lastType_; // eg Derive->Base->void = Base, Derive->Base->Derive = Base
190186
}
191187

192188

0 commit comments

Comments
 (0)