std::basic_format_arg
来自 cppreference.cn
| 定义于头文件 <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; |
(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; |
(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) | (C++26 起) |
| template< class R, class Visitor > R visit( this basic_format_arg arg, Visitor&& vis ); |
(2) | (C++26 起) |
将访问器 vis 应用于 arg 中包含的对象。
visit 函数不会修改它所调用的 basic_format_arg 对象,因为在调用 vis 时会使用对象的副本。
[编辑] 注解
| 特性测试宏 | 值 | 标准 | 特性 |
|---|---|---|---|
__cpp_lib_format |
202306L |
(C++26) | 成员 visit |
[编辑] 示例
| 本节不完整 原因:无示例 |
[编辑] 参阅
| (C++20)(C++20)(C++20) |
提供对所有格式化参数访问的类 (类模板) |