uvw 3.1.0
Loading...
Searching...
No Matches
enum.hpp
1#ifndef UVW_ENUM_INCLUDE_HPP
2#define UVW_ENUM_INCLUDE_HPP
3
4#include <type_traits>
5#include "config.h"
6
15template<typename Type>
16[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::_UVW_ENUM)>
17operator|(const Type lhs, const Type rhs) noexcept {
18 return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) | static_cast<std::underlying_type_t<Type>>(rhs));
19}
20
22template<typename Type>
23[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::_UVW_ENUM)>
24operator&(const Type lhs, const Type rhs) noexcept {
25 return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) & static_cast<std::underlying_type_t<Type>>(rhs));
26}
27
29template<typename Type>
30[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::_UVW_ENUM)>
31operator^(const Type lhs, const Type rhs) noexcept {
32 return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) ^ static_cast<std::underlying_type_t<Type>>(rhs));
33}
34
42template<typename Type>
43[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::_UVW_ENUM)>
44operator~(const Type value) noexcept {
45 return static_cast<Type>(~static_cast<std::underlying_type_t<Type>>(value));
46}
47
49template<typename Type>
50[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::_UVW_ENUM, bool{})>
51operator!(const Type value) noexcept {
52 return !static_cast<std::underlying_type_t<Type>>(value);
53}
54
56template<typename Type>
57constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::_UVW_ENUM) &>
58operator|=(Type &lhs, const Type rhs) noexcept {
59 return (lhs = (lhs | rhs));
60}
61
63template<typename Type>
64constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::_UVW_ENUM) &>
65operator&=(Type &lhs, const Type rhs) noexcept {
66 return (lhs = (lhs & rhs));
67}
68
70template<typename Type>
71constexpr std::enable_if_t<std::is_enum_v<Type>, decltype(Type::_UVW_ENUM) &>
72operator^=(Type &lhs, const Type rhs) noexcept {
73 return (lhs = (lhs ^ rhs));
74}
75
76#endif