What is a sink delegate?
Joel via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Oct 9 20:06:31 PDT 2014
On Tuesday, 30 September 2014 at 17:27:09 UTC, Adam D. Ruppe
wrote:
> On Tuesday, 30 September 2014 at 17:22:44 UTC, Gary Willoughby
> wrote:
>> What is a sink delegate?
>
> Instead of
>
> string toString() { return "foo"; }
>
> for example, you would use:
>
> void toString(void delegate(string) sink) { sink("foo"); }
>
> The sink argument there is then free to view and discard the
> data or to make a private copy using whatever scheme it desires.
How do you use that toString? Maybe an example? Below is my
failed effort.
import std.stdio;
struct Try {
string name;
long age;
void toString(void delegate(string) sink) {
sink("foo");
}
}
void main() {
Try t = Try("Joel", 35);
writeln(t);
}
More information about the Digitalmars-d-learn
mailing list