File indexing completed on 2026-05-03 08:13:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___FORMAT_FORMAT_PARSE_CONTEXT_H
0011 #define _LIBCPP___FORMAT_FORMAT_PARSE_CONTEXT_H
0012
0013 #include <__config>
0014 #include <__format/format_error.h>
0015 #include <__type_traits/is_constant_evaluated.h>
0016 #include <string_view>
0017
0018 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0019 # pragma GCC system_header
0020 #endif
0021
0022 _LIBCPP_BEGIN_NAMESPACE_STD
0023
0024 #if _LIBCPP_STD_VER >= 20
0025
0026 template <class _CharT>
0027 class _LIBCPP_TEMPLATE_VIS basic_format_parse_context {
0028 public:
0029 using char_type = _CharT;
0030 using const_iterator = typename basic_string_view<_CharT>::const_iterator;
0031 using iterator = const_iterator;
0032
0033 _LIBCPP_HIDE_FROM_ABI constexpr explicit basic_format_parse_context(
0034 basic_string_view<_CharT> __fmt, size_t __num_args = 0) noexcept
0035 : __begin_(__fmt.begin()),
0036 __end_(__fmt.end()),
0037 __indexing_(__unknown),
0038 __next_arg_id_(0),
0039 __num_args_(__num_args) {}
0040
0041 basic_format_parse_context(const basic_format_parse_context&) = delete;
0042 basic_format_parse_context& operator=(const basic_format_parse_context&) = delete;
0043
0044 _LIBCPP_HIDE_FROM_ABI constexpr const_iterator begin() const noexcept { return __begin_; }
0045 _LIBCPP_HIDE_FROM_ABI constexpr const_iterator end() const noexcept { return __end_; }
0046 _LIBCPP_HIDE_FROM_ABI constexpr void advance_to(const_iterator __it) { __begin_ = __it; }
0047
0048 _LIBCPP_HIDE_FROM_ABI constexpr size_t next_arg_id() {
0049 if (__indexing_ == __manual)
0050 std::__throw_format_error("Using automatic argument numbering in manual argument numbering mode");
0051
0052 if (__indexing_ == __unknown)
0053 __indexing_ = __automatic;
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 if (is_constant_evaluated() && __next_arg_id_ >= __num_args_)
0064 std::__throw_format_error("Argument index outside the valid range");
0065
0066 return __next_arg_id_++;
0067 }
0068 _LIBCPP_HIDE_FROM_ABI constexpr void check_arg_id(size_t __id) {
0069 if (__indexing_ == __automatic)
0070 std::__throw_format_error("Using manual argument numbering in automatic argument numbering mode");
0071
0072 if (__indexing_ == __unknown)
0073 __indexing_ = __manual;
0074
0075
0076
0077
0078
0079
0080
0081
0082 if (is_constant_evaluated() && __id >= __num_args_)
0083 std::__throw_format_error("Argument index outside the valid range");
0084 }
0085
0086 private:
0087 iterator __begin_;
0088 iterator __end_;
0089 enum _Indexing { __unknown, __manual, __automatic };
0090 _Indexing __indexing_;
0091 size_t __next_arg_id_;
0092 size_t __num_args_;
0093 };
0094 _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(basic_format_parse_context);
0095
0096 using format_parse_context = basic_format_parse_context<char>;
0097 # if _LIBCPP_HAS_WIDE_CHARACTERS
0098 using wformat_parse_context = basic_format_parse_context<wchar_t>;
0099 # endif
0100
0101 #endif
0102
0103 _LIBCPP_END_NAMESPACE_STD
0104
0105 #endif