function-style wrapper for Tango.io.Stdout
Christopher Wright
dhasenan at gmail.com
Thu Feb 14 04:50:37 PST 2008
Bill Baxter wrote:
> Since I'm not a big fan of the venerable St. Dout, I wrote these
> wrappers for Tango so you don't have to repeatedly invoke his name.
>
> --bb
>
Tun palsat:
/**********************************************************************
Unformatted layout, with commas inserted between args.
Currently supports a maximum of 24 arguments
print() with no arguments always flushes the stream.
**********************************************************************/
typeof(Stdout) print (...) {
static char[] slice = "{}, {}, {}, {}, {}, {}, {}, {}, "
"{}, {}, {}, {}, {}, {}, {}, {}, "
"{}, {}, {}, {}, {}, {}, {}, {}, ";
assert (_arguments.length <= slice.length/4, "Print :: too many
arguments");
if (_arguments.length is 0)
Stdout.flush;
else
Stdout.layout()(&Stdout.sink, _arguments, _argptr, slice[0 ..
_arguments.length * 4 - 2]);
return Stdout;
}
You could do something like:
if (_arguments.length < 24) {
// insert your code
} else {
foreach (i, arg; _arguments) {
char[] fmt = (i + 1 == _arguments.length) ? "{0}" : "{0}, ";
Stdout.layout()(&Stdout.sink, [arg], _argptr, fmt);
_argptr += arg.tsize();
}
}
More information about the Digitalmars-d-announce
mailing list