Created
August 9, 2010 17:15
-
-
Save sinfu/515732 to your computer and use it in GitHub Desktop.
赤い pragma(msg)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum int a = ensureNonNegative!(+42); // ok | |
enum int b = ensureNonNegative!(-42); // error! | |
template ensureNonNegative(int i) | |
{ | |
static if (i < 0) | |
mixin error!("Aiiieeeeeeeeeee! i=", i); | |
else | |
enum int ensureNonNegative = i; | |
} | |
//----------------------------------------------------------------------------// | |
template error(irritants...) | |
{ | |
mixin(function | |
{ | |
string ctex; | |
ctex ~= `"\u001B[1;31m", `; | |
{ | |
string idx = "0"; | |
foreach (i; 0 .. irritants.length) | |
{ | |
ctex ~= "irritants[" ~ idx ~ "], "; | |
idx ~= "+1"; | |
} | |
} | |
ctex ~= `"\u001B[m"`; | |
return "pragma(msg, " ~ ctex ~ ");"; | |
}()); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment