implement an utils::print() function similar to fmt::print()

this doesn't have the constexpr requirement for the format string.
also it will help porting to std::format in C++20, which doesn't
have a similar functionality either.
This commit is contained in:
Axel Kohlmeyer
2025-01-23 00:03:30 -05:00
parent b4f012057c
commit 8baec60155
6 changed files with 80 additions and 20 deletions

View File

@ -262,6 +262,22 @@ void utils::fmtargs_logmesg(LAMMPS *lmp, fmt::string_view format, fmt::format_ar
}
}
/* specialization for the case of just a single string argument */
void utils::print(FILE *fp, const std::string &mesg)
{
fputs(mesg.c_str(), fp);
}
void utils::fmtargs_print(FILE *fp, fmt::string_view format, fmt::format_args args)
{
try {
print(fp, fmt::vformat(format, args));
} catch (fmt::format_error &) {
; // do nothing
}
}
std::string utils::errorurl(int errorcode)
{
return fmt::format("\nFor more information see https://docs.lammps.org/err{:04d}", errorcode);