标准库头文件(C++20)

标准库头文件<format>(C++20)

C++

编译器支持

独立式和宿主式

语言

标准库

标准库头文件

命名要求

特性测试宏 (C++20)

语言支持库

概念库 (C++20)

诊断库

内存管理库

元编程库 (C++11)

通用工具库

容器库

迭代器库

范围库 (C++20)

算法库

字符串库

文本处理库

数值库

日期和时间库

输入/输出库

文件系统库 (C++17)

并发支持库 (C++11)

执行控制库 (C++26)

技术规范

符号索引

外部库

[编辑] 标准库头文件

语言支持

(C++20)

(C++26)

(C++20)

(C++11)

(C++11)

(C++20)

(C++23)

(C++20)

概念

(C++20)

诊断

(C++26)

(C++23)

(C++11)

内存管理

(C++17)

(C++11)

元编程

(C++11)

(C++11)

通用工具

(C++17)

(C++20)

(C++17)

(C++23)

(C++20)

(C++17)

(C++11)

(C++11)

(C++17)

容器

(C++11)

(C++23)

(C++23)

(C++11)

(C++26)

(C++26)

(C++23)

(C++20)

(C++11)

(C++11)

迭代器

范围

(C++23)

(C++20)

算法

字符串

(C++11)

(C++17)

文本处理

(C++11/17/26* 已弃用)

(C++11)

(C++26)

数值

(C++11)

(C++26)

(C++20)

(C++11)

(C++26)

时间

(C++11)

C 兼容性

(C++11/17/20* 已弃用)

(直到 C++20)

(C++11/17/20* 已弃用)

(C++11/17/20* 已弃用)

(C++11/17/20* 已弃用)

输入/输出

(C++11)

(C++17)

(C++23)

(C++23)

(C++98/26* 已弃用)

(C++20)

并发支持

(C++11)

(C++20)

(C++11)

(C++11)

(C++26)

(C++20)

(C++11)

(C++26)

(C++20)

(C++14)

(C++23)

(C++20)

(C++11)

执行支持

(C++17)

[编辑]

此头文件是 文本处理 库的一部分。

目录

1 概念

2 枚举

3 类

3.1 格式化器特化

4 函数

5 辅助工具

6 概要

6.1 类模板 std::basic_format_string

6.2 概念 std::formattable

6.3 类模板 std::basic_format_parse_context

6.4 类模板 std::basic_format_context

6.5 变量模板 std::format_kind

6.6 类模板 std::range_formatter

6.7 类模板 __range_default_formatter

6.8 __range_default_formatter 对 map 的特化

6.9 __range_default_formatter 对 set 的特化

6.10 __range_default_formatter 对字符串的特化

6.11 类模板 std::basic_format_arg

6.12 类 std::basic_format_arg::handle

6.13 类模板 __format_arg_store

6.14 类模板 std::basic_format_args

6.15 Tuple 格式化器

6.16 类 std::format_error

概念

formattable(C++23)

指定类型是可格式化的,即它特化了 std::formatter 并提供了成员函数 parse 和 format (概念) [编辑]

枚举

range_format(C++23)

指定范围应如何格式化 (枚举) [编辑]

formatter(C++20)

为给定类型定义格式化规则 (类模板) [编辑]

range_formatter(C++23)

类模板,帮助为范围类型实现 std::formatter 特化 (类模板) [编辑]

basic_format_parse_contextformat_parse_contextwformat_parse_context(C++20)(C++20)(C++20)

格式化字符串解析器状态 (类模板) [编辑]

basic_format_contextformat_contextwformat_context(C++20)(C++20)(C++20)

格式化状态,包括所有格式化参数和输出迭代器 (类模板) [编辑]

basic_format_arg(C++20)

类模板,为用户定义的格式化器提供对格式化参数的访问 (类模板) [编辑]

basic_format_argsformat_argswformat_args(C++20)(C++20)(C++20)

类,提供对所有格式化参数的访问 (类模板) [编辑]

basic_format_stringformat_stringwformat_string(C++20)(C++20)(C++20)

类模板,在构造时执行编译时格式字符串检查 (类模板) [编辑]

format_error(C++20)

在格式化错误时抛出的异常类型 (类) [编辑]

格式化器特化

std::formatter(C++23)

对 pair 和 tuple 的格式化支持 (类模板特化) [编辑]

std::formatter(C++23)

对范围的格式化支持 (类模板特化) [编辑]

函数

format(C++20)

将参数的格式化表示存储在新字符串中 (函数模板) [编辑]

format_to(C++20)

通过输出迭代器写出其参数的格式化表示 (函数模板) [编辑]

format_to_n(C++20)

