digitalmars.D.announce - function-style wrapper for Tango.io.Stdout
- Bill Baxter (3/3) Feb 14 2008 Since I'm not a big fan of the venerable St. Dout, I wrote these
- Christopher Wright (30/35) Feb 14 2008 Tun palsat:
- Bill Baxter (10/53) Feb 14 2008 The code is actually not mine but a slightly modified copy of the actual...
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
Feb 14 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. --bbTun 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(); } }
Feb 14 2008
Christopher Wright wrote:Bill Baxter wrote: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. --bbSince 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. --bbTun 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(); } }
Feb 14 2008