Advertisement
homer512

C++11 enum attribute set

Jul 21st, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <bitset>
  2.  
  3. namespace {
  4.  
  5.   namespace Source {
  6.     // not an enum class because these have no implicit conversion to int    
  7.     enum Type {
  8.       analog_radio,
  9.       internet_radio,
  10.       bluetooth
  11.     };
  12.     // keep updated when adding new Type
  13.     constexpr std::size_t size()
  14.     {
  15.       return Source::bluetooth + 1;
  16.     }
  17.   }
  18.   typedef std::bitset<Source::size()> SourceSet;
  19. }
  20.  
  21. int main()
  22. {
  23.   SourceSet attributes;
  24.   attributes[Source::analog_radio] = true;
  25.   attributes[Source::bluetooth] = true;
  26.   return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement