Skip to content

Commit

Permalink
Merge pull request dlang#709 from jmdavis/enforce
Browse files Browse the repository at this point in the history
Fix unnecessary template bloat in enforce.
  • Loading branch information
jmdavis committed Jul 22, 2012
2 parents 17ba4bb + 6c289a8 commit 304d94f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion std/exception.d
Expand Up @@ -333,6 +333,7 @@ unittest
}
}


/++
If $(D !!value) is true, $(D value) is returned. Otherwise,
$(D new Exception(msg)) is thrown.
Expand All @@ -352,7 +353,19 @@ auto line = readln(f);
enforce(line.length, "Expected a non-empty line.");
--------------------
+/
T enforce(T, string file = __FILE__, size_t line = __LINE__)
T enforce(T)(T value, lazy const(char)[] msg = null, string file = __FILE__, size_t line = __LINE__) @safe pure
{
if (!value) bailOut(file, line, msg);
return value;
}

/++
$(RED Scheduled for deprecation in January 2013. If passing the file or line
number explicitly, please use the version of enforce which takes them as
function arguments. Taking them as template arguments causes
unnecessary template bloat.)
+/
T enforce(T, string file, size_t line = __LINE__)
(T value, lazy const(char)[] msg = null) @safe pure
{
if (!value) bailOut(file, line, msg);
Expand Down

0 comments on commit 304d94f

Please sign in to comment.