why doesn't formattedRead take args by ref instead of by pointer?
Dmitry Olshansky
dmitry.olsh at gmail.com
Mon May 20 14:28:37 PDT 2013
21-May-2013 01:19, Timothee Cour пишет:
>
> IRC there was a problem with having a heterogeneous variadic
> (=compiler's type tuple) function to preserve ref-ness.
>
>
> could you please provide a code snippet demonstrating this?
>
>
Here:
void readf(Args...)(const(char)[] fmt, Args args)
{
...
}
the problem was that you couldn't do
void readf(Args...)(const(char)[] fmt, ref Args args)
{
...
}
and have each of args be a 'ref' to original var as there is no such
things outside function arguments declaration. I dunno how it was solved
but this now works:
void readf(Args...)(const(char)[] fmt, ref Args args)
{
foreach(i, v; args)
args[i] = i;
}
void main(){
int i, j, k;
readf("abc", i, j, k);
assert(i == 0);
assert(j == 1);
assert(k == 2);
}
--
Dmitry Olshansky
More information about the Digitalmars-d-learn
mailing list