@@ -432,21 +432,29 @@ public struct ${Self}<Pointee>
432
432
}
433
433
434
434
/// Returns the next consecutive position.
435
+ ///
436
+ /// - Precondition: The result is within the bounds of the same allocation.
435
437
public func successor( ) - > ${ Self} {
436
438
return self + 1
437
439
}
438
440
439
441
/// Returns the previous consecutive position.
442
+ ///
443
+ /// - Precondition: The result is within the bounds of the same allocation.
440
444
public func predecessor( ) - > ${ Self} {
441
445
return self - 1
442
446
}
443
447
444
448
/// Returns `end - self`.
445
- public func distance( to x: ${ Self} ) - > Int {
446
- return x - self
449
+ ///
450
+ /// - Precondition: The result is within the bounds of the same allocation.
451
+ public func distance( to end: ${ Self} ) - > Int {
452
+ return end - self
447
453
}
448
454
449
455
/// Returns `self + n`.
456
+ ///
457
+ /// - Precondition: The result is within the bounds of the same allocation.
450
458
public func advanced( by n: Int) - > ${ Self} {
451
459
return self + n
452
460
}
@@ -478,39 +486,43 @@ extension ${Self} : CustomPlaygroundQuickLookable {
478
486
}
479
487
}
480
488
481
- /// - Note: Strideable's implementation is potentially less efficient and cannot
482
- /// handle misaligned pointers.
489
+ // - Note: Strideable's implementation is potentially less efficient and cannot
490
+ // handle misaligned pointers.
483
491
@_transparent
484
492
public func == < Pointee> (
485
493
lhs: ${ Self} < Pointee> , rhs: ${ Self} < Pointee>
486
494
) - > Bool {
487
495
return Bool ( Builtin . cmp_eq_RawPointer ( lhs. _rawValue, rhs. _rawValue) )
488
496
}
489
497
490
- /// - Note: Strideable's implementation is potentially less efficient and cannot
491
- /// handle misaligned pointers.
492
- ///
493
- /// - Note: This is an unsigned comparison unlike Strideable's implementation.
498
+ // - Note: Strideable's implementation is potentially less efficient and cannot
499
+ // handle misaligned pointers.
500
+ //
501
+ // - Note: This is an unsigned comparison unlike Strideable's implementation.
494
502
@_transparent
495
503
public func < < Pointee> ( lhs: ${ Self} < Pointee> , rhs: ${ Self} < Pointee> ) - > Bool {
496
504
return Bool ( Builtin . cmp_ult_RawPointer ( lhs. _rawValue, rhs. _rawValue) )
497
505
}
498
506
499
- /// - Note: The following family of operator overloads are redundant
500
- /// with Strideable. However, optimizer improvements are needed
501
- /// before they can be removed without affecting performance.
507
+ // - Note: The following family of operator overloads are redundant
508
+ // with Strideable. However, optimizer improvements are needed
509
+ // before they can be removed without affecting performance.
510
+
511
+ /// - Precondition: The result is within bounds of the same allocation.
502
512
@_transparent
503
513
public func + < Pointee> ( lhs: ${ Self} < Pointee> , rhs: Int) - > ${ Self} < Pointee> {
504
514
return ${ Self} ( Builtin . gep_Word (
505
515
lhs. _rawValue, rhs. _builtinWordValue, Pointee . self) )
506
516
}
507
517
518
+ /// - Precondition: The result is within the bounds of the same allocation.
508
519
@_transparent
509
520
public func + < Pointee> ( lhs: Int,
510
521
rhs: ${ Self} < Pointee> ) - > ${ Self} < Pointee> {
511
522
return rhs + lhs
512
523
}
513
524
525
+ /// - Precondition: The result is within the bounds of the same allocation.
514
526
@_transparent
515
527
public func - < Pointee> ( lhs: ${ Self} < Pointee> , rhs: Int) - > ${ Self} < Pointee> {
516
528
return lhs + - rhs
@@ -524,11 +536,13 @@ public func - <Pointee>(lhs: ${Self}<Pointee>, rhs: ${Self}<Pointee>) -> Int {
524
536
/ MemoryLayout< Pointee> . stride
525
537
}
526
538
539
+ /// - Precondition: The result is within the bounds of the same allocation.
527
540
@_transparent
528
541
public func += < Pointee> ( lhs: inout ${ Self} < Pointee> , rhs: Int) {
529
542
lhs = lhs + rhs
530
543
}
531
544
545
+ /// - Precondition: The result is within the bounds of the same allocation.
532
546
@_transparent
533
547
public func -= < Pointee> ( lhs: inout ${ Self} < Pointee> , rhs: Int) {
534
548
lhs = lhs - rhs
0 commit comments