#pragma once #include "Environment.hpp" #include "TypeInfo.hpp" #include namespace tp { template using init_list = std::initializer_list; // Selects whether to pass by constant reference or by value template using SelCopyArg = typename TypeSelect<(sizeof(tType) > sizeof(tp::alni)), const tType&, tType>::Result; ualni next2pow(ualni v); uhalni next2pow(uhalni v); ufalni next2pow(ufalni v); ualni hash(const char* bytes); ualni hash(alni bytes); ualni hash(halni bytes); ualni hash(uhalni bytes); ualni hash(ualni bytes); ualni hash(alnf bytes); template [[nodiscard]] T clamp(T v, T l, T u) { if (v < l) { v = l; } else if (v > u) { v = u; } return v; } template [[nodiscard]] T max(T a, T b) { return (a > b) ? a : b; } template [[nodiscard]] T min(T a, T b) { return (a < b) ? a : b; } template [[nodiscard]] T abs(T v) { if (v < 0) { return -v; } return v; } template inline void swap(T& t1, T& t2) { const T tmp = t1; t1 = t2; t2 = tmp; } // only for x > 0 and y > 0 template [[nodiscard]] T ceil_positive(T x, T y) { return T( 1 + ((x - 1) / (tp::alnf)y) ); } // power template [[nodiscard]] T pow(T x, uhalni n) { T out = x; for (uhalni i = 0; i < n - 1; i++) { out = out * x; } return out; } template halni nDig10(Type val) { val = abs(val); halni out = 0; while (val != 0) { val = halni(val / 10); out++; } return out; } }