通过输出迭代器写出其参数的格式化表示,不超过指定大小 (函数模板) [编辑]

formatted_size(C++20)

确定存储其参数的格式化表示所需的字符数 (函数模板) [编辑]

runtime_format(C++26)

创建运行时格式字符串,可直接在面向用户的格式化函数中使用 (函数) [编辑]

vformat(C++20)

std::format 的非模板变体,使用类型擦除的参数表示 (函数) [编辑]

vformat_to(C++20)

std::format_to 的非模板变体,使用类型擦除的参数表示 (函数模板) [编辑]

visit_format_arg(C++20) (C++26 中已弃用)

用户定义的格式化器的参数访问接口 (函数模板) [编辑]

make_format_argsmake_wformat_args(C++20)(C++20)

创建一个类型擦除的对象,引用所有格式化参数,可转换为 format_args (函数模板) [编辑]

辅助工具

format_kind(C++23)

为范围选择合适的 std::range_format(变量模板)[编辑]

enable_nonlocking_formatter_optimization(C++23)

指示参数类型可以有效地打印(变量模板)[编辑]

[编辑] 概要

namespace std {

// class template basic_format_context

template class basic_format_context;

using format_context = basic_format_context;

using wformat_context = basic_format_context;

// class template basic_format_args

template class basic_format_args;

using format_args = basic_format_args;

using wformat_args = basic_format_args;

// class template basic_format_string

template

struct basic_format_string;

template

using format_string = basic_format_string...>;

template

using wformat_string = basic_format_string...>;

// formatting functions

template

string format(format_string fmt, Args&&... args);

template

wstring format(wformat_string fmt, Args&&... args);

template

string format(const locale& loc, format_string fmt, Args&&... args);

template

wstring format(const locale& loc, wformat_string fmt, Args&&... args);

string vformat(string_view fmt, format_args args);

wstring vformat(wstring_view fmt, wformat_args args);

string vformat(const locale& loc, string_view fmt, format_args args);

wstring vformat(const locale& loc, wstring_view fmt, wformat_args args);

template

Out format_to(Out out, format_string fmt, Args&&... args);

template

Out format_to(Out out, wformat_string fmt, Args&&... args);

template

Out format_to(Out out, const locale& loc, format_string fmt, Args&&... args);

template

Out format_to(Out out, const locale& loc, wformat_string fmt, Args&&... args);

template

Out vformat_to(Out out, string_view fmt, format_args args);

template

Out vformat_to(Out out, wstring_view fmt, wformat_args args);

template

Out vformat_to(Out out, const locale& loc, string_view fmt, format_args args);

template

Out vformat_to(Out out, const locale& loc, wstring_view fmt, wformat_args args);

template struct format_to_n_result {

Out out;

iter_difference_t size;

};

template

format_to_n_result format_to_n(Out out, iter_difference_t n,

format_string fmt, Args&&... args);

template

format_to_n_result format_to_n(Out out, iter_difference_t n,

wformat_string fmt, Args&&... args);

template

format_to_n_result format_to_n(Out out, iter_difference_t n,

const locale& loc, format_string fmt,

Args&&... args);

template

format_to_n_result format_to_n(Out out, iter_difference_t n,

const locale& loc, wformat_string fmt,

Args&&... args);

template

size_t formatted_size(format_string fmt, Args&&... args);

template

size_t formatted_size(wformat_string fmt, Args&&... args);

template

size_t formatted_size(const locale& loc, format_string fmt, Args&&... args);

template

size_t formatted_size(const locale& loc, wformat_string fmt, Args&&... args);

// formatter

template

struct formatter;

// variable template enable_nonlocking_formatter_optimization

template

constexpr bool enable_nonlocking_formatter_optimization = false;

// concept formattable

template

concept formattable = /* see description */;

template

concept __const_formattable_range = // exposition only

ranges::input_range &&

formattable, CharT>;

template

using __fmt_maybe_const = // exposition only

conditional_t<__const_formattable_range, const R, R>;

// class template basic_format_parse_context

template class basic_format_parse_context;

using format_parse_context = basic_format_parse_context;

using wformat_parse_context = basic_format_parse_context;

// formatting of ranges

// variable template format_kind

enum class range_format {

disabled,

map,

set,

sequence,

string,

debug_string

};

template

constexpr /* unspecified */ format_kind = /* unspecified */;

template

requires same_as>

constexpr range_format format_kind = /* see description */;

// class template range_formatter

template

requires same_as, T> && formattable

class range_formatter;

// class template range-default-formatter

template

struct __range_default_formatter; // exposition only

// specializations for maps, sets, and strings

template

requires (format_kind != range_format::disabled) &&

formattable, CharT>

struct formatter : __range_default_formatter, R, CharT> { };

// arguments

// class template basic_format_arg

template class basic_format_arg;

template

decltype(auto) visit_format_arg(Visitor&& vis, basic_format_arg arg);

// class template format-arg-store

template class __format_arg_store; // exposition only

template

__format_arg_store

make_format_args(Args&&... fmt_args);

template

__format_arg_store

make_wformat_args(Args&&... args);

// class format_error

class format_error;

}

