std:: basic_format_args
|
定义于头文件
<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 起) |
提供对格式化参数的访问。
目录 |
成员函数
|
(constructor)
|
构造
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
;
|
||
返回一个持有第
i
个参数的
std::basic_format_arg
,其中
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)
|
为用户定义格式化器提供格式化参数访问的类模板
(类模板) |