The Phobos Put
Paul Backus
snarwin at gmail.com
Thu Mar 30 15:44:11 UTC 2023
On Wednesday, 29 March 2023 at 20:50:04 UTC, Steven Schveighoffer
wrote:
> On 3/29/23 4:29 PM, ag0aep6g wrote:
>
>> But regardless of Salih's exact intent, the broader point is:
>> a non-ref overload could be added to Phobos. And that would
>> enable `a[1..$-1].phobos_put([2, 3])`. Which is what he asked
>> about originally.
>
> I think the idea of requiring ref output ranges is that you can
> then let the range keep track of its output state.
>
> An input range with lvalue elements is therefore an output
> range, but only if it's accepted via ref, since it has to be
> iterated as it goes. If you iterate it only internally, then
> it's either in an undetermined state when you exit `put`, or it
> is a forward range that was copied without using `save`.
>
> It's not the greatest situation. I feel like we probably
> shouldn't have made lvalue input ranges be output ranges
> automatically.
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.
More information about the Digitalmars-d-learn
mailing list