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

Added support for template deduction guides #87

Merged
merged 1 commit into from
Dec 5, 2023

Conversation

justinboswell
Copy link
Contributor

https://en.cppreference.com/w/cpp/language/class_template_argument_deduction

The parser was very close to being able to do this already, it just needed a bit of a peek to confirm. There might be a better way to do this, but it was the narrowest change I could come up with

@virtuald
Copy link
Member

virtuald commented Dec 2, 2023

This is really similar to a constructor in that it looks like a function that doesn't have a return type, so I think dealing with this in the same neighborhood would probably be easier -- see _parse_decl -- in particular, the comment if it's not a constructor/destructor would probably be the best place to put the arrow detection, and then set a variable that makes the following _parse_function parse the return type correctly.

I don't think I would set the return type to auto, because that isn't quite right.

I do wonder if this sort of thing should have its own type instead of using Function? I'm not sure what a user of this library would really do with these anyways, but it's a bit misleading to say they're functions.

@justinboswell
Copy link
Contributor Author

I modeled it after how Function is emitted for function forward declarations. I can move the check, that makes sense. The auto return type was just to ensure that function parsing works, in retrospect it should probably overwrite the return type with the trailing return type.

The output isn't that important, at least in my case, and it'd be a pretty impressive/pedantic code generator/parswr that cares about deduction guides. I just need it to survive parsing them 😁

@justinboswell
Copy link
Contributor Author

justinboswell commented Dec 5, 2023

I'm not entirely thrilled with the (ab)use of Function, but it works. I'm thinking it might clearer to just do the relevant steps in _parse_function and _parse_trailing_return_type() as _parse_deduction_guide()?

cxxheaderparser/parser.py Outdated Show resolved Hide resolved
* Added DeductionGuide as a language element
@virtuald virtuald merged commit 29b71ab into robotpy:main Dec 5, 2023
33 checks passed
@virtuald
Copy link
Member

virtuald commented Dec 5, 2023

Thanks!

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