Are enums the canonical way to implement bit flags?

后端 未结 3 2023
死守一世寂寞
死守一世寂寞 2021-02-19 04:30

Currently I\'m using enums to represent a state in a little game experiment. I declare them like so:

namespace State {
  enum Value {
    MoveUp = 1 << 0,          


        
3条回答
  •  一整个雨季
    2021-02-19 04:48

    To be honest I don't think there is a consistent pattern for them.

    Just look at std::ios_base::openmode and std::regex_constants::syntax_option_type as two completely different ways of structuring it in the standard library -- one using a struct, the other using an entire namespace. Both are enums all right, but structured differently.
    Check your standard library implementation to see the details of how the above two are implemented.

提交回复
热议问题