#pragma once #include "StarMemory.hpp" #include "StarException.hpp" #include "fmt/core.h" #include "fmt/ostream.h" #include "fmt/format.h" #include "fmt/ranges.h" namespace Star { STAR_EXCEPTION(FormatException, StarException); template std::string strf(fmt::format_string fmt, T&&... args) { try { return fmt::format(fmt, args...); } catch (std::exception const& e) { throw FormatException(strf("Exception thrown during string format: {}", e.what())); } } template void format(std::ostream& out, fmt::format_string fmt, T&&... args) { out << strf(fmt, args...); } // Automatically flushes, use format to avoid flushing. template void coutf(char const* fmt, Args const&... args) { format(std::cout, fmt, args...); std::cout.flush(); } // Automatically flushes, use format to avoid flushing. template void cerrf(char const* fmt, Args const&... args) { format(std::cerr, fmt, args...); std::cerr.flush(); } template inline std::string toString(Type const& t) { return fmt::to_string(t); } }