[Issue 12216] Overloading templates using alias

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Feb 10 22:21:22 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=12216

Seb <greensunny12 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |greensunny12 at gmail.com

--- Comment #1 from Seb <greensunny12 at gmail.com> ---
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.

--


More information about the Digitalmars-d-bugs mailing list