Skip to content

Commit 9171737

Browse files
committed
SafePtr: clean code
1 parent 6c0b59b commit 9171737

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

src/safe_mem/SafePtr.hpp

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,7 @@ template<class T> class SafePtr
3838
SafePtr() = default;
3939

4040
// any <-> void
41-
template<class From> SafePtr(const SafePtr<From>& aSafeFrom)
42-
: pT_(aSafeFrom.template get<T>())
43-
{
44-
HID(typeid(From).name() << " to " << typeid(T).name());
45-
if (! pT_)
46-
{
47-
HID("pT_ == nullptr"); // HID: ut debug only
48-
return;
49-
}
50-
realType_ = aSafeFrom.realType();
51-
if (! is_same<T, void>::value)
52-
{
53-
HID("not to void");
54-
return;
55-
}
56-
if (! is_same<From, void>::value)
57-
{
58-
HID("not from void");
59-
preVoidType_ = &typeid(From);
60-
}
61-
}
41+
template<class From> SafePtr(const SafePtr<From>&);
6242

6343
template<typename To> shared_ptr<To> get() const;
6444
shared_ptr<void> get() const;
@@ -73,6 +53,31 @@ template<class T> class SafePtr
7353
const type_info* realType_ = &typeid(T); // that pT_ point to, can safely cast to
7454
};
7555

56+
// ***********************************************************************************************
57+
template<class T>
58+
template<class From>
59+
SafePtr<T>::SafePtr(const SafePtr<From>& aSafeFrom)
60+
: pT_(aSafeFrom.template get<T>())
61+
{
62+
HID(typeid(From).name() << " to " << typeid(T).name());
63+
if (! pT_)
64+
{
65+
HID("pT_ == nullptr"); // HID: ut debug only
66+
return;
67+
}
68+
realType_ = aSafeFrom.realType();
69+
if (! is_same<T, void>::value)
70+
{
71+
HID("not to void");
72+
return;
73+
}
74+
if (! is_same<From, void>::value)
75+
{
76+
HID("not from void");
77+
preVoidType_ = &typeid(From);
78+
}
79+
}
80+
7681
// ***********************************************************************************************
7782
template<class T>
7883
template<class To>

0 commit comments

Comments
 (0)