@@ -873,6 +873,13 @@ extension ${Self} : CustomPlaygroundQuickLookable {
873
873
extension ${ Self} {
874
874
// - Note: Strideable's implementation is potentially less efficient and cannot
875
875
// handle misaligned pointers.
876
+ /// Returns a Boolean value indicating whether two pointers are equal.
877
+ ///
878
+ /// - Parameters:
879
+ /// - lhs: A pointer.
880
+ /// - rhs: Another pointer.
881
+ /// - Returns: `true` if `lhs` and `rhs` reference the same memory address;
882
+ /// otherwise, `false`.
876
883
@_transparent
877
884
public static func == ( lhs: ${ Self} < Pointee> , rhs: ${ Self} < Pointee> ) -> Bool {
878
885
return Bool ( Builtin . cmp_eq_RawPointer ( lhs. _rawValue, rhs. _rawValue) )
@@ -882,6 +889,14 @@ extension ${Self} {
882
889
// cannot handle misaligned pointers.
883
890
//
884
891
// - Note: This is an unsigned comparison unlike Strideable's implementation.
892
+ /// Returns a Boolean value indicating whether the first pointer references
893
+ /// an earlier memory location than the second pointer.
894
+ ///
895
+ /// - Parameters:
896
+ /// - lhs: A pointer.
897
+ /// - rhs: Another pointer.
898
+ /// - Returns: `true` if `lhs` references a memory address earlier than
899
+ /// `rhs`; otherwise, `false`.
885
900
@_transparent
886
901
public static func < ( lhs: ${ Self} < Pointee> , rhs: ${ Self} < Pointee> ) -> Bool {
887
902
return Bool ( Builtin . cmp_ult_RawPointer ( lhs. _rawValue, rhs. _rawValue) )
@@ -891,25 +906,78 @@ extension ${Self} {
891
906
// with Strideable. However, optimizer improvements are needed
892
907
// before they can be removed without affecting performance.
893
908
894
- /// - Precondition: The result is within bounds of the same allocation.
909
+ /// Creates a new pointer, offset from a pointer by a specified number of
910
+ /// instances of the pointer's `Pointee` type.
911
+ ///
912
+ /// You use the addition operator (`+`) to advance a pointer by a number of
913
+ /// contiguous instances. The resulting pointer must be within the bounds of
914
+ /// the same allocation as `lhs`.
915
+ ///
916
+ /// - Parameters:
917
+ /// - lhs: A pointer.
918
+ /// - rhs: The number of strides of the pointer's `Pointee` type to offset
919
+ /// `lhs`. To access the stride, use `MemoryLayout<Pointee>.stride`.
920
+ /// - Returns: A pointer offset from `lhs` by `rhs` instances of the
921
+ /// `Pointee` type.
922
+ ///
923
+ /// - SeeAlso: `MemoryLayout`
895
924
@_transparent
896
925
public static func + ( lhs: ${ Self} < Pointee> , rhs: Int) -> ${ Self} < Pointee> {
897
926
return ${ Self} ( Builtin. gep_Word(
898
927
lhs. _rawValue, rhs. _builtinWordValue, Pointee . self) )
899
928
}
900
929
901
- /// - Precondition: The result is within the bounds of the same allocation.
930
+ /// Creates a new pointer, offset from a pointer by a specified number of
931
+ /// instances of the pointer's `Pointee` type.
932
+ ///
933
+ /// You use the addition operator (`+`) to advance a pointer by a number of
934
+ /// contiguous instances. The resulting pointer must be within the bounds of
935
+ /// the same allocation as `rhs`.
936
+ ///
937
+ /// - Parameters:
938
+ /// - lhs: The number of strides of the pointer's `Pointee` type to offset
939
+ /// `rhs`. To access the stride, use `MemoryLayout<Pointee>.stride`.
940
+ /// - rhs: A pointer.
941
+ /// - Returns: A pointer offset from `rhs` by `lhs` instances of the
942
+ /// `Pointee` type.
943
+ ///
944
+ /// - SeeAlso: `MemoryLayout`
902
945
@_transparent
903
946
public static func + ( lhs: Int, rhs: ${ Self} < Pointee> ) - > ${ Self} < Pointee> {
904
947
return rhs + lhs
905
948
}
906
949
907
- /// - Precondition: The result is within the bounds of the same allocation.
950
+ /// Creates a new pointer, offset backward from a pointer by a specified
951
+ /// number of instances of the pointer's `Pointee` type.
952
+ ///
953
+ /// You use the subtraction operator (`-`) to shift a pointer backward by a
954
+ /// number of contiguous instances. The resulting pointer must be within the
955
+ /// bounds of the same allocation as `lhs`.
956
+ ///
957
+ /// - Parameters:
958
+ /// - lhs: A pointer.
959
+ /// - rhs: The number of strides of the pointer's `Pointee` type to offset
960
+ /// `lhs`. To access the stride, use `MemoryLayout<Pointee>.stride`.
961
+ /// - Returns: A pointer offset backward from `lhs` by `rhs` instances of
962
+ /// the `Pointee` type.
963
+ ///
964
+ /// - SeeAlso: `MemoryLayout`
908
965
@_transparent
909
966
public static func - ( lhs: ${ Self} < Pointee> , rhs: Int) - > ${ Self} < Pointee> {
910
967
return lhs + - rhs
911
968
}
912
969
970
+ /// Returns the distance between two pointers, counted as instances of the
971
+ /// pointers' `Pointee` type.
972
+ ///
973
+ /// - Parameters:
974
+ /// - lhs: A pointer.
975
+ /// - rhs: Another pointer.
976
+ /// - Returns: The distance from `lhs` to `rhs`, in strides of the pointer's
977
+ /// `Pointee` type. To access the stride, use
978
+ /// `MemoryLayout<Pointee>.stride`.
979
+ ///
980
+ /// - SeeAlso: `MemoryLayout`
913
981
@_transparent
914
982
public static func - ( lhs: ${ Self} < Pointee> , rhs: ${ Self} < Pointee> ) - > Int {
915
983
return
@@ -918,13 +986,37 @@ extension ${Self} {
918
986
/ MemoryLayout< Pointee> . stride
919
987
}
920
988
921
- /// - Precondition: The result is within the bounds of the same allocation.
989
+ /// Advances a pointer by a specified number of instances of the pointer's
990
+ /// `Pointee` type.
991
+ ///
992
+ /// You use the addition assignment operator (`+=`) to advance a pointer by a
993
+ /// number of contiguous instances. The resulting pointer must be within the
994
+ /// bounds of the same allocation as `rhs`.
995
+ ///
996
+ /// - Parameters:
997
+ /// - lhs: A pointer to advance in place.
998
+ /// - rhs: The number of strides of the pointer's `Pointee` type to offset
999
+ /// `lhs`. To access the stride, use `MemoryLayout<Pointee>.stride`.
1000
+ ///
1001
+ /// - SeeAlso: `MemoryLayout`
922
1002
@_transparent
923
1003
public static func += ( lhs: inout ${ Self} < Pointee> , rhs: Int) {
924
1004
lhs = lhs + rhs
925
1005
}
926
1006
927
- /// - Precondition: The result is within the bounds of the same allocation.
1007
+ /// Shifts a pointer backward by a specified number of instances of the
1008
+ /// pointer's `Pointee` type.
1009
+ ///
1010
+ /// You use the subtraction assignment operator (`-=`) to shift a pointer
1011
+ /// backward by a number of contiguous instances. The resulting pointer must
1012
+ /// be within the bounds of the same allocation as `rhs`.
1013
+ ///
1014
+ /// - Parameters:
1015
+ /// - lhs: A pointer to advance in place.
1016
+ /// - rhs: The number of strides of the pointer's `Pointee` type to offset
1017
+ /// `lhs`. To access the stride, use `MemoryLayout<Pointee>.stride`.
1018
+ ///
1019
+ /// - SeeAlso: `MemoryLayout`
928
1020
@_transparent
929
1021
public static func -= ( lhs: inout ${ Self} < Pointee> , rhs: Int) {
930
1022
lhs = lhs - rhs
0 commit comments