Using Enum Classes as Bitfields -- Anthony Williams

How to use enum classes as as bitfields in modern C++ programs.

Using Enum Classes as Bitfields

by Anthony Williams

From the article:

C++11 introduced a new feature in the form of scoped enumerations, also referred to as enum classes, since they are introduced with the double keyword enum class (though enum struct is also permissible, to identical effect). To a large extent, these are like standard enumerated types: you can declare a list of enumerators, which you may assign explicit values to, or which you may let the compiler assign values to. You can then assign these values to variables of that type. However, they have additional properties which make them ideal for use as bitfields. I recently answered a question on the accu-general mailing list about such a use, so I thought it might be worth writing a blog post about it.

 

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.