Fix typo
[rofl0r-order-pp.git] / example / enum.cpp
bloba6134da2772e9007862ed8c505f71f111e8e6cc1
1 // (C) Copyright Vesa Karvonen 2004.
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE.)
6 # include <iostream>
7 # include "enum.hpp"
9 // ### Usage
11 // To demonstrate the use of the `ENUM'-macro, we'll write a simple
12 // `ENUM'-specification:
14 //<
15 ENUM(naked_gun,
16 (from_the_files_of_police_squad, 1)
17 (the_smell_of_fear)
18 (the_final_insult, 33))
19 //>
20 // Then we'll use the generated conversion functions and output the
21 // strings returned by the `to_string'-function:
22 //<
23 int main(void) {
24 std::cout
25 << to_string(to_naked_gun("from_the_files_of_police_squad"))
26 << '\n'
27 << to_string(to_naked_gun("the_smell_of_fear"))
28 << '\n'
29 << to_string(to_naked_gun("the_final_insult"))
30 << '\n';
32 return 0;
34 //>
36 // \begin{exercise}
37 // The conversion from the value of an enumerator to a string can be
38 // done in constant time easily when the values of the enumerators
39 // are known to be consecutive. This is known to be the case when
40 // all but the first enumerator use the default value. Implement the
41 // constant time conversion as an optimization.
42 // \end{exercise}
44 // \begin{exercise}
45 // Extend the `ENUM'-macro to optionally generate a standard stream
46 // inserter and a stream extractor for the defined enumerated type.
47 // \end{exercise}
49 // \begin{exercise}
50 // Extend the `ENUM'-macro to optionally generate constructors for
51 // the enumerated type. The constructors should check that that the
52 // specified integral value or string identifier is one of the
53 // enumerators and throw an exception if that is not the case.
54 // \end{exercise}