Skip to content

[common] Add {:r} repr formatter for TypeSafeIndex and Identifier - #5

Draft
castor639 wants to merge 1 commit into
masterfrom
typesafeindex-repr-formatter
Draft

[common] Add {:r} repr formatter for TypeSafeIndex and Identifier#5
castor639 wants to merge 1 commit into
masterfrom
typesafeindex-repr-formatter

Conversation

@castor639

@castor639 castor639 commented Aug 29, 2026

Copy link
Copy Markdown
Owner

This branch targets upstream RobotLocomotion/drake. Opening that PR returned 403 for this environment's token; use the compare link below.

RobotLocomotion/drake@master...castor639:drake:typesafeindex-repr-formatter

Fixes RobotLocomotion#24262.

Adds a {:r} (repr) format specifier for TypeSafeIndex and Identifier so error messages can include a typed representation instead of a bare integer:

fmt::format("The given {:r} is out of bounds", index);
// e.g. "The given FooIndex(87) is out of bounds"

Default {} formatting is unchanged (still the underlying integer).

Also teaches NiceTypeName to canonicalize TypeSafeIndex<...Tag> to ...Index, matching the existing Identifier<...Tag>...Id rule.

Testing

  • bazel test //common:type_safe_index_test //common:identifier_test //common:nice_type_name_test (pass)
  • //geometry:kinematics_vector build (pass; GeometryId inherits Identifier formatter)
Open in Web Open in Cursor 

@cursor
cursor Bot force-pushed the typesafeindex-repr-formatter branch from ee4b6cf to 8a40c4b Compare August 29, 2026 17:20
Default fmt output remains the bare integer. The new {:r} specifier
prints a typed representation (e.g. FooIndex(0), FooId(1)) using
NiceTypeName. Also teach NiceTypeName to canonicalize TypeSafeIndex
the same way it already does for Identifier.

Fixes RobotLocomotion#24262.
@cursor
cursor Bot force-pushed the typesafeindex-repr-formatter branch from 8a40c4b to 34a5f64 Compare August 29, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Formatter options for TypeSafeIndex and Identifier

1 participant