Created
August 7, 2013 21:54
-
-
Save nikibobi/6179134 to your computer and use it in GitHub Desktop.
argnull.d
This file contains hidden or 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
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