Bug 12216 – Overloading templates using alias

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-02-20T21:32:51Z
Last change time
2024-12-13T18:17:15Z
Assigned to
No Owner
Creator
Jesse Phillips
Moved to GitHub: dmd#18778 →

Comments

Comment #0 by Jesse.K.Phillips+D — 2014-02-20T21:32:51Z
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; -------
Comment #1 by greensunny12 — 2018-02-10T22:21:22Z
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.
Comment #2 by robert.schadek — 2024-12-13T18:17:15Z
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