4 Commits

Author SHA1 Message Date
Anton Bachin
1cfe53e827 Option to opt in to implicit conversion to enum class instead of enum.
A Better Enum is normally implicitly convertible to its internal enum type,
which makes it then implicitly convertible to an integer as well. The former
conversion is necessary for Better Enums to be usable in switch statements.
This change makes it possible to define BETTER_ENUMS_SAFER_SWITCH, which makes
Better Enums convert to an enum class, preventing the implicit conversion to
integers. The drawback is that switch cases have to be written as

    case Enum::_Case::A:

instead of

    case Enum::A:
2015-05-18 00:53:00 -05:00
Anton Bachin
14bc834f7d Made to_string conversion constexpr and removed the last of the weak symbols.
The interface is now uniformly constexpr, including to_string and the _names
iterable. Without the weak symbol, the remaining code is also entirely standard
C++.

The compile-time string trimming code in this commit has a negative impact on
performance. The performance test is now twice as slow as including <iostream>,
whereas before it was faster. That test declares an excessive number of enums,
though, so perhaps in typical usage, and with some future optimizations, the
impact will not be so significant.

There may be other ways to solve this, such as providing a version of the macro
that does not trim strings at compile time, but only checks if they need
trimming. If some string does need trimming, that macro would fail a
static_assert and ask the user to use the slow macro.
2015-05-17 21:29:26 -05:00
Anton Bachin
460bb806a3 Eliminated separate map macro file and inlined its contents into enum.h. 2015-05-17 18:44:39 -05:00
Anton Bachin
dd606fd450 Initial release. 2015-05-11 17:38:41 -04:00