Skip to content

Commit

Permalink
Fix unnecessary template bloat in enforce.
Browse files Browse the repository at this point in the history
The version of enforce which takes the file and line number as template
arguments has been scheduled for deprecation and has been replaced with
one which takes them as function arguments. The only code that this will
effect is code which explicitly passes the file or line number to
enforce.
  • Loading branch information
jmdavis committed Jul 22, 2012
1 parent 17ba4bb commit 6c289a8
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__)

This comment has been minimized.

Copy link
@MartinNowak

MartinNowak Jul 23, 2012

Member

This is missing the default, it should read string file = __FILE__.

This comment has been minimized.

Copy link
@jmdavis

jmdavis Jul 23, 2012

Author Member

Nope. It's correct. It's missing it on purpose. If it had it, it would conflict with the new overload. The only reason that the old overload is still there is for the folks who pass the file (and possibly line number) explicitly. If they're doing that, then they don't need the default for file here, and those who use the defaults automatically get the new version.

This comment has been minimized.

Copy link
@MartinNowak

MartinNowak Jul 24, 2012

Member

Ah right.

(T value, lazy const(char)[] msg = null) @safe pure
{
if (!value) bailOut(file, line, msg);
Expand Down

0 comments on commit 6c289a8

Please sign in to comment.