make ApplyLeft/ApplyRight work with deep template#4374
make ApplyLeft/ApplyRight work with deep template#4374DmitryOlshansky merged 1 commit intodlang:masterfrom mogud:master
Conversation
std/meta.d
Outdated
| template ApplyLeft(right...) | ||
| { | ||
| static if (is(typeof(Template!(args, right)))) | ||
| static if (is(typeof({ enum _T = Template!(left, args); }))) |
There was a problem hiding this comment.
Does the alias ApplyLeft = Id!(Template!(args, right)); trick work here (where Id is a template that does the alias-ing/enum-ing)? (which would leave you with only one branch)
There was a problem hiding this comment.
@wilzbach I edited it on web. It's a mistake caused by ctrl + c/v. :(
|
To elaborate on my in-line comment, given this (which certainly exists somehwere in Phobos) alias Id(T) = T;
alias Id(alias T) = T;the implementation could simply be template ApplyLeft(alias Template, args...)
{
alias ApplyLeft(right...) = Id!(Template!(args, right));
}
template ApplyRight(alias Template, args...)
{
alias ApplyRight(left...) = Id!(Template!(left, args));
}I'm not sure why treating the zero-argument case differently would be required. Maybe that's an attempt at (premature?) optimisation; the original PR discussion should hopefully have more information. |
| static assert(is(Filter!(ApplyRight!(isImplicitlyConvertible, short), | ||
| ubyte, string, short, float, int) == AliasSeq!(ubyte, short))); | ||
|
|
||
| static assert(is(typeof({ |
There was a problem hiding this comment.
Thanks for adding the unit test; as you discovered, the current implementation is not nearly covered as well as it should be. However, I don't think it really makes sense to show this particular case in the documentation, as it looks pretty confusing at first, and users would just expect it to work transparently anyway. Could you move it to a non-DDoc unittest block?
There was a problem hiding this comment.
Agreed. Id -> Alias in meta.d? I tried the new implementation used Alias and all tests passed.
|
If you want to go this route instead of the simplified version (which is fair enough for a quick fix), could you please make sure that the unit test actually covers both the cases? It seems like the typo you had previously made in ApplyLeft slipped through the cracks. |
|
The |
|
I mentioned |
|
@mogucpp: Sorry about that, the GitHub UI makes such comments easy to miss. The basic issue here is that (simplifying a bit) |
|
Sorry for my poor English misleading. I mean the current implement of |
| /** | ||
| Tests whether all given items satisfy a template predicate, i.e. evaluates to | ||
| $(D F!(T[0]) && F!(T[1]) && ... && F!(T[$ - 1])). | ||
|
|
There was a problem hiding this comment.
Please leave those as a paragraph break.
|
In this case, you are right. I don't know of a case where that would be required either. That being said, the fact that you can always alias alias parameters is somewhat of a little-known implementation detail, so whoever wrote and reviewed |
|
This PR's commits looks awful. So weak I am. :( |
|
Ah, we've all started out at some point. What would be embarrassing is if I didn't remember any of the old tricks – after all, my name is on that module, too. ;) Apart from that, we generally ask people to squash their commits into one (or atomic pieces) before merging a PR anyway. |
|
All commits squashed into one now. Thanks for your patience. :) |
|
This also fixes issue https://issues.dlang.org/show_bug.cgi?id=16070 See also #4352 UPDATE: so this pull seems to be a superset of #4352 - @klickverbot which one to merge? ;) |
|
@DmitryOlshansky: Merge the other one of you are sure that it also works for all value cases, this one to play it safe. ;) |
|
Covered all cases now, i think. |
|
Just add "fixes Issue 16070" to commit message and it should be good to go. |
I think @mogucpp forgot to leave a note here. The commit message now contains "fix Issue 16070". |
|
Auto-merge toggled on |
The added codes in unittest not work before.