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 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> SK_WHEN(skstd::is_bitmask_enum<E>::value, E) operator|(E l, E r) { 17 using U = skstd::underlying_type_t<E>; 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) { 26 using U = skstd::underlying_type_t<E>; 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 35