Incorporated errata.

Fixes #13.
Fixes #14.

[ci skip]
This commit is contained in:
Anton Bachin 2015-12-10 16:45:27 -06:00
parent f148cc4314
commit 472a33fb64
6 changed files with 58 additions and 30 deletions

View File

@ -76,13 +76,25 @@ triplet::Color color;
You can, however, use `BETTER_ENUM` inside a namespace. You can, however, use `BETTER_ENUM` inside a namespace.
The macro has a soft limit of 64 declared constants. You can extend it by
following [these instructions][extend]. Ultimately, the number of constants is
limited by your compiler's maximum macro argument count.
In some cases, it is necessary to prefix constants such as `Channel::Red` with a
`+` to explicitly promote them to type `Channel`. For example, if you are doing
a comparison:
```
channel == +Channel::Red
```
[nested]: http://aantron.github.io/better-enums/DesignDecisionsFAQ.html#NoEnumInsideClass [nested]: http://aantron.github.io/better-enums/DesignDecisionsFAQ.html#NoEnumInsideClass
[extend]: http://aantron.github.io/better-enums/ExtendingLimits.html
## Contact and development ## Contact and development
Don't hesitate to contact me about features or bugs: Don't hesitate to contact me about features or bugs:
[antonbachin@yahoo.com][email], Twitter [@better_enums][twitter], or open an [antonbachin@yahoo.com][email], or open an issue on GitHub.
issue on GitHub.
If you'd like to help develop Better Enums, see [CONTRIBUTING][contributing]. If you'd like to help develop Better Enums, see [CONTRIBUTING][contributing].
@ -90,7 +102,6 @@ If you'd like to help develop Better Enums, see [CONTRIBUTING][contributing].
[![AppVeyor status][appveyor-img]][appveyor] [![AppVeyor status][appveyor-img]][appveyor]
[email]: mailto:antonbachin@yahoo.com [email]: mailto:antonbachin@yahoo.com
[twitter]: https://twitter.com/better_enums
[contributing]: https://github.com/aantron/better-enums/blob/master/doc/CONTRIBUTING.md [contributing]: https://github.com/aantron/better-enums/blob/master/doc/CONTRIBUTING.md
[stable]: https://img.shields.io/badge/master-kept_stable-brightgreen.svg [stable]: https://img.shields.io/badge/master-kept_stable-brightgreen.svg
[commits]: https://github.com/aantron/better-enums/blob/master/doc/CONTRIBUTING.md#commits [commits]: https://github.com/aantron/better-enums/blob/master/doc/CONTRIBUTING.md#commits

View File

@ -34,6 +34,17 @@ constants of full-`constexpr` enums. To extend:
- With CMake, you may need something like - With CMake, you may need something like
`add_definitions(-DBETTER_ENUMS_MACRO_FILE="$${CMAKE_SOURCE_DIR}/src/enum-macros.h")` `add_definitions(-DBETTER_ENUMS_MACRO_FILE="$${CMAKE_SOURCE_DIR}/src/enum-macros.h")`
You can also create a new header file that defines this macro, and then
includes `enum.h`. Then, include your new file everywhere where you would
otherwise include `enum.h`:
~~~comment
<em>#pragma once
#define BETTER_ENUMS_MACRO_FILE <common/enum_macros.h>
#include <enum.h></em>
~~~
6. Enjoy the looser limits. Just watch out &mdash; increasing the second 6. Enjoy the looser limits. Just watch out &mdash; increasing the second
number can really slow down compilation of full-`constexpr` enums. number can really slow down compilation of full-`constexpr` enums.
7. You don't need `make_macros.py` anymore. It's not part of your build 7. You don't need `make_macros.py` anymore. It's not part of your build

View File

@ -45,11 +45,10 @@ Resulting in the values `3`, `Foo::A`, and `"B"`, respectively.
--- ---
The interface is implemented in the optional header file The interface is implemented in the optional header file
[`extra/better-enums/n4428.h`][header]. There are two necessary differences. [`extra/better-enums/n4428.h`][header]. There is a necessary difference: the
interface is only available for enums declared through the `BETTER_ENUM` macro.
1. The interface is only available for enums declared through the `BETTER_ENUM` This is because the macro is what generates the information necessary for
macro. This is because the macro is what generates the information necessary reflection.
for reflection.
### Demo ### Demo

View File

@ -3,6 +3,12 @@
This tutorial shows some of the safety features of Better Enums: scope, how to This tutorial shows some of the safety features of Better Enums: scope, how to
control conversions, and the lack of a default constructor. control conversions, and the lack of a default constructor.
On balance, Better Enums are in one way less type-safe than enum class, and in
another way more type-safe. The first difference in safety is the presence of
implicit conversion to integral types. The second difference is the lack of a
default constructor. Both of these can be toggled, so you can make Better Enums
strictly safer than enum class, or just as safe.
$internal_toc $internal_toc
### Scope ### Scope
@ -47,6 +53,11 @@ will not compile:
The reason this is not enabled by default is explained in the reference page on The reason this is not enabled by default is explained in the reference page on
[strict conversions](${prefix}OptInFeatures.html#StrictConversions). [strict conversions](${prefix}OptInFeatures.html#StrictConversions).
You can conveniently define the macro on your compiler's command line, or by
creating a little header file that defines it, and then includes
<code>enum.h</code>. You can then include this new header file in your project
everywhere where you would have included <code>enum.h</code>.
### Default constructor ### Default constructor
Better Enums generate without a default constructor. The purpose is to support Better Enums generate without a default constructor. The purpose is to support

View File

@ -41,11 +41,9 @@
// Resulting in the values 3, Foo::A, and "B", respectively. // Resulting in the values 3, Foo::A, and "B", respectively.
// The interface is implemented in the optional header file // The interface is implemented in the optional header file
// extra/better-enums/n4428.h. There are two necessary differences. // extra/better-enums/n4428.h. There is a necessary difference: the interface is
// // only available for enums declared through the BETTER_ENUM macro. This is
// 1. The interface is only available for enums declared through the // because the macro is what generates the information necessary for reflection.
// BETTER_ENUM macro. This is because the macro is what generates the
// information necessary for reflection.
// //
// Demo // Demo
// //

View File

@ -5,6 +5,12 @@
// This tutorial shows some of the safety features of Better Enums: scope, how // This tutorial shows some of the safety features of Better Enums: scope, how
// to control conversions, and the lack of a default constructor. // to control conversions, and the lack of a default constructor.
// //
// On balance, Better Enums are in one way less type-safe than enum class, and
// in another way more type-safe. The first difference in safety is the presence
// of implicit conversion to integral types. The second difference is the lack
// of a default constructor. Both of these can be toggled, so you can make
// Better Enums strictly safer than enum class, or just as safe.
//
// Scope // Scope
// //
// You have probably noticed by now that Better Enums are scoped: when you // You have probably noticed by now that Better Enums are scoped: when you
@ -45,28 +51,20 @@ int main()
// The reason this is not enabled by default is explained in the reference page // The reason this is not enabled by default is explained in the reference page
// on strict conversions. // on strict conversions.
// //
// You can conveniently define the macro on your compiler's command line, or by
// creating a little header file that defines it, and then includes enum.h. You
// can then include this new header file in your project everywhere where you
// would have included enum.h.
//
// Default constructor // Default constructor
// //
// Better Enums don't have a default constructor, for three reasons. // Better Enums generate without a default constructor. The purpose is to
// // support the convention where if a Better Enum exists, then it has a valid
// 1. Better Enums is a library that can't know what your application would // value. So, if you uncomment this code, the program won't compile:
// like the default value to be for each enum, or whether you even want
// one.
// 2. I chose not to leave the default value undefined, because the idea is to
// encourage the convention that whenever a Better Enum exists, it has a
// valid value. This is borrowed from typed functional programming.
// 3. Better Enums is still under development, and this option is the most
// future-proof.
//
// So, if you uncomment this code, the file won't compile:
// //
// Channel channel; // Channel channel;
// //
// This may be too strict, and I may relax it in the future. In the meantime, // If this is too strict for your project, you can relax it as described here.
// the solution sketched in the special values demo can replace default
// constructors for some purposes, and in a more flexible way. I may eventually
// have the default constructor calling a template function like the one in that
// demo.
return 0; return 0;