#ifndef UTILS_INCLUDED #define UTILS_INCLUDED #include #include #include #include #include #include "types.h" #define no_copy_assign(T) \ T(const T&) = delete; \ void operator=(const T&) = delete namespace microtex { template inline sptr sptrOf(Args&&... args) { return std::make_shared(std::forward(args)...); } template inline uptr uptrOf(Args&&... args) { return std::make_unique(std::forward(args)...); } inline bool isAlpha(char c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } template inline std::vector keys(const std::map& map) { std::vector v; for (auto& it : map) { v.push_back(it.first); } return v; } /** Template version to find the max value of the given list */ template inline T maxOf(Args&&... args) { return std::max({args...}); } /** Get number of set bits in binary representation of the given number */ template u32 countSetBits(T n) { u32 cnt = 0; while (n) { n &= (n - 1); cnt++; } return cnt; } /** The default locale */ const std::locale& defaultLocale(); /** Test if a Unicode code point is lower case */ bool isUnicodeLower(c32 code); /** Test if a Unicode code point is digit */ bool isUnicodeDigit(c32 code); /** Convert given Unicode code point to upper case */ c32 toUnicodeUpper(c32 code); /** Convert given Unicode code point to lower case */ c32 toUnicodeLower(c32 code); /** * Binary-search for the index of the given target in a container. The items in the container must * be sorted. * * @param count total count of elements in the container * @param compare function to compare between the target value and the value at the given index * @param returnClosest whether return the closest index while not found, default is false * * @return the index which the target value found at, or the closest index if returnClosest is true, * or -1 otherwise */ int binIndexOf(int count, const std::function& compare, bool returnClosest = false); } // namespace microtex #endif