| |
| Posted by Bill Baxter in reply to Christopher Wright | PermalinkReply |
|
Bill Baxter
Posted in reply to Christopher Wright
| Christopher Wright wrote:
> 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();
> }
> }
The code is actually not mine but a slightly modified copy of the actual Tango print function. What I'd _like_ to have my function look like is something like this:
typeof(Stdout) print(...) {
return Stdout.vaprint(_arguments,_argptr);
}
However, Stdout.vaprint doesn't exist.
You make a good point about the implementation of Stdout.print, though.
--bb
|