https://issues.dlang.org/show_bug.cgi?id=13881

          Issue ID: 13881
           Summary: Optional length template argument for
                    std.range.takeExactly
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nob...@puremagic.com
          Reporter: bearophile_h...@eml.cc

In some cases it can be useful to specify the length as template argument to
takeExactly, allowing the range to have a length known at compile-time:


void main() pure @safe nothrow @nogc {
    import std.range: takeExactly;
    int[10] arr;
    auto r = arr.takeExactly!5;
    enum len = r.length;
}


If the first argument of takeExactly is a fixed-size array of sufficient
length, or a range that has length known at compile-time (like another
takeExactly!N or an infinite range), then takeExactly becomes nothrow @nogc.


Now r.length is usable in various compile-time contexts:

    int[r.length] arr2 = void;
    copy(r, arr2[]);


If you can't add such optional template argument, then you can add a similar
function named std.range.takeExactlyCt.

See also Issue 13880

--

Reply via email to