-
-
Notifications
You must be signed in to change notification settings - Fork 706
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
Fix issue 9591 - Add ApplyWith template #5738
Conversation
to a template alias that is passed at the end. Useful for staticMap.
|
Thanks for your pull request, @schveiguy! Bugzilla references
|
std/meta.d
Outdated
| alias functions = staticMap!(ApplyLeft!(ApplyWith, string), | ||
| leftJustify, center, rightJustify); | ||
| string result = ""; | ||
| static foreach(f; functions) |
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.
Spacing after foreach applies to static foreach too (that's why CircleCi is failing)
I will never be trained at this point to do that spacing properly... :) Updated. |
std/meta.d
Outdated
| * list of arguments to one template. | ||
| * | ||
| * `ApplyWith!(A0, A1, ..., An-1, An)` is equivalent to | ||
| * `An!(A0, A1, ..., An-1)` |
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 kept looking at this and I might be wrong, but I can't stop wondering if it wouldn't be more natural for the call to be A0!(A1, ..., An) ?
If so, maybe we could have the template declaration as ApplyWith(Func, Args...) ?
What do you think?
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 get what you are saying. By itself, ApplyWith (or whatever we should call it) looks weird when you add the template at the end. The whole point of this template is to work with ApplyLeft. It's like specifying all the parameters, and leaving the actual template to be used up to a later time.
For example:
template T1(T) {}
template T2(T) {}
alias X = ApplyLeft!(ApplyWith!string);
alias a = X!T1; // equivalent to T1!string
alias b = X!T2; // equivalent to T2!stringI'm thinking now, since pretty much ApplyLeft is required to make any sense, ApplyWith should use it internally instead of Instantiate. The fact that it's used can be hidden.
|
OK, I redesigned |
|
Isn't that simply |
|
(And if so, |
|
@klickverbot Yes, I didn't think of that mechanism. However, |
|
Opened said PR: #5739 |
Bikeshedding for
ApplyWithname welcome. If you look at the example, it reads well, but maybe not when specified on its own.