[编辑] 类模板 std::basic_format_string

namespace std {

template

struct basic_format_string {

private:

basic_string_view str; // exposition only

public:

template consteval basic_format_string(const T& s);

constexpr basic_string_view get() const noexcept { return str; }

};

}

[编辑] 概念 std::formattable

template

concept formattable =

semiregular, CharT>> &&

requires(formatter, CharT> f,

const formatter, CharT> cf,

T t,

basic_format_context<__fmt_iter_for, CharT> fc,

basic_format_parse_context pc) {

{ f.parse(pc) } -> same_as::iterator>;

{ cf.format(t, fc) } -> same_as<__fmt_iter_for>;

};

[编辑] 类模板 std::basic_format_parse_context

namespace std {

template

class basic_format_parse_context {

public:

using char_type = CharT;

using const_iterator = typename basic_string_view::const_iterator;

using iterator = const_iterator;

private:

iterator begin_; // exposition only

iterator end_; // exposition only

enum indexing { unknown, manual, automatic }; // exposition only

indexing indexing_; // exposition only

size_t next_arg_id_; // exposition only

size_t num_args_; // exposition only

public:

constexpr explicit basic_format_parse_context(basic_string_view fmt,

size_t num_args = 0) noexcept;

basic_format_parse_context(const basic_format_parse_context&) = delete;

basic_format_parse_context& operator=(const basic_format_parse_context&) = delete;

constexpr const_iterator begin() const noexcept;

constexpr const_iterator end() const noexcept;

constexpr void advance_to(const_iterator it);

constexpr size_t next_arg_id();

constexpr void check_arg_id(size_t id);

template

constexpr void check_dynamic_spec(size_t id) noexcept;

constexpr void check_dynamic_spec_integral(size_t id) noexcept;

constexpr void check_dynamic_spec_string(size_t id) noexcept;

};

}

[编辑] 类模板 std::basic_format_context

namespace std {

template

class basic_format_context {

basic_format_args args_; // exposition only

Out out_; // exposition only

basic_format_context(const basic_format_context&) = delete;

basic_format_context& operator=(const basic_format_context&) = delete;

public:

using iterator = Out;

using char_type = CharT;

template using formatter_type = formatter;

basic_format_arg arg(size_t id) const noexcept;

std::locale locale();

iterator out();

void advance_to(iterator it);

};

}

[编辑] 变量模板 std::format_kind

template

requires same_as>

constexpr range_format format_kind = /* see description */;

[编辑] 类模板 std::range_formatter

namespace std {

template

requires same_as, T> && formattable

class range_formatter {

formatter underlying_; // exposition only

basic_string_view separator_ = // exposition only

__STATICALLY_WIDEN(", ");

basic_string_view __opening_bracket_ = // exposition only

__STATICALLY_WIDEN("[");

basic_string_view __closing_bracket_ = // exposition only

__STATICALLY_WIDEN("]");

public:

constexpr void set_separator(basic_string_view sep);

constexpr void set_brackets(basic_string_view opening,

basic_string_view closing);

constexpr formatter& underlying() { return underlying_; }

constexpr const formatter& underlying() const { return underlying_; }

template

constexpr typename ParseContext::iterator

parse(ParseContext& ctx);

template

requires formattable, CharT> &&

same_as>, T>

typename FormatContext::iterator

format(R&& r, FormatContext& ctx) const;

};

}

[编辑] 类模板 __range_default_formatter

namespace std {

template

struct __range_default_formatter {

private:

using __maybe_const_r = __fmt_maybe_const;

range_formatter>,

CharT> underlying_; // exposition only

public:

constexpr void set_separator(basic_string_view sep);

constexpr void set_brackets(basic_string_view opening,

basic_string_view closing);

template

constexpr typename ParseContext::iterator

parse(ParseContext& ctx);

template

typename FormatContext::iterator

format(__maybe_const_r& elems, FormatContext& ctx) const;

};

}

[编辑] __range_default_formatter 对 map 的特化

namespace std {

template

struct __range_default_formatter {

private:

using __maybe_const_map = __fmt_maybe_const; // exposition only

using __element_type = // exposition only

remove_cvref_t>;

range_formatter<__element_type, CharT> underlying_; // exposition only

public:

constexpr __range_default_formatter();

template

constexpr typename ParseContext::iterator

parse(ParseContext& ctx);

template

typename FormatContext::iterator

format(__maybe_const_map& r, FormatContext& ctx) const;

};

}

