#pragma once #include #include #include #include namespace hack::utils { template auto func_memory(Result (*f)(Args...)) { std::map, Result> cache; return [f, cache](Args... args) mutable -> Result { const auto key = std::make_tuple(args...); const auto cached = cache.find(key); if(cached == cache.end()) { auto result = f(args...); cache[key] = result; return result; } return cached->second; }; } template auto func_concat(T t, Args... args) { if constexpr (sizeof...(args) > 0) { return [=](auto... params) { return t(func_concat(args...)(params...)); }; } else { return [=](auto... params) { return t(params...); }; } } inline std::string exec(const std::string& cmd) { std::string result; std::array buffer; std::unique_ptr pipe(popen(cmd.c_str(), "r"), pclose); if (!pipe) { throw std::runtime_error("bash cmd failed"); } while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { result += buffer.data(); } return result; } }