Skip to content

Make fmt::as_identifiers a struct instead of a variable - #4900

Open
avikivity wants to merge 1 commit into
fmtlib:mainfrom
avikivity:enum-marker-value
Open

Make fmt::as_identifiers a struct instead of a variable#4900
avikivity wants to merge 1 commit into
fmtlib:mainfrom
avikivity:enum-marker-value

Conversation

@avikivity

Copy link
Copy Markdown
Contributor

The annotation was a constant of an empty type, which left no room for options. Make the annotation type itself, fmt::as_identifiers, the thing users write, so it is now spelled

enum class [[=fmt::as_identifiers()]] color { red, green, blue };

and options can later be added as constructor arguments.

@avikivity
avikivity requested a review from vitaut as a code owner August 26, 2026 09:53
@avikivity

Copy link
Copy Markdown
Contributor Author

Note: this logically conflicts with #4899. If you want both (and you should), merge one and I'll refresh the other.

@avikivity

avikivity commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

v2:

  • rebased past e589a16
  • fixed clang-format error

@avikivity

Copy link
Copy Markdown
Contributor Author

v3:

The annotation was a constant of an empty type, which left no room for
options. Make the annotation type itself, fmt::as_identifiers, the thing
users write, so it is now spelled

  enum class [[=fmt::as_identifiers()]] color { red, green, blue };

and options can later be added as constructor arguments.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@avikivity

Copy link
Copy Markdown
Contributor Author

v4:

@vitaut

vitaut commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

What kind of options do you envision?

@avikivity

Copy link
Copy Markdown
Contributor Author

Let's say one's coding style is scary ENUM_OPTION_1 but one doesn't want to inflict it on one's users. One then writes [[=as_identifiers{.case = fmt::enum_options::lower}]] to show one's appreciation to one's coworkers, who would then likely respond by sending one some flowers and chocolate.

@avikivity

Copy link
Copy Markdown
Contributor Author

I also expect something like [[=fmt::format_as("alternative")]] when a particular identifier isn't suitable, but that isn't on the enum type itself.

@avikivity

Copy link
Copy Markdown
Contributor Author

Also: [[=fmt::as_identifiers{.with_numerical_value = true}]] useful when the enum represents something from a spec rather than just a list of stuff.

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.

2 participants