Skip to content

Commit 0ab1c70

Browse files
committed
Use Phobos version of staticIsSorted that uses alias assign
Reduces number of template instances of staticIsSorted from log(items.length) to 1
1 parent 4fdf97d commit 0ab1c70

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

Diff for: source/mir/internal/meta.d

+8-14
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ enum hasToHash(T) = __traits(hasMember, T, "toHash");
114114
static if (__VERSION__ < 2094)
115115
enum isCopyable(S) = is(typeof({ S foo = S.init; S copy = foo; }));
116116
else
117-
enum isCopyable(S) = __traits(isCopyable, S);
117+
enum isCopyable(S) = __traits(isCopyable, S);
118118
enum isPOD(T) = __traits(isPOD, T);
119119
enum Sizeof(T) = T.sizeof;
120120

@@ -136,20 +136,14 @@ enum hasSemiMutableConstruction(T) = __traits(compiles, {static struct S { T a;
136136
static assert(hasInoutConstruction!S);
137137
}
138138

139-
template staticIsSorted(alias cmp, Seq...)
140-
{
141-
static if (Seq.length <= 1)
142-
enum staticIsSorted = true;
143-
else static if (Seq.length == 2)
144-
enum staticIsSorted = cmp!(Seq[0], Seq[1]);
145-
else
139+
enum staticIsSorted(alias cmp, items...) =
146140
{
147-
enum staticIsSorted =
148-
cmp!(Seq[($ / 2) - 1], Seq[$ / 2]) &&
149-
staticIsSorted!(cmp, Seq[0 .. $ / 2]) &&
150-
staticIsSorted!(cmp, Seq[$ / 2 .. $]);
151-
}
152-
}
141+
static if (items.length > 1)
142+
static foreach (i, item; items[1 .. $])
143+
static if (cmp!(items[i], item))
144+
if (__ctfe) return false;
145+
return true;
146+
}();
153147

154148
template TryRemoveConst(T)
155149
{

0 commit comments

Comments
 (0)