命名空间
变体
操作

std::range-default-formatter<std::range_format::map>

来自 cppreference.cn
 
 
 
 
 
定义于头文件 <format>
template< ranges::input_range R, class CharT >
struct /*range-default-formatter*/<range_format::map, R, CharT>;
(自 C++23 起)
(仅为演示目的定义*)

类模板 /*range-default-formatter*/ 针对范围类型进行了特化,用于将范围格式化为键值对映射,如果 std::format_kind<R>std::range_format::map

内容

[编辑] 成员类型

成员 定义
maybe-const-map (私有) fmt-maybe-const<R, CharT>
(仅为演示目的的成员类型*)
element-type (私有) std::remove_cvref_t<ranges::range_reference_t<maybe-const-map>>
(仅为演示目的的成员类型*)

[编辑] 数据成员

成员 定义
underlying_ (私有) 类型为 std::range_formatter<element-type, CharT> 的底层格式化器
(仅为演示目的的成员对象*)

[编辑] 成员函数

(构造函数)
构造一个 range-default-formatter
(公有成员函数)
parse
解析格式说明符,如range-format-spec 所指定
(公有成员函数)
format
写入范围格式化输出,如range-format-spec 所指定
(公有成员函数)

std::range-default-formatter<std::range_format::map>::range-default-formatter

constexpr /*range-default-formatter*/();

等价于
underlying_.set_brackets(STATICALLY_WIDEN<CharT>("{"), STATICALLY_WIDEN<CharT>("}"));
underlying_.underlying().set_brackets({}, {});
underlying_.underlying().set_separator(STATICALLY_WIDEN<charT>(": "));

其中 STATICALLY_WIDEN<CharT>("...")CharTchar 时为 "...",而在 CharTwchar_t 时为 L"..."

除非满足以下条件,否则程序是非良构的:

  • element-typestd::pair 的特化,或
  • element-typestd::tuple 的特化且 std::tuple_size_v<element-type>2

std::range-default-formatter<std::range_format::map>::parse

template< class ParseContext >
constexpr auto parse( ParseContext& ctx ) -> ParseContext::iterator;

等价于: return underlying_.format(ctx);

返回一个迭代器,指向 range-format-spec 末尾之后的位置。

std::range-default-formatter<std::range_format::map>::format

template< class FormatContext >
auto format( maybe-const-map& r, FormatContext& ctx ) const -> FormatContext::iterator;

等价于: return underlying_.format(r, ctx);

返回一个迭代器,指向输出范围末尾之后的位置。

[编辑] 参见

(C++20)
为给定类型定义格式化规则
(类模板) [编辑]
类模板,帮助为范围类型实现 std::formatter 特化
(类模板) [编辑]