When importing a module D allows a modules functions to be brought into the overload set by declaring an alias. Example ------- import std.ascii; bool isLower(bool c) { return true; } alias isLower = std.ascii.isLower; ------- Templates should allow for the same behavior: ------- import std.range; import std.algorithm; import std.traits; bool isSorted(alias less = "a < b", Range)(Range r) if (isStaticArray!Arr) { return isSorted(r[]); } alias isSorted = std.algorithm.isSorted; -------
This is going to be tough because some templates are written like this: foo() if (a) foo() if (!a) There overloading is rather hard. However, the following trick should always work: --- bool isSorted(alias less = "a < b", Range)(Range r) { import std.algorithm : isSortedImpl = isSorted; static if (isStaticArray!Range) { return isSortedImpl!less(r[]); } else { return isSortedImpl!less(r[]); } } --- https://run.dlang.io/is/EL3VEj Though nowadays this isn't even necessary for isSorted.
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18778 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB