Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile time assert in Swift?

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?

like image 359
Neil Avatar asked Jun 12 '14 05:06

Neil


People also ask

Is assert compile time?

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.

Is static assert 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.


1 Answers

This has been accepted into Swift as of version 4.2, here is the Swift evolution for the proposal.

like image 156
bscothern Avatar answered Oct 26 '22 06:10

bscothern