Skip to content

Use Phobos version of staticIsSorted that uses alias assign #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions source/mir/algebraic.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 21 additions & 8 deletions source/mir/internal/meta.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 .. $]);
}
}
}

Expand Down