std::basic_format_args

< cpp‎ | utility‎ | format
定义于头文件 <format>
template<class Context>
class basic_format_args;
(1) (C++20 起)
using format_args = basic_format_args<std::format_context>;
(2) (C++20 起)
using wformat_args = basic_format_args<std::wformat_context>;
(3) (C++20 起)

提供到格式化参数的访问。

成员函数

(构造函数)
构造 basic_format_args 对象
(公开成员函数)
get
返回位于给定下标的格式化参数
(公开成员函数)

std::basic_format_args::basic_format_args

basic_format_args() noexcept;
(1)
template<class... Args>
basic_format_args(const /*format-arg-store*/<Context, Args...>& store) noexcept;
(2)
1) 构造不保有任何格式化参数的 basic_format_args 对象。
2) 从调用 std::make_format_argsstd::make_wformat_args 的结果构造 basic_format_args 对象。

std::basic_format_args 拥有引用语义。程序员负责确保 *this 不会比 store 活得更久(从而不应比 std::make_format_argsstd::make_wformat_args 的参数存活更久)。

std::basic_format_args::get

std::basic_format_arg<Context> get(std::size_t i) const noexcept;

返回保有 args 中第 i 参数的 std::basic_format_arg ,其中 args 是传递给 std::make_format_argsstd::make_wformat_args 的形参包。

若无足够的参数(即 *this 为默认构造或 i 不小于格式化参数数),则返回默认构造的 std::basic_format_arg (保有 std::monostate 对象)。

示例

缺陷报告

下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。

DR 应用于 出版时的行为 正确行为
P2216R3 C++20 由于 vformat_to 的过度参数化提供了 format_args_t 已移除

参阅