Is it possible to concoct a compile time assert in Swift like static_assert in C++? Maybe some way to exploit type constraints on generics to force a compiler break?
assert(f != must be done at run time. However, an assertion that tests the value of a constant expression, such as the size or offset of a structure member, can be done at compile time.
The _Static_assert keyword, and the static_assert macro, both test a software assertion at compile time. They can be used at global or function scope. In contrast, the assert macro and _assert and _wassert functions test a software assertion at runtime and incur a runtime cost.
This has been accepted into Swift as of version 4.2, here is the Swift evolution for the proposal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With