On 12-12-16 05:52 PM, Siarhei Siamashka wrote:
> -typedef enum
> -{
> +typedef int cpu_features_t;
> +
> +enum {
>      X86_MMX                  = (1 << 0),
>      X86_MMX_EXTENSIONS               = (1 << 1),
>      X86_SSE                  = (1 << 2) | X86_MMX_EXTENSIONS,
>      X86_SSE2                 = (1 << 3),
>      X86_CMOV                 = (1 << 4)
> -} cpu_features_t;
> +};
> 
> Using enum for bit flags is a bit cumbersome in C++:
>     
> http://stackoverflow.com/questions/199606/how-should-c-bitflag-enumerations-be-translated-into-c

I actually like the operator| approach and always thought it provides exactly
the kind of typesafety that you would hope C++ provides.  A little macro like
this would do:

#ifdef __cplusplus__
#define PIXMAN_FLAG_ENUM(X) \
  static inline X operator| (X a, X b) { \
    return (X) ((unsigned int) a | (unsigned int) b); \
  }
#else
#define PIXMAN_FLAG_ENUM(X)
#endif

-- 
behdad
http://behdad.org/
_______________________________________________
Pixman mailing list
Pixman@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pixman

Reply via email to