-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
Description
Introduction
Swift 5.9 (SE-0377) introduces borrowing and consuming parameter ownership modifiers.
An immediate use case
I'm working on some utility methods with the following inout convention:
@inlinable public static func incrementSufficientUnsignedInteger<T>(
_ pointee: inout T, by digit: T.Element, plus bit: inout Bool, at index: inout T.Index)
where T: MutableCollection, T.Element: NBKFixedWidthInteger & NBKUnsignedInteger { ... }These are used instead of the much more ergonomic return convention:
@inlinable public static func incrementSufficientUnsignedInteger<T>(
_ pointee: inout T, by digit: T.Element, plus bit: Bool, at index: T.Index) -> (index: T.Index, overflow: Bool)
where T: MutableCollection, T.Element: NBKFixedWidthInteger & NBKUnsignedInteger { ... }I've tried every reasonable combination of attributes, but can't make it perform as well as the inout version. I assume this is related to parameter ownership, and that I want to consume the arguments. I'm not sure this is the solution, but I hope so:
@inlinable public static func incrementSufficientUnsignedInteger<T>(
_ pointee: inout T, by digit: consuming T.Element, plus bit: consuming Bool, at index: consuming T.Index) -> (index: T.Index, overflow: Bool)
where T: MutableCollection, T.Element: NBKFixedWidthInteger & NBKUnsignedInteger { ... }lin72h