You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.8 KiB
60 lines
1.8 KiB
/*
|
|
* 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 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
|