std:: basic_format_parse_context
|
定义于头文件
<format>
|
||
|
template
<
class
CharT
>
class basic_format_parse_context ; |
(C++20 起) | |
提供对格式字符串解析状态的访问,该状态包含正在解析的格式字符串范围以及用于自动索引的参数计数器。
当解析格式规范时,会向
Formatter
传递一个
std::basic_format_parse_context
实例。
声明
std::basic_format_parse_context
显式或部分特化的程序是非良构的,不要求诊断。
提供了多种常见字符类型的类型定义:
|
定义于头文件
<format>
|
|
| 类型 | 定义 |
std::format_parse_context
|
std :: basic_format_parse_context < char > |
std::wformat_parse_context
|
std :: basic_format_parse_context < wchar_t > |
成员类型
| 类型 | 定义 |
char_type
|
CharT
|
iterator
|
std:: basic_string_view < CharT > :: const_iterator |
const_iterator
|
std:: basic_string_view < CharT > :: const_iterator |
成员函数
|
(constructor)
|
从格式字符串和参数数量构造
std::basic_format_parse_context
实例
(公开成员函数) |
|
operator=
[deleted]
|
std::basic_format_parse_context
不可复制
(公开成员函数) |
|
begin
|
返回指向格式字符串范围起始位置的迭代器
(公开成员函数) |
|
end
|
返回指向格式字符串范围结束位置的迭代器
(公开成员函数) |
|
advance_to
|
将起始迭代器推进到指定位置
(公开成员函数) |
|
next_arg_id
|
进入自动索引模式,并返回下一个参数索引
(公开成员函数) |
|
check_arg_id
|
进入手动索引模式,检查给定参数索引是否在有效范围内
(公开成员函数) |
|
check_dynamic_spec
(C++26)
|
检查具有给定参数索引的对应格式参数类型是否在给定的类型模板参数中
(公开成员函数) |
|
check_dynamic_spec_integral
(C++26)
|
检查具有给定参数索引的对应格式参数类型是否为整型
(公开成员函数) |
|
check_dynamic_spec_string
(C++26)
|
检查具有给定参数索引的对应格式参数类型是否为字符串类型
(公开成员函数) |
std::basic_format_parse_context:: basic_format_parse_context
| (1) | ||
|
constexpr
explicit
basic_format_parse_context
(
std::
basic_string_view
<
CharT
>
fmt,
|
(until C++26) | |
|
constexpr
explicit
basic_format_parse_context ( std:: basic_string_view < CharT > fmt ) noexcept ; |
(since C++26) | |
|
basic_format_parse_context
(
const
basic_format_parse_context
&
)
=
delete
;
|
(2) | |
std::basic_format_parse_context
实例。将格式字符串范围初始化为
[
fmt.
begin
(
)
,
fmt.
end
(
)
)
,并将参数数量初始化为
num_args
(until C++26)
0
(since C++26)
。
|
在此构造函数初始化的
|
(since C++26) |
std::basic_format_parse_context
不可拷贝。
std::basic_format_parse_context:: begin
|
constexpr
const_iterator begin
(
)
const
noexcept
;
|
||
返回指向格式字符串范围起始位置的迭代器。
std::basic_format_parse_context:: end
|
constexpr
const_iterator end
(
)
const
noexcept
;
|
||
返回指向格式字符串范围末尾的迭代器。
std::basic_format_parse_context:: advance_to
|
constexpr
void
advance_to
(
const_iterator it
)
;
|
||
将格式字符串范围的起始位置设置为
it
。调用
advance_to()
后,后续对
begin()
的调用将返回
it
的副本。
如果从 it 无法 到达 end ( ) ,则行为未定义。
std::basic_format_parse_context:: next_arg_id
|
constexpr
std::
size_t
next_arg_id
(
)
;
|
||
进入自动参数索引模式,并返回下一个参数索引,从0开始计数。
如果 * this 已进入手动参数索引模式,则抛出 std::format_error 。
如果下一个参数索引大于或等于构造函数中提供的 num_args ,该调用将不是核心常量表达式。
std::basic_format_parse_context:: check_arg_id
|
constexpr
void
check_arg_id
(
std::
size_t
id
)
;
|
||
进入手动参数索引模式。
如果 * this 已进入自动参数索引模式,则抛出 std::format_error 。
如果 id 大于或等于构造函数中提供的 num_args ,则该调用不是核心常量表达式。
std::basic_format_parse_context:: check_dynamic_spec
|
template
<
class
...
Ts
>
constexpr void check_dynamic_spec ( std:: size_t id ) noexcept ; |
(since C++26) | |
如果 id 大于或等于构造函数中提供的 num_args ,或者对应格式化参数的类型(在转换为 std::basic_format_arg 后)不在 Ts... 类型列表中,则该调用不是核心常量表达式。对 check_dynamic_spec 的调用在运行时无任何效果。
除非满足以下条件,否则程序非良构: sizeof... ( Ts ) >= 1 , Ts... 中的类型唯一,且每个类型均为 bool 、 char_type 、 int 、 unsigned int 、 long long int 、 unsigned long long int 、 float 、 double 、 long double 、 const char_type * 、 std:: basic_string_view < char_type > 或 const void * 之一。
std::basic_format_parse_context:: check_dynamic_spec_integral
|
constexpr
void
check_dynamic_spec_integral
(
std::
size_t
id
)
noexcept
;
|
(since C++26) | |
等价于调用 check_dynamic_spec < int , unsigned int , long long int , unsigned long long int > ( id ) 。对 check_dynamic_spec_integral 的调用在运行时无实际效果。
std::basic_format_parse_context:: check_dynamic_spec_string
|
constexpr
void
check_dynamic_spec_string
(
std::
size_t
id
)
noexcept
;
|
(since C++26) | |
等价于调用 check_dynamic_spec < const char_type * , std:: basic_string_view < char_type >> ( id ) 。对 check_dynamic_spec_string 的调用在运行时无实际效果。
示例
|
本节内容不完整
原因:缺少示例 |
缺陷报告
下列行为变更缺陷报告被追溯应用于先前发布的C++标准。
| 缺陷报告 | 应用于 | 发布时的行为 | 正确行为 |
|---|---|---|---|
| LWG 3825 | C++20 |
check_arg_id
具有编译时参数
id 检查,但
next_arg_id
未具备
|
已添加 |
| LWG 3975 | C++20 |
允许用户对
basic_format_parse_context
进行特化
|
已禁止 |