mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 22:21:09 +03:00
fix(format.read): formattedRead incorrectly static asserts with Tuple and compile-time format string
This method supports std.typecons.Tuple, however, when passing the format string at compile-time, the format validation does not correctly account for the std.typecons.Tuple's types and instead validates the std.typecons.Tuple itself leading to a static assert. This change now adds support for this feature when used with compile-time format strings. Fix Issue #23600 Signed-off-by: João Lourenço <jlourenco5691@gmail.com>
This commit is contained in:
parent
19b890230d
commit
c4192e855e
1 changed files with 16 additions and 1 deletions
|
@ -303,8 +303,23 @@ uint formattedRead(alias fmt, Range, Args...)(auto ref Range r, auto ref Args ar
|
||||||
if (isSomeString!(typeof(fmt)))
|
if (isSomeString!(typeof(fmt)))
|
||||||
{
|
{
|
||||||
import std.format : checkFormatException;
|
import std.format : checkFormatException;
|
||||||
|
import std.meta : staticMap;
|
||||||
|
import std.typecons : Tuple;
|
||||||
|
|
||||||
alias e = checkFormatException!(fmt, Args);
|
|
||||||
|
// formattedRead supports std.typecons.Tuple
|
||||||
|
// however, checkFormatException does not
|
||||||
|
// this means that all std.typecons.Tuple's types in Args must be unwrapped
|
||||||
|
// and passed to checkFormatException
|
||||||
|
template Flatten(T)
|
||||||
|
{
|
||||||
|
static if (is(T : Tuple!Args, Args...))
|
||||||
|
alias Flatten = Args;
|
||||||
|
else
|
||||||
|
alias Flatten = T;
|
||||||
|
}
|
||||||
|
|
||||||
|
alias e = checkFormatException!(fmt, staticMap!(Flatten, Args));
|
||||||
static assert(!e, e);
|
static assert(!e, e);
|
||||||
return .formattedRead(r, fmt, args);
|
return .formattedRead(r, fmt, args);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue