From 523db221c164302ab58c2967cd1bb3169ef9496b Mon Sep 17 00:00:00 2001 From: Nathan Sashihara <21227491+n8sh@users.noreply.github.com> Date: Thu, 25 Oct 2018 06:17:51 -0400 Subject: [PATCH] Port more efficient allSatisfy/anySatisfy from https://github.com/dlang/phobos/pull/6402 --- src/core/internal/traits.d | 43 ++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/src/core/internal/traits.d b/src/core/internal/traits.d index 1dc3f9d82c..91ae3847ba 100644 --- a/src/core/internal/traits.d +++ b/src/core/internal/traits.d @@ -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; } }