Lazy formatting

Steven Schveighoffer schveiguy at gmail.com
Mon Feb 1 00:25:42 UTC 2021


As a response to Andrei in DIP 1036 thread (as this is somewhat off topic):

> On 1/31/21 11:11 AM, Steven Schveighoffer wrote:
>> This is how I would do it:
>>
>> i"Hello, ${var.withFormat!"%45s"} world";
>>
>> (where withFormat provides a toString overload that works with idup). No extra intermediate allocations necessary.
> 
> I wonder if we can define a nice convention by the use of past tense vs. active.
> 
> format!"%45s"(val) -> format using this spec the following values
> 
> val.formatted!"%45s" -> value formatted with this spec
> 
> We have just a bit of that with sort/sorted.
> 
> Maybe flesh that up in phobos 2.0 :o).
> 

I have often wanted a lazy formatting feature where you aren't 
allocating but it returns a string-able thing that can be used as an 
input range. I was surprised that phobos doesn't provide this.

Would be really awesome to have, but I think possibly it means we need 
to reengineer the lower level. Probably a phobos 2.0 thing.

-Steve


More information about the Digitalmars-d mailing list