You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It turns out there is an exception to the orphan rule that we can exploit to make QHash<K,V> work that we didn't think of before.
Basically, whilst you generally cannot implement a foreign trait for a foreign type, you can actually do so, if the trait is templated and one of the template arguments is a local type!
So if we make the QHashPair trait templated over the Key and the Value, we can actually make this work:
because MyType is a local type, this is possible, even if the target type and trait are coming from cxx_qt_lib.
Backwards compatibility
The most problematic part of this refactoring is backwards-compatibility.
Our current tutorial videos already show QHash<QHashPair_K_V> and we want to keep those tutorials working as much as possible.
We may be able to solve this issue by using default type paramters, e.g. by setting V=(), we would allow users to use a QHashPair_K_V as the Key whilst leaving the value blank.
Because all behavior in the end is delegated to the trait anyway, we can implement QHashPair<QHashPair_K_V, ()>, while also adding a deprecation notice to the QHashPair_K_V.
Note that we likely want to remove this entirely for the final 1.0 release, as this solution is likely to require some contortion on the implementation of QHash.
The text was updated successfully, but these errors were encountered:
Idea
It turns out there is an exception to the orphan rule that we can exploit to make
QHash<K,V>
work that we didn't think of before.Basically, whilst you generally cannot implement a foreign trait for a foreign type, you can actually do so, if the trait is templated and one of the template arguments is a local type!
So if we make the QHashPair trait templated over the Key and the Value, we can actually make this work:
It would then be possible for users to:
because
MyType
is a local type, this is possible, even if the target type and trait are coming from cxx_qt_lib.Backwards compatibility
The most problematic part of this refactoring is backwards-compatibility.
Our current tutorial videos already show
QHash<QHashPair_K_V>
and we want to keep those tutorials working as much as possible.We may be able to solve this issue by using default type paramters, e.g. by setting
V=()
, we would allow users to use a QHashPair_K_V as theKey
whilst leaving the value blank.Because all behavior in the end is delegated to the trait anyway, we can implement
QHashPair<QHashPair_K_V, ()>
, while also adding a deprecation notice to theQHashPair_K_V
.Note that we likely want to remove this entirely for the final 1.0 release, as this solution is likely to require some contortion on the implementation of QHash.
The text was updated successfully, but these errors were encountered: