writeln if not empty

Timothee Cour thelastmammoth at gmail.com
Mon Mar 10 18:24:17 PDT 2014


Is there a way to do the following lazily:

writelnIfNotEmpty(T)(T a){
auto b=text(a);
if(b.length)
  writeln(b);
}

ie, without using std.conv.text (which needlessly computes an intermediate
string, which could be quite large) or launching a separate process ?

writelnIfNotEmpty(""); //doesn't print new line
writelnIfNotEmpty("a"); //prints "a\n"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20140310/38e0f3ba/attachment.html>


More information about the Digitalmars-d-learn mailing list