The Phobos Put

Steven Schveighoffer schveiguy at gmail.com
Fri Mar 31 02:23:29 UTC 2023


On 3/30/23 11:44 AM, Paul Backus wrote:

> It should be fine to have both a `ref` and non-`ref` overload for `put`, 
> though, right? If the non-`ref` overload is only called with rvalues, 
> then it's fine to leave them in an undetermined state, because nothing 
> can access them afterward anyway.

There's a certain attempt in phobos in some places to try and ensure 
code that is going to confuse will not compile. I think this is one of 
those attempts.

Consider that if you pass a slice into `put`, then it returns nothing. 
There is no indication of what actually was written. It's essentially an 
inconclusive call, because the "result" is the output range itself. How 
many elements were written? You can't tell.

I'd argue that the way input ranges are used as output ranges today is 
extremely confusing. It makes sort of a logical sense, but the fact that 
you need to store your "original" range, and then do some length math to 
figure out what was written makes such code very awkward all around. The 
output is decipherable, but not obvious.

I stand by my assertion that probably lvalue input ranges should never 
have been treated as output ranges implicitly. They should have had to 
go through some sort of wrapper.

-Steve


More information about the Digitalmars-d-learn mailing list