first pass compile time optimization

This commit is contained in:
ouwou
2023-01-29 21:33:34 -05:00
parent ff47134dc6
commit 5a6f8cac09
97 changed files with 87 additions and 166 deletions

38
src/misc/bitwise.hpp Normal file
View 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
View 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 {};