Currently, I have two ComptimeStringMap
s, and based on different runtime conditions. So, I have a get_map
function, but I’m facing issues while writing the return type.
const ComptimeStringMap = @import("std").ComptimeStringMap;
const KV = struct {
@"0": []const u8,
@"1": u32,
};
const map1 = ComptimeStringMap(u32, [_]KV{
.{ .@"0" = "foo", .@"1" = 42 },
.{ .@"0" = "barbaz", .@"1" = 99 },
});
const map2 = ComptimeStringMap(u32, [_]KV{
.{ .@"0" = "foo", .@"1" = 42 },
.{ .@"0" = "barbaz", .@"1" = 99 },
});
fn get_map(cond: bool) ??? { // here
if (cond) {
return map1;
} else {
return map2;
}
}
I tried using @TypeOf
, but my function parameters are runtime values, so I can’t use that. Is there any way to solve this? Thanks.