skia2/include/private/SkBitmaskEnum.h
Hal Canary bcfed55a8c experimental/editor: mouse drag select, modifierkeys cleanup.
Change-Id: I8c8de54ad6309424bdf18987ccf3eac6bdd41c19
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/233080
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
2019-08-08 02:33:44 +00:00

43 lines
1.4 KiB
C++

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