Summary
Recently Maksym Motornyy proposed on the Boost mailing list, a macro library for typesafe enums. This is not the first time someone has suggested macros for enhancing macros. I wish to demonstrate that you don't have to resort to macros for typesafe enums.

Advertisement

C++ enums are well-known to be not-typesafe. They look like type declarations, but are in fact simply integer constants. Their existance in C++ is vestigial, and they should not be used. On the other hand true enumerated types are themselves very useful. Here is a technique for implementing true enumerations in C++:

RSS Feed

About the Blogger

Christopher Diggins is a software developer and freelance writer. Christopher loves programming, but is eternally frustrated by the shortcomings of modern programming languages. As would any reasonable person in his shoes, he decided to quit his day job to write his own ( www.heron-language.com ). Christopher is the co-author of the C++ Cookbook from O'Reilly. Christopher can be reached through his home page at www.cdiggins.com.