[Issue 24348] New: Inaccurate documentation for hasSlicing with infinite range
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Jan 20 22:14:14 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24348
Issue ID: 24348
Summary: Inaccurate documentation for hasSlicing with infinite
range
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: snarwin+bugzilla at gmail.com
The documentation for std.range.hasSlicing states the following:
> For infinite ranges, when not using opDollar, the result of opSlice must be
> the result of take or takeExactly on the original range (they both return the
> same type for infinite ranges).
However, this is not true. The following program, which violates the above
rule, compiles without errors:
---
struct InfZeros
{
enum empty = false;
int front() => 0;
void popFront() {}
auto save() => this;
auto opIndex(size_t[2] bounds)
{
size_t i = bounds[0], j = bounds[1];
size_t length = i <= j ? j - i : 0;
return Slice(length);
}
size_t[2] opSlice(size_t dim : 0)(size_t i, size_t j) => [i, j];
}
struct Slice
{
size_t length;
bool empty() => length == 0;
int front() => 0;
void popFront() { --length; }
auto save() => this;
}
unittest
{
import std.range.primitives;
static assert(hasSlicing!InfZeros);
}
---
--
More information about the Digitalmars-d-bugs
mailing list