overloading operators for I/O

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Thu Feb 15 17:37:53 PST 2007


Frits van Bommel wrote:
> renoX wrote:
>> - a syntax 'a la Ruby' would permit to see better the resulting string:
>> writef("x is %{vx}, y is %{vy}\n"); of course you could still specify 
>> the format if you want: writef("x is %08x{vx}\n");
> 
> A syntax like this may be possible with string mixins. I'm pretty sure 
> you could write that like this:
> ---
> mixin(write!("x is %{vx}, y is %{vy}\n"));
> ---
> and get away with it, given the proper 'write' template. It might not 
> even be very difficult, it'd just need to find the %{} groups, parse 
> them out and generate the proper call(s) to other functions. The backend 
> could be writef, or Tango's Stdout.format or something custom-written.

Walter was talking about implementing this as an example :o).

Andrei



More information about the Digitalmars-d mailing list