Skip to content

Formatter options for TypeSafeIndex and Identifier #24262

Description

@jwnimmer-tri

Is your feature request related to a problem? Please describe.

When an error message incorporates a TypeSafeIndex<Tag> (e.g., BodyIndex) or Identifier<Tag> (e.g., GeometryId), right now the default fmt::format output for that value is just the underlying bare integer. The type (e.g., "body" or "geometry") might not always be clear from context, so sometimes the error message text needs to laboriously incorporate the type.

throw std::logic_error(fmt::format(
"The given {}Index({}) is out of bounds (must be less than {})",
nice_type, index, next_index()));

Describe the solution you'd like

Enhance TypeSafeIndex<Tag> and Identifier<Tag> to offer a repr formatter, so that the format string could be something like fmt::format("The given {:r} is out of bounds", index).

Describe alternatives you've considered

N/A

Additional context

N/A

Activity

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions