|
|
|
|
|
by listeria
452 days ago
|
|
I tried your example and got an error: error: type capture contains reference to comptime var
I'm not sure how you were suppossed to use it but here's my attempt: fn capitalize(tag: []u8) []u8 {
tag[0] &= 95;
return tag;
}
fn MyType(T: type, comptime tag: []u8, comptime count: usize) type {
const capitalized = capitalize(tag);
return struct {
fn name() []const u8 {
return capitalized;
}
array: [count]T,
};
}
pub fn main() void {
comptime var hello: [5]u8 = undefined;
@memcpy(&hello, "hello");
var v: MyType(i32, &hello, 10) = undefined;
v.name();
}
If you allow `capitalized` to be it's own instance then there's no reason to mutate the comptime parameter in the first place, and it can be replicated in C++17. |
|