[Issue 21216] New: SortedRange.empty should be const, .front should be inout
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Sep 2 20:51:44 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=21216
Issue ID: 21216
Summary: SortedRange.empty should be const, .front should be
inout
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: eiderdaus at gmail.com
Example code that fails to compile with DMD 2.093.0 on Linux 64-bit:
import std.range;
class C { }
struct A {
private:
SortedRange!(C[]) _backend;
public:
inout(C) front() inout {
return _backend.front();
}
bool empty() const {
return _backend.empty();
}
}
void main() { }
This generates two errors: Can't call front() on an inout _backend, and can't
call empty() on const _backend. The compiler even suggests annotating
SortedRange's methods with const/inout.
Expected instead: The above code compiles.
Workaround: Replace "SortedRange!(C[]) _backend;" with "C[] _backend;", and
design struct A to ensure that _backend is always sorted.
In Phobos's source for std.range.SortedRange, empty() is declared non-const,
but has a comment "//const". This has been untouched since at least 2014.
---
Related bug:
https://issues.dlang.org/show_bug.cgi?id=9792
length field of a const SortedRange
--
More information about the Digitalmars-d-bugs
mailing list