Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-5048] Tuples of homogenous contents should adopt a common protocol #47624

Open
phausler opened this issue May 30, 2017 · 1 comment
Open
Labels
compiler The Swift compiler in itself feature A feature request or implementation improvement

Comments

@phausler
Copy link
Member

Previous ID SR-5048
Radar None
Original Reporter @phausler
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, LanguageFeatureRequest
Assignee None
Priority Medium

md5: 8a8c9b3d5187913c99e7f1d321f78f13

relates to:

  • SR-4548 Swift needs a fixed-size array
  • SR-4929 Support non-inout homogeneous tuple argument conversion to UnsafePointer

Issue Description:

In many cases it would be more efficient to initialize a Data with a tuple of values. However there is no way to generically implement this.

e.g.

Data(bytes: (0x0f, 0x01))
Data(bytes: (0x0f, 0x01, 0x02))

to implement this with current implementations would mean that Data would have to have overloads for every single number of tuple element counts (which I would imagine would be expensive in terms of binary size).

So imagine a protocol as such:

protocol HomogenousTuple {
associatedtype Element
}

so a tuple as such:

(UInt8, UInt8, UInt8)

would adopt by compiler emission the protocol HomogenousTuple with the associated type Element as UInt8

This means that Data could adopt it as such:

extension Data {
public init<Tuple: HomogenousTuple>(bytes: Tuple) where Tuple.Element == UInt8 {
...
}
}

@belkadan
Copy link
Contributor

I suspect this is part of a bigger conversation about tuples and fixed-sized arrays.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself feature A feature request or implementation improvement
Projects
None yet
Development

No branches or pull requests

2 participants