Newsgroup: comp.lang.c++
Subject: Strongly-typed non-scoped enums in C++11?
From: Paavo Helde <myfirstname@...>
Date: Fri, 23 Aug 2013 02:28:33 -0500
In C++11, you can have 'enum class abc' which is strongly-typed and
scoped, and 'enum abc: type' which are not scoped, but also not
strongly-typed. However, I would like to have a non-scoped strongly-typed
enum, is this possible somehow?
Background: I would like to have strongly-typed enums in order to find
out and fix suspicious comparisons and conversions to integers. However,
only one of our build machines has a compiler version which supports C++
11 enums, a legacy enum is needed for other builds. For the diagnostics
point of view it is fine if it works only in one build, so I thought
doing something like:
#ifdef HAS_C11_STRONGLY_TYPED_ENUMS
enum class abc {
#else
enum abc {
#endif
val1,
val2,
....
};
Alas, now all the codebase must be changed to use the names abc::val1,
abc::val2 in the C11 branch, and must not use the prefix in the legacy
branch. This seems to kill the whole benefit of this approach. Any ideas?
TIA
Paavo
Subject: Strongly-typed non-scoped enums in C++11?
From: Paavo Helde <myfirstname@...>
Date: Fri, 23 Aug 2013 02:28:33 -0500
In C++11, you can have 'enum class abc' which is strongly-typed and
scoped, and 'enum abc: type' which are not scoped, but also not
strongly-typed. However, I would like to have a non-scoped strongly-typed
enum, is this possible somehow?
Background: I would like to have strongly-typed enums in order to find
out and fix suspicious comparisons and conversions to integers. However,
only one of our build machines has a compiler version which supports C++
11 enums, a legacy enum is needed for other builds. For the diagnostics
point of view it is fine if it works only in one build, so I thought
doing something like:
#ifdef HAS_C11_STRONGLY_TYPED_ENUMS
enum class abc {
#else
enum abc {
#endif
val1,
val2,
....
};
Alas, now all the codebase must be changed to use the names abc::val1,
abc::val2 in the C11 branch, and must not use the prefix in the legacy
branch. This seems to kill the whole benefit of this approach. Any ideas?
TIA
Paavo
via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?72045-Strongly-typed-non-scoped-enums-in-C-11&goto=newpost
View all the progranning help forums at:
http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums