3 ms·
Would it be possible to have a static assert? In that case I would expect it to fail at compile time, not run time.
by Leherenn 5y ago
Would it be possible to have a static assert? In that case I would expect it to fail at compile time, not run time.
- WalterBright 5y agoYou can use static asserts if you turn the constructor into a template and pass the initializer into a compile time parameter.
- mhh__ 5y agoNo. If D had unlimited access to C code at CTFE then maybe you could implement refinement types at compile time as a library but for now you are stuck with what Walter has posted. I implemented a sketch of the API for this ages ago but the actual type checking had to be done at module load time because was of aforementioned (justified) restrictions to CTFE Dependant types are a whole other monster.