You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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;
-------
The text was updated successfully, but these errors were encountered:
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.
Jesse Phillips reported this on 2014-02-20T21:32:51Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=12216
CC List
Description
The text was updated successfully, but these errors were encountered: