mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-19 20:11:59 +03:00
first pass compile time optimization
This commit is contained in:
38
src/misc/bitwise.hpp
Normal file
38
src/misc/bitwise.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
#include <type_traits>
|
||||
|
||||
template<typename T>
|
||||
struct Bitwise {
|
||||
static const bool enable = false;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
typename std::enable_if<Bitwise<T>::enable, T>::type operator|(T a, T b) {
|
||||
using x = typename std::underlying_type<T>::type;
|
||||
return static_cast<T>(static_cast<x>(a) | static_cast<x>(b));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
typename std::enable_if<Bitwise<T>::enable, T>::type operator|=(T &a, T b) {
|
||||
using x = typename std::underlying_type<T>::type;
|
||||
a = static_cast<T>(static_cast<x>(a) | static_cast<x>(b));
|
||||
return a;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
typename std::enable_if<Bitwise<T>::enable, T>::type operator&(T a, T b) {
|
||||
using x = typename std::underlying_type<T>::type;
|
||||
return static_cast<T>(static_cast<x>(a) & static_cast<x>(b));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
typename std::enable_if<Bitwise<T>::enable, T>::type operator&=(T &a, T b) {
|
||||
using x = typename std::underlying_type<T>::type;
|
||||
a = static_cast<T>(static_cast<x>(a) & static_cast<x>(b));
|
||||
return a;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
typename std::enable_if<Bitwise<T>::enable, T>::type operator~(T a) {
|
||||
return static_cast<T>(~static_cast<typename std::underlying_type<T>::type>(a));
|
||||
}
|
||||
9
src/misc/is_optional.hpp
Normal file
9
src/misc/is_optional.hpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
|
||||
template<typename T>
|
||||
struct is_optional : std::false_type {};
|
||||
|
||||
template<typename T>
|
||||
struct is_optional<std::optional<T>> : std::true_type {};
|
||||
Reference in New Issue
Block a user