std::basic_format_arg_C++中文网
| template<class Context> |
(C++20 起) | |
提供到格式化参数的访问。
basic_format_arg 对象通常由 std::make_format_args 创建并通过 std::visit_format_arg 访问。
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
成员类
| 类型 | 定义 |
| 允许格式化用户定义类型的对象的类型擦除包装 (类) | |
成员函数
构造 std::basic_format_arg (公开成员函数) | |
| 检查当前对象是否保有格式化参数 (公开成员函数) |
非成员函数
std::basic_format_arg::handle
| template<class Context> |
||
允许格式化用户定义类型的对象。
成员函数
| 以给定的环境格式化被引用对象 (公开成员函数) |
std::basic_format_arg::handle::format
| void format(std::basic_format_parse_context<Context::char_type>& parse_ctx, |
||
令 T 为关联的格式化参数的类型, ref 为指代该格式化参数的 const T& 。等价于:
typename Context::template formatter_type<T> f;
parse_ctx.advance_to(f.parse(parse_ctx));
format_ctx.advance_to(f.format(ref, format_ctx));
std::basic_format_arg::basic_format_arg
| basic_format_arg() noexcept; |
||
默认构造函数。构造不保有格式化参数的 basic_format_arg 。存储的对象拥有 std::monostate 类型。
为创建保有格式化参数的 basic_format_arg ,必须使用 std::make_format_args 。
std::basic_format_arg::operator bool
| explicit operator bool() const noexcept; |
||
检查 *this 是否保有格式化参数。
若 *this 保有格式化参数(即存储的对象不拥有 std::monostate 类型)则返回 true ,否则返回 false 。