Skip to content

feat: convenience accessor for query parameters #945

@alandefreitas

Description

@alandefreitas

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 found

Internal Discussion

11/07/2025

  • Peter Dimov pointed out that value_or is a method name reserved for optional types (.value_or(def)).
  • get_or aligns with the naming direction discussed in WG21 proposal P3091R4: get for associative containers and § “Other names for get”.
  • Peter noted that in his own code this is typically called lookup() returning a pointer, but get_or is 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, so get_or matches the expected C++ naming evolution (get and get_or pairs).
  • Avoids confusion with optional::value_or.

Next Steps

  • Confirm naming (get_or)
  • Implement in both params_encoded_view and params_view.

References:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions