Is there a way to check for some program-ending condition at compile time, assuming the parts of the calculation can also be evaluated at compile time. For my example, I need two unsigned integer types where one has a bit-width that is a positive multiple of the other's width.
Hi CTMacUser,
Can you provide a (pseudo) code example of what you are looking for?
KR Maarten
I want to compare my struct’s two generic arguments, which are both fixed-width unsigned integer types. I guess I’d put the check in the “designated” initializer(s), instead of somehow sitting directly in the definition block.
There was an experimental #assert()
in the compiler (which is one of the reasons why Swift Testing uses #expect()
instead, by the way) but it's been removed I think. To implement this feature correctly would presumably require @const
.