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

Allow aliases with using #407

Merged
merged 19 commits into from
Jan 17, 2025
Merged

Allow aliases with using #407

merged 19 commits into from
Jan 17, 2025

Conversation

charlesstaats
Copy link
Contributor

C++11 introduced the keyword using, which can be used for a more intuitive but equivalent version of typedef. For instance,

typedef int intop(int);
using intop = int(int);

are now equivalent. This PR introduces a similar feature into Asymptote. There's no new functionality, but many programmers find the using-style alias easier to read since it is much more similar to variable assignment.

@charlesstaats
Copy link
Contributor Author

Correction: The word using was already present in C++ (as in using namespace std;); it was not introduced in C++11, only given an additional use. I think it's unlikely that existing users have variables, functions, or types called using, but I'd be open to repurposing an existing keyword instead if there is one that would work.

Additional note: The way I've implemented using is a bit hacky. In some sense, I think this is unavoidable: the tradeoff for a very elegant implementation was the weird syntax that typedef uses to define function types. I welcome suggestions on how to make the implementation more elegant and/or more thorough (e.g., supporting comma-separated aliases rather than only the single alias, or refactoring the typedef definition rather than clunkily rewriting a using statement into a typedef). But I also urge the reviewers not to make the perfect the enemy of the good.

@charlesstaats
Copy link
Contributor Author

Upon further consideration, I actually think the current approach may be the best "reasonable" option available. I have added comments to camp.y to explain how the syntax of using is designed to imitate the type alias syntax in the C++ standard.

@johncbowman johncbowman merged commit 3683c52 into master Jan 17, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants