std::basic_format_arg
来自cppreference.com
| 在标头 <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) |
提供对所有格式化参数的访问的类 (类模板) |