mirror of
https://github.com/QuasarApp/QuasarAppLib.git
synced 2025-04-27 10:14:38 +00:00
68 lines
1.5 KiB
C++
68 lines
1.5 KiB
C++
#ifndef GLOBAL_H
|
|
#define GLOBAL_H
|
|
|
|
#include <cstdlib>
|
|
#include <type_traits>
|
|
|
|
template <typename T>
|
|
constexpr inline T operator | (T lhs, T rhs)
|
|
{
|
|
|
|
static_assert(std::is_enum<T>::value,
|
|
"template parameter is not an enum type");
|
|
|
|
return static_cast<T>(static_cast<int>(lhs) | static_cast<int>(rhs));
|
|
}
|
|
|
|
template <typename T>
|
|
constexpr inline T operator & (T lhs, T rhs)
|
|
{
|
|
|
|
static_assert(std::is_enum<T>::value,
|
|
"template parameter is not an enum type");
|
|
|
|
return static_cast<T>(static_cast<int>(lhs) & static_cast<int>(rhs));
|
|
}
|
|
|
|
template <typename T>
|
|
constexpr inline T operator >> (T lhs, T rhs)
|
|
{
|
|
|
|
static_assert(std::is_enum<T>::value,
|
|
"template parameter is not an enum type");
|
|
|
|
return static_cast<T>(static_cast<int>(lhs) >> static_cast<int>(rhs));
|
|
}
|
|
|
|
template <typename T>
|
|
constexpr inline T operator << (T lhs, T rhs)
|
|
{
|
|
|
|
static_assert(std::is_enum<T>::value,
|
|
"template parameter is not an enum type");
|
|
|
|
return static_cast<T>(static_cast<int>(lhs) << static_cast<int>(rhs));
|
|
}
|
|
|
|
template <typename T>
|
|
constexpr inline T operator ~ (T lhs)
|
|
{
|
|
|
|
static_assert(std::is_enum<T>::value,
|
|
"template parameter is not an enum type");
|
|
|
|
return static_cast<T>(~static_cast<int>(lhs));
|
|
}
|
|
|
|
template <typename T>
|
|
constexpr inline T operator ^ (T lhs, T rhs)
|
|
{
|
|
|
|
static_assert(std::is_enum<T>::value,
|
|
"template parameter is not an enum type");
|
|
|
|
return static_cast<T>(static_cast<int>(lhs) ^ static_cast<int>(rhs));
|
|
}
|
|
|
|
#endif // GLOBAL_H
|