schwartzSort with a const key

bearophile bearophileHUGS at lycos.com
Tue Sep 3 15:22:04 PDT 2013


Currently this code doesn't work, because the B array is const, 
so B[i] is const:


import std.algorithm: schwartzSort;
void main() {
     auto A = [0, 1, 2];
     const B = [10, -20, 30];
     schwartzSort!(i => B[i])(A);
}


dmd gives:

...\dmd2\src\phobos\std\conv.d(3734): Error: static assert  
"Don't know how to emplace a const(int) with a const(int)."
...\dmd2\src\phobos\std\algorithm.d(9210):        instantiated 
from here: emplace!(const(int), const(int))
test.d(5):        instantiated from here: 
schwartzSort!(__lambda2, "a < b", cast(SwapStrategy)0, int[])


But the array A is mutable. So is it acceptable for me to ask in 
Bugzilla this code to work?

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list