www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21022] New: std.range.only does not work with const


          Issue ID: 21022
           Summary: std.range.only does not work with const
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: andrej.mitrovich gmail.com

module test;

import std.range;

struct S
    S[] s;

void main ()
    const(S) x;
    const(S)[] arr;
    auto r1 = arr.chain(x.only);  // fail
    auto r2 = x.only.chain(arr);  // also fail

/Library/D/dmd/src/phobos/std/range/package.d(9805,23): Error: cannot
implicitly convert expression `value` of type `const(S)` to `S`
/Library/D/dmd/src/phobos/std/range/package.d(9890,57): Error: template
instance `std.range.OnlyResult!(const(S), 1LU).OnlyResult.__ctor!()` error 

`Only` internally stores an Unqual instance of the type. I don't know why, but
this will obviously fail to work..

Jul 07 2020