Updated documentation.

This commit is contained in:
Anton Bachin 2015-10-05 13:42:11 -05:00
parent e9b6792922
commit d99bae7284
13 changed files with 64 additions and 69 deletions

View File

@ -5,7 +5,7 @@ file.
![Better Enums code overview][sample]
[sample]: https://raw.githubusercontent.com/aantron/better-enums/0.10.1/doc/image/sample.gif
[sample]: https://raw.githubusercontent.com/aantron/better-enums/master/doc/image/sample.gif
[![Try online][wandbox-img]][wandbox] [![version 0.10.1][version]][releases]
[![BSD license][license-img]][license]
@ -25,7 +25,7 @@ See the [project page][project] for full documentation.
[max]: http://aantron.github.io/better-enums/demo/BitSets.html
[enforce]: http://aantron.github.io/better-enums/demo/SpecialValues.html
[project]: http://aantron.github.io/better-enums
[wandbox]: http://melpon.org/wandbox/permlink/5N9QZYdA5LqWy26R
[wandbox]: http://melpon.org/wandbox/permlink/2QCi3cwQnplAToge
[tutorial]: http://aantron.github.io/better-enums#Tutorial
[api]: http://aantron.github.io/better-enums/ApiReference.html
[releases]: https://github.com/aantron/better-enums/releases

View File

@ -2,7 +2,7 @@
Better Enums aims to support all major compilers. It is known to work on:
- clang 3.3 to 3.6
- clang 3.3 to 3.7
- gcc 4.3 to 5.2
- Visual C++ 2008 to 2015RC.
@ -78,6 +78,10 @@ vc2013 /EHsc /DBETTER_ENUMS_STRICT_CONVERSION
vc2012 /EHsc
vc2010 /EHsc
vc2008 /EHsc
clang++37 -std=c++11
clang++37 -std=c++11 -DBETTER_ENUMS_STRICT_CONVERSION
clang++37 -std=c++11 -DBETTER_ENUMS_CONSTEXPR_TO_STRING
clang++37 -std=c++98
clang++36 -std=c++11
clang++36 -std=c++11 -DBETTER_ENUMS_STRICT_CONVERSION
clang++36 -std=c++11 -DBETTER_ENUMS_CONSTEXPR_TO_STRING

View File

@ -192,8 +192,6 @@ However, it also introduces some difficulties.
- Traits types must be specialized in either the same namespace scope they are
declared in, or in an enclosing scope. This makes it impossible to declare an
enum and specialize traits for it in a user's custom namespace.
- Traits types are not intuitive for some $cxx users, which would present a
barrier to usage.
Despite the disadvantages listed just above, I consider the traits approach
interesting — it's a close call. There is an

View File

@ -6,6 +6,27 @@ default. Read this page if you want to enable them.
$internal_toc
### Default constructors
Better Enums generate with inaccessible (private or deleted) default
constructors. This is meant to help control where in your program Better Enums
values are introduced, and thus ensure that only valid, properly initialized
enum values are ever created.
If you want Better Enums to have a default constructor, you can do something
like the following:
~~~
<em>#define</em> <em>BETTER_ENUMS_DEFAULT_CONSTRUCTOR</em>(<em>Enum</em>) \
<em>public</em>: \
<em>Enum()</em> = <em>default</em>;
<em>#include</em> <<em>enum.h</em>>
~~~
You can put this in its own header file, and include that header file instead of
including `enum.h` directly.
### Compile-time name trimming
This makes `_to_string` and `_names` `constexpr`, i.e. "full" `constexpr` mode.

View File

