[Issue 6313] New: Type deduction with const/in

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jul 14 04:56:06 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6313

           Summary: Type deduction with const/in
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2011-07-14 04:50:53 PDT ---
A D2 program:


T[] foo(T)(const T[] x) {
    //static assert(is(U == int)); // false
    static assert(is(T == const(int)));
    return new T[1];
}
U[] bar(U)(const U[] y) {
    static assert(is(U == int));
    return foo(y);
}
void main() {
    bar([1]);
}


DMD 2.054 gives:
test.d(8): Error: cannot implicitly convert expression (foo(y)) of type
const(int)[] to int[]
test.d(11): Error: template instance test.bar!(int) error instantiating


This causes me problems because many of my functions have "in" arguments. When
they call each other they don't compile, as in this example (here I have used
"const" arguments just for clarity).


To solve the problem I have had to use code like this, that I don't like a lot:

Unqual![] foo(T)(const T[] x) {
    return new Unqual!T[1];
}
U[] bar(U)(const U[] y) {
    return foo(y);
}
void main() {
    bar([1]);
}


So, is it possible (and good) to change DMD so the type T of foo is "int"
instead of "const(int)"?


See also comments by Daniel Murphy:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=28147

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list