Skip to content

Instantly share code, notes, and snippets.

@nodefish
Created April 19, 2019 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nodefish/817927630113c3ed1a6d25ae8c47954b to your computer and use it in GitHub Desktop.
Save nodefish/817927630113c3ed1a6d25ae8c47954b to your computer and use it in GitHub Desktop.
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