From 4d7970d2618495b6e29ce6fd9c0f187e01ed4c0e Mon Sep 17 00:00:00 2001 From: Aarik Pokras <85502246+aarikpokras@users.noreply.github.com> Date: Mon, 23 Dec 2024 14:34:58 -0500 Subject: [PATCH] Massive bug fixes for `num` No template type deduction in func. prototype, changed num to double --- lib/io.cxlbund/io.h | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/io.cxlbund/io.h b/lib/io.cxlbund/io.h index 6c3ceee..7f45a99 100644 --- a/lib/io.cxlbund/io.h +++ b/lib/io.cxlbund/io.h @@ -11,10 +11,9 @@ #pragma once void print(std::string s); -template struct num { - T c; - num(T w) : c(w) {} + double c; + num(double w) : c(w) {} std::string as_str() { return std::to_string(c); } @@ -98,12 +97,9 @@ struct num { } }; -void loop(void (*what)(void), num times); +void loop(void (*what)(void), num times); -template -void printi(num i) { - std::cout << i.c; -} +void printi(num i); struct str { std::vector c; @@ -154,15 +150,18 @@ struct str { }; struct any { - std::variant, num, str, int, double> c; - any(str w) : c(w) {} - any(num w) : c(w) {} - any(num w) : c(w) {} - any(int w) : c(w) {} - any(double w) : c(w) {} + std::variant c; + str s = ""; + num ni = 0; + double d = 0; + int i = 0; + any(str w) : c(w), s(w) {} + any(num w) : c(w), ni(w) {} + any(int w) : c(w), i(w) {} + any(double w) : c(w), d(w) {} + bool is_num() { - if (std::holds_alternative>(c) - || std::holds_alternative>(c) + if (std::holds_alternative(c) || std::holds_alternative(c) || std::holds_alternative(c)) { return true; @@ -198,12 +197,12 @@ struct strarr { str whatf = str(what); c.push_back(whatf.c[0]); } - num items() { + num items() { std::string ret__ = std::to_string(c.size()); int ret_ = std::stoi(ret__); return num(ret_); } - str operator[](const num& o) { + str operator[](const num& o) { std::string ret_ = c[o.c]; return str(ret_); }