halcanary | 3287588 | 2016-08-16 09:36:23 -0700 | [diff] [blame] | 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 |
| 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/private/SkTLogic.h" |
halcanary | 3287588 | 2016-08-16 09:36:23 -0700 | [diff] [blame] | 11 | |
| 12 | namespace skstd { |
| 13 | template <typename T> struct is_bitmask_enum : std::false_type {}; |
| 14 | } |
| 15 | |
| 16 | template <typename E> SK_WHEN(skstd::is_bitmask_enum<E>::value, E) operator|(E l, E r) { |
Mike Klein | c3b4790 | 2019-02-04 10:03:04 -0500 | [diff] [blame] | 17 | using U = typename std::underlying_type<E>::type; |
halcanary | 3287588 | 2016-08-16 09:36:23 -0700 | [diff] [blame] | 18 | return static_cast<E>(static_cast<U>(l) | static_cast<U>(r)); |
| 19 | } |
| 20 | |
| 21 | template <typename E> SK_WHEN(skstd::is_bitmask_enum<E>::value, E&) operator|=(E& l, E r) { |
| 22 | return l = l | r; |
| 23 | } |
| 24 | |
| 25 | template <typename E> SK_WHEN(skstd::is_bitmask_enum<E>::value, E) operator&(E l, E r) { |
Mike Klein | c3b4790 | 2019-02-04 10:03:04 -0500 | [diff] [blame] | 26 | using U = typename std::underlying_type<E>::type; |
halcanary | 3287588 | 2016-08-16 09:36:23 -0700 | [diff] [blame] | 27 | return static_cast<E>(static_cast<U>(l) & static_cast<U>(r)); |
| 28 | } |
| 29 | |
| 30 | template <typename E> SK_WHEN(skstd::is_bitmask_enum<E>::value, E&) operator&=(E& l, E r) { |
| 31 | return l = l & r; |
| 32 | } |
| 33 | |
| 34 | #endif // SkEnumOperators_DEFINED |