[编辑] __range_default_formatter 对 set 的特化

namespace std {

template

struct __range_default_formatter {

private:

using __maybe_const_set = __fmt_maybe_const; // exposition only

range_formatter>,

CharT> underlying_; // exposition only

public:

constexpr __range_default_formatter();

template

constexpr typename ParseContext::iterator

parse(ParseContext& ctx);

template

typename FormatContext::iterator

format(__maybe_const_set& r, FormatContext& ctx) const;

};

}

[编辑] __range_default_formatter 对字符串的特化

namespace std {

template

requires (K == range_format::string || K == range_format::debug_string)

struct __range_default_formatter {

private:

formatter, CharT> underlying_; // exposition only

public:

template

constexpr typename ParseContext::iterator

parse(ParseContext& ctx);

template

typename FormatContext::iterator

format(/* see description */& str, FormatContext& ctx) const;

};

}

[编辑] 类模板 std::basic_format_arg

namespace std {

template

class basic_format_arg {

public:

class handle;

private:

using char_type = typename Context::char_type; // exposition only

variant

int, unsigned int, long long int, unsigned long long int,

float, double, long double,

const char_type*, basic_string_view,

const void*, handle> value; // exposition only

template explicit basic_format_arg(T&& v) noexcept; // exposition only

explicit basic_format_arg(float n) noexcept; // exposition only

explicit basic_format_arg(double n) noexcept; // exposition only

explicit basic_format_arg(long double n) noexcept; // exposition only

explicit basic_format_arg(const char_type* s); // exposition only

template

explicit basic_format_arg(

basic_string_view s) noexcept; // exposition only

template

explicit basic_format_arg(

const basic_string& s) noexcept; // exposition only

explicit basic_format_arg(nullptr_t) noexcept; // exposition only

template

explicit basic_format_arg(T* p) noexcept; // exposition only

public:

basic_format_arg() noexcept;

explicit operator bool() const noexcept;

template

decltype(auto) visit(this basic_format_arg arg, Visitor&& vis);

template

R visit(this basic_format_arg arg, Visitor&& vis);

};

}

[编辑] 类 std::basic_format_arg::handle

namespace std {

template

class basic_format_arg::handle {

const void* ptr_; // exposition only

void (*format_)(basic_format_parse_context&,

Context&, const void*); // exposition only

template explicit handle(T&& val) noexcept; // exposition only

friend class basic_format_arg; // exposition only

public:

void format(basic_format_parse_context&, Context& ctx) const;

};

}

[编辑] 类模板 __format_arg_store

namespace std {

template

class __format_arg_store { // exposition only

array, sizeof...(Args)> args; // exposition only

};

}

[编辑] 类模板 std::basic_format_args

namespace std {

template

class basic_format_args {

size_t size_; // exposition only

const basic_format_arg* data_; // exposition only

public:

template

basic_format_args(const __format_arg_store& store) noexcept;

basic_format_arg get(size_t i) const noexcept;

};

}

[编辑] Tuple 格式化器

namespace std {

template... Ts>

struct formatter<__pair_or_tuple, CharT> {

private:

tuple, CharT>...> underlying_; // exposition only

basic_string_view separator_ = // exposition only

__STATICALLY_WIDEN(", ");

basic_string_view opening_bracket_ = // exposition only

__STATICALLY_WIDEN("(");

basic_string_view closing_bracket_ = // exposition only

__STATICALLY_WIDEN(")");

public:

constexpr void set_separator(basic_string_view sep);

constexpr void set_brackets(basic_string_view opening,

basic_string_view closing);

template

constexpr typename ParseContext::iterator

parse(ParseContext& ctx);

template

typename FormatContext::iterator

format(/* see description */& elems, FormatContext& ctx) const;

};

}

[编辑] 类 std::format_error

namespace std {

class format_error : public runtime_error {

public:

explicit format_error(const string& what_arg);

explicit format_error(const char* what_arg);

};

}

相关推荐

万虹学习电脑怎么样 万虹学习电脑有哪些功能呢
beat365亚洲版登录

万虹学习电脑怎么样 万虹学习电脑有哪些功能呢

📅 07-27 👁️ 3843
街头篮球冠军手游 街头篮球手游SG哪个厉害
365bet现场走地盘

街头篮球冠军手游 街头篮球手游SG哪个厉害

📅 07-08 👁️ 3557
射手卡|日本2:1惊天逆转西班牙,身处死亡之组头名出线