Skip to content

Commit 8de33b4

Browse files
author
Max Moiseev
committed
Overloads for +/- on Strideable for Swift 3 compatibility mode
1 parent 54e5f5d commit 8de33b4

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

stdlib/public/core/Stride.swift.gyb

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,47 +77,45 @@ public func == <T : Strideable>(x: T, y: T) -> Bool {
7777
# types, and was deprecated, as it was a way to write mixed-type arithmetic
7878
# expressions, that are otherwise are not allowed.
7979
}%
80-
% for Requirement, VersionInfo in [
81-
% ('Self : _Pointer', None),
82-
% #('Self : SignedInteger', 'deprecated: 3.1, obsoleted: 4.0'),
83-
% #('Stride : ExpressibleByIntegerLiteral', 'obsoleted: 4.0'),
80+
% for Base, VersionInfo in [
81+
% ('Strideable where Self : _Pointer', None),
82+
% ('Strideable where Stride : SignedNumeric', 'deprecated: 3, obsoleted: 4'),
8483
% ]:
85-
% unavailable = 'Self : SignedInteger' == Requirement
86-
% Availability = (lambda what: '@available(swift, %s, message: "Mixed-type %s is deprecated. Please use explicit type conversion.")' % (VersionInfo, what)) if unavailable else (lambda _: '')
84+
% Availability = '@available(swift, %s, message: "Please use explicit type conversions or Strideable methods for mixed-type arithmetics.")' % (VersionInfo) if VersionInfo else ''
8785

88-
extension Strideable where ${Requirement} {
86+
extension ${Base} {
8987
@_transparent
90-
${Availability('addition')}
88+
${Availability}
9189
public static func + (lhs: Self, rhs: Self.Stride) -> Self {
9290
return lhs.advanced(by: rhs)
9391
}
9492

9593
@_transparent
96-
${Availability('addition')}
94+
${Availability}
9795
public static func + (lhs: Self.Stride, rhs: Self) -> Self {
9896
return rhs.advanced(by: lhs)
9997
}
10098

10199
@_transparent
102-
${Availability('subtraction')}
100+
${Availability}
103101
public static func - (lhs: Self, rhs: Self.Stride) -> Self {
104102
return lhs.advanced(by: -rhs)
105103
}
106104

107105
@_transparent
108-
${Availability('subtraction')}
106+
${Availability}
109107
public static func - (lhs: Self, rhs: Self) -> Self.Stride {
110108
return rhs.distance(to: lhs)
111109
}
112110

113111
@_transparent
114-
${Availability('addition')}
112+
${Availability}
115113
public static func += (lhs: inout Self, rhs: Self.Stride) {
116114
lhs = lhs.advanced(by: rhs)
117115
}
118116

119117
@_transparent
120-
${Availability('subtraction')}
118+
${Availability}
121119
public static func -= (lhs: inout Self, rhs: Self.Stride) {
122120
lhs = lhs.advanced(by: -rhs)
123121
}

0 commit comments

Comments
 (0)