diff options
Diffstat (limited to 'util.hpp')
-rw-r--r-- | util.hpp | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -10,6 +10,42 @@ #include <iomanip> 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<std::underlying_type<T>::type>(a)); +} + +template<typename T> inline void AlphabeticalSort(T start, T end, std::function<std::string(const typename std::iterator_traits<T>::value_type &)> get_string) { std::sort(start, end, [&](const auto &a, const auto &b) -> bool { const std::string &s1 = get_string(a); |