Showing with 16 additions and 2 deletions.
  1. +16 −2 std/conv.d
18 changes: 16 additions & 2 deletions std/conv.d
Original file line number Diff line number Diff line change
Expand Up @@ -3300,7 +3300,20 @@ Target parse(Target, Source)(ref Source s)
assert(b == true);
}

// input range to null literal conversions
/**
Parsing a character range to `typeof(null)` returns `null` if the range
spells `"null"`. This function is case insensitive.
Params:
Target = the type to convert to
s = the lvalue of an input range
Returns:
`null`
Throws:
A $(LREF ConvException) if the range doesn't represent `null`.
*/
Target parse(Target, Source)(ref Source s)
if (isInputRange!Source &&
isSomeChar!(ElementType!Source) &&
Expand All @@ -3316,9 +3329,10 @@ Target parse(Target, Source)(ref Source s)
return null;
}

///
@safe pure unittest
{
import std.exception;
import std.exception : assertThrown;

alias NullType = typeof(null);
auto s1 = "null";
Expand Down