mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 14:40:30 +03:00
Fix Issue 18152 - Make std.format.formattedRead usable with rvalues
This commit is contained in:
parent
0eaba0ed1e
commit
146306a27b
1 changed files with 14 additions and 2 deletions
16
std/format.d
16
std/format.d
|
@ -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))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue