diff --git a/source/mir/algebraic.d b/source/mir/algebraic.d index 8a2a743..9f61da9 100644 --- a/source/mir/algebraic.d +++ b/source/mir/algebraic.d @@ -369,17 +369,27 @@ template TypeSet(T...) // sort types by sizeof and them mangleof // but typeof(null) goes first static if (is(staticMap!(TryRemoveConst, T) == T)) + { static if (is(NoDuplicates!T == T)) + { static if (staticIsSorted!(TypeCmp, T)) - { + { alias TypeSet = T; - } + } else - alias TypeSet = .TypeSet!(staticSort!(TypeCmp, T)); + { + alias TypeSet = TypeSet!(staticSort!(TypeCmp, T)); + } + } else + { alias TypeSet = TypeSet!(NoDuplicates!T); + } + } else + { alias TypeSet = TypeSet!(staticMap!(TryRemoveConst, T)); + } } // IonNull goes first as well diff --git a/source/mir/internal/meta.d b/source/mir/internal/meta.d index da9b96e..2f6b90a 100644 --- a/source/mir/internal/meta.d +++ b/source/mir/internal/meta.d @@ -114,7 +114,7 @@ enum hasToHash(T) = __traits(hasMember, T, "toHash"); static if (__VERSION__ < 2094) enum isCopyable(S) = is(typeof({ S foo = S.init; S copy = foo; })); else - enum isCopyable(S) = __traits(isCopyable, S); + enum isCopyable(S) = __traits(isCopyable, S); enum isPOD(T) = __traits(isPOD, T); enum Sizeof(T) = T.sizeof; @@ -136,18 +136,31 @@ enum hasSemiMutableConstruction(T) = __traits(compiles, {static struct S { T a; static assert(hasInoutConstruction!S); } -template staticIsSorted(alias cmp, Seq...) +static if (__VERSION__ >= 2098) { + enum staticIsSorted(alias cmp, items...) = + { + static if (items.length > 1) + static foreach (i, item; items[1 .. $]) + static if (cmp!(items[i], item)) + if (__ctfe) return false; + return true; + }(); +} +else { - static if (Seq.length <= 1) - enum staticIsSorted = true; - else static if (Seq.length == 2) - enum staticIsSorted = cmp!(Seq[0], Seq[1]); - else + template staticIsSorted(alias cmp, Seq...) { - enum staticIsSorted = + static if (Seq.length <= 1) + enum staticIsSorted = true; + else static if (Seq.length == 2) + enum staticIsSorted = cmp!(Seq[0], Seq[1]); + else + { + enum staticIsSorted = cmp!(Seq[($ / 2) - 1], Seq[$ / 2]) && staticIsSorted!(cmp, Seq[0 .. $ / 2]) && staticIsSorted!(cmp, Seq[$ / 2 .. $]); + } } }