Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2016 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 #ifndef SkEnumOperators_DEFINED | |
| 8 #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.
| |
| 9 | |
| 10 #include "SkTLogic.h" | |
| 11 | |
| 12 namespace skstd { | |
| 13 template <typename T> struct is_bitmask_enum : std::false_type {}; | |
| 14 } | |
| 15 | |
| 16 template <typename E> | |
| 17 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.
| |
| 18 using U = skstd::underlying_type_t<E>; | |
| 19 return static_cast<E>(static_cast<U>(l) | static_cast<U>(r)); | |
| 20 } | |
| 21 | |
| 22 template <typename E> | |
| 23 SK_WHEN(skstd::is_bitmask_enum<E>::value, E&) operator|=(E& l, E r) { | |
| 24 return l = l | r; | |
| 25 } | |
| 26 | |
| 27 template <typename E> | |
| 28 SK_WHEN(skstd::is_bitmask_enum<E>::value, E) operator&(E l, E r) { | |
| 29 using U = skstd::underlying_type_t<E>; | |
| 30 return static_cast<E>(static_cast<U>(l) & static_cast<U>(r)); | |
| 31 } | |
| 32 | |
| 33 template <typename E> | |
| 34 SK_WHEN(skstd::is_bitmask_enum<E>::value, E&) operator&=(E& l, E r) { | |
| 35 return l = l & r; | |
| 36 } | |
| 37 | |
| 38 #endif // SkEnumOperators_DEFINED | |
| OLD | NEW |