Can I use reserved identifiers in a scoped enumerator; and importantly, why not?
enum struct token { void, int, return, not, if };
Can I use reserved identifiers in a scoped enumerator; and importantly, why not?
enum struct token { void, int, return, not, if };
Why not is VERY difficult to answer but isn't really all that important. We could spend years discussing why some features are in a language and why some aren't. It would be a waste of energy. This is the language definition you have to work with and all languages that I'm familiar with follow the same paradigm. (.NET allows reserved keywords used as identifier names with but only when prefixed with a special symbol(s).) Also, no language is perfect and certainly will not fit every single criteria that any individual programmer might be looking for.
But consider if keywords were allowed in enums and in other situations: The compiler would certainly be much, much more complicated and therefore slower. Also the resulting code would be more likely to confuse the reader and make it less maintainable. C++ gives plenty of rope to hang yourself with already. Why ask for more?
But, if you really want a collection of values that reflect the language's reserved symbols then you might consider using something like std::map
with string keys and string values. That might come close to giving you what you want w/o any internal voodoo.