std::basic_format_args
来自 cppreference.cn
定义于头文件 <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
template< class... Args > basic_format_args( const /*format-arg-store*/<Context, Args...>& store ) noexcept; |
||
从调用 std::make_format_args 或 std::make_wformat_args 的结果构造一个 basic_format_args
对象。
std::basic_format_args::get
std::basic_format_arg<Context> get( std::size_t i ) const noexcept; |
||
返回一个 std::basic_format_arg,其中持有 args
中的第 i 个参数,其中 args
是传递给 std::make_format_args 或 std::make_wformat_args 的参数包。
如果没有这样的格式化参数(即 *this 是默认构造的,或者 i 不小于格式化参数的数量),则返回一个默认构造的 std::basic_format_arg(持有 std::monostate 对象)。
[编辑] 推导指引
template< class Context, class... Args > basic_format_args( /*format-arg-store*/<Context, Args...> ) -> basic_format_args<Context>; |
(自 C++20 起) | |
[编辑] 注解
std::basic_format_args
具有引用语义。程序员有责任确保 *this 不会比 store 活得更久(而 store 反过来不应比 std::make_format_args 或 std::make_wformat_args 的参数活得更久)。
[编辑] 示例
本节不完整 原因:没有示例 |
[编辑] 缺陷报告
以下行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。
DR | 应用于 | 已发布行为 | 正确行为 |
---|---|---|---|
P2216R3 | C++20 | 由于 vformat_to 的过度参数化,提供了 format_args_t |
已移除 |
LWG 3810 | C++20 | basic_format_args 没有推导指引 |
已添加 |
LWG 4106 | C++20 | basic_format_args 是默认可构造的 |
默认构造函数已移除 |
[编辑] 参见
(C++20) |
为用户定义的格式化器提供对格式化参数访问的类模板 (类模板) |