[format.parse.ctx] (original) (raw)
28 Text processing library [text]
28.5 Formatting [format]
28.5.6 Formatter [format.formatter]
28.5.6.6 Class template basic_format_parse_context [format.parse.ctx]
namespace std { template<class charT> class basic_format_parse_context { public: using char_type = charT;using const_iterator = basic_string_view<charT>::const_iterator;using iterator = const_iterator;private: iterator begin_; iterator end_; enum indexing { unknown, manual, automatic }; indexing indexing_; size_t next_arg_id_; size_t num_args_; public: constexpr explicit basic_format_parse_context(basic_string_view<charT> 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);template<class... Ts> 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;};}
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.
If a program declares an explicit or partial specialization ofbasic_format_parse_context, the program is ill-formed, no diagnostic required.
constexpr explicit basic_format_parse_context(basic_string_view<charT> fmt) noexcept;
Effects: Initializesbegin_ with fmt.begin(),end_ with fmt.end(),indexing_ with unknown,next_arg_id_ with 0, andnum_args_ with 0.
[Note 1:
Any call tonext_arg_id, check_arg_id, or check_dynamic_specon an instance of basic_format_parse_contextinitialized using this constructor is not a core constant expression.
— _end note_]
constexpr const_iterator begin() const noexcept;
constexpr const_iterator end() const noexcept;
constexpr void advance_to(const_iterator it);
Preconditions: end() is reachable from it.
Effects: Equivalent to: begin_ = it;
constexpr size_t next_arg_id();
Effects: If indexing_ != manual is true, equivalent to:if (indexing_ == unknown) indexing_ = automatic;return next_arg_id_++;
Throws: format_error if indexing_ == manual is true.
[Note 2:
This indicates mixing of automatic and manual argument indexing.
— _end note_]
Remarks: Let cur-arg-id be the value of next_arg_id_ prior to this call.
Call expressions where cur-arg-id >= num_args_ is trueare not core constant expressions ([expr.const]).
constexpr void check_arg_id(size_t id);
Effects: If indexing_ != automatic is true, equivalent to:if (indexing_ == unknown) indexing_ = manual;
Throws: format_error ifindexing_ == automatic is true.
[Note 3:
This indicates mixing of automatic and manual argument indexing.
— _end note_]
Remarks: A call to this function is a core constant expression ([expr.const]) only ifid < num_args_ is true.
template<class... Ts> constexpr void check_dynamic_spec(size_t id) noexcept;
Mandates: sizeof...(Ts) ≥ 1.
The types in Ts... are unique.
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<char_type>, orconst void*.
Remarks: A call to this function is a core constant expression only if
- id < num_args_ is true and
- the type of the corresponding format argument (after conversion to basic_format_arg<Context>) is one of the types in Ts....
constexpr void check_dynamic_spec_integral(size_t id) noexcept;
Effects: Equivalent to:check_dynamic_spec<int, unsigned int, long long int, unsigned long long int>(id);
constexpr void check_dynamic_spec_string(size_t id) noexcept;
Effects: Equivalent to:check_dynamic_spec<const char_type*, basic_string_view<char_type>>(id);