www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24348] New: Inaccurate documentation for hasSlicing with

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 puremagic.com
          Reporter: snarwin+bugzilla 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); } --- --
Jan 20