Lazy formatting

Steven Schveighoffer schveiguy at gmail.com
Mon Feb 1 15:38:34 UTC 2021


On 2/1/21 10:28 AM, Vladimir Panteleev wrote:
> On Monday, 1 February 2021 at 00:25:42 UTC, Steven Schveighoffer wrote:
>> 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.
> 
> Um, do you mean something like this?
> 
> https://github.com/CyberShadow/ae/blob/904d5b6ab7a15b3ecac499ef41bb40a88fd64e1e/utils/text/package.d#L47 
> 
> 
> assert(64.formatted!"%x".text == "40");
> 
> It's not an input range (I think emitting formatted strings as an input 
> range without an intermediary buffer would be impractically difficult in 
> general), but it does use the sink toString interface.

Oh nice, yes! That would actually work with the DIP as defined.

Yeah, you definitely need a buffer for formatting, it's somewhat 
possible to do with integers, but not as pleasant.

But local buffers can be part of the type anyway (like a static array).

-Steve


More information about the Digitalmars-d mailing list