@ -55,6 +55,18 @@ code, samp {
margin-right: 150px;
}
.main .container > * {
max-width: 41em;
}
.index .main .container > * {
max-width: none;
}
.main .container > .contents {
max-width: none;
}
@media (max-width: 1400px) {
.container {
margin-left: auto;

View File

@ -44,14 +44,12 @@ Resulting in the values `3`, `Foo::A`, and `"B"`, respectively.
---
The optional Better Enums header file [`extra/better-enums/n4428.h`][header]
implements this interface, though with two necessary differences.
The interface is implemented in the optional header file
[`extra/better-enums/n4428.h`][header]. There are two necessary differences.
1. The interface is only available for Better Enums, i.e. enums declared through
the `BETTER_ENUM` macro. This is because the macro is what generates the
information necessary for reflection.
2. The type of `identifier` is `const char*`, not the ${cxx17} proposed
`string_literal`.
1. The interface is only available for enums declared through the `BETTER_ENUM`
macro. This is because the macro is what generates the information necessary
for reflection.
### Demo
@ -101,24 +99,11 @@ Let's declare an enum:
That prints `Blue`, as you would expect.
---
So, Better Enums can be used in $cxx11 to test N4428, and maybe start developing
libraries on top of it. N4428 is very low-level, so it needs additional code
over it to be truly useful. Whether developing now is a good idea is debatable,
since N4428 is still only a proposal. But, it's an interesting thing to
consider.
Also, Better Enums can be implemented almost completely *in terms of* N4428, so
the two interfaces are in some vaguely mathematical sense "equivalent." If N4428
is accepted, I may implement a variant of Better Enums on top of it, since it
will remove many limitations.
### Quirk
The reason for the `#define` in the code above is that there is one quirk:
the interface above is available only for Better Enums for which
[compile-time name trimming][slow-enum] is enabled, i.e. those declared when
[compile-time name trimming][slow-enum] is enabled &mdash; those declared when
`BETTER_ENUMS_CONSTEXPR_TO_STRING` was defined, or declared with the `SLOW_ENUM`
variant of `BETTER_ENUM`. As mentioned on the linked page, the reason
compile-time name trimming is not the default is that, while still pretty fast,
@ -183,7 +168,7 @@ enums, I will try to implement those as well.
[n3815]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3815.html
[slow-enum]: ${prefix}OptInFeatures.html#CompileTimeNameTrimming
[header]: https://github.com/aantron/better-enums/blob/$ref/extra/better-enums/n4428.h
[live]: http://melpon.org/wandbox/permlink/pNEx7UEWqDtqFAwm
[live]: http://melpon.org/wandbox/permlink/QelcwZNLi4gIx8Ux
%% description = Approximate implementation of N4428 enum reflection based on
Better Enums.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 79 KiB

View File

@ -72,7 +72,7 @@ fast, portable, and documented exhaustively.
To use it, just include <code>enum.h</code>.
Try it live online in
[Wandbox](http://melpon.org/wandbox/permlink/wICNzu2LW2vEgqzh), or begin the
[Wandbox](http://melpon.org/wandbox/permlink/6kFervewqeDsNAGu), or begin the
[tutorial](${prefix}tutorial/HelloWorld.html)!
<div class="hack"></div>

View File

@ -1,8 +1,7 @@
<p>
This page is an advanced demo showing the kind of code you can write on top of
Better Enums. It's a valid program &mdash; you can
<a href="$source">download</a> it and try it out. The program runs as part of
the automated test suite.
This is an example of code you can write on top of Better Enums. It's a valid
program &mdash; you can <a href="$source">download</a> it and try it out. The
program is also part of the test suite.
</p>
$demo_body

View File

@ -1 +1 @@
master
0.11.0

View File

@ -1 +1 @@
0.10.1
0.11.0

View File

@ -49,27 +49,16 @@ The reason this is not enabled by default is explained in the reference page on
### Default constructor
Better Enums don't have a default constructor, for three reasons.
- Better Enums is a library that can't know what your application would like
the default value to be for each enum, or whether you even want one.
- 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.
- 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:
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 value. So, if
you uncomment this code, the program won't compile:
~~~comment
Channel channel;
~~~
This may be too strict, and I may relax it in the future. In the meantime, the
solution sketched in the [special values demo](${prefix}demo/SpecialValues.html)
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.
If this is too strict for your project, you can relax it as described
[here](${prefix}OptInFeatures.html#DefaultConstructors).
---

View File

@ -40,14 +40,12 @@
//
// Resulting in the values 3, Foo::A, and "B", respectively.
// The optional Better Enums header file extra/better-enums/n4428.h implements
// this interface, though with two necessary differences.
// The interface is implemented in the optional header file
// extra/better-enums/n4428.h. There are two necessary differences.
//
// 1. The interface is only available for Better Enums, i.e. enums declared
// through the BETTER_ENUM macro. This is because the macro is what
// generates the information necessary for reflection.
// 2. The type of identifier is const char*, not the ${cxx17} proposed
// string_literal.
// 1. The interface is only available for enums declared through the
// BETTER_ENUM macro. This is because the macro is what generates the
// information necessary for reflection.
//
// Demo
//
@ -95,23 +93,12 @@ int main()
}
// That prints Blue, as you would expect.
// So, Better Enums can be used in C++11 to test N4428, and maybe start
// developing libraries on top of it. N4428 is very low-level, so it needs
// additional code over it to be truly useful. Whether developing now is a good
// idea is debatable, since N4428 is still only a proposal. But, it's an
// interesting thing to consider.
//
// Also, Better Enums can be implemented almost completely in terms of N4428, so
// the two interfaces are in some vaguely mathematical sense "equivalent." If
// N4428 is accepted, I may implement a variant of Better Enums on top of it,
// since it will remove many limitations.
//
// Quirk
//
// The reason for the #define in the code above is that there is one quirk: the
// interface above is available only for Better Enums for which compile-time
// name trimming is enabled, i.e. those declared when
// name trimming is enabled - those declared when
// BETTER_ENUMS_CONSTEXPR_TO_STRING was defined, or declared with the SLOW_ENUM
// variant of BETTER_ENUM. As mentioned on the linked page, the reason
// compile-time name trimming is not the default is that, while still pretty