Type Safe C++ enum Extensions -- Alf Steinbach
Is it possible to extend a value type in C++? Alf Steinbach describes how to extend enum values.
Type Safe C++ enum Extensions
by Alf Steinbach
From the article:
Consider if an
enumlike the following,enum class Suit{ spades, hearts, diamonds, clubs };could be extended like
enum class Suit_with_joker extends Suit { joker };where
Suit_with_jokerhas all the enumerators ofSuitplus thejokerenumerator; and- enumerators introduced in
Suit_with_jokerget integer values following those ofSuit; and- any
Suitvalue is also aSuit_with_jokervalue.This would be an example of what I’ll call a value type extension.
The apparently backwards is-a relationship in the last point, where any value of the original type is-a value of the derived type, is characteristic of value type extensions.
C++20 totally lacks support for value type extensions, of
enumtypes or other types.

Registration is now open for CppCon 2023! The conference starts on October 1 and will be held
Registration is now open for CppCon 2023! The conference starts on October 1 and will be held
Operator overloading. Looks great. Reduces verbosity. Until it doesn’t.
Registration is now open for CppCon 2023! The conference starts on October 1 and will be held
Registration is now open for CppCon 2023! The conference starts on October 1 and will be held
Guarded Suspension applies a unique strategy to deal with mutation. It signals when it is done with its modification.
Registration is now open for CppCon 2023! The conference starts on October 1 and will be held
Recently, our team at Meteksan Defense is upgrading its development environment to use newer versions of many tools and programming languages. One of the more difficult transitions has been the upgrade of our C++11 code base to C++17 for our embedded applications.