change return type of executeShell (etc) to Tuple!(int, "status", string, "output")

Timothee Cour thelastmammoth at gmail.com
Tue Jul 16 10:58:50 PDT 2013


On Thu, Jun 13, 2013 at 12:10 AM, Timothee Cour <thelastmammoth at gmail.com>wrote:

> 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.)
>
>
>
>
>
ping
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130716/4882511e/attachment.html>


More information about the Digitalmars-d mailing list