add overload to utils::print() so it can be used without FILE pointer

This commit is contained in:
Axel Kohlmeyer
2025-06-06 11:29:12 -04:00
parent bf97cc470f
commit 23b185a625
2 changed files with 26 additions and 1 deletions

View File

@ -274,6 +274,11 @@ void utils::print(FILE *fp, const std::string &mesg)
fputs(mesg.c_str(), fp); fputs(mesg.c_str(), fp);
} }
void utils::print(const std::string &mesg)
{
fputs(mesg.c_str(), stdout);
}
void utils::fmtargs_print(FILE *fp, fmt::string_view format, fmt::format_args args) void utils::fmtargs_print(FILE *fp, fmt::string_view format, fmt::format_args args)
{ {
print(fp, fmt::vformat(format, args)); print(fp, fmt::vformat(format, args));

View File

@ -151,7 +151,7 @@ output are compressed to a single blank by calling :cpp:func:`strcompress()`
\endverbatim \endverbatim
* *
* This function implements a version of fprintf() that uses {fmt} formatting * This function implements a version of (f)printf() that uses {fmt} formatting
* *
* \param fp stdio FILE pointer * \param fp stdio FILE pointer
* \param format format string of message to be printed * \param format format string of message to be printed
@ -163,12 +163,32 @@ output are compressed to a single blank by calling :cpp:func:`strcompress()`
} }
/*! \overload /*! \overload
*
* Print to stdout without specifying the FILE pointer.
*
* \param mesg string with message to be printed */
template <typename... Args> void print(const std::string &format, Args &&...args)
{
fmtargs_print(stdout, format, fmt::make_format_args(args...));
}
/*! \overload
*
* Print string message without format
* *
* \param fp stdio FILE pointer * \param fp stdio FILE pointer
* \param mesg string with message to be printed */ * \param mesg string with message to be printed */
void print(FILE *fp, const std::string &mesg); void print(FILE *fp, const std::string &mesg);
/*! \overload
*
* Print string message without format to stdout
*
* \param mesg string with message to be printed */
void print(const std::string &mesg);
/*! Return text redirecting the user to a specific paragraph in the manual /*! Return text redirecting the user to a specific paragraph in the manual
* *
* The LAMMPS manual contains detailed explanations for errors and * The LAMMPS manual contains detailed explanations for errors and