Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print inout parameters?

Tags:

d

How can I print inout parameters?

import std.stdio;

void main()
{
    foo(2);
    return;
}

inout(int) foo(inout(int) x)
{
    writeln(x);
    return x;
}

Compiler output:

c:\D\dmd2\windows\bin\..\..\src\phobos\std\conv.d(3881): Error: template instance Unqual!(__T4ImplTNgiZ) does not match template declaration Unqual(T)
c:\D\dmd2\windows\bin\..\..\src\phobos\std\stdio.d(757): Error: template instance std.conv.toTextRange!(inout(int), LockingTextWriter) error instantiating
c:\D\dmd2\windows\bin\..\..\src\phobos\std\stdio.d(1708):        instantiated from here: write!(inout(int), char)
x.d(11):        instantiated from here: writeln!(inout(int))
c:\D\dmd2\windows\bin\..\..\src\phobos\std\stdio.d(1708): Error: template instance std.stdio.File.write!(inout(int), char) error instantiating
x.d(11):        instantiated from here: writeln!(inout(int))
x.d(11): Error: template instance std.stdio.writeln!(inout(int)) error instantiating

Also, to!string doesn't work with the inout parameter.

Update: I've just found out (by trial and error) that the following works:

writeln(cast(const)x);

Is this the normal method or am I missing something?

like image 541
gerleim Avatar asked Oct 22 '22 06:10

gerleim


1 Answers

This is a library bug, most likely in Unqual. I added it here: http://d.puremagic.com/issues/show_bug.cgi?id=10544

like image 140
Andrei Alexandrescu Avatar answered Oct 25 '22 18:10

Andrei Alexandrescu