ARTICLE AD BOX
How can I get the maximum value for any enumeration without using a sentinel.
I can't use a sentinel as the enumerations are not part of my codebase.
I've seen some examples from copilot which appear that they should work but in practice they run into computer errors and I don't understand enough to correct them.
36.9k18 gold badges79 silver badges114 bronze badges
2,9934 gold badges34 silver badges45 bronze badges
10

You cannot. Not with the standard C++ anyway. There is a library called magic_enum that can do it for you but it relies on non-standard extensions for popular compilers.
2026-01-27 13:06:24 +00:00
Commented 17 hours ago
I am pretty sure you could with C++26, using the new reflexion system.
2026-01-27 13:13:14 +00:00
Commented 17 hours ago
@prapin Right, but the question is about C++14.
2026-01-27 13:21:08 +00:00
Commented 17 hours ago
@n.m.couldbeanAI, isn't magic_enum a C++17 library?
2026-01-27 13:27:21 +00:00
Commented 17 hours ago