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

std.traits: Add SetFunctionAttributes. #555

Merged
merged 4 commits into from May 28, 2012
Merged

Conversation

dnadlinger
Copy link
Member

Currently, function/delegate types are quite hard to handle in D. For example, there is no easy way to add or remove attributes from functions in generic code (in situations like shown in the examples). Additionally, attributes can currently only specified in some declarations, but e.g. cast(extern(C) void function()) does not compile.

The added template provides an easy solution for the former problem. I have been using it in various projects to implement things like assumeNothrow(someDg), ExternC, etc. While something like assumePure (or adding attributes in general) should be included in Phobos as well (like assumeUnique), I think this is a solid start in any case.

It is not clear whether the accepted linkage types should be restricted at all; currently, the set of acceptable names is strictly specified in the grammar, but it is conceivable that other compiler implementations provide additional types, e.g. extern(Java), which SetFunctionAttributes could work with as well without any required changes. However, without the restriction, mistyped arguments would potentially give users a confusing error message in string mixin code…
They were hardly useful and deemed potentially confusing, because not specifying them did not mean that no change should occur, which would arguably be the expected behavior.
@dnadlinger
Copy link
Member Author

Rebased and incorporated a few suggestions made in #D (thanks, everyone!).

Is there anything holding this back? I understand that the implementation is not exactly beautiful, but I believe there is no better way given the current D grammar.

jmdavis added a commit that referenced this pull request May 28, 2012
std.traits: Add SetFunctionAttributes.
@jmdavis jmdavis merged commit 5d423fe into dlang:master May 28, 2012
@jmdavis
Copy link
Member

jmdavis commented May 28, 2012

Merged.

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