What's the accepted way of doing something like this? The current code is a bit too verbose for my liking.
I've read about (decl literals)[https://github.com/ziglang/zig/issues/9938] but it seems those are stuck in limbo for perpetuity.
#Concise way to instantiate generic types?
1 messages · Page 1 of 1 (latest)
std.AutoHashMap(vector.Vector3, section.Section).init(std.heap.page_allocator).
You could only make it shorter by using an unmanaged hashmap (no allocator; can use T{} syntax to init it), or shorten the names with things like const V3 = vector.Vector3;

thanks, I think i'll just do the name shortening stuff, shame it all has to be typed out manually
I will just point out: std.hash_map.AutoHashMap -> std.AutoHashMap
and also, you oculd just shorten the generic type name itself:
sections: SectionsMap,
const SectionsMap = std.AutoHashMap(vector.Vector3, section.Section);
pub fn new() World {
return .{
.sections = SectionsMap.init(...),
};
}
besides that, I would recommend against using std.heap.page_allocator directly, unless you want to have very slow code
rather you should accept an allocator: std.mem.Allocator parameter