On Sun, Oct 07, 2012 at 01:15:50PM +0400, Dmitry Olshansky wrote:
[...]
> Just define method with this signature:
> void toString(scope void delegate(const(char)[]) sink)
> 
> And bingo! It's used in all of formatting stuff like write(f)(ln),
> format, formattedWrite etc.
> 
> e.g. before posting I played with this:
> 
> import std.stdio, std.format;
> 
> struct A{
>       int k;
>       void toString(scope void delegate(const(char)[]) sink)
>       {
>               formattedWrite(sink, "[%d]", k);
>       }
> }
> 
> void main(){
>       A a = A(90);
>       writeln(a);
> }
[...]

+1. This is much more powerful and useful, not to mention more efficient
in many cases (by avoiding the need to create multiple string buffers),
than the current toString(). I like this.


T

-- 
We are in class, we are supposed to be learning, we have a teacher... Is
it too much that I expect him to teach me??? -- RL

Reply via email to