I find this solution (and its syntax) very elegant. Much more than @retroactive
. In short:
~Copyable
assumes type is not copyable unless you addwhere T: Copyable
?Copyable
assumes type is copyable unless you addwhere T: ~Copyable
I'll note that the later only makes sense for types with conditional conformance (in addition to protocols). It'd probably be best to make ?Copyable
an error for types declarations that don't have a conditional conformance to Copyable
.
And with this in mind, perhaps ?Copyable
could be used to declare conditional conformances too. For instance, we could consider all the ?Copyable
in a generic type declaration to be "linked together":
struct Array<Element: ?Copyable>: ?Copyable {}
// or:
struct Array<Element>: ?Copyable
where Element: ?Copyable {}
Since the two ?Copyable
in the declaration are linked together, Array
becomes copyable when its element is. This eliminates the need for a separate conditional conformance declaration (as long as we want our type to be "assumed copyable" by default).
If you don't want them to be linked, use ~Copyable
.