www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - function-style wrapper for Tango.io.Stdout

reply Bill Baxter <dnewsgroup billbaxter.com> writes:
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

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
parent reply Christopher Wright <dhasenan gmail.com> writes:
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(); } }
Feb 14 2008
parent Bill Baxter <dnewsgroup billbaxter.com> writes:
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
Feb 14 2008