writeln if not empty
Nick Sabalausky
SeeWebsiteToContactMe at semitwist.com
Mon Mar 10 18:50:25 PDT 2014
On 3/10/2014 9:24 PM, Timothee Cour wrote:
> 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"
>
Sounds like what you need is a version of to!string() or text() that
takes an output sink. Taking a look at std.conv, I'm kinda surprised I
don't see one :/
More information about the Digitalmars-d-learn
mailing list