On Friday, 2 August 2013 at 13:47:06 UTC, Nicolas Sicard wrote:

String mixins are fun, but you could also use a more classic template:
---
void checkNonNull(alias var)() {
    if (var is null)
        throw new Exception(var.stringof ~ " cannot be null.");
}

void main() {
        string s;
        checkNonNull!s;
}
---

Or with file and line:
---
void checkNonNull(alias var)(string file = __FILE__, size_t line = __LINE__) {
    if (var is null)
throw new Exception(var.stringof ~ " cannot be null.", file, line);
}
---

Good point! Alias parameter for the win!

With this, there is simply no reason to use a mixin.

Reply via email to