Extracted from #4752.
The only meaningful difference between slices and single-item-pointer-to-array is that in the latter case, the length is compile-time known. Just like slices, arrays already have a len property, which works even through a single-pointer-to-array. Should pointer-to-array also gain a ptr property to match, which gives the pointer as an unknown length pointer?
The main use case for this would be generic code.
const std = @import("std");
test ".ptr property to single-pointer-to-array which decays it into [*]" {
var array: [10]u8 = undefined;
const array_ptr = &array;
const ptr = array_ptr.ptr;
std.testing.expect(@TypeOf(ptr) == [*]u8);
}
Status quo:
./test2.zig:6:26: error: no member named 'ptr' in '*[10]u8'
const ptr = array_ptr.ptr;
^
With this proposal implemented, it would pass.
Extracted from #4752.
The only meaningful difference between slices and single-item-pointer-to-array is that in the latter case, the length is compile-time known. Just like slices, arrays already have a
lenproperty, which works even through a single-pointer-to-array. Should pointer-to-array also gain aptrproperty to match, which gives the pointer as an unknown length pointer?The main use case for this would be generic code.
Status quo:
With this proposal implemented, it would pass.