best replacement for - cout << "hello D" << endl; ?
Don Clugston
dac at nospam.com.au
Thu Jul 19 05:23:25 PDT 2007
Bill Baxter 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);
>
> Or just dout.writefln(foo,bar,2); in this case.
>
>
>> %s doesn't mean "pretend it's a string," but rather "write its string
>> representation."
>
> I agree that compile time type-checked format parameters would be nice.
>
> writefln("%d", someObject);
>
> >> ERROR: someObject is not an integer
>
> Would be nice. A couple of people were trying to get this to work using
> compile time string processing. Maybe they'll pipe in here at some
> point...
>
> --bb
It's still waiting for macros.
mixin(Writefln(`"%d", someObject`));
will work perfectly (including error messages pointing to the line of the user's
code), but it's just too ugly.
The nice thing about it is, there's no template bloat, and no use of RTTI.
It is also already possible to do:
Writefln!("%d")(someObject);
also a bit ugly, and with code bloat.
All we need is a tiny bit of syntax sugar.
More information about the Digitalmars-d-learn
mailing list