www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12568] New: std.functional.memoize with constant array

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

          Issue ID: 12568
           Summary: std.functional.memoize with constant array argument
                    too
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: bearophile_hugs eml.cc

I'd like the len2 function to compile:


import std.functional: memoize;

uint len1(string s) { // OK
    alias mLen1 = memoize!len1;
    if (s.length == 0)
        return 0;
    else
        return 1 + mLen1(s[1 .. $]);
}

uint len2(const string s) { // Error
    alias mLen2 = memoize!len2;
    if (s.length == 0)
        return 0;
    else
        return 1 + mLen2(s[1 .. $]);
}
void main() {}


DMD 2.066alpha gives:

...\dmd2\src\phobos\std\functional.d(674,18): Error: cannot implicitly convert
expression (t) of type Tuple!string to Tuple!(const(immutable(char)[]))
...\dmd2\src\phobos\std\functional.d(682,14): Error: cannot implicitly convert
expression (t) of type Tuple!string to Tuple!(const(immutable(char)[]))
test.d(12,19): Error: template instance std.functional.memoize!(len2) error
instantiating

--
Apr 12 2014