On Wednesday, 24 December 2014 at 14:11:37 UTC, Adam D. Ruppe wrote:
auto check(alias func)(int x, string file = __FILE__, size_t line = __LINE__) {
    /* snip */
throw new Exception("%d < 0".format(result), file, line); // L10

Thanks! I guess that's what my confusion was partially about -- when exactly the __FILE__ and __LINE__ are substituted (particularly in the case when you're dealing with templates).

It looks like this would even work with generic callables:

auto check(alias func)(ParameterTypeTuple!(func) args, string __line__ = __LINE__, int __file__ == __FILE__) {
    static if (is(ReturnType!(func) == void))
        func(args);
    else {
        auto result = func(args);
        if (result < 0)
            throw new Exception("foo", __line__, __file__);
        return result;
    }
}

Reply via email to