digitalmars.D.bugs - [Issue 10960] New: Copying a const value type should yield unqual
- d-bugmail puremagic.com (33/33) Sep 03 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10960
- d-bugmail puremagic.com (10/13) Sep 03 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10960
- d-bugmail puremagic.com (19/19) Sep 03 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10960
http://d.puremagic.com/issues/show_bug.cgi?id=10960 Summary: Copying a const value type should yield unqual Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: hsteoh quickfur.ath.cx This is from a forum post. Code: ------ void main(){ auto A = [0, 1, 2]; const B = [10, -20, 30]; schwartzSort!(i => B[i])(A); // NG } ------ This fails because the return type of the lambda is deduced as const(int). This is silly since a copied const value type no longer needs to be const; it should be unqual. Explicitly naming the unqual type for the delegate fixes the problem: schwartzSort!(delegate int (i) => B[i])(A); // OK The user shouldn't be required to do this; returning a const value type by value should be stripped of its constness, since it is not the original value being returned, but a copy. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 03 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10960returning a const value type by value should be stripped of its constness, since it is not the original value being returned, but a copy.The main point of my question in D.learn was: if the array A is mutable, and the array B contains constant references (like const references to class instances), is code like this acceptable? schwartzSort!(i => B[i])(A); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 03 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10960 Oh I see. I misunderstood your question, my bad. :) Nevertheless, both issues are worth consideration. The unqual issue should be fixed, definitely. About your actual question: I'm not so sure this is possible, although in theory, it *could* be made possible if B's elements are rebindable. So in theory, this should work: class C { ... } auto A = [0, 1, 2]; const B = [new C(1), new C(2), new C(3)]; schwartzSort!(i => B[i])(A); The idea being that schwartzSort stores an array of rebindable references to the C instances, and uses that to sort A. This probably doesn't work right now because the language currently has no way to express tail-const in class references, though I'm guessing that if you use Rebindable!C, it should work. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 03 2013