Assert compilation failure with certain message

Andrej Mitrovic andrej.mitrovich at gmail.com
Thu Feb 10 16:51:05 PST 2011


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;
}


More information about the Digitalmars-d-learn mailing list