std:: basic_format_arg
|
定义于头文件
<format>
|
||
|
template
<
class
Context
>
class basic_format_arg ; |
(C++20 起) | |
提供对格式化参数的访问。
basic_format_arg
对象通常由
std::make_format_args
创建,并通过
std::visit_format_arg
或
visit
成员函数
(C++26 起)
进行访问。
一个
basic_format_arg
对象的行为类似于包含以下类型的
std::variant
:
- std:: monostate (仅当对象为默认构造时)
- bool
- Context :: char_type
- int
- unsigned int
- long long int
- unsigned long long int
- float
- double
- long double
- const Context :: char_type *
- std:: basic_string_view < Context :: char_type >
- const void *
- basic_format_arg :: handle
目录 |
成员类
|
(C++20)
|
允许格式化用户自定义类型对象的类型擦除包装器
(公开成员类) |
成员函数
|
(构造函数)
(C++20)
|
构造
std::basic_format_arg
(公开成员函数) |
|
operator bool
(C++20)
|
检查当前对象是否持有格式化参数
(公开成员函数) |
|
visit
(C++26)
|
访问所含的格式化参数
(公开成员函数) |
非成员函数
|
(C++20)
(C++26起弃用)
|
用户自定义格式化器的参数访问接口
(函数模板) |
std::basic_format_arg:: basic_format_arg
|
basic_format_arg
(
)
noexcept
;
|
(since C++20) | |
默认构造函数。构造一个不持有格式化参数的
basic_format_arg
。所包含的对象具有类型
std::monostate
。
要创建持有格式化参数的
basic_format_arg
,必须使用
std::make_format_args
。
std::basic_format_arg:: operator bool
|
explicit
operator
bool
(
)
const
noexcept
;
|
(since C++20) | |
检查 * this 是否持有格式化参数。
当 * this 持有格式化参数时(即所包含对象的类型不是 std::monostate )返回 true ,否则返回 false 。
std::basic_format_arg:: visit
|
template
<
class
Visitor
>
decltype ( auto ) visit ( this basic_format_arg arg, Visitor && vis ) ; |
(1) | (since C++26) |
|
template
<
class
R,
class
Visitor
>
R visit ( this basic_format_arg arg, Visitor && vis ) ; |
(2) | (since C++26) |
对包含在 arg 中的对象应用访问器 vis 。
visit
函数不会修改调用它的
basic_format_arg
对象,因为在调用
vis
时使用的是该对象的副本。
v
是包含在
arg
中的
std::variant
。
v
是包含在
arg
中的
std::variant
。
注释
| 功能测试宏 | 值 | 标准 | 功能特性 |
|---|---|---|---|
__cpp_lib_format
|
202306L
|
(C++26) |
成员函数
visit
|
示例
|
本节内容不完整
原因:缺少示例 |
参见
|
(C++20)
(C++20)
(C++20)
|
提供对所有格式化参数访问的类
(类模板) |