better-enums/example/4-switch.cc
Anton Bachin 2acb5743fa Complete documentation and testing overhaul.
The documentation is now generated from markdown. Samples are generated from the
tutorial pages. Testing is done by a Python script which runs the tests for a
large number of compilers.

This version is not very developer-friendly - the Python scripts need ways of
limiting what compilers they try to run. If you don't have 15 compilers
installed, you won't be able to run the tests in this commit. Fix coming soon.
2015-05-27 09:58:34 -05:00

29 lines
602 B
C++

// This file was generated automatically
// Safe switch
//
// A Better Enum can be used directly in a switch statement:
#include <iostream>
#include <enum.h>
ENUM(Channel, int, Red, Green, Blue)
int main()
{
Channel channel = Channel::Green;
int n;
switch (channel) {
case Channel::Red: n = 13; break;
case Channel::Green: n = 37; break;
case Channel::Blue: n = 42; break;
}
// If you miss a case or add a redundant one, your compiler should be able to
// give you a warning &mdash; try it!
std::cout << n << std::endl;
return 0;
}