digitalmars.D - link-time codegen assert?
A very minimal example: template ctfe(alias any) { alias ctfe = any; } double ms(double val) pure nothrow property { if(__ctfe) return val / 1000.0; else assert(false); } The above allows for writing... ctfe!(10.ms) ... which is in natural reading order as opposed to... ms!10 ... but one would have to guard against users accidentally writing... 10.ms ... which would be a catastrophic hidden performance bug. I was not able to find a way to use static assert only when there is code-generated for the function, so my question is. Do you see a generic need for a 3rd type of assert or can you find a way to solve the above issue in another way?
Oct 01 2013
On Tuesday, 1 October 2013 at 11:42:20 UTC, Tove wrote:A very minimal example: template ctfe(alias any) { alias ctfe = any; } double ms(double val) pure nothrow property { if(__ctfe) return val / 1000.0; else assert(false); }Turns out it was quite easy to solve... void link_assert() pure nothrow; link_assert();
Oct 01 2013