why doesn't formattedRead take args by ref instead of by pointer?
Timothee Cour
thelastmammoth at gmail.com
Mon May 20 14:39:13 PDT 2013
That was indeed what I was using in my updated ref based reimplementation
of formattedRead (see my original post for the link), and the other
functions getopt, readf) are the same AFAIK.
so why not add it to phobos:
it's safer (no null / invalid pointers)
simpler user code
more consistent with rest of phobos
we could either make the existing by pointer functions enter a deprecation
path, or add a 'formattedReadRef' version for all those functions.
Thoughts?
On Mon, May 20, 2013 at 2:28 PM, Dmitry Olshansky <dmitry.olsh at gmail.com>wrote:
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130520/48702540/attachment.html>
More information about the Digitalmars-d-learn
mailing list