std::basic_format_arg<Context>::handle
格式化函数 | ||||
(C++20)
|
||||
(C++20)
|
||||
(C++20)
|
||||
(C++20)
|
||||
(C++20)
|
||||
(C++20)
|
||||
格式化概念 | ||||
(C++23)
|
||||
格式化器 | ||||
(C++20)
|
||||
(C++23)
|
||||
(C++20)(C++20)(C++20)
|
||||
(C++20)(C++20)(C++20)
|
||||
(C++23)
|
||||
(C++23)
|
||||
格式化参数 | ||||
(C++20)
|
||||
basic_format_arg::handle
(C++20)
|
||||
(C++20)(C++20)(C++20)
|
||||
(C++20)(C++20)(C++20)
|
||||
(C++20)
(C++26
中弃用)
|
||||
(C++20)(C++20)
|
||||
格式错误 | ||||
(C++20)
|
在标头
<format>
定义
|
||
template<
class
Context >
class basic_format_arg<Context>::handle; |
(C++20 起) | |
允许格式化用户定义类型对象的类型擦除包装。
handle
对象常由 std::make_format_args
创建并通过 std::visit_format_arg 或 std::basic_format_arg 的
visit
成员函数 (C++26
起)访问。
数据成员
handle
的典型实现为可平凡复制 (TriviallyCopyable)
并仅存储二个非静态数据成员:
- 指向待格式化对象的 const void* 指针,以及
- 指向进行
format
成员函数(见后述)所需操作的 void (*)(std::basic_format_parse_context<Context::char_type>&, Context&, const void*) 函数指针。
成员函数
format
(C++20)
|
以给定的环境格式化被引用的对象 (公开成员函数) |
std::basic_format_arg<Context>::handle::format
void
format(
std::basic_format_parse_context<Context::char_type>&
parse_ctx,
Context& format_ctx ) const; |
(C++20 起) | |
令
-
T
为被格式化参数的类型, -
TD
为 std::remove_const_t<T>, -
TQ
若 const TD 满足 __formattable_with<Context> 则为 const TD,否则为TD
,而 -
ref
为到被格式化参数的引用。
等价于:
typename Context::template
formatter_type<TD> f;
parse_ctx.advance_to(f.parse(parse_ctx));
format_ctx.advance_to(f.format(const_cast<TQ&>(static_cast<const TD&>(ref)), format_ctx));
注解
handle
拥有对被格式化参数的引用语义而不延长其生存期。程序员负责确保该参数存活得比 handle
更久。通常 handle
仅在格式化函数内使用。
参阅
(C++20)
|
提供对用户定义格式化器的格式化参数的访问的类模板 (类模板) |
(C++20)(C++20)
|
创建引用所有格式化参数的类型擦除对象,可转换到 format_args (函数模板) |