Format

cc cc at nevernet.com
Fri May 21 15:28:15 UTC 2021


On Friday, 21 May 2021 at 14:19:03 UTC, newbie wrote:
> Thank you, and formatValue?

formattedWrite should handle this.

```d
@safe struct Foo {
	int x = 3;
	void toString(W)(ref W writer) if (isOutputRange!(W, char)) {
		writer.formattedWrite("Foo(%s)", x);
	}
}
Foo foo;
writeln(foo);
```

Oddly enough this form of toString works from @safe code even if 
it's not marked @safe, or even marked @system...


More information about the Digitalmars-d-learn mailing list