[Issue 20314] New: passing const variables to `only` forces const range element type

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Oct 24 12:17:48 UTC 2019


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

          Issue ID: 20314
           Summary: passing const variables to `only` forces const range
                    element type
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: default_357-line at yahoo.de

Consider this code:

import std;
void main()
{
    const string s = "foo", t = "bar";
    auto range = only(s, t);
    [range].joiner(only(", ")).join.writeln;
}

Since `only` takes its parameters by `auto ref`, the fact that s and t are
`const string` forces `only` to have an `ElementType` of `const(string)`, which
then breaks `joiner`.

There's no reason for `only` to be `auto ref`, since it copies its parameters
anyways.

--


More information about the Digitalmars-d-bugs mailing list