mirror of
https://github.com/aantron/better-enums.git
synced 2025-12-06 16:56:42 +08:00
34 lines
683 B
C++
34 lines
683 B
C++
// Usage with std::bitset.
|
|
|
|
#include <bitset>
|
|
#include <iostream>
|
|
#include <enum.h>
|
|
|
|
ENUM(Channel, int, Red, Green, Blue);
|
|
|
|
int main()
|
|
{
|
|
using ChannelSet = std::bitset<Channel::_span>;
|
|
|
|
ChannelSet red_only;
|
|
red_only.set(Channel::Red);
|
|
|
|
ChannelSet blue_only;
|
|
blue_only.set(Channel::Blue);
|
|
|
|
ChannelSet red_and_blue = red_only | blue_only;
|
|
|
|
for (Channel channel : Channel::_values) {
|
|
std::cout
|
|
<< channel.to_string()
|
|
<< " bit is set to "
|
|
<< red_and_blue[channel]
|
|
<< std::endl;
|
|
}
|
|
|
|
if (red_and_blue[Channel::Green])
|
|
std::cout << "bit set contains Green" << std::endl;
|
|
|
|
return 0;
|
|
}
|