mirror of
https://github.com/aantron/better-enums.git
synced 2025-12-07 01:06:42 +08:00
These modifications ensure enum.h can be used in a wider selection of end user projects without triggering warnings. GCC 4.9.2 was used with the following warning flags set: -Wall -Wextra -Wshadow -Weffc++ -Wno-unused-parameter -Wno-unused-local-typedefs -Wno-long-long -Wstrict-aliasing -Werror -pedantic -std=c++1y -Wformat=2 -Wmissing-include-dirs -Wsync-nand -Wuninitialized -Wconditionally-supported -Wconversion -Wuseless-cast -Wzero-as-null-pointer-constant This commit includes the modifications required to enable successful use of enum.h via both the "test" and "example" directories.
39 lines
813 B
C++
39 lines
813 B
C++
// Switch case exhaustiveness checking.
|
|
|
|
#include <iostream>
|
|
#include <enum.h>
|
|
|
|
ENUM(Channel, int, Red, Green, Blue)
|
|
|
|
void respond_to_channel(Channel channel)
|
|
{
|
|
// Try adding an extra case or removing one. Your compiler should issue a
|
|
// warning.
|
|
switch (channel) {
|
|
case +Channel::Red:
|
|
std::cout << "red channel" << std::endl;
|
|
break;
|
|
|
|
case +Channel::Green:
|
|
std::cout << "green channel" << std::endl;
|
|
break;
|
|
|
|
case +Channel::Blue:
|
|
std::cout << "blue channel" << std::endl;
|
|
break;
|
|
|
|
// A redundant case.
|
|
// case 3:
|
|
// break;
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
respond_to_channel(Channel::Red);
|
|
respond_to_channel(Channel::Blue);
|
|
respond_to_channel(Channel::Green);
|
|
|
|
return 0;
|
|
}
|