Skip to content

Add fmt_print and fmt_println to C API#4789

Open
Ferdi265 wants to merge 2 commits into
fmtlib:mainfrom
Ferdi265:feature/fmt-c-print
Open

Add fmt_print and fmt_println to C API#4789
Ferdi265 wants to merge 2 commits into
fmtlib:mainfrom
Ferdi265:feature/fmt-c-print

Conversation

@Ferdi265
Copy link
Copy Markdown
Contributor

This PR introduces fmt_print() and fmt_println() macros to the C API, which print to a FILE* stream using fmt::vprint(stream, fmt, format_args).

Additionally, this PR introduces the following helpers in fmt-c.h:

  • a helper macro FMT_FORMAT_ARGS(fmt, ...) that abstracts away the macro magic necessary to produce the fmt_arg array, useful for avoiding duplicated logic when declaring additional wrapper macros that expand to calls to fmt_vformat or similar
  • a fmt_vprint() function used to implement the fmt_print() macro
  • a fmt_vprintln() function used to implement the fmt_println() macro

and the following helpers in fmt-c.cc:

  • a helper template fmt_c_wrapper() that performs the conversion from fmt_arg to fmt::basic_format_arg, calls the passed lambda, and handles exceptions, to reduce boilerplate and duplication between fmt_vformat(), fmt_vprint(), and fmt_vprintln()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant