2016-08-16 16:36:23 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
#include <type_traits>
|
2016-08-16 16:36:23 +00:00
|
|
|
|
2020-04-30 11:45:25 +00:00
|
|
|
namespace sknonstd {
|
2016-08-16 16:36:23 +00:00
|
|
|
template <typename T> struct is_bitmask_enum : std::false_type {};
|
2019-08-07 14:59:27 +00:00
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
template <typename E>
|
2020-04-30 11:45:25 +00:00
|
|
|
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;
|
2019-08-07 14:59:27 +00:00
|
|
|
}
|
2020-04-30 11:45:25 +00:00
|
|
|
} // namespace sknonstd
|
2016-08-16 16:36:23 +00:00
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
template <typename E>
|
2020-04-30 11:45:25 +00:00
|
|
|
std::enable_if_t<sknonstd::is_bitmask_enum<E>::value, E> constexpr operator|(E l, E r) {
|
|
|
|
using U = std::underlying_type_t<E>;
|
2016-08-16 16:36:23 +00:00
|
|
|
return static_cast<E>(static_cast<U>(l) | static_cast<U>(r));
|
|
|
|
}
|
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
template <typename E>
|
2020-04-30 11:45:25 +00:00
|
|
|
std::enable_if_t<sknonstd::is_bitmask_enum<E>::value, E&> constexpr operator|=(E& l, E r) {
|
2016-08-16 16:36:23 +00:00
|
|
|
return l = l | r;
|
|
|
|
}
|
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
template <typename E>
|
2020-04-30 11:45:25 +00:00
|
|
|
std::enable_if_t<sknonstd::is_bitmask_enum<E>::value, E> constexpr operator&(E l, E r) {
|
|
|
|
using U = std::underlying_type_t<E>;
|
2016-08-16 16:36:23 +00:00
|
|
|
return static_cast<E>(static_cast<U>(l) & static_cast<U>(r));
|
|
|
|
}
|
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
template <typename E>
|
2020-04-30 11:45:25 +00:00
|
|
|
std::enable_if_t<sknonstd::is_bitmask_enum<E>::value, E&> constexpr operator&=(E& l, E r) {
|
2016-08-16 16:36:23 +00:00
|
|
|
return l = l & r;
|
|
|
|
}
|
|
|
|
|
2020-07-01 15:12:19 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
template <typename E>
|
2020-04-30 11:45:25 +00:00
|
|
|
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));
|
2019-08-07 14:59:27 +00:00
|
|
|
}
|
|
|
|
|
2016-08-16 16:36:23 +00:00
|
|
|
#endif // SkEnumOperators_DEFINED
|