best replacement for - cout << "hello D" << endl; ?

Bill Baxter dnewsgroup at billbaxter.com
Wed Jul 11 19:47:46 PDT 2007


Bruce Adams wrote:
> Carlos Santander Wrote:
> 
>> Bruce Adams escribió:
>>> and type safe compared to:
>>>
>>> stdout.writefln("%s%s%i", foo,bar,2);
>>>
>> D has typesafe variadics, so you can just say:
>>
>> dout.writefln("%s%s%s", foo,bar,2);
>>
>> %s doesn't mean "pretend it's a string," but rather "write its string 
>> representation."
>>
>> -- 
>> Carlos Santander Bernal
> 
> I see. That makes quite a lot of difference. Now is there a way to remove the format string entirely.
>   a) as a function
>   b) as a template that can be expanded at compile time.

Easier than that:

writefln("This is test number ", i, " out of ", num_tests, " test(s).");

But it doesn't really buy you any safety over the %s version.  It 
doesn't do anything differently except maybe avoid a tiny bit of string 
processing to extract and replace the "%s" strings.


> It sounds like its trivial to write a) if it doesn't already exist. Hopefully, it does though.


--bb


More information about the Digitalmars-d-learn mailing list