-
Notifications
You must be signed in to change notification settings - Fork 35
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
Consider introducing a map
function combining contains check and value retrieval
#1608
Labels
Comments
bbannier
added
Runtime Library
Issues related to the HILTI or Spicy runtime libraries
Codegen
labels
Dec 5, 2023
rsmmr
added a commit
that referenced
this issue
Jun 6, 2024
This returns an optional either containing the map's element for the given key if that entry exists, or an unset optional if it does not. Closes #1608. (Note that we cannot use the same, improved implementation for the existing `get()` method because that needs to return a reference.)
rsmmr
added a commit
that referenced
this issue
Jun 7, 2024
This returns an optional either containing the map's element for the given key if that entry exists, or an unset optional if it does not. Closes #1608. (Note that we cannot use the same, improved implementation for the existing `get()` method because that needs to return a reference.)
rsmmr
added a commit
that referenced
this issue
Jun 12, 2024
This returns an optional either containing the map's element for the given key if that entry exists, or an unset optional if it does not. Closes #1608. (Note that we cannot use the same, improved implementation for the existing `get()` method because that needs to return a reference.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
If one wants to check whether a
map
contains a value and retrieve it one currently is nudged into a double iteration pattern, e.g.,We currently provide
map::get
which bundles this into one operation (though it also generates code which does a double iteration), but this can only be used for this use case if the there is some magic "default" value which cannot appear in the genuine value domain (else we couldn't distinguish entries at default from absent values).We should consider introducing a
map
method (e.g.,get_if
or similar) which given a key returns anoptional
value (set if present, else unset). We could then also use this to provide a more efficient implementation ofget
.The text was updated successfully, but these errors were encountered: