Ali Çehreli:
Here is a quick and dirty implementation that is based on the assumption that byKey and byValue visit the elements in the same order:
I think that currently the D specs do not assert that quality of byKey/byValue. So your code is not portable.
Bye, bearophile