Chromium Code Reviews| Index: src/core/SkEnumOperators.h |
| diff --git a/src/core/SkEnumOperators.h b/src/core/SkEnumOperators.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ebf5aead2d65dc92b2a266b762a95de4b3844f4f |
| --- /dev/null |
| +++ b/src/core/SkEnumOperators.h |
| @@ -0,0 +1,38 @@ |
| +/* |
| + * Copyright 2016 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| +#ifndef SkEnumOperators_DEFINED |
| +#define SkEnumOperators_DEFINED |
|
bungeman-skia
2016/08/15 21:41:36
I don't think these are generally desirable enum o
hal.canary
2016/08/16 01:27:38
Done.
|
| + |
| +#include "SkTLogic.h" |
| + |
| +namespace skstd { |
| +template <typename T> struct is_bitmask_enum : std::false_type {}; |
| +} |
| + |
| +template <typename E> |
| +SK_WHEN(skstd::is_bitmask_enum<E>::value, E) operator|(E l, E r) { |
|
bungeman-skia
2016/08/15 21:41:36
nit: I personally prefer lines 16 and 17 here on o
hal.canary
2016/08/16 01:27:38
Done.
|
| + using U = skstd::underlying_type_t<E>; |
| + return static_cast<E>(static_cast<U>(l) | static_cast<U>(r)); |
| +} |
| + |
| +template <typename E> |
| +SK_WHEN(skstd::is_bitmask_enum<E>::value, E&) operator|=(E& l, E r) { |
| + return l = l | r; |
| +} |
| + |
| +template <typename E> |
| +SK_WHEN(skstd::is_bitmask_enum<E>::value, E) operator&(E l, E r) { |
| + using U = skstd::underlying_type_t<E>; |
| + return static_cast<E>(static_cast<U>(l) & static_cast<U>(r)); |
| +} |
| + |
| +template <typename E> |
| +SK_WHEN(skstd::is_bitmask_enum<E>::value, E&) operator&=(E& l, E r) { |
| + return l = l & r; |
| +} |
| + |
| +#endif // SkEnumOperators_DEFINED |