Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit f7c61c5

Browse files
authored
Merge pull request #2338 from n8sh/port-phobos-6402
Port more efficient allSatisfy/anySatisfy from dlang/phobos#6402 merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>
2 parents d37c37d + 523db22 commit f7c61c5

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

src/core/internal/traits.d

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -128,45 +128,38 @@ template dtorIsNothrow(T)
128128
enum dtorIsNothrow = is(typeof(function{T t=void;}) : void function() nothrow);
129129
}
130130

131-
/*
132-
Tests whether all given items satisfy a template predicate, i.e. evaluates to
133-
$(D F!(T[0]) && F!(T[1]) && ... && F!(T[$ - 1])).
134-
*/
131+
// taken from std.meta.allSatisfy
135132
package(core.internal)
136133
template allSatisfy(alias F, T...)
137134
{
138-
static if (T.length == 0)
139-
{
140-
enum allSatisfy = true;
141-
}
142-
else static if (T.length == 1)
135+
static foreach (Ti; T)
143136
{
144-
enum allSatisfy = F!(T[0]);
137+
static if (!is(typeof(allSatisfy) == bool) && // not yet defined
138+
!F!(Ti))
139+
{
140+
enum allSatisfy = false;
141+
}
145142
}
146-
else
143+
static if (!is(typeof(allSatisfy) == bool)) // if not yet defined
147144
{
148-
static if (allSatisfy!(F, T[0 .. $/2]))
149-
enum allSatisfy = allSatisfy!(F, T[$/2 .. $]);
150-
else
151-
enum allSatisfy = false;
145+
enum allSatisfy = true;
152146
}
153147
}
154148

149+
// taken from std.meta.anySatisfy
155150
template anySatisfy(alias F, T...)
156151
{
157-
static if (T.length == 0)
158-
{
159-
enum anySatisfy = false;
160-
}
161-
else static if (T.length == 1)
152+
static foreach (Ti; T)
162153
{
163-
enum anySatisfy = F!(T[0]);
154+
static if (!is(typeof(anySatisfy) == bool) && // not yet defined
155+
F!(Ti))
156+
{
157+
enum anySatisfy = true;
158+
}
164159
}
165-
else
160+
static if (!is(typeof(anySatisfy) == bool)) // if not yet defined
166161
{
167-
enum anySatisfy =
168-
anySatisfy!(F, T[ 0 .. $/2]) ||
169-
anySatisfy!(F, T[$/2 .. $ ]);
162+
enum anySatisfy = false;
170163
}
171164
}
172165

0 commit comments

Comments
 (0)