Made most of the overloads for enforce @safe.

The delegate version isn't @safe, but that would require conditional
attributes and/or multiple overloads where the delegate is @safe,
@trusted, or @system. I'm not quite sure what it would take, so I'm
leaving it alone for now.
This commit is contained in:
jmdavis 2011-06-09 02:44:41 -07:00
parent ba114906ea
commit 29cafe3d22

View file

@ -350,7 +350,7 @@ enforce(line.length, "Expected a non-empty line."));
-------------------- --------------------
+/ +/
T enforce(T, string file = __FILE__, int line = __LINE__) T enforce(T, string file = __FILE__, int line = __LINE__)
(T value, lazy const(char)[] msg = null) (T value, lazy const(char)[] msg = null) @safe
{ {
if (!value) bailOut(file, line, msg); if (!value) bailOut(file, line, msg);
return value; return value;
@ -367,7 +367,7 @@ T enforce(T, string file = __FILE__, int line = __LINE__)
return value; return value;
} }
private void bailOut(string file, int line, in char[] msg) private void bailOut(string file, int line, in char[] msg) @safe
{ {
throw new Exception(msg ? msg.idup : "Enforcement failed", file, line); throw new Exception(msg ? msg.idup : "Enforcement failed", file, line);
} }
@ -399,7 +399,7 @@ auto line = readln(f);
enforce(line.length, new IOException); // expect a non-empty line enforce(line.length, new IOException); // expect a non-empty line
-------------------- --------------------
+/ +/
T enforce(T)(T value, lazy Throwable ex) T enforce(T)(T value, lazy Throwable ex) @safe
{ {
if (!value) throw ex(); if (!value) throw ex();
return value; return value;
@ -431,7 +431,7 @@ enforce(line.length); // expect a non-empty line
-------------------- --------------------
+/ +/
T errnoEnforce(T, string file = __FILE__, int line = __LINE__) T errnoEnforce(T, string file = __FILE__, int line = __LINE__)
(T value, lazy string msg = null) (T value, lazy string msg = null) @safe
{ {
if (!value) throw new ErrnoException(msg, file, line); if (!value) throw new ErrnoException(msg, file, line);
return value; return value;
@ -448,7 +448,7 @@ T errnoEnforce(T, string file = __FILE__, int line = __LINE__)
enforceEx!DataCorruptionException(line.length); enforceEx!DataCorruptionException(line.length);
-------------------- --------------------
+/ +/
T enforceEx(E, T)(T value, lazy string msg = "") T enforceEx(E, T)(T value, lazy string msg = "") @safe
{ {
if (!value) throw new E(msg); if (!value) throw new E(msg);
return value; return value;