Fix Issue 18152 - Make std.format.formattedRead usable with rvalues

This commit is contained in:
Daniel Kozak 2017-12-29 10:07:39 +01:00 committed by Sebastian Wilzbach
parent 0eaba0ed1e
commit 146306a27b

View file

@ -631,7 +631,7 @@ matching failure happens.
Throws: Throws:
An `Exception` if `S.length == 0` and `fmt` has format specifiers. An `Exception` if `S.length == 0` and `fmt` has format specifiers.
*/ */
uint formattedRead(alias fmt, R, S...)(ref R r, auto ref S args) uint formattedRead(alias fmt, R, S...)(auto ref R r, auto ref S args)
if (isSomeString!(typeof(fmt))) if (isSomeString!(typeof(fmt)))
{ {
alias e = checkFormatException!(fmt, S); alias e = checkFormatException!(fmt, S);
@ -640,7 +640,7 @@ if (isSomeString!(typeof(fmt)))
} }
/// ditto /// ditto
uint formattedRead(R, Char, S...)(ref R r, const(Char)[] fmt, auto ref S args) uint formattedRead(R, Char, S...)(auto ref R r, const(Char)[] fmt, auto ref S args)
{ {
import std.typecons : isTuple; import std.typecons : isTuple;
@ -978,6 +978,18 @@ uint formattedRead(R, Char, S...)(ref R r, const(Char)[] fmt, auto ref S args)
assert(aa3 == ["hello":1, "world":2]); assert(aa3 == ["hello":1, "world":2]);
} }
// test rvalue using
@system pure unittest
{
string[int] aa1;
formattedRead!("%s")(`[1:"hello", 2:"world"]`, aa1);
assert(aa1 == [1:"hello", 2:"world"]);
int[string] aa2;
formattedRead(`{"hello"=1; "world"=2}`, "{%(%s=%s; %)}", aa2);
assert(aa2 == ["hello":1, "world":2]);
}
template FormatSpec(Char) template FormatSpec(Char)
if (!is(Unqual!Char == Char)) if (!is(Unqual!Char == Char))
{ {