#ifndef ENTT_CORE_ENUM_HPP #define ENTT_CORE_ENUM_HPP #include #include "../config/config.h" namespace entt { /** * @brief Enable bitmask support for enum classes. * @tparam Type The enum type for which to enable bitmask support. */ template struct enum_as_bitmask: std::false_type {}; /*! @copydoc enum_as_bitmask */ template struct enum_as_bitmask>: std::is_enum {}; /** * @brief Helper variable template. * @tparam Type The enum class type for which to enable bitmask support. */ template inline constexpr bool enum_as_bitmask_v = enum_as_bitmask::value; } // namespace entt /** * @brief Operator available for enums for which bitmask support is enabled. * @tparam Type Enum class type. * @param lhs The first value to use. * @param rhs The second value to use. * @return The result of invoking the operator on the underlying types of the * two values provided. */ template [[nodiscard]] constexpr std::enable_if_t, Type> operator|(const Type lhs, const Type rhs) ENTT_NOEXCEPT { return static_cast(static_cast>(lhs) | static_cast>(rhs)); } /*! @copydoc operator| */ template [[nodiscard]] constexpr std::enable_if_t, Type> operator&(const Type lhs, const Type rhs) ENTT_NOEXCEPT { return static_cast(static_cast>(lhs) & static_cast>(rhs)); } /*! @copydoc operator| */ template [[nodiscard]] constexpr std::enable_if_t, Type> operator^(const Type lhs, const Type rhs) ENTT_NOEXCEPT { return static_cast(static_cast>(lhs) ^ static_cast>(rhs)); } /** * @brief Operator available for enums for which bitmask support is enabled. * @tparam Type Enum class type. * @param value The value to use. * @return The result of invoking the operator on the underlying types of the * value provided. */ template [[nodiscard]] constexpr std::enable_if_t, Type> operator~(const Type value) ENTT_NOEXCEPT { return static_cast(~static_cast>(value)); } /*! @copydoc operator~ */ template [[nodiscard]] constexpr std::enable_if_t, bool> operator!(const Type value) ENTT_NOEXCEPT { return !static_cast>(value); } /*! @copydoc operator| */ template constexpr std::enable_if_t, Type &> operator|=(Type &lhs, const Type rhs) ENTT_NOEXCEPT { return (lhs = (lhs | rhs)); } /*! @copydoc operator| */ template constexpr std::enable_if_t, Type &> operator&=(Type &lhs, const Type rhs) ENTT_NOEXCEPT { return (lhs = (lhs & rhs)); } /*! @copydoc operator| */ template constexpr std::enable_if_t, Type &> operator^=(Type &lhs, const Type rhs) ENTT_NOEXCEPT { return (lhs = (lhs ^ rhs)); } #endif