Skip to content

Instantly share code, notes, and snippets.

@sinfu
Created August 9, 2010 17:15
Show Gist options
  • Save sinfu/515732 to your computer and use it in GitHub Desktop.
Save sinfu/515732 to your computer and use it in GitHub Desktop.
赤い pragma(msg)
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