Assert compilation failure with certain message
Tomek Sowiński
just at ask.me
Fri Feb 11 12:06:30 PST 2011
Andrej Mitrovic napisał:
> I've managed to screw up the colon placement though, here's a quick fix:
>
> import std.stdio;
> import std.conv;
>
> void staticAssert(alias exp, string message, string file = __FILE__,
> int line = __LINE__)()
> {
> static if (!exp)
> {
> pragma(msg, file ~ "(" ~ to!string(line) ~ "): " ~
> "staticAssert: " ~ to!string(message));
> assert(0);
> }
> }
>
> void main()
> {
> enum x = false;
> staticAssert!(x, "Oh no we failed!");
>
> int y;
> }
How does it help to find out that compilation tripped on a specific static assertion?
--
Tomek
More information about the Digitalmars-d-learn
mailing list