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++ 标准。
缺陷报告 | 应用于 | 发布时的行为 | 正确的行为 |
---|---|---|---|
P2216R3 | C++20 | 由于 vformat_to 的过度参数化而提供了 format_args_t |
已移除 |
LWG 3810 | C++20 | basic_format_args 没有推导指南 |
已添加 |
LWG 4106 | C++20 | basic_format_args 是默认可构造的 |
已移除默认构造函数 |
[编辑] 参见
(C++20) |
为用户定义格式化器提供格式化参数访问的类模板 (类模板) |