Forward ranges in Phobos v2

Atila Neves atila.neves at gmail.com
Fri Nov 5 11:43:01 UTC 2021


On Thursday, 4 November 2021 at 23:30:05 UTC, H. S. Teoh wrote:
> On Thu, Nov 04, 2021 at 06:38:30PM -0400, Andrei Alexandrescu 
> via Digitalmars-d wrote:
>> On 2021-11-04 12:39, Paul Backus wrote:
>> > Again, this is the same distinction we already have between 
>> > rvalue `front` and lvalue `front`
>> 
>> That reminds me, we should drop that like a bad habit too :o).
>> 
>> Currently ranges have all sorts of weird, random genericity. 
>> Recalling from memory (perhaps/hopefully some of these have 
>> been fixed):
>
> Yeah, we need to get rid of useless genericity, and also 
> exactly what is expected of range operations should be stated 
> clearly and unambiguously in the API docs.  The current range 
> API suffers from insufficient clarity, so many such cases went 
> "under the radar" and inevitably ended up being implemented 
> when some kind soul decided that it would be nice to support 
> this or that niche case.

Sometimes genericity is a good thing. Take C++, where range for 
was originally specified in C++11 such that the begin and end 
iterators had to be the same type, which on the face it seems to 
makes sense. But then that was found out to be overly 
constraining, and to be able to add ranges to C++17 they had to 
change the definition of a range for loop so that end only had to 
be comparable to begin and could be a different type.

>> - At least at some point `empty` did not have to return bool, 
>> just something convertible to bool. Like immutable(bool).
>
> Yeah, .empty should return bool, and only bool.  Not 
> immutable(bool), not something that alias this to bool, none of 
> that sort.
>
> Also, the spec should specify precisely whether .empty must be 
> a function (and whether it should be a member function, a free 
> function, or both), or it's allowed to be a member variable.

Similarly to what I said above, I don't think the spec should do 
this at all. Plasticity is what D is good at, and leaving it to 
"range.empty is a bool" is, IMHO, far better. I *love* not using 
parens for functions with no args and being able to use a 
function/variable/enum, then being able to change that and not 
have to touch the rest of the code at all.




More information about the Digitalmars-d mailing list