Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

schveiguy
Copy link
Member

Bikeshedding for ApplyWith name welcome. If you look at the example, it reads well, but maybe not when specified on its own.

to a template alias that is passed at the end. Useful for staticMap.
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @schveiguy!

Bugzilla references

Auto-close Bugzilla Description
9591 std.typetuple.staticApplyMap

std/meta.d Outdated
alias functions = staticMap!(ApplyLeft!(ApplyWith, string),
leftJustify, center, rightJustify);
string result = "";
static foreach(f; functions)
Copy link
Member

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)

@schveiguy
Copy link
Member Author

Spacing

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)`
Copy link
Contributor

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?

Copy link
Member Author

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!string

I'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.

@schveiguy
Copy link
Member Author

OK, I redesigned ApplyWith so it is much less confusing. Thanks @edi33416 for the review, please take a look at the new design.

@dnadlinger
Copy link
Member

dnadlinger commented Sep 17, 2017

Isn't that simply ApplyRight!(Instantiate, Args)?

@dnadlinger
Copy link
Member

(And if so, alias functions = staticMap!(ApplyRight!(Instantiate, string), leftJustify, center, rightJustify); imho reads just fine and is self-explanatory, no need for ApplyWith.)

@schveiguy
Copy link
Member Author

@klickverbot Yes, I didn't think of that mechanism. However, Instantiate is private. Maybe I can just close this and make a PR to make it public?

@schveiguy schveiguy closed this Sep 17, 2017
@schveiguy schveiguy deleted the fix9591 branch September 17, 2017 16:18
@schveiguy
Copy link
Member Author

Opened said PR: #5739

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants