-
-
Notifications
You must be signed in to change notification settings - Fork 753
Make some traits iterative using static foreach #6402
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -277,13 +277,13 @@ if (!isAggregateType!T || is(Unqual!T == T)) | |
| */ | ||
| template staticIndexOf(T, TList...) | ||
| { | ||
| enum staticIndexOf = genericIndexOf!(T, TList).index; | ||
| enum staticIndexOf = genericIndexOf!(T, TList); | ||
| } | ||
|
|
||
| /// Ditto | ||
| template staticIndexOf(alias T, TList...) | ||
| { | ||
| enum staticIndexOf = genericIndexOf!(T, TList).index; | ||
| enum staticIndexOf = genericIndexOf!(T, TList); | ||
| } | ||
|
|
||
| /// | ||
|
|
@@ -303,27 +303,17 @@ template staticIndexOf(alias T, TList...) | |
| private template genericIndexOf(args...) | ||
| if (args.length >= 1) | ||
| { | ||
| alias e = OldAlias!(args[0]); | ||
| alias tuple = args[1 .. $]; | ||
|
|
||
| static if (tuple.length) | ||
| static foreach (idx, arg; args[1 .. $]) | ||
| { | ||
| alias head = OldAlias!(tuple[0]); | ||
| alias tail = tuple[1 .. $]; | ||
|
|
||
| static if (isSame!(e, head)) | ||
| static if (is(typeof(genericIndexOf) == void) && // not yet defined | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice trick 👍
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wow
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| isSame!(args[0], arg)) | ||
| { | ||
| enum index = 0; | ||
| } | ||
| else | ||
| { | ||
| enum next = genericIndexOf!(e, tail).index; | ||
| enum index = (next == -1) ? -1 : 1 + next; | ||
| enum genericIndexOf = idx; | ||
| } | ||
| } | ||
| else | ||
| static if (is(typeof(genericIndexOf) == void)) // no hit | ||
| { | ||
| enum index = -1; | ||
| enum genericIndexOf = -1; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -844,19 +834,17 @@ template predicate must be instantiable with all the given items. | |
| */ | ||
| 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 | ||
| { | ||
| enum allSatisfy = | ||
| allSatisfy!(F, T[ 0 .. $/2]) && | ||
| allSatisfy!(F, T[$/2 .. $ ]); | ||
| enum allSatisfy = true; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -878,19 +866,17 @@ template predicate must be instantiable with one of the given items. | |
| */ | ||
| template anySatisfy(alias F, T...) | ||
| { | ||
| static if (T.length == 0) | ||
| static foreach (Ti; T) | ||
| { | ||
| enum anySatisfy = false; | ||
| } | ||
| else static if (T.length == 1) | ||
| { | ||
| 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; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6931,17 +6931,20 @@ template isInstanceOf(alias S, alias T) | |
| * | ||
| * See_Also: $(LREF isTypeTuple). | ||
| */ | ||
| template isExpressions(T ...) | ||
| template isExpressions(T...) | ||
| { | ||
| static if (T.length >= 2) | ||
| enum bool isExpressions = | ||
| isExpressions!(T[0 .. $/2]) && | ||
| isExpressions!(T[$/2 .. $]); | ||
| else static if (T.length == 1) | ||
| enum bool isExpressions = | ||
| !is(T[0]) && __traits(compiles, { auto ex = T[0]; }); | ||
| else | ||
| enum bool isExpressions = true; // default | ||
| static foreach (Ti; T) | ||
| { | ||
| static if (!is(typeof(isExpressions) == bool) && // not yet defined | ||
| (is(Ti) || !__traits(compiles, { auto ex = Ti; }))) | ||
| { | ||
| enum isExpressions = false; | ||
| } | ||
| } | ||
| static if (!is(typeof(isExpressions) == bool)) // if not yet defined | ||
| { | ||
| enum isExpressions = true; | ||
| } | ||
| } | ||
|
|
||
| /// | ||
|
|
@@ -8487,13 +8490,18 @@ private template getSymbolsByUDAImpl(alias symbol, alias attribute, names...) | |
| */ | ||
| template allSameType(T...) | ||
| { | ||
| static if (T.length <= 1) | ||
| static foreach (idx, Ti; T) | ||
| { | ||
| enum bool allSameType = true; | ||
| static if (idx + 1 < T.length && | ||
| !is(typeof(allSameType) == bool) && | ||
| !is(T[idx] == T[idx + 1])) | ||
| { | ||
| enum bool allSameType = false; | ||
| } | ||
| } | ||
| else | ||
| static if (!is(typeof(allSameType) == bool)) | ||
| { | ||
| enum bool allSameType = is(T[0] == T[1]) && allSameType!(T[1..$]); | ||
| enum bool allSameType = true; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm looks like DScanner's check is bogus here: I don't know why the other very similar code is accepted though. (Ideally preceded by a reference to a DScanner issue)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still needed @wilzbach ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't recall that this would have been fixed on the dscanner side. Though opening an issue there might help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, ok to keep as is then so we can pull this?