diff options
author | Jon Santmyer <jon@jonsantmyer.com> | 2022-06-22 17:41:59 -0400 |
---|---|---|
committer | Jon Santmyer <jon@jonsantmyer.com> | 2022-06-22 17:41:59 -0400 |
commit | 5e3a2492c7bb73daa4e27398daaf490d09980ff3 (patch) | |
tree | 75178d823d596b6a898002c3f1d45b9ceede0e1e /include/util.hpp | |
download | systemviewer-5e3a2492c7bb73daa4e27398daaf490d09980ff3.tar.gz systemviewer-5e3a2492c7bb73daa4e27398daaf490d09980ff3.tar.bz2 systemviewer-5e3a2492c7bb73daa4e27398daaf490d09980ff3.zip |
Base system viewer with data loaded from csv files
Diffstat (limited to 'include/util.hpp')
-rw-r--r-- | include/util.hpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/include/util.hpp b/include/util.hpp new file mode 100644 index 0000000..3c795d1 --- /dev/null +++ b/include/util.hpp @@ -0,0 +1,45 @@ +#include <type_traits> +#ifndef UTIL_HPP +#define UTIL_HPP 1 + +#include <variant> +#include <cstddef> + +#if UNICODE == 1 +using screenchr = wchar_t; +#else +using screenchr = char; +#endif + +/*Shamelessly stolen from stackoverflow + * https://stackoverflow.com/questions/52303316/get-index-by-type-in-stdvariant + * by Barry*/ +template <typename> struct tag { }; +template <typename T, typename V> +struct get_index; +template <typename T, typename... Ts> +struct get_index<T, std::variant<Ts...>> + : std::integral_constant<size_t, std::variant<tag<Ts>...>(tag<T>()).index()> +{ }; + +template<typename T, typename variant_type> +struct is_variant : std::false_type {}; +template<typename T, typename ... Vs> +struct is_variant<T, std::variant<Vs...>> + : std::disjunction<std::is_same<T, Vs>...> {}; +template<typename T, typename variant_type> +constexpr bool is_variant_v = is_variant<T, variant_type>::value; + +template<typename T, unsigned base, unsigned p> +struct cxpow { static constexpr T value = (T)base * cxpow<T, base, p - 1>::value; }; +template<typename T, unsigned base> +struct cxpow<T, base, 0> { static constexpr T value = 1; }; +template<typename T, unsigned base, unsigned p> +constexpr T cxpow_v = cxpow<T, base, p>::value; + +template<typename T, unsigned base, int p> +struct cxrt { static constexpr T value = (T)base / cxpow<T, base, -p>::value; }; +template<typename T, unsigned base, int p> +constexpr T cxrt_v = cxrt<T, base, p>::value; + +#endif |