Skip to content

Introduce value_or() for std::map #3444

Open

Description

@Lestropie

Inspired by #1571.

There a template function value_or_default() is used to replace the ubiquitous design pattern of checking for the presence of a key in a std::map, and yielding its value if present or some default value if absent. This is a frequent and annoying pattern so would be nice to have a clean substitute. While it seems std::map hasn't inherited such a functionality yet in the language specification, std::optional sets a precedent with value_or().

Could make an attempt at a regular expression for check_syntax that could find all such instances. An LLM could likely recognise them but it's both an expensive sweep of the code base and would not protect against regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions