About variadic in functions and dstring type

torhu no at spam.invalid
Tue Jan 22 06:41:12 PST 2008


Lorenzo Villani wrote:
> Hi, I want to modify or extend std.stdio.writefln in order to support (for example) a String object.. i.e.: I would like to be able to do something like that
> 
> String s = new String("Hello World");
> writefln(s);
> 
> I thought that it should be possible by writing some sort of wrapper around the original writefln which scans the _arguments array and if an argument is a String object it does an in-place substitution of the argument to a standard D string type printable by writefln.

You just need to define a toString() method for your class, then 
writefln will automatically call that.

> 
> Now let's come to my 2nd question: what are dchar and dstring and their differences from char[] (or wchar[]) ?

dchar is a 32-bit type, for storing a UTF-32 code unit.  dstring is an 
array of dchar, in other words a UTF-32 string.  wchar and wstring are 
for UTF-16.



More information about the Digitalmars-d mailing list