[Issue 17771] foreach over const input range fails
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Aug 21 08:47:55 PDT 2017
https://issues.dlang.org/show_bug.cgi?id=17771
Steven Schveighoffer <schveiguy at yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|REOPENED |RESOLVED
Resolution|--- |INVALID
--- Comment #3 from Steven Schveighoffer <schveiguy at yahoo.com> ---
The compiler doesn't attempt to modify attributes in almost any case.
For instance:
auto foo()
{
const int x = 5;
return x;
}
auto y = foo(); // y is const(int), even though it could be just int
So this behavior is consistent. You need to tell the compiler to make the copy
with the correct attributes.
Note that many many ranges are not implicitly copyable to a mutable version, so
this ability would not help in most cases.
One valid enhancement that you could propose is to add a function somewhere in
phobos (probably in typecons) that returns a copy of the item with as many
qualifiers removed as possible. Then your code could become something like:
foreach(x; unqual(r))
--
More information about the Digitalmars-d-bugs
mailing list