-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
Description
I propose that if you have a type T=struct{foo: U} and slice []T, accessing a slice with a field ([]T.foo) returns a slice []U with stride @sizeOf(T).
Example use case:
const entry = struct {
key: []const u8,
value: []u8,
}
const entrylist = std.ArrayList(entry);
fn getKeys(self: entrylist) [][]const u8 {
return self.toSlice().key; // returns slice with stride equal to @sizeOf(entry)
}
fn getKeyList(self: entrylist, allocator: *Allocator) []u8 {
return std.mem.join(allocator, ",", self.getKeys());
}
fn getValues(self: entrylist) [][]const u8 {
return self.toSlice().value; // returns slice with stride equal to @sizeOf(entry)
}
fn getValueList(self: entrylist, allocator: *Allocator) []u8 {
return std.mem.join(allocator, ",", self.getValues());
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.