Skip to content

Instantly share code, notes, and snippets.

@nikibobi
Created August 7, 2013 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikibobi/6179134 to your computer and use it in GitHub Desktop.
Save nikibobi/6179134 to your computer and use it in GitHub Desktop.
argnull.d
import std.string : format;
///Use with mixins. mixin(ArgNull!<arg>);
template ArgNull(alias argument) {
enum ArgNull = format(
"if(%1$s is null)
throw new Exception(\"%1$s cannot be null.\");", argument.stringof);
}
unittest {
import std.exception;
void func(string str) {
mixin(ArgNull!str);
}
assertThrown(func(null));
assertNotThrown(func("test"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment