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-10163] simd.float4 loses Collection conformance in Swift 5 #52565

Open
an0 mannequin opened this issue Mar 24, 2019 · 3 comments
Open

[SR-10163] simd.float4 loses Collection conformance in Swift 5 #52565

an0 mannequin opened this issue Mar 24, 2019 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@an0
Copy link
Mannequin

an0 mannequin commented Mar 24, 2019

Previous ID SR-10163
Radar None
Original Reporter @an0
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: b787c775780c2d3314627404d774b34d

Issue Description:

simd.float4 and other similar simd types used to conform to `Collection` protocol but no longer do in Swift 5. So code like this stops compiling:

import simd

float4().map { $0 }
@stephentyrone
Copy link
Member

The conformance was removed as part of migrating these types into the standard library, because it doesn’t really make sense semantically. As a workaround, you can use the .indices property, which conforms to collection both before and after 5.0:

v.indices.map { v[$0] }

@stephentyrone
Copy link
Member

The dropping of Collection is not a bug, but we may want to consider adding Sequence conformance at some future point.

@benrimmington
Copy link
Collaborator

An alternative to the Sequence conformance might be:

extension SIMD {
  /// A random-access collection of scalars.
  public var elements: LazyMapCollection<Range<Int>, Scalar> {
    indices.lazy.map { self[$0] }
  }
}

@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
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

2 participants