Define HB_MARK_AS_FLAG_T as a macro instead of using templates

The generic template operator overloading was causing more problems than it
solved.  Eg:

https://github.com/behdad/harfbuzz/pull/163
https://github.com/behdad/harfbuzz/issues/175

So, just use macros.

Fixes https://github.com/behdad/harfbuzz/issues/175
Fixes https://github.com/behdad/harfbuzz/pull/178
pull/177/head
Behdad Esfahbod 9 years ago
parent 9cc1ed4fa6
commit f94c0ecbb1
  1. 27
      src/hb-private.hh

@ -896,27 +896,22 @@ hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3)
* one enum to another... So this doesn't provide the type-checking that I * one enum to another... So this doesn't provide the type-checking that I
* originally had in mind... :(. * originally had in mind... :(.
* *
* On MSVC use DEFINE_ENUM_FLAG_OPERATORS. See: * For MSVC warnings, see: https://github.com/behdad/harfbuzz/pull/163
* https://github.com/behdad/harfbuzz/pull/163
*/ */
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma warning(disable:4200) # pragma warning(disable:4200)
# pragma warning(disable:4800) # pragma warning(disable:4800)
# define HB_MARK_AS_FLAG_T(flags_t) DEFINE_ENUM_FLAG_OPERATORS (##flags_t##);
#else
# define HB_MARK_AS_FLAG_T(flags_t) template <> class hb_mark_as_flags_t<flags_t> {};
template <class T> class hb_mark_as_flags_t;
template <class T> static inline T operator | (T l, T r)
{ hb_mark_as_flags_t<T> unused HB_UNUSED; return T ((unsigned int) l | (unsigned int) r); }
template <class T> static inline T operator & (T l, T r)
{ hb_mark_as_flags_t<T> unused HB_UNUSED; return T ((unsigned int) l & (unsigned int) r); }
template <class T> static inline T operator ~ (T r)
{ hb_mark_as_flags_t<T> unused HB_UNUSED; return T (~(unsigned int) r); }
template <class T> static inline T& operator |= (T &l, T r)
{ hb_mark_as_flags_t<T> unused HB_UNUSED; l = l | r; return l; }
template <class T> static inline T& operator &= (T& l, T r)
{ hb_mark_as_flags_t<T> unused HB_UNUSED; l = l & r; return l; }
#endif #endif
# define HB_MARK_AS_FLAG_T(T) \
extern "C++" { \
static inline T operator | (T l, T r) { return T ((unsigned) l | (unsigned) r); } \
static inline T operator & (T l, T r) { return T ((unsigned) l & (unsigned) r); } \
static inline T operator ^ (T l, T r) { return T ((unsigned) l ^ (unsigned) r); } \
static inline T operator ~ (T r) { return T (~(unsigned int) r); } \
static inline T& operator |= (T &l, T r) { l = l | r; return l; } \
static inline T& operator &= (T& l, T r) { l = l & r; return l; } \
static inline T& operator ^= (T& l, T r) { l = l ^ r; return l; } \
}
/* Useful for set-operations on small enums. /* Useful for set-operations on small enums.

Loading…
Cancel
Save