Range Redesign: Copy Semantics

Alexandru Ermicioi alexandru.ermicioi at gmail.com
Mon Jan 22 09:17:08 UTC 2024


On Monday, 22 January 2024 at 03:52:02 UTC, Jonathan M Davis 
wrote:
> I'd have to think about it more to see whether having hasNext 
> instead of returning a nullable type from next would be an 
> improvement, make it worse, or be more or less equal. A lot of 
> that depends on how it would affect the typical implementation 
> of a basic input range.

Well one advantage of `hasNext` is that you can check in advance 
whether range is empty or not, without the need to pop front 
element.

> Part of the point here is to _not_ do that, because they 
> fundamentally have different semantics.

That would mean that you need to overload a method to accept both 
input, and forward ranges when foreach is not used, right?

> If this is coming across as complicated, then it's probably 
> because of all of the explanatory text I had to give as to why 
> these changes should be made. But the changes themselves 
> simplify things for forward ranges.

Could be the case :). Perhaps it would be nice to see it as a 
code example.



More information about the Digitalmars-d mailing list