[stdlib] Add CT @in Macro/Builtin (#2662)

* [stdlib] Add CT `@in` Macro/Builtin
This commit is contained in:
Zack Puhl
2025-12-19 09:55:20 -05:00
committed by GitHub
parent dec49b05b8
commit 9aec5de105
3 changed files with 26 additions and 0 deletions

View File

@@ -93,6 +93,21 @@ macro usz bitsizeof($Type) @builtin @const => $Type.sizeof * 8u;
macro usz @bitsizeof(#expr) @builtin @const => $sizeof(#expr) * 8u;
<*
Compile-time check for whether a set of constants contains a certain expression.
@param #needle : "The expression whose value should be located."
*>
macro bool @in(#needle, ...) @builtin @const
{
$for var $x = 0; $x < $vacount; $x++:
$assert $defined(#needle == $vaconst[$x])
: "Index %s: types '%s' (needle) and '%s' are not equatable", $x, $typeof(#needle), $typeof($vaconst[$x]);
$if #needle == $vaconst[$x]: return true; $endif
$endfor
return false;
}
<*
Convert an `any` type to a type, returning an failure if there is a type mismatch.