[format.parse.ctx] # 28 Text processing library [[text]](./#text) ## 28.5 Formatting [[format]](format#parse.ctx) ### 28.5.6 Formatter [[format.formatter]](format.formatter#format.parse.ctx) #### 28.5.6.6 Class template basic_format_parse_context [format.parse.ctx] [🔗](#lib:basic_format_parse_context) namespace std {templateclass 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) 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); templateconstexpr 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; };} [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7482) An instance of basic_format_parse_context holds the format string parsing state, consisting of the format string range being parsed and the argument counter for automatic indexing[.](#1.sentence-1) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7488) If a program declares an explicit or partial specialization ofbasic_format_parse_context, the program is ill-formed, no diagnostic required[.](#2.sentence-1) [🔗](#lib:basic_format_parse_context,constructor) `constexpr explicit basic_format_parse_context(basic_string_view fmt) noexcept; ` [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7499) *Effects*: Initializesbegin_ with fmt.begin(),end_ with fmt.end(),indexing_ with unknown,next_arg_id_ with 0, andnum_args_ with 0[.](#3.sentence-1) [*Note [1](#note-1)*: Any call tonext_arg_id, check_arg_id, or check_dynamic_spec on an instance of basic_format_parse_context initialized using this constructor is not a core constant expression[.](#3.sentence-2) — *end note*] [🔗](#lib:begin,basic_format_parse_context) `constexpr const_iterator begin() const noexcept; ` [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7521) *Returns*: begin_[.](#4.sentence-1) [🔗](#lib:end,basic_format_parse_context) `constexpr const_iterator end() const noexcept; ` [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7532) *Returns*: end_[.](#5.sentence-1) [🔗](#lib:advance_to,basic_format_parse_context) `constexpr void advance_to(const_iterator it); ` [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7543) *Preconditions*: end() is reachable from it[.](#6.sentence-1) [7](#7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7547) *Effects*: Equivalent to: begin_ = it; [🔗](#lib:next_arg_id,basic_format_parse_context) `constexpr size_t next_arg_id(); ` [8](#8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7558) *Effects*: If indexing_ != manual is true, equivalent to:if (indexing_ == unknown) indexing_ = automatic;return next_arg_id_++; [9](#9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7567) *Throws*: format_error if indexing_ == manual is true[.](#9.sentence-1) [*Note [2](#note-2)*: This indicates mixing of automatic and manual argument indexing[.](#9.sentence-2) — *end note*] [10](#10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7574) *Remarks*: Let *cur-arg-id* be the value of next_arg_id_ prior to this call[.](#10.sentence-1) Call expressions where *cur-arg-id* >= num_args_ is true are not core constant expressions ([[expr.const]](expr.const "7.7 Constant expressions"))[.](#10.sentence-2) [🔗](#lib:check_arg_id,basic_format_parse_context) `constexpr void check_arg_id(size_t id); ` [11](#11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7587) *Effects*: If indexing_ != automatic is true, equivalent to:if (indexing_ == unknown) indexing_ = manual; [12](#12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7595) *Throws*: format_error ifindexing_ == automatic is true[.](#12.sentence-1) [*Note [3](#note-3)*: This indicates mixing of automatic and manual argument indexing[.](#12.sentence-2) — *end note*] [13](#13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7603) *Remarks*: A call to this function is a core constant expression ([[expr.const]](expr.const "7.7 Constant expressions")) only ifid < num_args_ is true[.](#13.sentence-1) [🔗](#lib:check_dynamic_spec,basic_format_parse_context) `template constexpr void check_dynamic_spec(size_t id) noexcept; ` [14](#14) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7616) *Mandates*: sizeof...(Ts) ≥ 1[.](#14.sentence-1) The types in Ts... are unique[.](#14.sentence-2) Each type in Ts... is one ofbool,char_type,int,unsigned int,long long int,unsigned long long int,float,double,long double,const char_type*,basic_string_view, orconst void*[.](#14.sentence-3) [15](#15) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7634) *Remarks*: A call to this function is a core constant expression only if - [(15.1)](#15.1) id < num_args_ is true and - [(15.2)](#15.2) the type of the corresponding format argument (after conversion to basic_format_arg) is one of the types in Ts...[.](#15.sentence-1) [🔗](#lib:check_dynamic_spec_integral,basic_format_parse_context) `constexpr void check_dynamic_spec_integral(size_t id) noexcept; ` [16](#16) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7652) *Effects*: Equivalent to:check_dynamic_spec(id); [🔗](#lib:check_dynamic_spec_string,basic_format_parse_context) `constexpr void check_dynamic_spec_string(size_t id) noexcept; ` [17](#17) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L7666) *Effects*: Equivalent to:check_dynamic_spec>(id);