-
-
Save nodefish/817927630113c3ed1a6d25ae8c47954b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const mem = std.mem; | |
const X: usize = 100; | |
fn isConstDefined(name: []const u8) bool { | |
const type_info = @typeInfo(@This()); | |
inline for (type_info.Struct.defs) |def| { | |
if (mem.eql(u8, def.name, name)) { | |
return true; | |
} | |
} | |
return false; | |
} | |
test "defs" { | |
std.debug.warn("\nIs X defined? {}\n", isConstDefined("X")); | |
std.debug.warn("\nIs Y defined? {}\n", isConstDefined("Y")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment