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

Generalize get in map utils #4483

Merged
merged 4 commits into from
Feb 29, 2024
Merged

Generalize get in map utils #4483

merged 4 commits into from
Feb 29, 2024

Conversation

asl
Copy link
Contributor

@asl asl commented Feb 28, 2024

No description provided.

@asl asl requested a review from vlstill February 28, 2024 09:20
@fruffy fruffy added the core Topics concerning the core segments of the compiler (frontend, midend, parser) label Feb 28, 2024
@asl asl mentioned this pull request Feb 28, 2024
Copy link
Contributor

@vlstill vlstill left a comment

Choose a reason for hiding this comment

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

Thank you. Just a few things:

lib/map.h Outdated Show resolved Hide resolved
lib/map.h Outdated Show resolved Hide resolved
// Given a map and a key, return a optional<V> if the key exists and None if the
// key does not exist in the map.
template <class Map, typename Key = typename Map::key_type>
std::optional<typename Map::mapped_type> get_optional(const Map &m, const Key &key) {
Copy link
Contributor

Choose a reason for hiding this comment

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

getopt would be more consistent with getref. I'm not sure myself which one is better, we could go with the more explicit name you have chosen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I though about this. But getopt in a global scope is already taken by...getopt :) https://man7.org/linux/man-pages/man3/getopt.3.html So, less name clashes. It has different signature, but since it's a C function I'm afraid of macroses. We can give getopt a try and see how it will go.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Now I'm slightly leaning towards get_optional to avoid possible confusion. The error messages could get weird with getopt too.

lib/map.h Show resolved Hide resolved
@asl asl requested a review from vlstill February 29, 2024 17:55
lib/map.h Outdated Show resolved Hide resolved
lib/map.h Outdated Show resolved Hide resolved
lib/map.h Outdated Show resolved Hide resolved
@asl asl added this pull request to the merge queue Feb 29, 2024
Merged via the queue into p4lang:main with commit 098ea24 Feb 29, 2024
16 of 17 checks passed
@asl asl deleted the map-utils branch February 29, 2024 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Topics concerning the core segments of the compiler (frontend, midend, parser)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants