Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
Merged
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
43 changes: 18 additions & 25 deletions src/core/internal/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -128,45 +128,38 @@ template dtorIsNothrow(T)
enum dtorIsNothrow = is(typeof(function{T t=void;}) : void function() nothrow);
}

/*
Tests whether all given items satisfy a template predicate, i.e. evaluates to
$(D F!(T[0]) && F!(T[1]) && ... && F!(T[$ - 1])).
*/
// taken from std.meta.allSatisfy
package(core.internal)
template allSatisfy(alias F, T...)
{
static if (T.length == 0)
{
enum allSatisfy = true;
}
else static if (T.length == 1)
static foreach (Ti; T)
{
enum allSatisfy = F!(T[0]);
static if (!is(typeof(allSatisfy) == bool) && // not yet defined
!F!(Ti))
{
enum allSatisfy = false;
}
}
else
static if (!is(typeof(allSatisfy) == bool)) // if not yet defined
{
static if (allSatisfy!(F, T[0 .. $/2]))
enum allSatisfy = allSatisfy!(F, T[$/2 .. $]);
else
enum allSatisfy = false;
enum allSatisfy = true;
}
}

// taken from std.meta.anySatisfy
template anySatisfy(alias F, T...)
{
static if (T.length == 0)
{
enum anySatisfy = false;
}
else static if (T.length == 1)
static foreach (Ti; T)
{
enum anySatisfy = F!(T[0]);
static if (!is(typeof(anySatisfy) == bool) && // not yet defined
F!(Ti))
{
enum anySatisfy = true;
}
}
else
static if (!is(typeof(anySatisfy) == bool)) // if not yet defined
{
enum anySatisfy =
anySatisfy!(F, T[ 0 .. $/2]) ||
anySatisfy!(F, T[$/2 .. $ ]);
enum anySatisfy = false;
}
}

Expand Down