skia2/include/private/SkBitmaskEnum.h
Mike Klein dc976a96ea update skstd
- Lots of skstd::foo is now std::foo since C++14.
- Get rid of SK_WHEN(cond,T); std::enable_if_t<cond,T> is pithy enough.
- Move SkBitmaskEnum.h contents into sknonstd.

Change-Id: Ie5dc459405b1ff55e5b3ac57e70df7edd7cf38c0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/286315
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
2020-04-30 15:05:43 +00:00

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