-
Notifications
You must be signed in to change notification settings - Fork 447
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
Conversation
There was a problem hiding this 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:
// 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
No description provided.