This is a cross-platform, header-only library for core routines.
- Benchmark.h
- DateTime.h
- Delay.h
- FlankDetector.h
- FolderHelper.h
- Histogram.h
- MarkovChain.h
- MathUtils.h
- Mtx2.h
- OneShot.h
- Physics.h
- Rand.h
- StlOperators.h
- StlUtils.h
- StringBox.h
- StringHelper.h
- System.h
- TextIO.h
- Timer.h
- Utils.h
- Uuid.h
- Vec2.h
- bool_vector.h
- build.sh
- build.bat
Namespace: benchmark.
Macros:
BM_FUNC(for use withBenchmark::reg())
Classes / Structs:
class Benchmarkvoid reg(Lambda&& func, const std::string& tag)void start(const std::string& tag)void stop(const std::string& tag)
Functions:
float calc_time_ms(Lambda&& func)void tic(TicTocTimer& time)float toc(const TicTocTimer& time)void tic()(globalTicTocTimerobject)float toc()(-''-)
Namespace: datetime.
Classes / Structs:
class datetime_unit_tclass day_t : public datetime_unit_t<30, 1>struct Datestruct Timestruct DateTimeusing hour_t = datetime_unit_t<24, 0>using sexagesimal_t = datetime_unit_t<60, 0>using month_t = datetime_unit_t<12, 1>
Functions:
void update_date_time(DateTime& date_time, const DateTime& date_time_0, double time_s)Time rand_time(const Time& start, const Time& end)Time randn_time(const Time& mu, float sigma_seconds, const Time& start, const Time& end)Date rand_date(const Date& start, const Date& end)Date randn_date(const Date& mu, float sigma_days, const Date& start, const Date& end)DateTime rand_datetime(const DateTime& start, const DateTime& end)DateTime randn_datetime(const Date& mu, float sigma_days, const DateTime& start, const DateTime& end)std::string get_datetime_str(const DateTime& date_time, const std::string& format = "%Y-%m-%d %H:%M:%S")
Namespace: Delay.
Functions:
sleep(T us)update_loop(int fps, std::function<bool(void)> update_func)
Namespace: -
Classes / Structs:
class FlankDetector<T>FlankDetector() = defaultFlankDetector(T curr, T prev)void update()void set(T val)void update(T val)bool pos_flank(T threshold = static_cast<T>(0)) constbool neg_flank(T threshold = static_cast<T>(0)) constT curr() constT prev() const
Namespace: folder
Functions:
bool delete_file(const std::string& file_path)std::string get_exe_dir()(Windows only for now)std::string get_pwd()void set_pwd(const std::string& new_pwd)char get_path_separator()bool is_path_separator(char c)std::vector<std::string> split_path(const std::string& path)std::string join_path(const std::vector<std::string>& path_parts)std::string format_path(const std::string& path)std::pair<std::string, std::string> split_file_path(const std::string& file_path)std::string join_file_path(const std::pair<std::string, std::string>& path_and_filename)std::pair<std::string, std::string> split_filename_ext(const std::string& filename)std::string join_filename_ext(const std::pair<std::string, std::string>& basefilename_and_ext)bool exists(const std::string file_path)
Namespace: hist
Classes / Structs:
struct Buck<T>class Histogram<T>Histogram(size_t N_buck, T start, T end)void operator+=(T val)void resize(size_t N_buck, T start, T end)str::StringBox to_stringbox(int nr, int nc)int sanity_check_bucket_samples() const
Namespace: markov_chain
Classes / Structs:
class MarkovChain<T>MarkovChain(T empty_val)void add_transitions(const std::vector<T>& items)int import_transitions(const std::string& filename)void print() constvoid normalize_transition_weights()T generate(int min_num_items = -1, int max_num_items = -1) const
Namespace: math
Constants:
static constexpr long double cld_pistatic constexpr long double cld_2pistatic constexpr long double cld_pi_2static constexpr long double cld_pi_3static constexpr long double cld_pi_4static constexpr long double cld_pi_6static constexpr long double cld_3pi_2static constexpr long double cld_3pi_4static constexpr long double cld_5pi_4static constexpr long double cld_7pi_4static constexpr long double cld_1_pistatic constexpr long double cld_2_pistatic constexpr long double cld_sqrt2static constexpr long double cld_2_sqrt_pi(2/sqrt(pi))static constexpr long double cld_sqrt1_2(1/sqrt(2))static constexpr long double cld_ln2static constexpr long double cld_ln10static constexpr long double cld_estatic constexpr long double cld_1_estatic constexpr long double cld_log2estatic constexpr long double cld_log10estatic constexpr double cd_pistatic constexpr double cd_2pistatic constexpr double cd_pi_2static constexpr double cd_pi_3static constexpr double cd_pi_4static constexpr double cd_pi_6static constexpr double cd_3pi_2static constexpr double cd_3pi_4static constexpr double cd_5pi_4static constexpr double cd_7pi_4static constexpr double cd_1_pistatic constexpr double cd_2_pistatic constexpr double cd_sqrt2static constexpr double cd_2_sqrt_pi(2/sqrt(pi))static constexpr double cd_sqrt1_2(1/sqrt(2))static constexpr double cd_ln2static constexpr double cd_ln10static constexpr double cd_estatic constexpr double cd_1_estatic constexpr double cd_log2estatic constexpr double cd_log10estatic constexpr float c_pistatic constexpr float c_2pistatic constexpr float c_pi_2static constexpr float c_pi_3static constexpr float c_pi_4static constexpr float c_pi_6static constexpr float c_3pi_2static constexpr float c_3pi_4static constexpr float c_5pi_4static constexpr float c_7pi_4static constexpr float c_1_pistatic constexpr float c_2_pistatic constexpr float c_sqrt2static constexpr float c_2_sqrt_pi(2/sqrt(pi))static constexpr float c_sqrt1_2(1/sqrt(2))static constexpr float c_ln2static constexpr float c_ln10static constexpr float c_estatic constexpr float c_1_estatic constexpr float c_log2estatic constexpr float c_log10e
Enums:
enum class Range { Free, Closed, Open, ClosedOpen, OpenClosed, ClosedFree, FreeClosed, OpenFree, FreeOpen };
Classes / Structs:
struct RangeData<T>
Functions:
int roundI(T val)int floorI(T val)int ceilI(T val)int sgn(T val)int sign(T val)T sq(T val)T cube(T val)T length_squared(T x, T y)T length_squared(T x, T y, T z)T length_squared(T x, T y, T z, T w)T length(T x, T y)T length(T x, T y, T z)T length(T x, T y, T z, T w)T distance_squared(T x0, T y0, T x1, T y1)T distance_squared(T x0, T y0, T z0, T x1, T y1, T z1)T distance_squared(T x0, T y0, T z0, T w0, T x1, T y1, T z1, T w1)T distance(T x0, T y0, T x1, T y1)T distance(T x0, T y0, T z0, T x1, T y1, T z1)T distance(T x0, T y0, T z0, T w0, T x1, T y1, T z1, T w1)bool normalize(T& x, T& y)bool normalize(T& x, T& y, T& z)bool normalize(T& x, T& y, T& z, T& w)T normalize_angle(T ang)(Normalizes the angle to the range [-0, 2pi])T atan2n(T y, T x)(Normalizes the angle to the range [-0, 2pi])T dot(T x0, T y0, T x1, T y1)T dot(T x0, T y0, T z0, T x1, T y1, T z1)T dot(T x0, T y0, T z0, T w0, T x1, T y1, T z1, T w1)T clamp(T val, T lo, T hi)T lerp(float t, T a, T b)float value_to_param(T val, T start, T end)float value_to_param_clamped(T val, T start, T end)- ´std::vector linspace(T start, T step, T end)`
T1 linmap(T0 val_0, T0 start_0, T0 end_0, T1 start_1, T1 end_1)T1 linmap_clamped(T0 val_0, T0 start_0, T0 end_0, T1 start_1, T1 end_1)bool in_range(T val, std::optional<T> start, std::optional<T> end, Range type)bool in_range(T val, const RangeData<T>& rd)bool in_unit_range(T val, Range type)inline bool in_r_c(T val, T start, T end) noexceptinline bool in_r_o(T val, T start, T end) noexceptinline bool in_r_co(T val, T start, T end) noexceptinline bool in_r_oc(T val, T start, T end) noexceptinline bool in_r_cu(T val) noexceptinline bool in_r_ou(T val) noexceptinline bool in_r_cou(T val) noexceptinline bool in_r_ocu(T val) noexceptbool minimize(T& val, T test, const RangeData<T>& rd = {})bool maximize(T& val, T test, const RangeData<T>& rd = {})constexpr T get_max()constexpr T get_min()bool fuz_zero(T v, T eps = std::numeric_limits<T>::epsilon())bool fuz_eq(T a, T b, T eps = std::numeric_limits<T>::epsilon())T deg2rad(T deg)T rad2deg(T rad)int gcd(int a, int b)float gcd(float a, float b)bool toggle(bool& val)
Namespace: -
Classes / Structs:
struct Mtx2Mtx2() = defaultMtx2(float v00, float v01, float v10, float v11)Vec2 operator*(const Vec2& v)
Namespace: -
Classes / Structs:
class OneShotOneShot() = defaultOneShot(bool preset)bool once()bool was_triggered() constvoid reset()
Namespaces: physics, physics::UnitConversion
Functions:
float deg_celcius_to_kelvin(float degC)float kelvin_to_deg_celcius(float K)
Namespace: rnd
Functions:
unsigned int srand_time()void srand(unsigned int seed)float rand()(Uniform random value in range [0, 1])float randn(float mu, float sigma)(Normal-distributed random value using the Box-Muller algorithm)int randn_int(float mu, float sigma)float randn_clamp(float mu, float sigma, float min, float max)float randn_range(float lo, float hi)float randn_range_clamp(float lo, float hi)int randn_clamp_int(float mu, float sigma, int min, int max)int randn_range_int(int lo, int hi)int randn_range_clamp_int(int lo, int hi)EnumType rand_enum()EnumType randn_enum(float mu, float sigma)bool rand_bool()float rand_float(float start, float end)int rand_int(int start, int end)int rand_idx(size_t N)T rand_select(const std::vector<T>& values)T rand_select(const std::vector<std::pair<float, T>>& values)int rand_select_index(const std::vector<float>& values)T randn_select(float mu, float sigma, const std::vector<T>& values)int dice(int num_faces = 6)bool one_in(int N)(Returns true if the dice of size N rolled a 1)
Namespace: stloperators
Functions:
std::optional<T> operator* (const std::optional<T>& A, const std::optional<T>& B)std::optional<T> operator* (const std::optional<T>& A, const T& B)std::optional<T> operator* (const T& A, const std::optional<T>& B)
Namespace: stlutils
Functions:
constexpr int sizeI(const Cont& c) noexceptvoid fill(Cont& c, typename Cont::value_type v)void memset(Cont& c, typename Cont::value_type val)void memclr(Cont& c)typename Cont::value_type sum(const Cont& c)- `T sum(const Cont& c, Lambda unary_op)´
T sum(const std::vector<std::vector<T>>& v)Cont diff(const Cont& c)RetT average(const Cont& c)typename Cont::value_type prod(const Cont& c)Cont comp_prod(const Cont& cA, const Cont& cB)Cont comp_sq(const Cont& c)std::vector<std::vector<T>> comp_prod(const std::vector<std::vector<T>>& vA, const std::vector<std::vector<T>>& vB)Cont mult_scalar(const Cont& c, typename Cont::value_type s)std::vector<std::vector<T>> mult_scalar(const std::vector<std::vector<T>>& vec, T s)Cont comp_div(const Cont& cA, const Cont& cB)Cont scalar_div(typename Cont::value_type s, const Cont& c)Cont add(const Cont& cA, const Cont& cB)std::vector<std::vector<T>> add(const std::vector<std::vector<T>>& vA, const std::vector<std::vector<T>>& vB)Cont subtract(const Cont& cA, const Cont& cB)std::vector<std::vector<T>> subtract(const std::vector<std::vector<T>>& vA, const std::vector<std::vector<T>>& vB)Cont add_scalar(const Cont& c, typename Cont::value_type s)std::vector<std::vector<T>> add_scalar(const std::vector<std::vector<T>>& vec, T s)Cont subtract_scalar(const Cont& c, typename Cont::value_type s)std::vector<std::vector<T>> subtract_scalar(const std::vector<std::vector<T>>& vec, T s)Cont scalar_subtract(typename Cont::value_type s, const Cont& c)Cont unary_minus(const Cont& c)typename Cont::value_type dot(const Cont& cA, const Cont& cB)T dot(const std::vector<std::vector<T>>& vA, const std::vector<std::vector<T>>& vB)Cont sqrt(const Cont& c)Cont sin(const Cont& c)Cont cos(const Cont& c)std::vector<Tdst> static_cast_vector(const std::vector<Tsrc>& v)size_t max_element_idx(const Cont& c)size_t min_element_idx(const Cont& c)constexpr decltype(auto) select_if(T&& a, T&& b, Lambda&& pred) noexcept(noexcept(pred(a, b)))(Returns a if pred(a, b) == true (i.e. "a < b" for "min_if" or "a > b" for "max_if"))std::vector<size_t> argmax(const Cont& c)std::vector<size_t> argmin(const Cont& c)Cont cat(const Cont& c) { return c; }Cont cat(const Cont& c, ContN... cn)void append(Cont& c, ContN... cn)std::vector<T> repval(T val, size_t n)std::vector<T> subset(const std::vector<T>& v, size_t idx_begin, size_t idx_end)std::vector<std::vector<T>> subset(const std::vector<std::vector<T>>& v, size_t r_idx_begin, size_t r_idx_end, size_t c_idx_begin, size_t c_idx_end)std::vector<std::vector<T>> subset_columns(const std::vector<std::vector<T>>& v, size_t c_idx_begin, size_t c_idx_end)std::vector<T> to_vector(const std::array<T, N>& arr)std::vector<std::vector<T>> to_vector(const std::array<std::array<T, Nc>, Nr>& arr)std::array<T, N> to_array(const std::vector<T>& vec)std::array<std::array<T, Nc>, Nr> to_array(const std::vector<std::vector<T>>& vec)void resize(std::vector<T>& vec, size_t N)void resize(std::vector<std::vector<T>>& vec, size_t Nr, size_t Nc)void resize(std::vector<std::vector<std::vector<T>>>& vec, size_t Ns, size_t Nr, size_t Nc)size_t count(const std::vector<T>& vec, T val)size_t count(const std::array<T, N>& arr, T val)size_t count_if(const std::vector<T>& vec, Lambda&& pred)size_t count_if(const std::array<T, N>& arr, Lambda&& pred)void sort(Cont& c)void sort(Cont& c, Lambda pred)int find_if_idx(Cont& c, Lambda pred)typename Cont::iterator find_if(Cont& c, Lambda pred)typename Cont::const_iterator find_if(const Cont& c, Lambda pred)typename Cont::iterator find(Cont& c, const typename Cont::value_type& val)int find_idx(Cont& c, const typename Cont::value_type& val)bool contains_if(const Cont& c, Lambda pred)bool contains_if(const Iterator it_begin, const Iterator it_end, Lambda pred)bool contains(const Cont& c, const typename Cont::value_type& val)bool emplace_back_unique(Cont& c, const typename Cont::value_type& val)bool emplace_back_if_not(Cont& c, const typename Cont::value_type& val, Lambda pred)void erase(Cont& c, const typename Cont::value_type& val)bool erase_at(Cont& c, size_t idx)bool erase_if(Cont& c, Lambda pred)bool erase_if_idcs(Cont& c, std::vector<Int>& indices, Lambda pred)typename Cont::value_type try_get(const Cont& cont, int idx, typename Cont::value_type def_val = static_cast<typename Cont::value_type>(0))T& at_growing(std::vector<T>& vec, int idx, T default_val = {})bool in_range(const Cont& c, size_t idx)bool in_range(const Cont& c, int idx)
Namespace: str
Structs / Classes:
struct StringBoxStringBox() = defaultStringBox(size_t N)StringBox(const std::vector<std::string>& texts)StringBox(const std::string& text)std::string& operator[](size_t r_idx)void print() constsize_t size() constbool empty() const noexcept
Namespace: str
Enums:
enum class BracketType { None, Parentheses, SquareBrackets, Braces, MatrixStyle };
Functions:
std::string rep_char(char c, int num)enum class Adjustment { Left, Center, Right, LeftInteger }; std::string adjust_str(const std::string& str, Adjustment adj, int width, int start_idx = 0, char empty_char = ' ')char_t to_lower(char_t ch)char_t to_upper(char_t ch)std::basic_string<char_t> to_lower(const std::basic_string<char_t>& str)std::basic_string<char_t> to_upper(const std::basic_string<char_t>& str)bool is_digit(char ch)bool is_vowel(char ch)bool is_letter(char ch)std::string cat(const std::vector<std::string>& strings)std::string row_vector(const Cont& c, BracketType bracket = BracketType::SquareBrackets, const std::string& separator = ", ")std::string column_vector(const Cont& c, BracketType bracket = BracketType::SquareBrackets)inline void ltrim(std::string& s)(trim from start (in place))inline void rtrim(std::string& s)(trim from end (in place))inline void trim(std::string &s)(trim from both ends (in place))inline std::string ltrim_ret(std::string s)(trim from start (copying))inline std::string rtrim_ret(std::string s)(trim from end (copying))inline std::string trim_ret(std::string s)(trim from both ends (copying))inline void remove_spaces(std::string& str)bool is_an(const std::string& str)std::string indef_art(const std::string& str)std::string anfangify(std::string str)std::vector<std::basic_string<CharT>> tokenize(const std::basic_string<CharT>& str, const std::vector<CharT>& delim, const std::vector<CharT>& scope_delim = {}, size_t min_scope_size = 1)std::vector<std::string> to_string_vector(const Cont& c)std::string flatten(const std::vector<std::string>& string_vec, const std::string& separator = ", ")
Namespace: sys
Functions:
std::string exec(const char* cmd)bool is_wsl()bool is_bsd()bool is_linux()bool is_windows()bool is_apple()
Namespace: TextIO
Functions:
bool read_file(const std::string& file_path, std::vector<std::string>& lines)bool write_file(const std::string& file_path, const std::vector<std::string>& lines)
Namespace: -
Structs / Classes:
class TimerTimer(float d)bool start_if_stopped(float t)void force_start(float t)bool finished(float t) constbool wait_then_reset(float t)bool is_ticking(float t) constvoid reset()bool is_active() constvoid set_delay(float d)float get_delay() const
Namespaces: utils, utils::literals
Functions:
bool try_set(T* dst, const T& src)T try_get(T* ptr, const T def_val = static_cast<T>(0))T* get_raw_ptr(T& o)const T* get_raw_ptr(const T& o)T* get_raw_ptr(T* o)const T* get_raw_ptr(const T* o)T* get_raw_ptr(std::unique_ptr<T>& o)const T* get_raw_ptr(const std::unique_ptr<T>& o)
Namespace: uuid
Functions:
std::string generate_uuid_v4()
Namespace: -
Structs / Classes:
struct Vec2Vec2()Vec2(float rr, float cc)Vec2(const Vec2& v)const Vec2& operator+() constVec2 operator-() constVec2 operator+(const Vec2& v) constVec2 operator-(const Vec2& v) constVec2& operator+=(const Vec2& v)Vec2& operator-=(const Vec2& v)Vec2 operator*(float v) const- `Vec2 operator/(float v) const´
Vec2& operator/=(float v)std::string str() const
Functions:
Vec2 operator*(float v, const Vec2& p)float length_squared(const Vec2& pt)(namespacemath)float length(const Vec2& pt)(namespacemath)float distance_squared(const Vec2& ptA, const Vec2& ptB)(namespacemath)float distance(const Vec2& ptA, const Vec2& ptB)(namespacemath)float distance_squared_ar(const Vec2& ptA, const Vec2& ptB, float ar)(namespacemath)float distance_ar(const Vec2& ptA, const Vec2& ptB, float ar)(namespacemath)Vec2 normalize(const Vec2& v)(namespacemath)float dot(const Vec2& vA, const Vec2& vB)(namespacemath)
Namespace: -
Structs / Classes:
class BoolBool()Bool(bool v)Bool(const Bool& b)Bool(int v)Bool(double v)operator bool() constoperator bool&()bool operator==(Bool b) constbool operator!=(Bool b) const
using bool_vector = std::vector<Bool>