Skip to content

Commit

Permalink
Fix Issue 18152 - Make std.format.formattedRead usable with rvalues
Browse files Browse the repository at this point in the history
  • Loading branch information
Kozzi11 authored and wilzbach committed Jan 2, 2018
1 parent 0eaba0e commit 146306a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions std/format.d
Expand Up @@ -631,7 +631,7 @@ matching failure happens.
Throws:
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)))
{
alias e = checkFormatException!(fmt, S);
Expand All @@ -640,7 +640,7 @@ if (isSomeString!(typeof(fmt)))
}

/// 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;

Expand Down Expand Up @@ -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]);
}

// 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)
if (!is(Unqual!Char == Char))
{
Expand Down

0 comments on commit 146306a

Please sign in to comment.