File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,12 @@ class MaybeOwned {
32
32
MaybeOwned (MaybeOwned&&) = default ;
33
33
MaybeOwned& operator =(MaybeOwned&&) = default ;
34
34
35
+ template <DerivedFrom<T> U>
36
+ MaybeOwned (MaybeOwned<U>&& other)
37
+ : m_handle(downcast<U, T>(move(other.m_handle)))
38
+ {
39
+ }
40
+
35
41
T* ptr ()
36
42
{
37
43
if (m_handle.template has <T*>())
@@ -57,7 +63,22 @@ class MaybeOwned {
57
63
bool is_owned () const { return m_handle.template has <NonnullOwnPtr<T>>(); }
58
64
59
65
private:
60
- Variant<NonnullOwnPtr<T>, T*> m_handle;
66
+ template <typename F>
67
+ friend class MaybeOwned ;
68
+
69
+ template <typename HT>
70
+ using Handle = Variant<NonnullOwnPtr<HT>, HT*>;
71
+
72
+ template <typename U, typename D>
73
+ Handle<D> downcast (Handle<U>&& variant)
74
+ {
75
+ if (variant.template has <U*>())
76
+ return variant.template get <U*>();
77
+ else
78
+ return static_cast <NonnullOwnPtr<T>&&>(move (variant.template get <NonnullOwnPtr<U>>()));
79
+ }
80
+
81
+ Handle<T> m_handle;
61
82
};
62
83
63
84
}
You can’t perform that action at this time.
0 commit comments