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
This commit is contained in:
Behdad Esfahbod 2015-11-20 13:21:29 -08:00
parent 9cc1ed4fa6
commit f94c0ecbb1
1 changed files with 11 additions and 16 deletions

View File

@ -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
* originally had in mind... :(.
*
* On MSVC use DEFINE_ENUM_FLAG_OPERATORS. See:
* https://github.com/behdad/harfbuzz/pull/163
* For MSVC warnings, see: https://github.com/behdad/harfbuzz/pull/163
*/
#ifdef _MSC_VER
# pragma warning(disable:4200)
# 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
# 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.