-
Notifications
You must be signed in to change notification settings - Fork 58
Open
Description
Context
Currently, to get a parameter with a fallback, you must write:
auto p = u.params();
auto it = p.find("id");
if (it != p.end())
use(*it);
else
use("na");Proposal
Add a shorthand:
u.params().get_or("id", "na"); // returns "na" if not foundInternal Discussion
11/07/2025
- Peter Dimov pointed out that
value_oris a method name reserved foroptionaltypes (.value_or(def)). get_oraligns with the naming direction discussed in WG21 proposal P3091R4:getfor associative containers and § “Other names for get”.- Peter noted that in his own code this is typically called
lookup()returning a pointer, butget_oris acceptable since it’s clear and consistent. - The committee papers P3857R0 and P3091R4 show that the final naming direction for standard containers is still unsettled but likely to be
get, soget_ormatches the expected C++ naming evolution (getandget_orpairs). - Avoids confusion with
optional::value_or.
Next Steps
- Confirm naming (
get_or) - Implement in both
params_encoded_viewandparams_view.
References:
Metadata
Metadata
Assignees
Labels
No labels