-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
These are just some examples, but it extends to any array that does not start at 0. Depending on the array and if 0 can be converted to the index type, they will have a bug at runtime or just will not compile.
import flatty
var
arr: array[-2..0, int]
arr2: array[10..11, int]
for i, x in arr.pairs:
arr[i] = i
for i, x in arr2.pairs:
arr2[i] = i
assert arr2.toFlatty().fromFlatty(array[10..11, int]) == [10, 11] # Compile time error
assert arr.toFlatty().fromFlatty(array[-2..0, int]) == [-2, -1, 0] # Runtime bugPerhaps instead of your present api you may want to consider
proc toFlatty*[T](s: var string, x: openarray[T]) =
when T.supportsMemCopy:
# Copy to
else:
for val in x:
s.toFlatty(val)
proc toFlatty*[N, T](s: var string, x: array[N, T]) =
s.toFlatty(x.toOpenArray(0, x.len - 1))
proc toFlatty*[T](s: var string, x: seq[T]) =
if x.len > 0:
s.toFlatty x.len
s.toFlatty(x.toOpenArray(0, x.len - 1))
Metadata
Metadata
Assignees
Labels
No labels