www.digitalmars.com         C & C++   DMDScript  

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

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.)
Jun 13 2013