Skip to content

[4.2] Add constraints to FixedWidthInteger.Stride and .Magnitude (#17716) #17766

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stdlib/public/SDK/Foundation/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
}

public subscript<R: RangeExpression>(_ rangeExpression: R) -> Data
where R.Bound: FixedWidthInteger, R.Bound.Stride : SignedInteger {
where R.Bound: FixedWidthInteger {
get {
let lower = R.Bound(_sliceRange.lowerBound)
let upper = R.Bound(_sliceRange.upperBound)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SDK/Foundation/NSRange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ extension NSRange {

extension NSRange {
public init<R: RangeExpression>(_ region: R)
where R.Bound: FixedWidthInteger, R.Bound.Stride : SignedInteger {
where R.Bound: FixedWidthInteger {
let r = region.relative(to: 0..<R.Bound.max)
self.init(location: numericCast(r.lowerBound), length: numericCast(r.count))
}
Expand Down
4 changes: 1 addition & 3 deletions stdlib/public/core/FloatingPoint.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -2398,9 +2398,7 @@ extension BinaryFloatingPoint {
% for Range in ['Range', 'ClosedRange']:
% exampleRange = '10.0..<20.0' if Range == 'Range' else '10.0...20.0'
extension BinaryFloatingPoint
where Self.RawSignificand : FixedWidthInteger,
Self.RawSignificand.Stride : SignedInteger,
Self.RawSignificand.Magnitude : UnsignedInteger {
where Self.RawSignificand : FixedWidthInteger {

/// Returns a random value within the specified range, using the given
/// generator as a source for randomness.
Expand Down
7 changes: 3 additions & 4 deletions stdlib/public/core/Integers.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -2271,7 +2271,8 @@ extension BinaryInteger {
/// other arithmetic methods and operators.
public protocol FixedWidthInteger :
BinaryInteger, LosslessStringConvertible, _BitwiseOperations
where Magnitude : FixedWidthInteger
where Magnitude : FixedWidthInteger & UnsignedInteger,
Stride : FixedWidthInteger & SignedInteger
{
/// The number of bits used for the underlying binary representation of
/// values of this type.
Expand Down Expand Up @@ -2540,9 +2541,7 @@ ${assignmentOperatorComment(x.operator, False)}
% for Range in ['Range', 'ClosedRange']:
% exampleRange = '1..<100' if Range == 'Range' else '1...100'

extension FixedWidthInteger
where Self.Stride : SignedInteger,
Self.Magnitude : UnsignedInteger {
extension FixedWidthInteger {

/// Returns a random value within the specified range, using the given
/// generator as a source for randomness.
Expand Down