[Issue 18577] Loose isForwardRange
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Mar 8 09:34:04 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18577
Simen Kjaeraas <simen.kjaras at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |simen.kjaras at gmail.com
Resolution|--- |WONTFIX
--- Comment #1 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
I assume you meant isInputRange!(Unqual!R) in the first half there.
Now, the problem with this idea is that const(R) generally is not a forward
range, or even an input range, and loosening the constraints really doesn't
make it one.
For a quick example, consider const(int[]) arr. Can I call arr.popFront() to
iterate over it? No, that would need to modify the range, and the range is
const, so I can't. If isForwardRange!(const(int[])) returned true, that would
give the impression that I could indeed change the range, and would wreak havoc
with the whole idea of ranges.
Generally, I would simply suggest using isForwardRange!(Unqual!R), but it seems
that's not enough in your case - you want something like this:
enum bool isConstForwardRange(R) = isForwardRange!(Unqual!R) &&
isForwardRange!(ReturnType!((R r) => r.save));
That's probably too niche to put in Phobos, but it should at least solve your
problem here and how.
--
More information about the Digitalmars-d-bugs
mailing list