An array of int’s works:
import std;
struct List(T) {
class Node {
T data;
Node next;
this(T data) {
this.data=data;
}
override string toString() const {
return data.to!string;
}
}
Node start;
this(T[] data...) {
void add(T data) {
auto newNode=new Node(data);
if (start is null)
start=newNode;
else {
auto cur=start;
while(cur.next) {
cur=cur.next;
}
cur.next=newNode;
}
}
data.each!(d => add(d));
}
int opApply(int delegate(ref T) dg) {
auto cur=start;
while(cur) {
int result=dg(cur.data);
if (result)
return result;
cur=cur.next;
}
return 0;
}
auto opIndex() {
return this.array;
}
}
void main() {
auto j=List!char("Joel".to!(char[]));
j.each!(c => write(c, " "));
writeln;
j[].sort!"a>b".each!(c => c.writeln);
auto i=List!int(1979,4,30);
writeln;
i[].sort!"a<b".each!(n => n.writeln);
}
I get this:
onlineapp.d(49): Error: none of the overloads of template `std.algorithm.sorting.sort` are callable using argument types `!("a>b")(char[])`
/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/sorting.d(1925): Candidate is: `sort(alias less = "a < b", SwapStrategy ss = SwapStrategy.unstable, Range)(Range r)`
with `less = "a>b",
ss = SwapStrategy.unstable,
Range = char[]`
must satisfy one of the following constraints:
` hasSwappableElements!Range
hasAssignableElements!Range
ss != SwapStrategy.unstable`