[#absl-FormatUntyped] = xref:absl.adoc[absl]::FormatUntyped :relfileprefix: ../ :mrdocs: Writes a formatted string to an arbitrary sink object (implementing the `absl::FormatRawSink` interface), using an `UntypedFormatSpec` and zero or more additional arguments. == Synopsis Declared in `<absl/strings/str_format.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- [[nodiscard]] bool FormatUntyped( xref:absl/FormatRawSink.adoc[FormatRawSink] raw_sink, xref:absl/UntypedFormatSpec.adoc[UntypedFormatSpec] const& format, xref:absl/Span.adoc[absl::Span<FormatArg const>] args); ---- == Description This function acts as the most generic formatting function in the `str_format` library. The caller provides a raw sink, an unchecked format string, and (usually) a runtime specified list of arguments; no compile‐time checking of formatting is performed within this function. As a result, a caller should check the return value to verify that no error occurred. On failure, this function returns `false` and the state of the sink is unspecified. The arguments are provided in an `absl::Span<const absl::FormatArg>`. Each `absl::FormatArg` object binds to a single argument and keeps a reference to it. The values used to create the `FormatArg` objects must outlive this function call. Example: std::optional<std::string> FormatDynamic( const std::string& in_format, const vector<std::string>& in_args) { std::string out; std::vector<absl::FormatArg> args; for (const auto& v : in_args) { // It is important that 'v' is a reference to the objects in in_args. // The values we pass to FormatArg must outlive the call to // FormatUntyped. args.emplace_back(v); } absl::UntypedFormatSpec format(in_format); if (!absl::FormatUntyped(&out, format, args)) { return std::nullopt; } return std::move(out); } == Return Value `true` on success, `false` on error. [NOTE] ==== The return value https://en.cppreference.com/cpp/language/attributes/nodiscard[should not be discarded^]. ==== == Parameters [cols="1,4"] |=== | Name| Description | *raw_sink* | The sink that receives the formatted output. | *format* | The untyped format spec. | *args* | The arguments substituted into the format string. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#