better-enums/example/2-iterate.cc
Anton Bachin d9bd109172 Removed range properties.
They can now be easily computed using the random access iterators. There appears
to be a slight performance improvement.
2015-05-18 09:29:35 -05:00

30 lines
650 B
C++

// Iteration over all constants.
#include <iostream>
#include <enum.h>
ENUM(Channel, int, Red = 3, Green = 4, Blue = 0);
int main()
{
// Listing declared values. Output is 3 4 0.
for (Channel channel : Channel::_values)
std::cout << channel.to_integral() << " ";
std::cout << std::endl;
// Listing declared names. Output is Red Green Blue.
for (const char *name : Channel::_names)
std::cout << name << " ";
std::cout << std::endl;
// Direct iterator usage. Output is Red.
std::cout
<< "first (using iterator): "
<< *Channel::_names.begin()
<< std::endl;
return 0;
}