~Copyable and functions

Here, transform expects T to be copyable. You have to declare it explicitly as ~Copyable for T to accept a non-copyable type:

func transform<T: ~Copyable>(_ f: @escaping (T) -> T ) -> (consuming T) -> T {
    { t in f(t) }
}

This feature is not ready and not in any release yet however. There is a pitch, but no evolution proposal yet. Try a nightly build with flags -enable-experimental-feature NoncopyableGenerics if you want to play with it. You can also try with godbolt.

3 Likes