diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-09-24 02:15:25 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-09-24 02:15:25 -0400 |
commit | 83417819186394e8d840167841103211ebe5fe33 (patch) | |
tree | 5dce1e411716d5be161d2e9795a99460b80e6c8c /util.hpp | |
parent | dbe9dc3c64555f1aaaed1755d37e6f8b450a54f6 (diff) | |
download | abaddon-portaudio-83417819186394e8d840167841103211ebe5fe33.tar.gz abaddon-portaudio-83417819186394e8d840167841103211ebe5fe33.zip |
basic permission handling + use for edit/delete
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); |