Is it possible to determine if the result of a function can be determined at comptime, here is some code where it would be useful
const builtin = @import("builtin");
extern fn systemGetHandle() u64;
extern fn useHandle(handle: u64) u64;
fn getHandle() u64 {
return if (builtin.os.tag == .windows) systemGetHandle() else 1;
}
const handle_comptime_known = builtin.os.tag != .windows;
pub const Wrapper = struct {
handle: if (handle_comptime_known) void else u64,
const Self = @This();
pub fn init() Self {
if (!handle_comptime_known) {
return .{.handle = getHandle()};
} else {
return .{.handle = {}};
}
}
pub fn action(self: Self) u64 {
if (!handle_comptime_known) {
return useHandle(self.handle);
} else {
return useHandle(comptime getHandle());
}
}
};
I would like to make handle_comptime_known not be dependent on the internal logic of getHandle(), such as the case where it is provided by a library.