/* * 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 #include "include/private/SkTLogic.h" namespace skstd { template struct is_bitmask_enum : std::false_type {}; template SK_WHEN(skstd::is_bitmask_enum::value, bool) constexpr Any(E e) { return static_cast::type>(e) != 0; } } template SK_WHEN(skstd::is_bitmask_enum::value, E) constexpr operator|(E l, E r) { using U = typename std::underlying_type::type; return static_cast(static_cast(l) | static_cast(r)); } template SK_WHEN(skstd::is_bitmask_enum::value, E&) constexpr operator|=(E& l, E r) { return l = l | r; } template SK_WHEN(skstd::is_bitmask_enum::value, E) constexpr operator&(E l, E r) { using U = typename std::underlying_type::type; return static_cast(static_cast(l) & static_cast(r)); } template SK_WHEN(skstd::is_bitmask_enum::value, E&) constexpr operator&=(E& l, E r) { return l = l & r; } template SK_WHEN(skstd::is_bitmask_enum::value, E) constexpr operator~(E e) { return static_cast(~static_cast::type>(e)); } #endif // SkEnumOperators_DEFINED