www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - change return type of executeShell (etc) to Tuple!(int, "status",

--089e0141abacc827d004df03d33c
Content-Type: text/plain; charset=ISO-8859-1

in the doc to executeShell (etc) it says:

Returns:
A struct which contains the fields int status and string output. (This will
most likely change to become a
std.typecons.Tuple!(int,"status",string,"output") in the future, but a
compiler bug currently prevents this.)

However, it works for me when i replace
----
struct ProcessOutput { int status; string output; }
return ProcessOutput(wait(p.pid), cast(string) a.data);
----
by:

return Tuple!(int, "status", string, "output")(wait(p.pid), cast(string)
a.data);
(and import std.typecons in header)

I'd like to change to this 2nd version sooner rather than later (now?)
because:
* doing it now is ok since std.process was just upgraded so not too much
code will be broken if we do it right away
* in current situation, ReturnType!executeShell !is ReturnType!execute
which sounds silly

For example I wanted to add a forwarding function usable as:
"command".executeShell.outputThrows.writeln;
but it will work with executeShell and not execute (unless we make it
templated), see below:

 string outputThrows(ReturnType!executeShell ret){
    import std.exception;
    enforce(!ret.status,ret.output);
    return ret.output;
}
*Returns:*
A struct which contains the fields int status and string output. (This will
most likely change to become a
std.typecons.Tuple!(int,"status",string,"output") in the future, but a
compiler bug currently prevents this.)

--089e0141abacc827d004df03d33c
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

in the doc to executeShell (etc) it says:<div><br></div><div>Returns:<div>A=
 struct which contains the fields int status and string output. (This will =
most likely change to become a std.typecons.Tuple!(int,&quot;status&quot;,s=
tring,&quot;output&quot;) in the future, but a compiler bug currently preve=
nts this.)</div>
<div><br></div><div>However, it works for me when i replace=A0</div><div>--=
--</div><div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre">=
	</span>struct ProcessOutput { int status; string output; }</div><div><span=
 class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>return ProcessO=
utput(wait(p.pid), cast(string) a.data);</div>
<div><div>----</div><div>by:</div><div><br></div><div></div></div><div>retu=
rn Tuple!(int, &quot;status&quot;, string, &quot;output&quot;)(wait(p.pid),=
 cast(string) a.data);=A0</div></div><div>(and import std.typecons in heade=
r)</div>
<div><br></div><div>I&#39;d like to change to this 2nd version sooner rathe=
r than later (now?) because:</div><div>* doing it now is ok since std.proce=
ss was just upgraded so not too much code will be broken if we do it right =
away</div>
<div>* in current situation,=A0ReturnType!executeShell !is=A0<span style=3D=
"font-family:Menlo;color:rgb(68,68,68)">ReturnType</span><span style=3D"fon=
t-family:Menlo;color:rgb(68,68,68)">!</span><span style=3D"font-family:Menl=
o;color:rgb(68,68,68)">execute which sounds silly</span></div>
<div><br></div><div>For example I wanted to add a forwarding function usabl=
e as:</div><div>&quot;command&quot;.executeShell.outputThrows.writeln;</div=
<div>but it will work with=A0executeShell and not execute (unless we make =

<div><br></div> <font face=3D"Menlo"> <span style=3D"color:#009695">string</span><span style=3D"color:#444444">= =A0</span><span style=3D"color:#444444">outputThrows</span><span style=3D"c= olor:#444444">(</span><span style=3D"color:#444444">ReturnType</span><span = style=3D"color:#444444">!</span><span style=3D"color:#444444">executeShell<= /span><span style=3D"color:#444444">=A0</span><span style=3D"color:#444444"=
ret</span><span style=3D"color:#444444">)</span><span style=3D"color:#4444=

<span style=3D"color:#444444">=A0=A0=A0=A0</span><span style=3D"color:#0096= 95">import</span><span style=3D"color:#444444">=A0</span><span style=3D"col= or:#444444">std</span><span style=3D"color:#444444">.</span><span style=3D"= color:#444444">exception</span><span style=3D"color:#444444">;</span><br> <span style=3D"color:#444444">=A0=A0=A0=A0</span><span style=3D"color:#4444= 44">enforce</span><span style=3D"color:#444444">(</span><span style=3D"colo= r:#444444">!</span><span style=3D"color:#444444">ret</span><span style=3D"c= olor:#444444">.</span><span style=3D"color:#444444">status</span><span styl= e=3D"color:#444444">,</span><span style=3D"color:#444444">ret</span><span s= tyle=3D"color:#444444">.</span><span style=3D"color:#444444">output</span><= span style=3D"color:#444444">)</span><span style=3D"color:#444444">;</span>= <br> <span style=3D"color:#444444">=A0=A0=A0=A0</span><span style=3D"color:#0096= 95">return</span><span style=3D"color:#444444">=A0</span><span style=3D"col= or:#444444">ret</span><span style=3D"color:#444444">.</span><span style=3D"= color:#444444">output</span><span style=3D"color:#444444">;</span><br> </font><div><span style=3D"color:rgb(68,68,68);font-family:Menlo">}</span>= =A0</div><div><b style=3D"color:rgb(31,37,43);font-family:Verdana,&#39;Deja= Vu&#39;,&#39;Bitstream Vera Sans&#39;,sans-serif;font-size:0px;background-= color:rgb(31,37,43)">Returns:</b><br style=3D"color:rgb(31,37,43);font-fami= ly:Verdana,&#39;Deja Vu&#39;,&#39;Bitstream Vera Sans&#39;,sans-serif;font-= size:0px;background-color:rgb(31,37,43)"> <span style=3D"color:rgb(31,37,43);font-family:Verdana,&#39;Deja Vu&#39;,&#= 39;Bitstream Vera Sans&#39;,sans-serif;font-size:0px;background-color:rgb(3= 1,37,43)">A=A0</span><span class=3D"d_inlinecode" style=3D"font-family:Cons= olas,&#39;Bitstream Vera Sans Mono&#39;,&#39;Andale Mono&#39;,Monaco,&#39;D= ejaVu Sans Mono&#39;,&#39;Lucida Console&#39;,monospace;font-weight:bold;co= lor:rgb(31,37,43);font-size:0px;background-color:rgb(31,37,43)">struct</spa= n><span style=3D"color:rgb(31,37,43);font-family:Verdana,&#39;Deja Vu&#39;,= &#39;Bitstream Vera Sans&#39;,sans-serif;font-size:0px;background-color:rgb= (31,37,43)">=A0which contains the fields=A0</span><span class=3D"d_inlineco= de" style=3D"font-family:Consolas,&#39;Bitstream Vera Sans Mono&#39;,&#39;A= ndale Mono&#39;,Monaco,&#39;DejaVu Sans Mono&#39;,&#39;Lucida Console&#39;,= monospace;font-weight:bold;color:rgb(31,37,43);font-size:0px;background-col= or:rgb(31,37,43)">int status</span><span style=3D"color:rgb(31,37,43);font-= family:Verdana,&#39;Deja Vu&#39;,&#39;Bitstream Vera Sans&#39;,sans-serif;f= ont-size:0px;background-color:rgb(31,37,43)">=A0and=A0</span><span class=3D= "d_inlinecode" style=3D"font-family:Consolas,&#39;Bitstream Vera Sans Mono&= #39;,&#39;Andale Mono&#39;,Monaco,&#39;DejaVu Sans Mono&#39;,&#39;Lucida Co= nsole&#39;,monospace;font-weight:bold;color:rgb(31,37,43);font-size:0px;bac= kground-color:rgb(31,37,43)">string output</span><span style=3D"color:rgb(3= 1,37,43);font-family:Verdana,&#39;Deja Vu&#39;,&#39;Bitstream Vera Sans&#39= ;,sans-serif;font-size:0px;background-color:rgb(31,37,43)">. (This will mos= t likely change to become a=A0</span><span class=3D"d_inlinecode" style=3D"= font-family:Consolas,&#39;Bitstream Vera Sans Mono&#39;,&#39;Andale Mono&#3= 9;,Monaco,&#39;DejaVu Sans Mono&#39;,&#39;Lucida Console&#39;,monospace;fon= t-weight:bold;color:rgb(31,37,43);font-size:0px;background-color:rgb(31,37,= 43)">std.typecons.Tuple!(int,&quot;status&quot;,string,&quot;output&quot;)<= /span><span style=3D"color:rgb(31,37,43);font-family:Verdana,&#39;Deja Vu&#= 39;,&#39;Bitstream Vera Sans&#39;,sans-serif;font-size:0px;background-color= :rgb(31,37,43)">=A0in the future, but a compiler bug currently prevents thi= s.)</span></div> </div><div><span style=3D"color:rgb(31,37,43);font-family:Verdana,&#39;Deja= Vu&#39;,&#39;Bitstream Vera Sans&#39;,sans-serif;font-size:0px;background-= color:rgb(31,37,43)"><br></span></div><div><span style=3D"color:rgb(31,37,4= 3);font-family:Verdana,&#39;Deja Vu&#39;,&#39;Bitstream Vera Sans&#39;,sans= -serif;font-size:0px;background-color:rgb(31,37,43)"><br> </span></div><div><span style=3D"color:rgb(31,37,43);font-family:Verdana,&#= 39;Deja Vu&#39;,&#39;Bitstream Vera Sans&#39;,sans-serif;font-size:0px;back= ground-color:rgb(31,37,43)"><br></span></div><div><span style=3D"color:rgb(= 31,37,43);font-family:Verdana,&#39;Deja Vu&#39;,&#39;Bitstream Vera Sans&#3= 9;,sans-serif;font-size:0px;background-color:rgb(31,37,43)"><br> </span></div> --089e0141abacc827d004df03d33c--
Jun 13 2013