Skip to content

Make getAttr, getSpecificAttr, hasAttr, and hasSpecificAttr variadic #78518

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

erichkeane
Copy link
Collaborator

Discussed elsewhere, it makes sense to have these functions be variadic. They work as an 'or', that is, 'hasAttr' is "one of the set", and "getAttr" means "first of the set".

This is accomplished by extracting specific_attr_iterator into a _impl version, and creating a version + partial specialization for the _iterator version that inherits from the _impl. The result is that all of the 'existing' code 'just works'.

One exception (see the change in SemaOverload.cpp) could be solved with a conversion function, but instead I put 'auto' in. Else, I could specify the 'AttrVec' if it were preferential.

Discussed elsewhere, it makes sense to have these functions be
variadic. They work as an 'or', that is, 'has*Attr' is "one of the set",
and "get*Attr" means "first of the set".

This is accomplished by extracting specific_attr_iterator into a _impl
version, and creating a version + partial specialization for the
_iterator version that inherits from the _impl.  The result is that all
of the 'existing' code 'just works'.

One exception (see the change in SemaOverload.cpp) could be solved with
a conversion function, but instead I put 'auto' in.  Else, I could
specify the 'AttrVec' if it were preferential.
Copy link
Collaborator Author

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created as a draft, but I'd still love feedback on the approach, see if there is anyone with ideas on how to manage the 'might take just a single attr, might take a container + variadic list' functionality (as combining a default and a variadic parameter isn't really possible afaik).

I haven't found a good use for the variadic functions yet, but can either look more, or take suggestions/will put them in as a part of moving this to not a draft.

};

template <typename Container, typename... SpecificAttrs>
class specific_attr_iterator
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a version I played with where I put a conversion operator here, so that we can convert to the partial specialization, but it would only be useful in 1 place.

The downside we have here is you cannot do:

specific_attr_iterator<MyAttr> Foo = Decl->specific_attr_iterator_begin<MyAttr>()

since the two specializations are 'different' types. I was hoping @ldionne /someone else might have a clever way of combining the uses of these two.

NewE = New->specific_attr_end<EnableIfAttr>(),
OldI = Old->specific_attr_begin<EnableIfAttr>(),
OldE = Old->specific_attr_end<EnableIfAttr>();
for (auto NewI = New->specific_attr_begin<EnableIfAttr>(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A conversion operator makes this unnecessary, but it is only used 1x, so I wasn't sure of its value.

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.

1 participant