29#ifndef _GLIBCXX_FORMAT
30#define _GLIBCXX_FORMAT 1
33#pragma GCC system_header
38#define __glibcxx_want_format
39#define __glibcxx_want_format_ranges
40#define __glibcxx_want_format_uchar
41#define __glibcxx_want_constexpr_exceptions
42#define __glibcxx_want_constexpr_format
45#ifdef __cpp_lib_format
67#ifdef __glibcxx_constexpr_format
68# define _GLIBCXX_CONSTEXPR_FORMAT constexpr
70# define _GLIBCXX_CONSTEXPR_FORMAT
73#pragma GCC diagnostic push
74#pragma GCC diagnostic ignored "-Wpedantic"
75#pragma GCC diagnostic ignored "-Wc++23-extensions"
77namespace std _GLIBCXX_VISIBILITY(default)
79_GLIBCXX_BEGIN_NAMESPACE_VERSION
82 template<
typename _CharT,
typename... _Args>
struct basic_format_string;
92 template<
typename _CharT>
94 _Widen(
const char* __narrow,
const wchar_t* __wide)
96 if constexpr (is_same_v<_CharT, wchar_t>)
101#define _GLIBCXX_WIDEN_(C, S) ::std::__format::_Widen<C>(S, L##S)
102#define _GLIBCXX_WIDEN(S) _GLIBCXX_WIDEN_(_CharT, S)
105 template<
typename _CharT>
106 constexpr size_t __stackbuf_size = 32 *
sizeof(
void*) /
sizeof(_CharT);
109 template<
typename _CharT>
class _Sink;
110 template<
typename _CharT>
class _Fixedbuf_sink;
111 template<
typename _Out,
typename _CharT>
class _Padding_sink;
112 template<
typename _Out,
typename _CharT>
class _Escaping_sink;
115 template<
typename _CharT>
119 template<
typename _CharT>
123 template<
typename _CharT>
125 {
using type = _Drop_iter<_CharT>; };
127 template<
typename _CharT>
128 using __format_context = basic_format_context<_Sink_iter<_CharT>, _CharT>;
130 template<
typename _CharT>
131 struct _Dynamic_format_string
133 [[__gnu__::__always_inline__]]
134 _GLIBCXX_CONSTEXPR_FORMAT
135 _Dynamic_format_string(basic_string_view<_CharT> __s) noexcept
138 _Dynamic_format_string(
const _Dynamic_format_string&) =
delete;
139 void operator=(
const _Dynamic_format_string&) =
delete;
142 basic_string_view<_CharT> _M_str;
144 template<
typename,
typename...>
friend struct std::basic_format_string;
150 using format_context = __format::__format_context<char>;
151#ifdef _GLIBCXX_USE_WCHAR_T
152 using wformat_context = __format::__format_context<wchar_t>;
156 template<
typename _Context>
class basic_format_args;
157 using format_args = basic_format_args<format_context>;
158#ifdef _GLIBCXX_USE_WCHAR_T
159 using wformat_args = basic_format_args<wformat_context>;
164 template<
typename _Context>
165 class basic_format_arg;
171 template<
typename _CharT,
typename... _Args>
172 struct basic_format_string
174 template<
typename _Tp>
175 requires convertible_to<const _Tp&, basic_string_view<_CharT>>
177 basic_format_string(
const _Tp& __s)
noexcept;
179 [[__gnu__::__always_inline__]]
180 _GLIBCXX_CONSTEXPR_FORMAT
181 basic_format_string(__format::_Dynamic_format_string<_CharT> __s) noexcept
185 [[__gnu__::__always_inline__]]
186 constexpr basic_string_view<_CharT>
191 basic_string_view<_CharT> _M_str;
194 template<
typename... _Args>
195 using format_string = basic_format_string<char, type_identity_t<_Args>...>;
197#ifdef _GLIBCXX_USE_WCHAR_T
198 template<
typename... _Args>
200 = basic_format_string<wchar_t, type_identity_t<_Args>...>;
203#if __cpp_lib_format >= 202603L
204 [[__gnu__::__always_inline__]]
205 inline _GLIBCXX_CONSTEXPR_FORMAT __format::_Dynamic_format_string<char>
206 dynamic_format(string_view __fmt)
noexcept
209#ifdef _GLIBCXX_USE_WCHAR_T
210 [[__gnu__::__always_inline__]]
211 inline _GLIBCXX_CONSTEXPR_FORMAT __format::_Dynamic_format_string<wchar_t>
212 dynamic_format(wstring_view __fmt)
noexcept
220 template<
typename _Tp,
typename _CharT>
223 formatter() =
delete;
224 formatter(
const formatter&) =
delete;
225 formatter& operator=(
const formatter&) =
delete;
232 _GLIBCXX_CONSTEXPR_FORMAT
233 explicit format_error(
const string& __what)
234 : runtime_error(__what) { }
236 _GLIBCXX_CONSTEXPR_FORMAT
explicit
237 format_error(
const char* __what)
238 : runtime_error(__what) { }
243 inline _GLIBCXX_CONSTEXPR_FORMAT
void
244 __throw_format_error(
const char* __what)
245 { _GLIBCXX_THROW_OR_ABORT(format_error(__what)); }
252 inline _GLIBCXX_CONSTEXPR_FORMAT
void
253 __unmatched_left_brace_in_format_string()
254 { __throw_format_error(
"format error: unmatched '{' in format string"); }
257 inline _GLIBCXX_CONSTEXPR_FORMAT
void
258 __unmatched_right_brace_in_format_string()
259 { __throw_format_error(
"format error: unmatched '}' in format string"); }
262 inline _GLIBCXX_CONSTEXPR_FORMAT
void
263 __conflicting_indexing_in_format_string()
264 { __throw_format_error(
"format error: conflicting indexing style in format string"); }
267 inline _GLIBCXX_CONSTEXPR_FORMAT
void
268 __invalid_arg_id_in_format_string()
269 { __throw_format_error(
"format error: invalid arg-id in format string"); }
272 inline _GLIBCXX_CONSTEXPR_FORMAT
void
273 __failed_to_parse_format_spec()
274 { __throw_format_error(
"format error: failed to parse format-spec"); }
276 template<
typename _CharT>
class _Scanner;
282 template<
typename _CharT>
class basic_format_parse_context;
283 using format_parse_context = basic_format_parse_context<char>;
284#ifdef _GLIBCXX_USE_WCHAR_T
285 using wformat_parse_context = basic_format_parse_context<wchar_t>;
288 template<
typename _CharT>
291 class _GLIBCXX_NO_SPECIALIZATIONS basic_format_parse_context
294 using char_type = _CharT;
295 using const_iterator =
typename basic_string_view<_CharT>::const_iterator;
296 using iterator = const_iterator;
299 basic_format_parse_context(basic_string_view<_CharT> __fmt) noexcept
300 : _M_begin(__fmt.begin()), _M_end(__fmt.end())
303 basic_format_parse_context(
const basic_format_parse_context&) =
delete;
304 void operator=(
const basic_format_parse_context&) =
delete;
306 constexpr const_iterator begin() const noexcept {
return _M_begin; }
307 constexpr const_iterator end() const noexcept {
return _M_end; }
310 advance_to(const_iterator __it)
noexcept
316 if (_M_indexing == _Manual)
317 __format::__conflicting_indexing_in_format_string();
322 if (std::is_constant_evaluated())
323 if (_M_next_arg_id == _M_num_args)
324 __format::__invalid_arg_id_in_format_string();
325 return _M_next_arg_id++;
329 check_arg_id(
size_t __id)
331 if (_M_indexing == _Auto)
332 __format::__conflicting_indexing_in_format_string();
333 _M_indexing = _Manual;
335 if (std::is_constant_evaluated())
336 if (__id >= _M_num_args)
337 __format::__invalid_arg_id_in_format_string();
340#if __cpp_lib_format >= 202305L
341 template<
typename... _Ts>
343 check_dynamic_spec(
size_t __id)
noexcept
345 static_assert(__valid_types_for_check_dynamic_spec<_Ts...>(),
346 "template arguments for check_dynamic_spec<Ts...>(id) "
347 "must be unique and must be one of the allowed types");
349 __check_dynamic_spec<_Ts...>(__id);
354 check_dynamic_spec_integral(
size_t __id)
noexcept
357 __check_dynamic_spec<int, unsigned,
long long,
358 unsigned long long>(__id);
363 check_dynamic_spec_string(
size_t __id)
noexcept
366 __check_dynamic_spec<const _CharT*, basic_string_view<_CharT>>(__id);
372 template<
typename _Tp,
typename... _Ts>
373 static constexpr bool __once = (is_same_v<_Tp, _Ts> + ...) == 1;
375 template<
typename... _Ts>
377 __valid_types_for_check_dynamic_spec()
381 if constexpr (
sizeof...(_Ts) == 0)
390 = __once<bool, _Ts...>
391 + __once<char_type, _Ts...>
392 + __once<int, _Ts...>
393 + __once<
unsigned int, _Ts...>
394 + __once<
long long int, _Ts...>
395 + __once<
unsigned long long int, _Ts...>
396 + __once<float, _Ts...>
397 + __once<double, _Ts...>
398 + __once<
long double, _Ts...>
399 + __once<
const char_type*, _Ts...>
400 + __once<basic_string_view<char_type>, _Ts...>
401 + __once<
const void*, _Ts...>;
402 return __sum ==
sizeof...(_Ts);
406 template<
typename... _Ts>
408 __check_dynamic_spec(
size_t __id)
noexcept;
411 static void __invalid_dynamic_spec(
const char*);
413 friend __format::_Scanner<_CharT>;
418 basic_format_parse_context(basic_string_view<_CharT> __fmt,
419 size_t __num_args) noexcept
420 : _M_begin(__fmt.begin()), _M_end(__fmt.end()), _M_num_args(__num_args)
426 enum _Indexing { _Unknown, _Manual, _Auto };
427 _Indexing _M_indexing = _Unknown;
428 size_t _M_next_arg_id = 0;
429 size_t _M_num_args = 0;
433 template<
typename _Tp,
template<
typename...>
class _Class>
434 constexpr bool __is_specialization_of =
false;
435 template<
template<
typename...>
class _Class,
typename... _Args>
436 constexpr bool __is_specialization_of<_Class<_Args...>, _Class> =
true;
441 template<
typename _CharT>
442 constexpr pair<unsigned short, const _CharT*>
443 __parse_integer(
const _CharT* __first,
const _CharT* __last)
445 if (__first == __last)
446 __builtin_unreachable();
448 if constexpr (is_same_v<_CharT, char>)
450 const auto __start = __first;
451 unsigned short __val = 0;
453 if (__detail::__from_chars_alnum<true>(__first, __last, __val, 10)
454 && __first != __start) [[likely]]
455 return {__val, __first};
459 constexpr int __n = 32;
461 for (
int __i = 0; __i < __n && (__first + __i) != __last; ++__i)
462 __buf[__i] = __first[__i];
463 auto [__v, __ptr] = __format::__parse_integer(__buf, __buf + __n);
464 if (__ptr) [[likely]]
465 return {__v, __first + (__ptr - __buf)};
470 template<
typename _CharT>
471 constexpr pair<unsigned short, const _CharT*>
472 __parse_arg_id(
const _CharT* __first,
const _CharT* __last)
474 if (__first == __last)
475 __builtin_unreachable();
478 return {0, __first + 1};
480 if (
'1' <= *__first && *__first <=
'9')
482 const unsigned short __id = *__first -
'0';
483 const auto __next = __first + 1;
485 if (__next == __last || !(
'0' <= *__next && *__next <=
'9'))
486 return {__id, __next};
488 return __format::__parse_integer(__first, __last);
493 enum class _Pres_type :
unsigned char {
497 _Pres_c = 2, _Pres_x, _Pres_X, _Pres_d, _Pres_o, _Pres_b, _Pres_B,
499 _Pres_g = 1, _Pres_G, _Pres_a, _Pres_A, _Pres_e, _Pres_E, _Pres_f, _Pres_F,
503 using enum _Pres_type;
505 enum class _Sign :
unsigned char {
513 enum _WidthPrec :
unsigned char {
518 using enum _WidthPrec;
520 template<
typename _Context>
521 _GLIBCXX_CONSTEXPR_FORMAT
size_t
522 __int_from_arg(
const basic_format_arg<_Context>& __arg);
524 constexpr bool __is_digit(
char __c)
525 {
return std::__detail::__from_chars_alnum_to_val(__c) < 10; }
527 constexpr bool __is_xdigit(
char __c)
528 {
return std::__detail::__from_chars_alnum_to_val(__c) < 16; }
535 template<
typename _CharT>
536 struct _Spec : _SpecBase
538 unsigned short _M_width;
539 unsigned short _M_prec;
540 char32_t _M_fill =
' ';
544 unsigned _M_localized : 1;
545 unsigned _M_zero_fill : 1;
546 _WidthPrec _M_width_kind : 2;
547 _WidthPrec _M_prec_kind : 2;
548 unsigned _M_debug : 1;
549 _Pres_type _M_type : 4;
550 unsigned _M_reserved : 8;
554 using iterator =
typename basic_string_view<_CharT>::iterator;
556 static constexpr _Align
557 _S_align(_CharT __c)
noexcept
561 case '<':
return _Align_left;
562 case '>':
return _Align_right;
563 case '^':
return _Align_centre;
564 default:
return _Align_default;
570 _M_parse_fill_and_align(iterator __first, iterator __last)
noexcept
571 {
return _M_parse_fill_and_align(__first, __last,
"{"); }
575 _M_parse_fill_and_align(iterator __first, iterator __last, string_view __not_fill)
noexcept
577 for (
char __c : __not_fill)
578 if (*__first ==
static_cast<_CharT
>(__c))
581 using namespace __unicode;
582 if constexpr (__literal_encoding_is_unicode<_CharT>())
585 _Utf32_view<ranges::subrange<iterator>> __uv({__first, __last});
588 auto __beg = __uv.begin();
589 char32_t __c = *__beg++;
590 if (__is_scalar_value(__c))
591 if (
auto __next = __beg.base(); __next != __last)
592 if (_Align __align = _S_align(*__next); __align != _Align_default)
600 else if (__last - __first >= 2)
601 if (_Align __align = _S_align(__first[1]); __align != _Align_default)
608 if (_Align __align = _S_align(__first[0]); __align != _Align_default)
617 static constexpr _Sign
618 _S_sign(_CharT __c)
noexcept
622 case '+':
return _Sign_plus;
623 case '-':
return _Sign_minus;
624 case ' ':
return _Sign_space;
625 default:
return _Sign_default;
631 _M_parse_sign(iterator __first, iterator)
noexcept
633 if (_Sign __sign = _S_sign(*__first); __sign != _Sign_default)
643 _M_parse_alternate_form(iterator __first, iterator)
noexcept
655 _M_parse_zero_fill(iterator __first, iterator )
noexcept
666 static constexpr iterator
667 _S_parse_width_or_precision(iterator __first, iterator __last,
668 unsigned short& __val,
bool& __arg_id,
669 basic_format_parse_context<_CharT>& __pc)
671 if (__format::__is_digit(*__first))
673 auto [__v, __ptr] = __format::__parse_integer(__first, __last);
675 __throw_format_error(
"format error: invalid width or precision "
680 else if (*__first ==
'{')
684 if (__first == __last)
685 __format::__unmatched_left_brace_in_format_string();
687 __val = __pc.next_arg_id();
690 auto [__v, __ptr] = __format::__parse_arg_id(__first, __last);
691 if (__ptr ==
nullptr || __ptr == __last || *__ptr !=
'}')
692 __format::__invalid_arg_id_in_format_string();
694 __pc.check_arg_id(__v);
697#if __cpp_lib_format >= 202305L
698 __pc.check_dynamic_spec_integral(__val);
707 _M_parse_width(iterator __first, iterator __last,
708 basic_format_parse_context<_CharT>& __pc)
710 bool __arg_id =
false;
712 __throw_format_error(
"format error: width must be non-zero in "
714 auto __next = _S_parse_width_or_precision(__first, __last, _M_width,
716 if (__next != __first)
717 _M_width_kind = __arg_id ? _WP_from_arg : _WP_value;
723 _M_parse_precision(iterator __first, iterator __last,
724 basic_format_parse_context<_CharT>& __pc)
726 if (__first[0] !=
'.')
729 iterator __next = ++__first;
730 bool __arg_id =
false;
731 if (__next != __last)
732 __next = _S_parse_width_or_precision(__first, __last, _M_prec,
734 if (__next == __first)
735 __throw_format_error(
"format error: missing precision after '.' in "
737 _M_prec_kind = __arg_id ? _WP_from_arg : _WP_value;
743 _M_parse_locale(iterator __first, iterator )
noexcept
753 template<
typename _Context>
754 _GLIBCXX_CONSTEXPR_FORMAT
size_t
755 _M_get_width(_Context& __ctx)
const
758 if (_M_width_kind == _WP_value)
760 else if (_M_width_kind == _WP_from_arg)
761 __width = __format::__int_from_arg(__ctx.arg(_M_width));
765 template<
typename _Context>
766 _GLIBCXX_CONSTEXPR_FORMAT
size_t
767 _M_get_precision(_Context& __ctx)
const
770 if (_M_prec_kind == _WP_value)
772 else if (_M_prec_kind == _WP_from_arg)
773 __prec = __format::__int_from_arg(__ctx.arg(_M_prec));
778 template<
typename _Int>
779 inline _GLIBCXX_CONSTEXPR_FORMAT
char*
780 __put_sign(_Int __i, _Sign __sign,
char* __dest)
noexcept
784 else if (__sign == _Sign_plus)
786 else if (__sign == _Sign_space)
794 template<
typename _Out,
typename _CharT>
795 requires output_iterator<_Out, const _CharT&>
796 inline _GLIBCXX_CONSTEXPR_FORMAT _Out
797 __write(_Out __out, basic_string_view<_CharT> __str)
799 if constexpr (is_same_v<_Out, _Sink_iter<_CharT>>)
805 for (_CharT __c : __str)
812 template<
typename _Out,
typename _CharT>
813 _GLIBCXX_CONSTEXPR_FORMAT _Out
814 __write_padded(_Out __out, basic_string_view<_CharT> __str,
815 _Align __align,
size_t __nfill,
char32_t __fill_char)
817 const size_t __buflen = 0x20;
818 _CharT __padding_chars[__buflen];
819 __padding_chars[0] = _CharT();
820 basic_string_view<_CharT> __padding{__padding_chars, __buflen};
822 auto __pad = [&__padding] (
size_t __n, _Out& __o) {
825 while (__n > __padding.size())
827 __o = __format::__write(
std::move(__o), __padding);
828 __n -= __padding.size();
831 __o = __format::__write(
std::move(__o), __padding.substr(0, __n));
834 size_t __l, __r, __max;
835 if (__align == _Align_centre)
838 __r = __l + (__nfill & 1);
841 else if (__align == _Align_right)
854 using namespace __unicode;
855 if constexpr (__literal_encoding_is_unicode<_CharT>())
856 if (!__is_single_code_unit<_CharT>(__fill_char)) [[unlikely]]
859 const char32_t __arr[1]{ __fill_char };
860 _Utf_view<_CharT, span<const char32_t, 1>> __v(__arr);
861 basic_string<_CharT> __padstr(__v.begin(), __v.end());
862 __padding = __padstr;
864 __out = __format::__write(
std::move(__out), __padding);
865 __out = __format::__write(
std::move(__out), __str);
867 __out = __format::__write(
std::move(__out), __padding);
871 if (__max < __buflen)
872 __padding.remove_suffix(__buflen - __max);
876 char_traits<_CharT>::assign(__padding_chars, __max, __fill_char);
878 __out = __format::__write(
std::move(__out), __str);
886 template<
typename _CharT,
typename _Out>
887 _GLIBCXX_CONSTEXPR_FORMAT _Out
888 __write_padded_as_spec(basic_string_view<type_identity_t<_CharT>> __str,
889 size_t __estimated_width,
890 basic_format_context<_Out, _CharT>& __fc,
891 const _Spec<_CharT>& __spec,
892 _Align __align = _Align_left)
894 size_t __width = __spec._M_get_width(__fc);
896 if (__width <= __estimated_width)
897 return __format::__write(__fc.out(), __str);
899 const size_t __nfill = __width - __estimated_width;
901 if (__spec._M_align != _Align_default)
902 __align = __spec._M_align;
904 return __format::__write_padded(__fc.out(), __str, __align, __nfill,
908 template<
typename _CharT>
909 _GLIBCXX_CONSTEXPR_FORMAT
size_t
910 __truncate(basic_string_view<_CharT>& __s,
size_t __prec)
912 if constexpr (__unicode::__literal_encoding_is_unicode<_CharT>())
914 if (__prec != (
size_t)-1)
915 return __unicode::__truncate(__s, __prec);
917 return __unicode::__field_width(__s);
921 __s = __s.substr(0, __prec);
926 enum class _Term_char :
unsigned char {
931 using enum _Term_char;
933 template<
typename _CharT>
936 using _Str_view = basic_string_view<_CharT>;
940 {
return _GLIBCXX_WIDEN(
"\t\\t\n\\n\r\\r\\\\\\\"\\\"'\\'\\u\\x"); }
944 {
return _S_all().substr(0, 3); }
947 _Str_view _S_newline()
948 {
return _S_all().substr(3, 3); }
951 _Str_view _S_return()
952 {
return _S_all().substr(6, 3); }
955 _Str_view _S_bslash()
956 {
return _S_all().substr(9, 3); }
960 {
return _S_all().substr(12, 3); }
964 {
return _S_all().substr(15, 3); }
968 {
return _S_all().substr(18, 2); }
972 {
return _S_all().substr(20, 2); }
975 _Str_view _S_term(_Term_char __term)
982 return _S_quote().substr(0, 1);
984 return _S_apos().substr(0, 1);
986 __builtin_unreachable();
990 template<
typename _CharT>
993 using _Str_view = basic_string_view<_CharT>;
997 {
return _GLIBCXX_WIDEN(
"[]{}(), : "); }
1000 _Str_view _S_squares()
1001 {
return _S_all().substr(0, 2); }
1004 _Str_view _S_braces()
1005 {
return _S_all().substr(2, 2); }
1008 _Str_view _S_parens()
1009 {
return _S_all().substr(4, 2); }
1012 _Str_view _S_comma()
1013 {
return _S_all().substr(6, 2); }
1016 _Str_view _S_colon()
1017 {
return _S_all().substr(8, 2); }
1020 template<
typename _CharT>
1021 constexpr bool __should_escape_ascii(_CharT __c, _Term_char __term)
1023 using _Esc = _Escapes<_CharT>;
1026 case _Esc::_S_tab()[0]:
1027 case _Esc::_S_newline()[0]:
1028 case _Esc::_S_return()[0]:
1029 case _Esc::_S_bslash()[0]:
1031 case _Esc::_S_quote()[0]:
1032 return __term == _Term_quote;
1033 case _Esc::_S_apos()[0]:
1034 return __term == _Term_apos;
1036 return (__c >= 0 && __c < 0x20) || __c == 0x7f;
1041 constexpr bool __should_escape_unicode(
char32_t __c,
bool __prev_esc)
1043 if (__unicode::__should_escape_category(__c))
1047 return __unicode::__grapheme_cluster_break_property(__c)
1048 == __unicode::_Gcb_property::_Gcb_Extend;
1051 using uint_least32_t = __UINT_LEAST32_TYPE__;
1052 template<
typename _Out,
typename _CharT>
1053 _GLIBCXX_CONSTEXPR_FORMAT _Out
1054 __write_escape_seq(_Out __out, uint_least32_t __val,
1055 basic_string_view<_CharT> __prefix)
1057 constexpr size_t __max = 8;
1059 const string_view __narrow(
1061 std::__to_chars_i<uint_least32_t>(__buf, __buf + __max, __val, 16).ptr);
1063 __out = __format::__write(__out, __prefix);
1064 *__out = _Separators<_CharT>::_S_braces()[0];
1066 if constexpr (is_same_v<char, _CharT>)
1067 __out = __format::__write(__out, __narrow);
1068#ifdef _GLIBCXX_USE_WCHAR_T
1071 wchar_t __wbuf[__max];
1072 const size_t __n = __narrow.size();
1073 std::__to_wstring_numeric(__narrow.data(), __n, __wbuf);
1074 __out = __format::__write(__out, wstring_view(__wbuf, __n));
1077 *__out = _Separators<_CharT>::_S_braces()[1];
1081 template<
typename _Out,
typename _CharT>
1082 _GLIBCXX_CONSTEXPR_FORMAT _Out
1083 __write_escape_seqs(_Out __out, basic_string_view<_CharT> __units)
1085 using _UChar = make_unsigned_t<_CharT>;
1086 for (_CharT __c : __units)
1087 __out = __format::__write_escape_seq(
1088 __out,
static_cast<_UChar
>(__c), _Escapes<_CharT>::_S_x());
1092 template<
typename _Out,
typename _CharT>
1093 _GLIBCXX_CONSTEXPR_FORMAT _Out
1094 __write_escaped_char(_Out __out, _CharT __c)
1096 using _UChar = make_unsigned_t<_CharT>;
1097 using _Esc = _Escapes<_CharT>;
1100 case _Esc::_S_tab()[0]:
1101 return __format::__write(__out, _Esc::_S_tab().substr(1, 2));
1102 case _Esc::_S_newline()[0]:
1103 return __format::__write(__out, _Esc::_S_newline().substr(1, 2));
1104 case _Esc::_S_return()[0]:
1105 return __format::__write(__out, _Esc::_S_return().substr(1, 2));
1106 case _Esc::_S_bslash()[0]:
1107 return __format::__write(__out, _Esc::_S_bslash().substr(1, 2));
1108 case _Esc::_S_quote()[0]:
1109 return __format::__write(__out, _Esc::_S_quote().substr(1, 2));
1110 case _Esc::_S_apos()[0]:
1111 return __format::__write(__out, _Esc::_S_apos().substr(1, 2));
1113 return __format::__write_escape_seq(
1114 __out,
static_cast<_UChar
>(__c), _Esc::_S_u());
1118 template<
typename _CharT,
typename _Out>
1119 _GLIBCXX_CONSTEXPR_FORMAT _Out
1120 __write_escaped_ascii(_Out __out,
1121 basic_string_view<_CharT> __str,
1124 using _Str_view = basic_string_view<_CharT>;
1128 constexpr _Str_view __supported(_GLIBCXX_WIDEN(
1129 "ABCDEFGHIJKLMNOPQRSTUWXYZ"
1130 "abdeefghijklmnopqrstuwzyz"
1131 " !#$%&'()*+-./:;<=>?[]^_{|}~"
1132 "0123456789" "\t\n\r\\\"\'\0"
1134 if (__str.find_first_not_of(__supported) != _Str_view::npos)
1135#if __has_builtin(__builtin_constexpr_diag)
1136 __builtin_constexpr_diag (2,
"",
1137 "for non-Unicode literal encodings, only"
1138 " printable ASCII characters and standard"
1139 " escape sequencess can be escaped in constant"
1146 auto __first = __str.begin();
1147 auto const __last = __str.end();
1148 while (__first != __last)
1150 auto __print = __first;
1152 while (__print != __last
1153 && !__format::__should_escape_ascii(*__print, __term))
1156 if (__print != __first)
1157 __out = __format::__write(__out, _Str_view(__first, __print));
1159 if (__print == __last)
1163 __out = __format::__write_escaped_char(__out, *__first);
1169 template<
typename _CharT,
typename _Out>
1170 _GLIBCXX_CONSTEXPR_FORMAT _Out
1171 __write_escaped_unicode_part(_Out __out, basic_string_view<_CharT>& __str,
1172 bool& __prev_esc, _Term_char __term)
1174 using _Str_view = basic_string_view<_CharT>;
1175 using _Esc = _Escapes<_CharT>;
1177 static constexpr char32_t __replace = U
'\uFFFD';
1178 static constexpr _Str_view __replace_rep = []
1181 if constexpr (is_same_v<char, _CharT>)
1182 return "\xEF\xBF\xBD";
1187 __unicode::_Utf_view<char32_t, _Str_view> __v(
std::move(__str));
1190 auto __first = __v.begin();
1191 auto const __last = __v.end();
1192 while (__first != __last)
1194 bool __esc_ascii =
false;
1195 bool __esc_unicode =
false;
1196 bool __esc_replace =
false;
1197 auto __should_escape = [&](
auto const& __it)
1201 = __format::__should_escape_ascii(*__it.base(), __term);
1202 if (__format::__should_escape_unicode(*__it, __prev_esc))
1203 return __esc_unicode =
true;
1204 if (*__it == __replace)
1206 _Str_view __units(__it.base(), __it._M_units());
1207 return __esc_replace = (__units != __replace_rep);
1212 auto __print = __first;
1213 while (__print != __last && !__should_escape(__print))
1219 if (__print != __first)
1220 __out = __format::__write(__out, _Str_view(__first.base(), __print.base()));
1222 if (__print == __last)
1227 __out = __format::__write_escaped_char(__out, *__first.base());
1228 else if (__esc_unicode)
1229 __out = __format::__write_escape_seq(__out, *__first, _Esc::_S_u());
1231 else if (_Str_view __units(__first.base(), __first._M_units());
1232 __units.end() != __last.base())
1233 __out = __format::__write_escape_seqs(__out, __units);
1247 template<
typename _CharT,
typename _Out>
1248 _GLIBCXX_CONSTEXPR_FORMAT _Out
1249 __write_escaped_unicode(_Out __out, basic_string_view<_CharT> __str,
1252 bool __prev_escape =
true;
1253 __out = __format::__write_escaped_unicode_part(__out, __str,
1254 __prev_escape, __term);
1255 __out = __format::__write_escape_seqs(__out, __str);
1259 template<
typename _CharT,
typename _Out>
1260 _GLIBCXX_CONSTEXPR_FORMAT _Out
1261 __write_escaped(_Out __out, basic_string_view<_CharT> __str, _Term_char __term)
1263 __out = __format::__write(__out, _Escapes<_CharT>::_S_term(__term));
1265 if constexpr (__unicode::__literal_encoding_is_unicode<_CharT>())
1266 __out = __format::__write_escaped_unicode(__out, __str, __term);
1267 else if constexpr (is_same_v<char, _CharT>
1268 && __unicode::__literal_encoding_is_extended_ascii())
1269 __out = __format::__write_escaped_ascii(__out, __str, __term);
1272 __out = __format::__write_escaped_ascii(__out, __str, __term);
1274 return __format::__write(__out, _Escapes<_CharT>::_S_term(__term));
1278 struct _Optional_locale
1280 [[__gnu__::__always_inline__]]
1281 _GLIBCXX_CONSTEXPR_FORMAT
1282 _Optional_locale() : _M_dummy(), _M_hasval(false) { }
1284 _Optional_locale(
const locale& __loc) noexcept
1285 : _M_loc(__loc), _M_hasval(
true)
1288 _GLIBCXX_CONSTEXPR_FORMAT
1289 _Optional_locale(
const _Optional_locale& __l) noexcept
1290 : _M_dummy(), _M_hasval(__l._M_hasval)
1293 std::construct_at(&_M_loc, __l._M_loc);
1296 _GLIBCXX_CONSTEXPR_FORMAT
1298 operator=(
const _Optional_locale& __l)
noexcept
1303 _M_loc = __l._M_loc;
1310 else if (__l._M_hasval)
1312 std::construct_at(&_M_loc, __l._M_loc);
1318 _GLIBCXX_CONSTEXPR_FORMAT
1319 ~_Optional_locale() {
if (_M_hasval) _M_loc.~locale(); }
1322 operator=(locale&& __loc)
noexcept
1328 std::construct_at(&_M_loc,
std::move(__loc));
1339 std::construct_at(&_M_loc);
1345 _GLIBCXX_CONSTEXPR_FORMAT
bool
1346 has_value() const noexcept {
return _M_hasval; }
1349 char _M_dummy =
'\0';
1352 bool _M_hasval =
false;
1355 template<__
char _CharT>
1356 struct __formatter_str
1358 __formatter_str() =
default;
1361 __formatter_str(_Spec<_CharT> __spec) noexcept
1365 constexpr typename basic_format_parse_context<_CharT>::iterator
1366 parse(basic_format_parse_context<_CharT>& __pc)
1368 auto __first = __pc.begin();
1369 const auto __last = __pc.end();
1370 _Spec<_CharT> __spec{};
1372 auto __finalize = [
this, &__spec] {
1376 auto __finished = [&] {
1377 if (__first == __last || *__first ==
'}')
1388 __first = __spec._M_parse_fill_and_align(__first, __last);
1392 __first = __spec._M_parse_width(__first, __last, __pc);
1396 __first = __spec._M_parse_precision(__first, __last, __pc);
1400 if (*__first ==
's')
1402 __spec._M_type = _Pres_s;
1405#if __glibcxx_format_ranges
1406 else if (*__first ==
'?')
1408 __spec._M_debug =
true;
1416 __format::__failed_to_parse_format_spec();
1419 template<
typename _Out>
1420 _GLIBCXX_CONSTEXPR_FORMAT _Out
1421 format(basic_string_view<_CharT> __s,
1422 basic_format_context<_Out, _CharT>& __fc)
const
1424 if (_M_spec._M_debug)
1425 return _M_format_escaped(__s, __fc);
1427 if (_M_spec._M_width_kind == _WP_none
1428 && _M_spec._M_prec_kind == _WP_none)
1429 return __format::__write(__fc.out(), __s);
1431 const size_t __maxwidth = _M_spec._M_get_precision(__fc);
1432 const size_t __width = __format::__truncate(__s, __maxwidth);
1433 return __format::__write_padded_as_spec(__s, __width, __fc, _M_spec);
1436 template<
typename _Out>
1437 _GLIBCXX_CONSTEXPR_FORMAT _Out
1438 _M_format_escaped(basic_string_view<_CharT> __s,
1439 basic_format_context<_Out, _CharT>& __fc)
const
1441 const size_t __padwidth = _M_spec._M_get_width(__fc);
1442 if (__padwidth == 0 && _M_spec._M_prec_kind == _WP_none)
1443 return __format::__write_escaped(__fc.out(), __s, _Term_quote);
1445 const size_t __maxwidth = _M_spec._M_get_precision(__fc);
1446 const size_t __width = __truncate(__s, __maxwidth);
1448 if (__padwidth <= __width && _M_spec._M_prec_kind == _WP_none)
1449 return __format::__write_escaped(__fc.out(), __s, _Term_quote);
1454 _Padding_sink<_Out, _CharT> __sink(__fc.out(), __padwidth, __maxwidth);
1455 __format::__write_escaped(__sink.out(), __s, _Term_quote);
1456 return __sink._M_finish(_M_spec._M_align, _M_spec._M_fill);
1459#if __glibcxx_format_ranges
1460 template<ranges::input_range _Rg,
typename _Out>
1461 requires same_as<remove_cvref_t<ranges::range_reference_t<_Rg>>, _CharT>
1462 _GLIBCXX_CONSTEXPR_FORMAT _Out
1463 _M_format_range(_Rg&& __rg, basic_format_context<_Out, _CharT>& __fc)
const
1465 using _Range = remove_reference_t<_Rg>;
1466 using _String_view = basic_string_view<_CharT>;
1467 if constexpr (ranges::contiguous_range<_Rg>)
1469 _String_view __str(ranges::data(__rg),
1470 size_t(ranges::distance(__rg)));
1471 return format(__str, __fc);
1473 else if constexpr (!is_const_v<_Range>
1474 && __simply_formattable_range<_Range, _CharT>)
1475 return _M_format_range<const _Range&>(__rg, __fc);
1476 else if constexpr (!is_lvalue_reference_v<_Rg>)
1477 return _M_format_range<_Range&>(__rg, __fc);
1480 auto __handle_debug = [
this, &__rg]<
typename _NOut>(_NOut __nout)
1482 if (!_M_spec._M_debug)
1483 return ranges::copy(__rg,
std::move(__nout)).out;
1485 _Escaping_sink<_NOut, _CharT>
1487 ranges::copy(__rg, __sink.out());
1488 return __sink._M_finish();
1491 const size_t __padwidth = _M_spec._M_get_width(__fc);
1492 if (__padwidth == 0 && _M_spec._M_prec_kind == _WP_none)
1493 return __handle_debug(__fc.out());
1495 _Padding_sink<_Out, _CharT>
1496 __sink(__fc.out(), __padwidth, _M_spec._M_get_precision(__fc));
1497 __handle_debug(__sink.out());
1498 return __sink._M_finish(_M_spec._M_align, _M_spec._M_fill);
1503 set_debug_format() noexcept
1504 { _M_spec._M_debug =
true; }
1508 _Spec<_CharT> _M_spec{};
1513 [[__gnu__::__always_inline__]]
1515 __toupper_numeric(
char __c)
1519 case 'a':
return 'A';
1520 case 'b':
return 'B';
1521 case 'c':
return 'C';
1522 case 'd':
return 'D';
1523 case 'e':
return 'E';
1524 case 'f':
return 'F';
1525 case 'i':
return 'I';
1526 case 'n':
return 'N';
1527 case 'p':
return 'P';
1528 case 'x':
return 'X';
1529 default:
return __c;
1533 template<__
char _CharT>
1534 struct __formatter_int
1538 static constexpr _Pres_type _AsInteger = _Pres_d;
1539 static constexpr _Pres_type _AsBool = _Pres_s;
1540 static constexpr _Pres_type _AsChar = _Pres_c;
1542 __formatter_int() =
default;
1545 __formatter_int(_Spec<_CharT> __spec) noexcept
1548 if (_M_spec._M_type == _Pres_none)
1549 _M_spec._M_type = _Pres_d;
1552 constexpr typename basic_format_parse_context<_CharT>::iterator
1553 _M_do_parse(basic_format_parse_context<_CharT>& __pc, _Pres_type __type)
1555 _Spec<_CharT> __spec{};
1556 __spec._M_type = __type;
1558 const auto __last = __pc.end();
1559 auto __first = __pc.begin();
1561 auto __finalize = [
this, &__spec] {
1565 auto __finished = [&] {
1566 if (__first == __last || *__first ==
'}')
1577 __first = __spec._M_parse_fill_and_align(__first, __last);
1581 __first = __spec._M_parse_sign(__first, __last);
1585 __first = __spec._M_parse_alternate_form(__first, __last);
1589 __first = __spec._M_parse_zero_fill(__first, __last);
1593 __first = __spec._M_parse_width(__first, __last, __pc);
1597 __first = __spec._M_parse_locale(__first, __last);
1604 __spec._M_type = _Pres_b;
1608 __spec._M_type = _Pres_B;
1614 if (__type != _AsBool)
1616 __spec._M_type = _Pres_c;
1621 __spec._M_type = _Pres_d;
1625 __spec._M_type = _Pres_o;
1629 __spec._M_type = _Pres_x;
1633 __spec._M_type = _Pres_X;
1637 if (__type == _AsBool)
1639 __spec._M_type = _Pres_s;
1643#if __glibcxx_format_ranges
1645 if (__type == _AsChar)
1647 __spec._M_debug =
true;
1657 __format::__failed_to_parse_format_spec();
1660 template<
typename _Tp>
1661 constexpr typename basic_format_parse_context<_CharT>::iterator
1662 _M_parse(basic_format_parse_context<_CharT>& __pc)
1664 if constexpr (is_same_v<_Tp, bool>)
1666 auto __end = _M_do_parse(__pc, _AsBool);
1667 if (_M_spec._M_type == _Pres_s)
1668 if (_M_spec._M_sign != _Sign_default || _M_spec._M_alt
1669 || _M_spec._M_zero_fill)
1670 __throw_format_error(
"format error: format-spec contains "
1671 "invalid formatting options for "
1675 else if constexpr (__char<_Tp>)
1677 auto __end = _M_do_parse(__pc, _AsChar);
1678 if (_M_spec._M_type == _Pres_c)
1679 if (_M_spec._M_sign != _Sign_default || _M_spec._M_alt
1680 || _M_spec._M_zero_fill
1682 __throw_format_error(
"format error: format-spec contains "
1683 "invalid formatting options for "
1688 return _M_do_parse(__pc, _AsInteger);
1691 template<
typename _Int,
typename _Out>
1692 _GLIBCXX_CONSTEXPR_FORMAT
1693 typename basic_format_context<_Out, _CharT>::iterator
1694 format(_Int __i, basic_format_context<_Out, _CharT>& __fc)
const
1696 if (_M_spec._M_type == _Pres_c)
1697 return _M_format_character(_S_to_character(__i), __fc);
1699 constexpr size_t __buf_size =
sizeof(_Int) * __CHAR_BIT__ + 3;
1700 char __buf[__buf_size];
1701 to_chars_result __res{};
1703 string_view __base_prefix;
1704 make_unsigned_t<_Int> __u;
1706 __u = -
static_cast<make_unsigned_t<_Int>
>(__i);
1710 char* __start = __buf + 3;
1711 char*
const __end = __buf +
sizeof(__buf);
1712 char*
const __start_digits = __start;
1714 switch (_M_spec._M_type)
1718 __base_prefix = _M_spec._M_type == _Pres_b ?
"0b" :
"0B";
1719 __res = to_chars(__start, __end, __u, 2);
1723 return _M_format_character(_S_to_character(__i), __fc);
1730 __res = to_chars(__start, __end, __u, 10);
1734 __base_prefix =
"0";
1735 __res = to_chars(__start, __end, __u, 8);
1739 __base_prefix = _M_spec._M_type == _Pres_x ?
"0x" :
"0X";
1740 __res = to_chars(__start, __end, __u, 16);
1741 if (_M_spec._M_type == _Pres_X)
1742 for (
auto __p = __start; __p != __res.ptr; ++__p)
1743 *__p = __format::__toupper_numeric(*__p);
1747 if (_M_spec._M_alt && __base_prefix.size())
1749 __start -= __base_prefix.size();
1750 ranges::copy(__base_prefix, __start);
1752 __start = __format::__put_sign(__i, _M_spec._M_sign, __start - 1);
1754 string_view __narrow_str(__start, __res.ptr - __start);
1755 size_t __prefix_len = __start_digits - __start;
1756 if constexpr (is_same_v<char, _CharT>)
1757 return _M_format_int(__narrow_str, __prefix_len, __fc);
1758#ifdef _GLIBCXX_USE_WCHAR_T
1761 _CharT __wbuf[__buf_size];
1762 size_t __n = __narrow_str.size();
1765 std::__to_wstring_numeric(__narrow_str.data(), __n, __wbuf);
1766 return _M_format_int(basic_string_view<_CharT>(__wbuf, __n),
1767 __prefix_len, __fc);
1772 template<
typename _Out>
1773 _GLIBCXX_CONSTEXPR_FORMAT
1774 typename basic_format_context<_Out, _CharT>::iterator
1775 format(
bool __i, basic_format_context<_Out, _CharT>& __fc)
const
1777 if (_M_spec._M_type == _Pres_c)
1778 return _M_format_character(
static_cast<unsigned char>(__i), __fc);
1779 if (_M_spec._M_type != _Pres_s)
1780 return format(
static_cast<unsigned char>(__i), __fc);
1782 basic_string<_CharT> __s;
1784 if (_M_spec._M_localized) [[unlikely]]
1787 __s = __i ? __np.truename() : __np.falsename();
1788 __est_width = __s.size();
1792 if constexpr (is_same_v<char, _CharT>)
1793 __s = __i ?
"true" :
"false";
1795 __s = __i ? L
"true" : L
"false";
1796 __est_width = __s.size();
1799 return __format::__write_padded_as_spec(__s, __est_width, __fc,
1803 template<
typename _Out>
1804 _GLIBCXX_CONSTEXPR_FORMAT
1805 typename basic_format_context<_Out, _CharT>::iterator
1806 _M_format_character(_CharT __c,
1807 basic_format_context<_Out, _CharT>& __fc)
const
1809 basic_string_view<_CharT> __in(&__c, 1u);
1810 size_t __width = 1u;
1812 if constexpr (
sizeof(_CharT) > 1u &&
1813 __unicode::__literal_encoding_is_unicode<_CharT>())
1814 __width = __unicode::__field_width(__c);
1816 if (!_M_spec._M_debug)
1817 return __format::__write_padded_as_spec(__in, __width,
1821 if (_M_spec._M_get_width(__fc) <= __width)
1822 return __format::__write_escaped(__fc.out(), __in, _Term_apos);
1825 _Fixedbuf_sink<_CharT> __sink(__buf);
1826 __format::__write_escaped(__sink.out(), __in, _Term_apos);
1828 __in = __sink.view();
1829 if (__in[1] == _Escapes<_CharT>::_S_bslash()[0])
1830 __width = __in.size();
1831 return __format::__write_padded_as_spec(__in, __width,
1835 template<
typename _Int>
1836 static _GLIBCXX_CONSTEXPR_FORMAT _CharT
1837 _S_to_character(_Int __i)
1840 if constexpr (is_signed_v<_Int> == is_signed_v<_CharT>)
1842 if (_Traits::__min <= __i && __i <= _Traits::__max)
1843 return static_cast<_CharT
>(__i);
1845 else if constexpr (is_signed_v<_Int>)
1847 if (__i >= 0 && make_unsigned_t<_Int>(__i) <= _Traits::__max)
1848 return static_cast<_CharT
>(__i);
1850 else if (__i <= make_unsigned_t<_CharT>(_Traits::__max))
1851 return static_cast<_CharT
>(__i);
1852 __throw_format_error(
"format error: integer not representable as "
1856 template<
typename _Out>
1857 _GLIBCXX_CONSTEXPR_FORMAT
1858 typename basic_format_context<_Out, _CharT>::iterator
1859 _M_format_int(basic_string_view<_CharT> __str,
size_t __prefix_len,
1860 basic_format_context<_Out, _CharT>& __fc)
const
1862 size_t __width = _M_spec._M_get_width(__fc);
1863 if (_M_spec._M_localized)
1865 const auto& __l = __fc.locale();
1866 if (__l.name() !=
"C")
1868 auto& __np = use_facet<numpunct<_CharT>>(__l);
1869 string __grp = __np.grouping();
1872 size_t __n = __str.size() - __prefix_len;
1873 auto __p = (_CharT*)__builtin_alloca(2 * __n
1876 auto __s = __str.data();
1877 char_traits<_CharT>::copy(__p, __s, __prefix_len);
1878 __s += __prefix_len;
1879 auto __end = std::__add_grouping(__p + __prefix_len,
1880 __np.thousands_sep(),
1884 __str = {__p, size_t(__end - __p)};
1889 if (__width <= __str.size())
1890 return __format::__write(__fc.out(), __str);
1892 char32_t __fill_char = _M_spec._M_fill;
1893 _Align __align = _M_spec._M_align;
1895 size_t __nfill = __width - __str.size();
1896 auto __out = __fc.out();
1897 if (__align == _Align_default)
1899 __align = _Align_right;
1900 if (_M_spec._M_zero_fill)
1902 __fill_char = _CharT(
'0');
1904 if (__prefix_len != 0)
1906 __out = __format::__write(
std::move(__out),
1907 __str.substr(0, __prefix_len));
1908 __str.remove_prefix(__prefix_len);
1912 __fill_char = _CharT(
' ');
1914 return __format::__write_padded(
std::move(__out), __str,
1915 __align, __nfill, __fill_char);
1918 _Spec<_CharT> _M_spec{};
1921#ifdef __BFLT16_DIG__
1922 using __bflt16_t =
decltype(0.0bf16);
1933#undef _GLIBCXX_FORMAT_F128
1935#ifdef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
1938 using __flt128_t = __ieee128;
1939# define _GLIBCXX_FORMAT_F128 1
1941#ifdef __LONG_DOUBLE_IEEE128__
1945 to_chars(
char*,
char*, __ibm128)
noexcept
1946 __asm(
"_ZSt8to_charsPcS_e");
1949 to_chars(
char*,
char*, __ibm128, chars_format)
noexcept
1950 __asm(
"_ZSt8to_charsPcS_eSt12chars_format");
1953 to_chars(
char*,
char*, __ibm128, chars_format,
int)
noexcept
1954 __asm(
"_ZSt8to_charsPcS_eSt12chars_formati");
1955#elif __cplusplus == 202002L
1957 to_chars(
char*,
char*, __ieee128)
noexcept
1958 __asm(
"_ZSt8to_charsPcS_u9__ieee128");
1961 to_chars(
char*,
char*, __ieee128, chars_format)
noexcept
1962 __asm(
"_ZSt8to_charsPcS_u9__ieee128St12chars_format");
1965 to_chars(
char*,
char*, __ieee128, chars_format,
int)
noexcept
1966 __asm(
"_ZSt8to_charsPcS_u9__ieee128St12chars_formati");
1969#elif defined _GLIBCXX_LDOUBLE_IS_IEEE_BINARY128
1972 using __flt128_t =
long double;
1973# define _GLIBCXX_FORMAT_F128 2
1975#elif __FLT128_DIG__ && defined(_GLIBCXX_HAVE_FLOAT128_MATH)
1978 using __flt128_t = _Float128;
1979# define _GLIBCXX_FORMAT_F128 3
1981# if __cplusplus == 202002L
1985 to_chars(
char*,
char*, _Float128)
noexcept
1986# if _GLIBCXX_INLINE_VERSION
1987 __asm(
"_ZNSt3__88to_charsEPcS0_DF128_");
1989 __asm(
"_ZSt8to_charsPcS_DF128_");
1993 to_chars(
char*,
char*, _Float128, chars_format)
noexcept
1994# if _GLIBCXX_INLINE_VERSION
1995 __asm(
"_ZNSt3__88to_charsEPcS0_DF128_NS_12chars_formatE");
1997 __asm(
"_ZSt8to_charsPcS_DF128_St12chars_format");
2001 to_chars(
char*,
char*, _Float128, chars_format,
int)
noexcept
2002# if _GLIBCXX_INLINE_VERSION
2003 __asm(
"_ZNSt3__88to_charsEPcS0_DF128_NS_12chars_formatEi");
2005 __asm(
"_ZSt8to_charsPcS_DF128_St12chars_formati");
2010 using std::to_chars;
2013 template<
typename _Tp>
2014 concept __formattable_float
2015 = is_same_v<remove_cv_t<_Tp>, _Tp> &&
requires (_Tp __t,
char* __p)
2016 { __format::to_chars(__p, __p, __t, chars_format::scientific, 6); };
2018 template<__
char _CharT>
2019 struct __formatter_fp
2021 constexpr typename basic_format_parse_context<_CharT>::iterator
2022 parse(basic_format_parse_context<_CharT>& __pc)
2024 _Spec<_CharT> __spec{};
2025 const auto __last = __pc.end();
2026 auto __first = __pc.begin();
2028 auto __finalize = [
this, &__spec] {
2032 auto __finished = [&] {
2033 if (__first == __last || *__first ==
'}')
2044 __first = __spec._M_parse_fill_and_align(__first, __last);
2048 __first = __spec._M_parse_sign(__first, __last);
2052 __first = __spec._M_parse_alternate_form(__first, __last);
2056 __first = __spec._M_parse_zero_fill(__first, __last);
2060 if (__first[0] !=
'.')
2062 __first = __spec._M_parse_width(__first, __last, __pc);
2067 __first = __spec._M_parse_precision(__first, __last, __pc);
2071 __first = __spec._M_parse_locale(__first, __last);
2078 __spec._M_type = _Pres_a;
2082 __spec._M_type = _Pres_A;
2086 __spec._M_type = _Pres_e;
2090 __spec._M_type = _Pres_E;
2094 __spec._M_type = _Pres_f;
2098 __spec._M_type = _Pres_F;
2102 __spec._M_type = _Pres_g;
2106 __spec._M_type = _Pres_G;
2114 __format::__failed_to_parse_format_spec();
2117 template<
typename _Fp,
typename _Out>
2118 typename basic_format_context<_Out, _CharT>::iterator
2119 format(_Fp __v, basic_format_context<_Out, _CharT>& __fc)
const
2123 to_chars_result __res{};
2126 bool __use_prec = _M_spec._M_prec_kind != _WP_none;
2128 __prec = _M_spec._M_get_precision(__fc);
2131 bool __upper =
false;
2132 bool __trailing_zeros =
false;
2134 size_t __offset = 1;
2136 switch (_M_spec._M_type)
2139 if (__builtin_isfinite(__v))
2145 __fmt = chars_format::hex;
2148 if (__builtin_isfinite(__v))
2153 __fmt = chars_format::hex;
2161 __fmt = chars_format::scientific;
2168 __fmt = chars_format::fixed;
2175 __trailing_zeros =
true;
2177 __fmt = chars_format::general;
2182 __fmt = chars_format::general;
2186 char* __start = __buf + __offset;
2187 char* __end = __buf +
sizeof(__buf);
2190 auto __to_chars = [&](
char* __b,
char* __e) {
2192 return __format::to_chars(__b, __e, __v, __fmt, __prec);
2193 else if (__fmt != chars_format{})
2194 return __format::to_chars(__b, __e, __v, __fmt);
2196 return __format::to_chars(__b, __e, __v);
2200 __res = __to_chars(__start, __end);
2202 if (__builtin_expect(__res.ec == errc::value_too_large, 0))
2206 size_t __guess = 7 + __offset + __prec;
2207 if (__fmt == chars_format::fixed)
2209 if constexpr (is_same_v<_Fp, float> || is_same_v<_Fp, double>
2210 || is_same_v<_Fp, long double>)
2215 if constexpr (is_same_v<_Fp, float>)
2216 __builtin_frexpf(__v, &__exp);
2217 else if constexpr (is_same_v<_Fp, double>)
2218 __builtin_frexp(__v, &__exp);
2219 else if constexpr (is_same_v<_Fp, long double>)
2220 __builtin_frexpl(__v, &__exp);
2222 __guess += 1U + __exp * 4004U / 13301U;
2225 __guess += numeric_limits<_Fp>::max_exponent10;
2227 if (__guess <=
sizeof(__buf)) [[unlikely]]
2228 __guess =
sizeof(__buf) * 2;
2237 auto __overwrite = [&__to_chars, &__res, __offset] (
char* __p,
size_t __n)
2239 __res = __to_chars(__p + __offset, __p + __n - __offset);
2240 return __res.ec == errc{} ? __res.ptr - __p : 0;
2245 __start = __dynbuf.
data() + __offset;
2246 __end = __dynbuf.
data() + __dynbuf.
size();
2248 while (__builtin_expect(__res.ec == errc::value_too_large, 0));
2254 if (__builtin_signbit(__v))
2255 ranges::copy(string_view(
"-0x"), __start);
2257 ranges::copy(string_view(
"0x"), __start);
2263 for (
char* __p = __start; __p != __res.ptr; ++__p)
2264 *__p = __format::__toupper_numeric(*__p);
2268 if (!__builtin_signbit(__v))
2270 if (_M_spec._M_sign == _Sign_plus)
2272 else if (_M_spec._M_sign == _Sign_space)
2278 string_view __narrow_str(__start, __res.ptr - __start);
2282 if (_M_spec._M_alt && __builtin_isfinite(__v))
2284 string_view __s = __narrow_str;
2288 size_t __d = __s.find(
'.');
2289 if (__d != __s.npos)
2291 __p = __s.find(__expc, __d + 1);
2292 if (__p == __s.npos)
2296 if (__trailing_zeros)
2299 if (__s[__offset] !=
'0')
2301 __sigfigs = __p - __offset - 1;
2306 __sigfigs = __p - __s.find_first_not_of(
'0', __d + 1);
2311 __p = __s.find(__expc);
2312 if (__p == __s.npos)
2315 __sigfigs = __d - __offset;
2318 if (__trailing_zeros && __prec != 0)
2323 __z = __prec - __sigfigs;
2326 if (
size_t __extras =
int(__d == __p) + __z)
2328 if (__dynbuf.
empty() && __extras <=
size_t(__end - __res.ptr))
2332 __builtin_memmove(__start + __p + __extras,
2336 __start[__p++] =
'.';
2337 __builtin_memset(__start + __p,
'0', __z);
2338 __narrow_str = {__s.data(), __s.size() + __extras};
2342 __dynbuf.
reserve(__s.size() + __extras);
2343 if (__dynbuf.
empty())
2345 __dynbuf = __s.
substr(0, __p);
2349 __dynbuf.
append(__z,
'0');
2350 __dynbuf.
append(__s.substr(__p));
2354 __dynbuf.
insert(__p, __extras,
'0');
2356 __dynbuf[__p] =
'.';
2358 __narrow_str = __dynbuf;
2363 basic_string<_CharT> __wstr;
2364 basic_string_view<_CharT> __str;
2365 if constexpr (is_same_v<_CharT, char>)
2366 __str = __narrow_str;
2367#ifdef _GLIBCXX_USE_WCHAR_T
2372 __wstr = std::__to_wstring_numeric(__narrow_str);
2377 if (_M_spec._M_localized && __builtin_isfinite(__v))
2379 auto __s = _M_localize(__str, __expc, __offset, __fc.locale());
2384 size_t __width = _M_spec._M_get_width(__fc);
2386 if (__width <= __str.size())
2387 return __format::__write(__fc.out(), __str);
2389 char32_t __fill_char = _M_spec._M_fill;
2390 _Align __align = _M_spec._M_align;
2392 size_t __nfill = __width - __str.size();
2393 auto __out = __fc.out();
2394 if (__align == _Align_default)
2396 __align = _Align_right;
2397 if (_M_spec._M_zero_fill && __builtin_isfinite(__v))
2399 __fill_char = _CharT(
'0');
2402 __out = __format::__write(__out, __str.substr(0, __offset));
2403 __str.remove_prefix(__offset);
2407 __fill_char = _CharT(
' ');
2409 return __format::__write_padded(
std::move(__out), __str,
2410 __align, __nfill, __fill_char);
2414 basic_string<_CharT>
2415 _M_localize(basic_string_view<_CharT> __str,
char __expc,
2416 int __offset,
const locale& __loc)
const
2418 basic_string<_CharT> __lstr;
2420 if (__loc == locale::classic())
2423 const auto& __np = use_facet<numpunct<_CharT>>(__loc);
2424 const _CharT __point = __np.decimal_point();
2425 const string __grp = __np.grouping();
2427 _CharT __dot, __exp;
2428 if constexpr (is_same_v<_CharT, char>)
2451 __builtin_unreachable();
2455 if (__grp.empty() && __point == __dot)
2458 size_t __d = __str.find(__dot);
2459 size_t __e = min(__d, __str.find(__exp));
2460 if (__e == __str.npos)
2462 const size_t __r = __str.size() - __e;
2463 auto __overwrite = [&](_CharT* __p, size_t) {
2465 ranges::copy_n(__str.data(), __offset, __p);
2467 auto __end = std::__add_grouping(__p + __offset, __np.thousands_sep(),
2468 __grp.data(), __grp.size(),
2469 __str.data() + __offset,
2470 __str.data() + __e);
2473 if (__d != __str.npos)
2479 const size_t __rlen = __str.size() - __e;
2481 char_traits<_CharT>::copy(__end, __str.data() + __e, __rlen);
2484 return (__end - __p);
2486 __lstr.__resize_and_overwrite(__e * 2 + __r, __overwrite);
2490 _Spec<_CharT> _M_spec{};
2493 template<__format::__
char _CharT>
2494 struct __formatter_ptr
2497 __formatter_ptr() noexcept
2500 _M_spec._M_type = _Pres_x;
2501 _M_spec._M_alt =
true;
2505 __formatter_ptr(_Spec<_CharT> __spec) noexcept
2507 { _M_set_default(); }
2509 constexpr typename basic_format_parse_context<_CharT>::iterator
2510 parse(basic_format_parse_context<_CharT>& __pc)
2512 __format::_Spec<_CharT> __spec{};
2513 const auto __last = __pc.end();
2514 auto __first = __pc.begin();
2516 auto __finalize = [
this, &__spec] {
2521 auto __finished = [&] {
2522 if (__first == __last || *__first ==
'}')
2533 __first = __spec._M_parse_fill_and_align(__first, __last);
2539#if __glibcxx_format >= 202304L
2540 __first = __spec._M_parse_zero_fill(__first, __last);
2545 __first = __spec._M_parse_width(__first, __last, __pc);
2549 if (*__first ==
'p')
2551 __spec._M_type = _Pres_x;
2552 __spec._M_alt =
true;
2555#if __glibcxx_format >= 202304L
2556 else if (*__first ==
'P')
2558 __spec._M_type = _Pres_X;
2559 __spec._M_alt =
true;
2567 __format::__failed_to_parse_format_spec();
2570 template<
typename _Out>
2571 _GLIBCXX_CONSTEXPR_FORMAT
2572 typename basic_format_context<_Out, _CharT>::iterator
2573 format(
const void* __v, basic_format_context<_Out, _CharT>& __fc)
const
2576 ?
reinterpret_cast<__UINTPTR_TYPE__
>(__v)
2577 : static_cast<__UINTPTR_TYPE__>(0);
2578 return __formatter_int<_CharT>(_M_spec).format(__u, __fc);
2582 [[__gnu__::__always_inline__]]
2586 if (_M_spec._M_type == _Pres_none)
2588 _M_spec._M_type = _Pres_x;
2589 _M_spec._M_alt =
true;
2593 __format::_Spec<_CharT> _M_spec;
2600 template<__format::__
char _CharT>
2601 struct formatter<_CharT, _CharT>
2603 formatter() =
default;
2605 constexpr typename basic_format_parse_context<_CharT>::iterator
2606 parse(basic_format_parse_context<_CharT>& __pc)
2608 return _M_f.template _M_parse<_CharT>(__pc);
2611 template<
typename _Out>
2612 _GLIBCXX_CONSTEXPR_FORMAT
2613 typename basic_format_context<_Out, _CharT>::iterator
2614 format(_CharT __u, basic_format_context<_Out, _CharT>& __fc)
const
2616 if (_M_f._M_spec._M_type == __format::_Pres_c)
2617 return _M_f._M_format_character(__u, __fc);
2619 return _M_f.format(
static_cast<make_unsigned_t<_CharT>
>(__u), __fc);
2622#if __glibcxx_format_ranges
2624 set_debug_format() noexcept
2625 { _M_f._M_spec._M_debug =
true; }
2629 __format::__formatter_int<_CharT> _M_f;
2632#if __glibcxx_print >= 202403L
2633 template<__format::__
char _CharT>
2634 constexpr bool enable_nonlocking_formatter_optimization<_CharT> =
true;
2637#ifdef _GLIBCXX_USE_WCHAR_T
2640 struct formatter<char, wchar_t>
2642 formatter() =
default;
2644 constexpr typename basic_format_parse_context<wchar_t>::iterator
2645 parse(basic_format_parse_context<wchar_t>& __pc)
2647 return _M_f._M_parse<
char>(__pc);
2650 template<
typename _Out>
2651 _GLIBCXX_CONSTEXPR_FORMAT
2652 typename basic_format_context<_Out, wchar_t>::iterator
2653 format(
char __u, basic_format_context<_Out, wchar_t>& __fc)
const
2655 if (_M_f._M_spec._M_type == __format::_Pres_c)
2656 return _M_f._M_format_character(__u, __fc);
2658 return _M_f.format(
static_cast<unsigned char>(__u), __fc);
2661#if __glibcxx_format_ranges
2663 set_debug_format() noexcept
2664 { _M_f._M_spec._M_debug =
true; }
2668 __format::__formatter_int<wchar_t> _M_f;
2675 template<__format::__
char _CharT>
2676 struct formatter<_CharT*, _CharT>
2678 formatter() =
default;
2680 [[__gnu__::__always_inline__]]
2681 constexpr typename basic_format_parse_context<_CharT>::iterator
2682 parse(basic_format_parse_context<_CharT>& __pc)
2683 {
return _M_f.parse(__pc); }
2685 template<
typename _Out>
2686 [[__gnu__::__nonnull__]]
2687 _GLIBCXX_CONSTEXPR_FORMAT
2688 typename basic_format_context<_Out, _CharT>::iterator
2689 format(_CharT* __u, basic_format_context<_Out, _CharT>& __fc)
const
2690 {
return _M_f.format(__u, __fc); }
2692#if __glibcxx_format_ranges
2693 constexpr void set_debug_format() noexcept { _M_f.set_debug_format(); }
2697 __format::__formatter_str<_CharT> _M_f;
2700#if __glibcxx_print >= 202403L
2701 template<__format::__
char _CharT>
2702 constexpr bool enable_nonlocking_formatter_optimization<_CharT*> =
true;
2705 template<__format::__
char _CharT>
2706 struct formatter<const _CharT*, _CharT>
2708 formatter() =
default;
2710 [[__gnu__::__always_inline__]]
2711 constexpr typename basic_format_parse_context<_CharT>::iterator
2712 parse(basic_format_parse_context<_CharT>& __pc)
2713 {
return _M_f.parse(__pc); }
2715 template<
typename _Out>
2716 [[__gnu__::__nonnull__]]
2717 _GLIBCXX_CONSTEXPR_FORMAT
2718 typename basic_format_context<_Out, _CharT>::iterator
2719 format(
const _CharT* __u,
2720 basic_format_context<_Out, _CharT>& __fc)
const
2721 {
return _M_f.format(__u, __fc); }
2723#if __glibcxx_format_ranges
2724 constexpr void set_debug_format() noexcept { _M_f.set_debug_format(); }
2728 __format::__formatter_str<_CharT> _M_f;
2731#if __glibcxx_print >= 202403L
2732 template<__format::__
char _CharT>
2734 enable_nonlocking_formatter_optimization<const _CharT*> =
true;
2737 template<__format::__
char _CharT,
size_t _Nm>
2738 struct formatter<_CharT[_Nm], _CharT>
2740 formatter() =
default;
2742 [[__gnu__::__always_inline__]]
2743 constexpr typename basic_format_parse_context<_CharT>::iterator
2744 parse(basic_format_parse_context<_CharT>& __pc)
2745 {
return _M_f.parse(__pc); }
2747 template<
typename _Out>
2748 _GLIBCXX_CONSTEXPR_FORMAT
2749 typename basic_format_context<_Out, _CharT>::iterator
2750 format(
const _CharT (&__u)[_Nm],
2751 basic_format_context<_Out, _CharT>& __fc)
const
2752 {
return _M_f.format({__u, _Nm}, __fc); }
2754#if __glibcxx_format_ranges
2755 constexpr void set_debug_format() noexcept { _M_f.set_debug_format(); }
2759 __format::__formatter_str<_CharT> _M_f;
2762#if __glibcxx_print >= 202403L
2763 template<__format::__
char _CharT,
size_t _Nm>
2764 constexpr bool enable_nonlocking_formatter_optimization<_CharT[_Nm]> =
true;
2767 template<
typename _Traits,
typename _Alloc>
2768 struct formatter<
basic_string<char, _Traits, _Alloc>, char>
2770 formatter() =
default;
2772 [[__gnu__::__always_inline__]]
2773 constexpr typename basic_format_parse_context<char>::iterator
2774 parse(basic_format_parse_context<char>& __pc)
2775 {
return _M_f.parse(__pc); }
2777 template<
typename _Out>
2778 _GLIBCXX_CONSTEXPR_FORMAT
2779 typename basic_format_context<_Out, char>::iterator
2780 format(
const basic_string<char, _Traits, _Alloc>& __u,
2781 basic_format_context<_Out, char>& __fc)
const
2782 {
return _M_f.format(__u, __fc); }
2784#if __glibcxx_format_ranges
2785 constexpr void set_debug_format() noexcept { _M_f.set_debug_format(); }
2789 __format::__formatter_str<char> _M_f;
2792#if __glibcxx_print >= 202403L
2793 template<
typename _Tr,
typename _Alloc>
2795 enable_nonlocking_formatter_optimization<basic_string<char, _Tr, _Alloc>>
2799#ifdef _GLIBCXX_USE_WCHAR_T
2800 template<
typename _Traits,
typename _Alloc>
2801 struct formatter<
basic_string<wchar_t, _Traits, _Alloc>, wchar_t>
2803 formatter() =
default;
2805 [[__gnu__::__always_inline__]]
2806 constexpr typename basic_format_parse_context<wchar_t>::iterator
2807 parse(basic_format_parse_context<wchar_t>& __pc)
2808 {
return _M_f.parse(__pc); }
2810 template<
typename _Out>
2811 _GLIBCXX_CONSTEXPR_FORMAT
2812 typename basic_format_context<_Out, wchar_t>::iterator
2813 format(
const basic_string<wchar_t, _Traits, _Alloc>& __u,
2814 basic_format_context<_Out, wchar_t>& __fc)
const
2815 {
return _M_f.format(__u, __fc); }
2817#if __glibcxx_format_ranges
2818 constexpr void set_debug_format() noexcept { _M_f.set_debug_format(); }
2822 __format::__formatter_str<wchar_t> _M_f;
2825#if __glibcxx_print >= 202403L
2826 template<
typename _Tr,
typename _Alloc>
2828 enable_nonlocking_formatter_optimization<basic_string<wchar_t, _Tr, _Alloc>>
2834 template<
typename _Traits>
2837 formatter() =
default;
2839 [[__gnu__::__always_inline__]]
2840 constexpr typename basic_format_parse_context<char>::iterator
2841 parse(basic_format_parse_context<char>& __pc)
2842 {
return _M_f.parse(__pc); }
2844 template<
typename _Out>
2845 _GLIBCXX_CONSTEXPR_FORMAT
2846 typename basic_format_context<_Out, char>::iterator
2847 format(basic_string_view<char, _Traits> __u,
2848 basic_format_context<_Out, char>& __fc)
const
2849 {
return _M_f.format(__u, __fc); }
2851#if __glibcxx_format_ranges
2852 constexpr void set_debug_format() noexcept { _M_f.set_debug_format(); }
2856 __format::__formatter_str<char> _M_f;
2859#if __glibcxx_print >= 202403L
2860 template<
typename _Tr>
2862 enable_nonlocking_formatter_optimization<basic_string_view<char, _Tr>>
2866#ifdef _GLIBCXX_USE_WCHAR_T
2867 template<
typename _Traits>
2870 formatter() =
default;
2872 [[__gnu__::__always_inline__]]
2873 constexpr typename basic_format_parse_context<wchar_t>::iterator
2874 parse(basic_format_parse_context<wchar_t>& __pc)
2875 {
return _M_f.parse(__pc); }
2877 template<
typename _Out>
2878 _GLIBCXX_CONSTEXPR_FORMAT
2879 typename basic_format_context<_Out, wchar_t>::iterator
2880 format(basic_string_view<wchar_t, _Traits> __u,
2881 basic_format_context<_Out, wchar_t>& __fc)
const
2882 {
return _M_f.format(__u, __fc); }
2884#if __glibcxx_format_ranges
2885 constexpr void set_debug_format() noexcept { _M_f.set_debug_format(); }
2889 __format::__formatter_str<wchar_t> _M_f;
2892#if __glibcxx_print >= 202403L
2893 template<
typename _Tr>
2895 enable_nonlocking_formatter_optimization<basic_string_view<wchar_t, _Tr>>
2906 template<
typename _Tp>
2907 constexpr bool __is_formattable_integer = __is_integer<_Tp>::__value;
2909#if defined __SIZEOF_INT128__
2910 template<>
inline constexpr bool __is_formattable_integer<__int128> =
true;
2911 template<>
inline constexpr bool __is_formattable_integer<unsigned __int128>
2915 template<>
inline constexpr bool __is_formattable_integer<char> =
false;
2916 template<>
inline constexpr bool __is_formattable_integer<wchar_t> =
false;
2917#ifdef _GLIBCXX_USE_CHAR8_T
2918 template<>
inline constexpr bool __is_formattable_integer<char8_t> =
false;
2920 template<>
inline constexpr bool __is_formattable_integer<char16_t> =
false;
2921 template<>
inline constexpr bool __is_formattable_integer<char32_t> =
false;
2923 template<
typename _Tp>
2924 concept __formattable_integer = __is_formattable_integer<_Tp>;
2929 template<__format::__formattable_
integer _Tp, __format::__
char _CharT>
2930 struct formatter<_Tp, _CharT>
2932 formatter() =
default;
2934 [[__gnu__::__always_inline__]]
2935 constexpr typename basic_format_parse_context<_CharT>::iterator
2936 parse(basic_format_parse_context<_CharT>& __pc)
2938 return _M_f.template _M_parse<_Tp>(__pc);
2941 template<
typename _Out>
2942 _GLIBCXX_CONSTEXPR_FORMAT
2943 typename basic_format_context<_Out, _CharT>::iterator
2944 format(_Tp __u, basic_format_context<_Out, _CharT>& __fc)
const
2945 {
return _M_f.format(__u, __fc); }
2948 __format::__formatter_int<_CharT> _M_f;
2951#if __glibcxx_print >= 202403L
2952 template<__format::__formattable_
integer _Tp>
2954 enable_nonlocking_formatter_optimization<_Tp> =
true;
2957#if defined __glibcxx_to_chars
2959 template<__format::__formattable_
float _Tp, __format::__
char _CharT>
2960 struct formatter<_Tp, _CharT>
2962 formatter() =
default;
2964 [[__gnu__::__always_inline__]]
2965 constexpr typename basic_format_parse_context<_CharT>::iterator
2966 parse(basic_format_parse_context<_CharT>& __pc)
2967 {
return _M_f.parse(__pc); }
2969 template<
typename _Out>
2970 typename basic_format_context<_Out, _CharT>::iterator
2971 format(_Tp __u, basic_format_context<_Out, _CharT>& __fc)
const
2972 {
return _M_f.format(__u, __fc); }
2975 __format::__formatter_fp<_CharT> _M_f;
2978#if __glibcxx_print >= 202403L
2979 template<__format::__formattable_
float _Tp>
2981 enable_nonlocking_formatter_optimization<_Tp> =
true;
2984#if __LDBL_MANT_DIG__ == __DBL_MANT_DIG__
2986 template<__format::__
char _CharT>
2987 struct formatter<long double, _CharT>
2989 formatter() =
default;
2991 [[__gnu__::__always_inline__]]
2992 constexpr typename basic_format_parse_context<_CharT>::iterator
2993 parse(basic_format_parse_context<_CharT>& __pc)
2994 {
return _M_f.parse(__pc); }
2996 template<
typename _Out>
2997 typename basic_format_context<_Out, _CharT>::iterator
2998 format(
long double __u, basic_format_context<_Out, _CharT>& __fc)
const
2999 {
return _M_f.format((
double)__u, __fc); }
3002 __format::__formatter_fp<_CharT> _M_f;
3006#if defined(__FLT32_DIG__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
3008 template<__format::__
char _CharT>
3009 struct formatter<_Float32, _CharT>
3011 formatter() =
default;
3013 [[__gnu__::__always_inline__]]
3014 constexpr typename basic_format_parse_context<_CharT>::iterator
3015 parse(basic_format_parse_context<_CharT>& __pc)
3016 {
return _M_f.parse(__pc); }
3018 template<
typename _Out>
3019 typename basic_format_context<_Out, _CharT>::iterator
3020 format(_Float32 __u, basic_format_context<_Out, _CharT>& __fc)
const
3021 {
return _M_f.format((
float)__u, __fc); }
3024 __format::__formatter_fp<_CharT> _M_f;
3028#if defined(__FLT64_DIG__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
3030 template<__format::__
char _CharT>
3031 struct formatter<_Float64, _CharT>
3033 formatter() =
default;
3035 [[__gnu__::__always_inline__]]
3036 constexpr typename basic_format_parse_context<_CharT>::iterator
3037 parse(basic_format_parse_context<_CharT>& __pc)
3038 {
return _M_f.parse(__pc); }
3040 template<
typename _Out>
3041 typename basic_format_context<_Out, _CharT>::iterator
3042 format(_Float64 __u, basic_format_context<_Out, _CharT>& __fc)
const
3043 {
return _M_f.format((
double)__u, __fc); }
3046 __format::__formatter_fp<_CharT> _M_f;
3050#if defined(__FLT128_DIG__) && _GLIBCXX_FORMAT_F128
3052 template<__format::__
char _CharT>
3053 struct formatter<_Float128, _CharT>
3055 formatter() =
default;
3057 [[__gnu__::__always_inline__]]
3058 constexpr typename basic_format_parse_context<_CharT>::iterator
3059 parse(basic_format_parse_context<_CharT>& __pc)
3060 {
return _M_f.parse(__pc); }
3062 template<
typename _Out>
3063 typename basic_format_context<_Out, _CharT>::iterator
3064 format(_Float128 __u, basic_format_context<_Out, _CharT>& __fc)
const
3065 {
return _M_f.format((__format::__flt128_t)__u, __fc); }
3068 __format::__formatter_fp<_CharT> _M_f;
3072#if defined(__SIZEOF_FLOAT128__) && _GLIBCXX_FORMAT_F128 == 2
3075 template<__format::__
char _CharT>
3076 struct formatter<__float128, _CharT>
3078 formatter() =
default;
3080 [[__gnu__::__always_inline__]]
3081 constexpr typename basic_format_parse_context<_CharT>::iterator
3082 parse(basic_format_parse_context<_CharT>& __pc)
3083 {
return _M_f.parse(__pc); }
3085 template<
typename _Out>
3086 typename basic_format_context<_Out, _CharT>::iterator
3087 format(__float128 __u, basic_format_context<_Out, _CharT>& __fc)
const
3088 {
return _M_f.format((__format::__flt128_t)__u, __fc); }
3091 __format::__formatter_fp<_CharT> _M_f;
3100 template<__format::__
char _CharT>
3101 struct formatter<const void*, _CharT>
3103 formatter() =
default;
3105 constexpr typename basic_format_parse_context<_CharT>::iterator
3106 parse(basic_format_parse_context<_CharT>& __pc)
3107 {
return _M_f.parse(__pc); }
3109 template<
typename _Out>
3110 _GLIBCXX_CONSTEXPR_FORMAT
3111 typename basic_format_context<_Out, _CharT>::iterator
3112 format(
const void* __v, basic_format_context<_Out, _CharT>& __fc)
const
3113 {
return _M_f.format(__v, __fc); }
3116 __format::__formatter_ptr<_CharT> _M_f;
3119#if __glibcxx_print >= 202403L
3121 inline constexpr bool
3122 enable_nonlocking_formatter_optimization<const void*> =
true;
3125 template<__format::__
char _CharT>
3126 struct formatter<void*, _CharT>
3128 formatter() =
default;
3130 [[__gnu__::__always_inline__]]
3131 constexpr typename basic_format_parse_context<_CharT>::iterator
3132 parse(basic_format_parse_context<_CharT>& __pc)
3133 {
return _M_f.parse(__pc); }
3135 template<
typename _Out>
3136 _GLIBCXX_CONSTEXPR_FORMAT
3137 typename basic_format_context<_Out, _CharT>::iterator
3138 format(
void* __v, basic_format_context<_Out, _CharT>& __fc)
const
3139 {
return _M_f.format(__v, __fc); }
3142 __format::__formatter_ptr<_CharT> _M_f;
3145#if __glibcxx_print >= 202403l
3147 inline constexpr bool
3148 enable_nonlocking_formatter_optimization<void*> =
true;
3151 template<__format::__
char _CharT>
3152 struct formatter<nullptr_t, _CharT>
3154 formatter() =
default;
3156 [[__gnu__::__always_inline__]]
3157 constexpr typename basic_format_parse_context<_CharT>::iterator
3158 parse(basic_format_parse_context<_CharT>& __pc)
3159 {
return _M_f.parse(__pc); }
3161 template<
typename _Out>
3162 _GLIBCXX_CONSTEXPR_FORMAT
3163 typename basic_format_context<_Out, _CharT>::iterator
3164 format(nullptr_t, basic_format_context<_Out, _CharT>& __fc)
const
3165 {
return _M_f.format(
nullptr, __fc); }
3168 __format::__formatter_ptr<_CharT> _M_f;
3172#if __glibcxx_print >= 202403L
3174 inline constexpr bool
3175 enable_nonlocking_formatter_optimization<nullptr_t> =
true;
3178#if defined _GLIBCXX_USE_WCHAR_T && __glibcxx_format_ranges
3182 struct __formatter_disabled
3184 __formatter_disabled() =
delete;
3185 __formatter_disabled(
const __formatter_disabled&) =
delete;
3186 __formatter_disabled& operator=(
const __formatter_disabled&) =
delete;
3190 struct formatter<char*,
wchar_t>
3191 :
private __formatter_disabled { };
3193 struct formatter<const char*,
wchar_t>
3194 :
private __formatter_disabled { };
3195 template<
size_t _Nm>
3196 struct formatter<char[_Nm], wchar_t>
3197 :
private __formatter_disabled { };
3198 template<
class _Traits,
class _Allocator>
3199 struct formatter<
basic_string<char, _Traits, _Allocator>, wchar_t>
3200 :
private __formatter_disabled { };
3201 template<
class _Traits>
3203 :
private __formatter_disabled { };
3208 template<
typename _Out>
3209 struct format_to_n_result
3212 iter_difference_t<_Out> size;
3215_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
3216template<
typename,
typename>
class vector;
3217_GLIBCXX_END_NAMESPACE_CONTAINER
3222 template<
typename _CharT>
3226 using iterator_category = output_iterator_tag;
3227 using value_type = void;
3228 using difference_type = ptrdiff_t;
3229 using pointer = void;
3230 using reference = void;
3232 _Drop_iter() =
default;
3233 _Drop_iter(
const _Drop_iter&) =
default;
3234 _Drop_iter& operator=(
const _Drop_iter&) =
default;
3236 [[__gnu__::__always_inline__]]
3237 constexpr _Drop_iter&
3238 operator=(_CharT __c)
3241 [[__gnu__::__always_inline__]]
3242 constexpr _Drop_iter&
3243 operator=(basic_string_view<_CharT> __s)
3246 [[__gnu__::__always_inline__]]
3247 constexpr _Drop_iter&
3250 [[__gnu__::__always_inline__]]
3251 constexpr _Drop_iter&
3252 operator++() {
return *
this; }
3254 [[__gnu__::__always_inline__]]
3255 constexpr _Drop_iter
3256 operator++(
int) {
return *
this; }
3259 template<
typename _CharT>
3262 _Sink<_CharT>* _M_sink =
nullptr;
3265 using iterator_category = output_iterator_tag;
3266 using value_type = void;
3267 using difference_type = ptrdiff_t;
3268 using pointer = void;
3269 using reference = void;
3271 _Sink_iter() =
default;
3272 _Sink_iter(
const _Sink_iter&) =
default;
3273 _Sink_iter& operator=(
const _Sink_iter&) =
default;
3275 [[__gnu__::__always_inline__]]
3277 _Sink_iter(_Sink<_CharT>& __sink) : _M_sink(std::
addressof(__sink)) { }
3279 [[__gnu__::__always_inline__]]
3280 constexpr _Sink_iter&
3281 operator=(_CharT __c)
3283 _M_sink->_M_write(__c);
3287 [[__gnu__::__always_inline__]]
3288 constexpr _Sink_iter&
3289 operator=(basic_string_view<_CharT> __s)
3291 _M_sink->_M_write(__s);
3295 [[__gnu__::__always_inline__]]
3296 constexpr _Sink_iter&
3299 [[__gnu__::__always_inline__]]
3300 constexpr _Sink_iter&
3301 operator++() {
return *
this; }
3303 [[__gnu__::__always_inline__]]
3304 constexpr _Sink_iter
3305 operator++(
int) {
return *
this; }
3307 _GLIBCXX_CONSTEXPR_FORMAT
auto
3308 _M_reserve(
size_t __n)
const
3309 {
return _M_sink->_M_reserve(__n); }
3311 _GLIBCXX_CONSTEXPR_FORMAT
bool
3312 _M_discarding()
const
3313 {
return _M_sink->_M_discarding(); }
3319 template<
typename _CharT>
3322 friend class _Sink_iter<_CharT>;
3324 span<_CharT> _M_span;
3325 typename span<_CharT>::iterator _M_next;
3331 virtual void _M_overflow() = 0;
3335 [[__gnu__::__always_inline__]]
3337 _Sink(span<_CharT> __span) noexcept
3338 : _M_span(__span), _M_next(__span.begin())
3342 [[__gnu__::__always_inline__]]
3343 _GLIBCXX_CONSTEXPR_FORMAT span<_CharT>
3344 _M_used() const noexcept
3345 {
return _M_span.first(_M_next - _M_span.begin()); }
3348 [[__gnu__::__always_inline__]]
3349 constexpr span<_CharT>
3350 _M_unused() const noexcept
3351 {
return _M_span.subspan(_M_next - _M_span.begin()); }
3354 [[__gnu__::__always_inline__]]
3356 _M_rewind() noexcept
3357 { _M_next = _M_span.begin(); }
3360 _GLIBCXX_CONSTEXPR_FORMAT
void
3361 _M_reset(span<_CharT> __s,
size_t __pos = 0) noexcept
3364 _M_next = __s.begin() + __pos;
3369 _M_write(_CharT __c)
3372 if (_M_next - _M_span.begin() ==
std::ssize(_M_span)) [[unlikely]]
3377 _M_write(basic_string_view<_CharT> __s)
3379 span __to = _M_unused();
3380 while (__to.size() <= __s.size())
3382 __s.copy(__to.data(), __to.size());
3383 _M_next += __to.size();
3384 __s.remove_prefix(__to.size());
3390 __s.copy(__to.data(), __s.size());
3391 _M_next += __s.size();
3400 _GLIBCXX_CONSTEXPR_FORMAT
3401 explicit operator bool() const noexcept {
return _M_sink; }
3403 _GLIBCXX_CONSTEXPR_FORMAT _CharT*
3404 get() const noexcept {
return _M_sink->_M_next.operator->(); }
3406 _GLIBCXX_CONSTEXPR_FORMAT
void
3407 _M_bump(
size_t __n) { _M_sink->_M_bump(__n); }
3415 _GLIBCXX_CONSTEXPR_FORMAT
virtual _Reservation
3416 _M_reserve(
size_t __n)
3418 if (__n <= _M_unused().size())
3421 if (__n <= _M_span.size())
3424 if (__n <= _M_unused().size())
3432 _GLIBCXX_CONSTEXPR_FORMAT
virtual void
3437 _GLIBCXX_CONSTEXPR_FORMAT
virtual bool
3438 _M_discarding()
const
3442 _Sink(
const _Sink&) =
delete;
3443 _Sink& operator=(
const _Sink&) =
delete;
3445 [[__gnu__::__always_inline__]]
3446 constexpr _Sink_iter<_CharT>
3448 {
return _Sink_iter<_CharT>(*
this); }
3452 template<
typename _CharT>
3453 class _Fixedbuf_sink final :
public _Sink<_CharT>
3455 _GLIBCXX_CONSTEXPR_FORMAT
void
3456 _M_overflow()
override
3458 __glibcxx_assert(
false);
3463 [[__gnu__::__always_inline__]]
3465 _Fixedbuf_sink(span<_CharT> __buf)
3466 : _Sink<_CharT>(__buf)
3469 constexpr basic_string_view<_CharT>
3472 auto __s = this->_M_used();
3473 return basic_string_view<_CharT>(__s.data(), __s.size());
3478 template<
typename _CharT>
3479 class _Buf_sink :
public _Sink<_CharT>
3482 _CharT _M_buf[__stackbuf_size<_CharT>];
3484 [[__gnu__::__always_inline__]]
3486 _Buf_sink() noexcept
3487 : _Sink<_CharT>(_M_buf)
3491 using _GLIBCXX_STD_C::vector;
3495 template<
typename _Seq>
3496 class _Seq_sink :
public _Buf_sink<typename _Seq::value_type>
3498 using _CharT =
typename _Seq::value_type;
3503 _GLIBCXX_CONSTEXPR_FORMAT
void
3504 _M_overflow()
override
3506 auto __s = this->_M_used();
3507 if (__s.empty()) [[unlikely]]
3511 _GLIBCXX_DEBUG_ASSERT(__s.data() != _M_seq.data());
3513 if constexpr (__is_specialization_of<_Seq, basic_string>)
3514 _M_seq.append(__s.data(), __s.size());
3516 _M_seq.insert(_M_seq.end(), __s.begin(), __s.end());
3522 _GLIBCXX_CONSTEXPR_FORMAT
typename _Sink<_CharT>::_Reservation
3523 _M_reserve(
size_t __n)
override
3532 if constexpr (__is_specialization_of<_Seq, basic_string>
3533 || __is_specialization_of<_Seq, vector>)
3536 if (this->_M_used().size()) [[unlikely]]
3537 _Seq_sink::_M_overflow();
3540 const auto __sz = _M_seq.size();
3541 if constexpr (is_same_v<string, _Seq> || is_same_v<wstring, _Seq>)
3542 _M_seq.__resize_and_overwrite(__sz + __n,
3543 [](
auto,
auto __n2) {
3547 _M_seq.resize(__sz + __n);
3551 this->_M_reset(_M_seq, __sz);
3555 return _Sink<_CharT>::_M_reserve(__n);
3558 _GLIBCXX_CONSTEXPR_FORMAT
void
3559 _M_bump(
size_t __n)
override
3561 if constexpr (__is_specialization_of<_Seq, basic_string>
3562 || __is_specialization_of<_Seq, vector>)
3564 auto __s = this->_M_used();
3565 _GLIBCXX_DEBUG_ASSERT(__s.data() == _M_seq.data());
3567 _M_seq.resize(__s.size() + __n);
3569 this->_M_reset(this->_M_buf);
3573 _GLIBCXX_CONSTEXPR_FORMAT
void
3574 _M_trim(span<const _CharT> __s)
3575 requires __is_specialization_of<_Seq, basic_string>
3577 _GLIBCXX_DEBUG_ASSERT(__s.data() == this->_M_buf
3578 || __s.data() == _M_seq.data());
3579 if (__s.data() == _M_seq.data())
3580 _M_seq.resize(__s.size());
3582 this->_M_reset(this->_M_buf, __s.size());
3589 [[__gnu__::__always_inline__]]
3590 _GLIBCXX_CONSTEXPR_FORMAT
3591 _Seq_sink() noexcept(is_nothrow_default_constructible_v<_Seq>)
3594 _GLIBCXX_CONSTEXPR_FORMAT
3595 _Seq_sink(_Seq&& __s)
noexcept(is_nothrow_move_constructible_v<_Seq>)
3596 : _M_seq(std::move(__s))
3599 using _Sink<_CharT>::out;
3601 _GLIBCXX_CONSTEXPR_FORMAT _Seq
3604 if (this->_M_used().size() != 0)
3605 _Seq_sink::_M_overflow();
3611 _GLIBCXX_CONSTEXPR_FORMAT span<_CharT>
3614 auto __s = this->_M_used();
3617 if (__s.size() != 0)
3618 _Seq_sink::_M_overflow();
3624 _GLIBCXX_CONSTEXPR_FORMAT basic_string_view<_CharT>
3627 auto __span = _M_span();
3628 return basic_string_view<_CharT>(__span.data(), __span.size());
3632 template<
typename _CharT,
typename _Alloc = allocator<_CharT>>
3634 = _Seq_sink<basic_string<_CharT, char_traits<_CharT>, _Alloc>>;
3640 template<
typename _CharT,
typename _OutIter>
3641 class _Iter_sink :
public _Buf_sink<_CharT>
3644 iter_difference_t<_OutIter> _M_max;
3647 size_t _M_count = 0;
3649 _GLIBCXX_CONSTEXPR_FORMAT
void
3650 _M_overflow()
override
3652 auto __s = this->_M_used();
3654 _M_out = ranges::copy(__s,
std::move(_M_out)).out;
3655 else if (_M_count <
static_cast<size_t>(_M_max))
3657 auto __max = _M_max - _M_count;
3658 span<_CharT> __first;
3659 if (__max < __s.size())
3660 __first = __s.first(
static_cast<size_t>(__max));
3663 _M_out = ranges::copy(__first,
std::move(_M_out)).out;
3666 _M_count += __s.size();
3669 _GLIBCXX_CONSTEXPR_FORMAT
bool
3670 _M_discarding()
const override
3678 [[__gnu__::__always_inline__]]
3679 _GLIBCXX_CONSTEXPR_FORMAT
explicit
3680 _Iter_sink(_OutIter __out, iter_difference_t<_OutIter> __max = -1)
3681 : _M_out(std::move(__out)), _M_max(__max)
3684 using _Sink<_CharT>::out;
3686 _GLIBCXX_CONSTEXPR_FORMAT format_to_n_result<_OutIter>
3689 if (this->_M_used().size() != 0)
3690 _Iter_sink::_M_overflow();
3691 iter_difference_t<_OutIter> __count(_M_count);
3703 template<
typename _CharT>
3704 class _Ptr_sink :
public _Sink<_CharT>
3706 static constexpr size_t _S_no_limit = size_t(-1);
3710 size_t _M_count = 0;
3715 _GLIBCXX_CONSTEXPR_FORMAT
void
3716 _M_overflow()
override
3718 if (this->_M_unused().size() != 0)
3721 auto __s = this->_M_used();
3723 if (_M_max != _S_no_limit)
3725 _M_count += __s.size();
3729 this->_M_reset(this->_M_buf);
3735 _M_rebuf(__s.data(), __s.size() + 1024, __s.size());
3739 _GLIBCXX_CONSTEXPR_FORMAT
bool
3740 _M_discarding()
const override
3747 _GLIBCXX_CONSTEXPR_FORMAT
typename _Sink<_CharT>::_Reservation
3748 _M_reserve(
size_t __n)
final
3750 auto __avail = this->_M_unused();
3751 if (__n > __avail.size())
3753 if (_M_max != _S_no_limit)
3756 auto __s = this->_M_used();
3757 _M_rebuf(__s.data(), __s.size() + __n, __s.size());
3763 template<
typename _IterDifference>
3764 static _GLIBCXX_CONSTEXPR_FORMAT
size_t
3765 _S_trim_max(_IterDifference __max)
3769 if constexpr (!is_integral_v<_IterDifference> ||
sizeof(__max) >
sizeof(size_t))
3771 if (_IterDifference((
size_t)-1) < __max)
3773 return size_t(__max);
3776 [[__gnu__::__always_inline__]]
3777 _GLIBCXX_CONSTEXPR_FORMAT
void
3778 _M_rebuf(_CharT* __ptr,
size_t __total,
size_t __inuse = 0)
3780 std::span<_CharT> __span(__ptr, __total);
3781 this->_M_reset(__span, __inuse);
3785 _GLIBCXX_CONSTEXPR_FORMAT
explicit
3786 _Ptr_sink(_CharT* __ptr,
size_t __n = _S_no_limit) noexcept
3787 : _Sink<_CharT>(_M_buf), _M_max(__n)
3791 else if (__n != _S_no_limit)
3792 _M_rebuf(__ptr, __n);
3793#if __has_builtin(__builtin_dynamic_object_size)
3794 else if (
size_t __bytes = __builtin_dynamic_object_size(__ptr, 2))
3795 _M_rebuf(__ptr, __bytes /
sizeof(_CharT));
3800 const auto __off =
reinterpret_cast<__UINTPTR_TYPE__
>(__ptr) % 1024;
3801 __n = (1024 - __off) /
sizeof(_CharT);
3802 if (__n > 0) [[likely]]
3803 _M_rebuf(__ptr, __n);
3809 template<contiguous_iterator _OutIter>
3810 _GLIBCXX_CONSTEXPR_FORMAT
explicit
3811 _Ptr_sink(_OutIter __out, iter_difference_t<_OutIter> __n = -1)
3812 : _Ptr_sink(std::
to_address(__out), _S_trim_max(__n))
3815 template<contiguous_iterator _OutIter>
3816 _GLIBCXX_CONSTEXPR_FORMAT format_to_n_result<_OutIter>
3817 _M_finish(_OutIter __first)
const
3819 auto __s = this->_M_used();
3820 if (__s.data() == _M_buf)
3823 iter_difference_t<_OutIter> __m(_M_max);
3824 iter_difference_t<_OutIter> __count(_M_count + __s.size());
3825 return { __first + __m, __count };
3829 iter_difference_t<_OutIter> __count(__s.size());
3830 return { __first + __count, __count };
3835 template<
typename _CharT,
typename _OutIter>
3836 concept __contiguous_char_iter
3837 = contiguous_iterator<_OutIter>
3838 && same_as<iter_value_t<_OutIter>, _CharT>;
3849 template<
typename _Out,
typename _CharT>
3850 class _Padding_sink :
public _Str_sink<_CharT>
3855 size_t _M_printwidth;
3857 [[__gnu__::__always_inline__]]
3858 _GLIBCXX_CONSTEXPR_FORMAT
bool
3860 {
return _M_printwidth >= _M_maxwidth; }
3862 [[__gnu__::__always_inline__]]
3863 _GLIBCXX_CONSTEXPR_FORMAT
bool
3864 _M_buffering()
const
3866 if (_M_printwidth < _M_padwidth)
3868 if (_M_maxwidth != (
size_t)-1)
3869 return _M_printwidth < _M_maxwidth;
3873 _GLIBCXX_CONSTEXPR_FORMAT
void
3874 _M_sync_discarding()
3876 if constexpr (is_same_v<_Out, _Sink_iter<_CharT>>)
3877 if (_M_out._M_discarding())
3878 _M_maxwidth = _M_printwidth;
3881 _GLIBCXX_CONSTEXPR_FORMAT
void
3884 span<_CharT> __new = this->_M_used();
3885 basic_string_view<_CharT> __str(__new.data(), __new.size());
3886 _M_out = __format::__write(
std::move(_M_out), __str);
3887 _M_sync_discarding();
3891 _GLIBCXX_CONSTEXPR_FORMAT
bool
3894 auto __str = this->view();
3896 _M_printwidth = __format::__truncate(__str, _M_maxwidth);
3898 this->_M_trim(__str);
3904 if (_M_printwidth >= _M_padwidth)
3906 _M_out = __format::__write(
std::move(_M_out), __str);
3907 _M_sync_discarding();
3912 _Str_sink<_CharT>::_M_overflow();
3915 this->_M_reset(this->_M_buf);
3919 _GLIBCXX_CONSTEXPR_FORMAT
bool
3920 _M_update(
size_t __new)
3922 _M_printwidth += __new;
3924 if (_M_printwidth >= _M_padwidth || _M_printwidth >= _M_maxwidth)
3925 return _M_force_update();
3929 _GLIBCXX_CONSTEXPR_FORMAT
void
3930 _M_overflow()
override
3936 else if (!_M_buffering())
3940 else if (_M_update(this->_M_used().size()))
3941 _Str_sink<_CharT>::_M_overflow();
3944 _GLIBCXX_CONSTEXPR_FORMAT
bool
3945 _M_discarding()
const override
3946 {
return _M_ignoring(); }
3948 _GLIBCXX_CONSTEXPR_FORMAT
typename _Sink<_CharT>::_Reservation
3949 _M_reserve(
size_t __n)
override
3954 else if constexpr (is_same_v<_Out, _Sink_iter<_CharT>>)
3955 if (!_M_buffering())
3958 if (!this->_M_used().empty())
3961 if (
auto __reserved = _M_out._M_reserve(__n))
3964 return _Sink<_CharT>::_M_reserve(__n);
3967 _GLIBCXX_CONSTEXPR_FORMAT
void
3968 _M_bump(
size_t __n)
override
3975 _Sink<_CharT>::_M_bump(__n);
3981 [[__gnu__::__always_inline__]]
3982 _GLIBCXX_CONSTEXPR_FORMAT
explicit
3983 _Padding_sink(_Out __out,
size_t __padwidth,
size_t __maxwidth)
3984 : _M_padwidth(__padwidth), _M_maxwidth(__maxwidth),
3985 _M_out(std::move(__out)), _M_printwidth(0)
3986 { _M_sync_discarding(); }
3988 [[__gnu__::__always_inline__]]
3989 _GLIBCXX_CONSTEXPR_FORMAT
explicit
3990 _Padding_sink(_Out __out,
size_t __padwidth)
3991 : _Padding_sink(std::move(__out), __padwidth, (size_t)-1)
3994 _GLIBCXX_CONSTEXPR_FORMAT _Out
3995 _M_finish(_Align __align,
char32_t __fill_char)
3998 if (
auto __rem = this->_M_used().size())
4002 else if (!_M_buffering())
4008 if (!_M_buffering() || !_M_force_update())
4010 if (_M_printwidth >= _M_padwidth)
4013 const auto __str = this->view();
4014 if (_M_printwidth >= _M_padwidth)
4015 return __format::__write(
std::move(_M_out), __str);
4017 const size_t __nfill = _M_padwidth - _M_printwidth;
4018 return __format::__write_padded(
std::move(_M_out), __str,
4019 __align, __nfill, __fill_char);
4023 template<
typename _Out,
typename _CharT>
4024 class _Escaping_sink :
public _Buf_sink<_CharT>
4026 using _Esc = _Escapes<_CharT>;
4029 _Term_char _M_term : 2;
4030 unsigned _M_prev_escape : 1;
4031 unsigned _M_out_discards : 1;
4033 _GLIBCXX_CONSTEXPR_FORMAT
void
4034 _M_sync_discarding()
4036 if constexpr (is_same_v<_Out, _Sink_iter<_CharT>>)
4037 _M_out_discards = _M_out._M_discarding();
4040 _GLIBCXX_CONSTEXPR_FORMAT
void
4043 span<_CharT> __bytes = this->_M_used();
4044 basic_string_view<_CharT> __str(__bytes.data(), __bytes.size());
4047 if constexpr (__unicode::__literal_encoding_is_unicode<_CharT>())
4049 bool __prev_escape = _M_prev_escape;
4050 _M_out = __format::__write_escaped_unicode_part(
4051 std::move(_M_out), __str, __prev_escape, _M_term);
4052 _M_prev_escape = __prev_escape;
4054 __rem = __str.size();
4055 if (__rem > 0 && __str.data() != this->_M_buf) [[unlikely]]
4056 ranges::move(__str, this->_M_buf);
4059 _M_out = __format::__write_escaped_ascii(
4062 this->_M_reset(this->_M_buf, __rem);
4063 _M_sync_discarding();
4066 _GLIBCXX_CONSTEXPR_FORMAT
void
4067 _M_overflow()
override
4069 if (_M_out_discards)
4075 _GLIBCXX_CONSTEXPR_FORMAT
bool
4076 _M_discarding()
const override
4077 {
return _M_out_discards; }
4080 [[__gnu__::__always_inline__]]
4081 _GLIBCXX_CONSTEXPR_FORMAT
explicit
4082 _Escaping_sink(_Out __out, _Term_char __term)
4083 : _M_out(std::move(__out)), _M_term(__term),
4084 _M_prev_escape(true), _M_out_discards(false)
4086 _M_out = __format::__write(
std::move(_M_out), _Esc::_S_term(_M_term));
4087 _M_sync_discarding();
4090 _GLIBCXX_CONSTEXPR_FORMAT _Out
4093 if (_M_out_discards)
4096 if (!this->_M_used().empty())
4099 if constexpr (__unicode::__literal_encoding_is_unicode<_CharT>())
4100 if (
auto __rem = this->_M_used(); !__rem.empty())
4102 basic_string_view<_CharT> __str(__rem.data(), __rem.size());
4103 _M_out = __format::__write_escape_seqs(
std::move(_M_out), __str);
4106 return __format::__write(
std::move(_M_out), _Esc::_S_term(_M_term));
4110 enum class _Arg_t :
unsigned char {
4111 _Arg_none, _Arg_bool, _Arg_c, _Arg_i, _Arg_u, _Arg_ll, _Arg_ull,
4112 _Arg_flt, _Arg_dbl, _Arg_ldbl, _Arg_str, _Arg_sv, _Arg_ptr, _Arg_handle,
4113 _Arg_i128, _Arg_u128, _Arg_float128,
4114 _Arg_bf16, _Arg_f16, _Arg_f32, _Arg_f64,
4117#ifdef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
4118 _Arg_ibm128 = _Arg_ldbl,
4119 _Arg_ieee128 = _Arg_float128,
4124 template<
typename _Context>
4127 using _CharT =
typename _Context::char_type;
4131 using _CharT =
typename _Context::char_type;
4132 using _Func = void(*)(basic_format_parse_context<_CharT>&,
4133 _Context&,
const void*);
4136 template<
typename _Tp>
4137 using __maybe_const_t
4138 = __conditional_t<__formattable_with<const _Tp, _Context>,
4141 template<
typename _Tq>
4142 static _GLIBCXX_CONSTEXPR_FORMAT
void
4143 _S_format(basic_format_parse_context<_CharT>& __parse_ctx,
4144 _Context& __format_ctx,
const void* __ptr)
4146 using _Td = remove_const_t<_Tq>;
4147 typename _Context::template formatter_type<_Td> __f;
4148 __parse_ctx.advance_to(__f.parse(__parse_ctx));
4149 _Tq& __val = *
const_cast<_Tq*
>(
static_cast<const _Td*
>(__ptr));
4150 __format_ctx.advance_to(__f.format(__val, __format_ctx));
4153 template<
typename _Tp>
4154 requires (!is_same_v<remove_cv_t<_Tp>, handle>)
4155 explicit _GLIBCXX_CONSTEXPR_FORMAT
4156 handle(_Tp& __val) noexcept
4157 : _M_ptr(__builtin_addressof(__val))
4158 , _M_func(&_S_format<__maybe_const_t<_Tp>>)
4161 friend class basic_format_arg<_Context>;
4164 handle(
const handle&) =
default;
4165 handle& operator=(
const handle&) =
default;
4167 [[__gnu__::__always_inline__]]
4168 void _GLIBCXX_CONSTEXPR_FORMAT
4169 format(basic_format_parse_context<_CharT>& __pc, _Context& __fc)
const
4170 { _M_func(__pc, __fc, this->_M_ptr); }
4185 unsigned long long _M_ull;
4188#ifndef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
4189 long double _M_ldbl;
4192 __ieee128 _M_ieee128;
4194#ifdef __SIZEOF_FLOAT128__
4195 __float128 _M_float128;
4197 const _CharT* _M_str;
4198 basic_string_view<_CharT> _M_sv;
4201#ifdef __SIZEOF_INT128__
4203 unsigned __int128 _M_u128;
4205#ifdef __BFLT16_DIG__
4219 [[__gnu__::__always_inline__]]
4220 _GLIBCXX_CONSTEXPR_FORMAT
4221 _Arg_value() : _M_none() { }
4224 template<
typename _Tp>
4225 _GLIBCXX_CONSTEXPR_FORMAT
4226 _Arg_value(in_place_type_t<_Tp>, _Tp __val)
4227 { _S_get<_Tp>() = __val; }
4232 template<
typename _Tp,
typename _Self,
typename... _Value>
4233 [[__gnu__::__always_inline__]]
4234 static _GLIBCXX_CONSTEXPR_FORMAT
auto&
4235 _S_access(_Self& __u, _Value... __value)
noexcept
4237 static_assert(
sizeof...(_Value) <= 1);
4238 if constexpr (is_same_v<_Tp, bool>)
4239 return (__u._M_bool = ... = __value);
4240 else if constexpr (is_same_v<_Tp, _CharT>)
4241 return (__u._M_c = ... = __value);
4242 else if constexpr (is_same_v<_Tp, int>)
4243 return (__u._M_i = ... = __value);
4244 else if constexpr (is_same_v<_Tp, unsigned>)
4245 return (__u._M_u = ... = __value);
4246 else if constexpr (is_same_v<_Tp, long long>)
4247 return (__u._M_ll = ... = __value);
4248 else if constexpr (is_same_v<_Tp, unsigned long long>)
4249 return (__u._M_ull = ... = __value);
4250 else if constexpr (is_same_v<_Tp, float>)
4251 return (__u._M_flt = ... = __value);
4252 else if constexpr (is_same_v<_Tp, double>)
4253 return (__u._M_dbl = ... = __value);
4254#ifndef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
4255 else if constexpr (is_same_v<_Tp, long double>)
4256 return (__u._M_ldbl = ... = __value);
4258 else if constexpr (is_same_v<_Tp, __ibm128>)
4259 return (__u._M_ibm128 = ... = __value);
4260 else if constexpr (is_same_v<_Tp, __ieee128>)
4261 return (__u._M_ieee128 = ... = __value);
4263#ifdef __SIZEOF_FLOAT128__
4264 else if constexpr (is_same_v<_Tp, __float128>)
4265 return (__u._M_float128 = ... = __value);
4267 else if constexpr (is_same_v<_Tp, const _CharT*>)
4268 return (__u._M_str = ... = __value);
4269 else if constexpr (is_same_v<_Tp, basic_string_view<_CharT>>)
4270 return (__u._M_sv = ... = __value);
4271 else if constexpr (is_same_v<_Tp, const void*>)
4272 return (__u._M_ptr = ... = __value);
4273#ifdef __SIZEOF_INT128__
4274 else if constexpr (is_same_v<_Tp, __int128>)
4275 return (__u._M_i128 = ... = __value);
4276 else if constexpr (is_same_v<_Tp, unsigned __int128>)
4277 return (__u._M_u128 = ... = __value);
4279#ifdef __BFLT16_DIG__
4280 else if constexpr (is_same_v<_Tp, __bflt16_t>)
4281 return (__u._M_bf16 = ... = __value);
4284 else if constexpr (is_same_v<_Tp, _Float16>)
4285 return (__u._M_f16 = ... = __value);
4288 else if constexpr (is_same_v<_Tp, _Float32>)
4289 return (__u._M_f32 = ... = __value);
4292 else if constexpr (is_same_v<_Tp, _Float64>)
4293 return (__u._M_f64 = ... = __value);
4295 else if constexpr (is_same_v<_Tp, handle>)
4296 return __u._M_handle;
4298 __builtin_unreachable();
4301 template<
typename _Tp>
4302 [[__gnu__::__always_inline__]]
4303 _GLIBCXX_CONSTEXPR_FORMAT
auto&
4305 {
return _S_access<_Tp>(*
this); }
4307 template<
typename _Tp>
4308 [[__gnu__::__always_inline__]]
4309 _GLIBCXX_CONSTEXPR_FORMAT
const auto&
4310 _M_get() const noexcept
4311 {
return _S_access<_Tp>(*
this); }
4313 template<
typename _Tp>
4314 [[__gnu__::__always_inline__]]
4315 _GLIBCXX_CONSTEXPR_FORMAT
void
4316 _M_set(_Tp __v)
noexcept
4319 if constexpr (is_same_v<_Tp, basic_string_view<_CharT>>)
4320 std::construct_at(&_M_sv, __v);
4321 else if constexpr (is_same_v<_Tp, handle>)
4322 std::construct_at(&_M_handle, __v);
4326 _S_access<_Tp>(*
this, __v);
4331 template<
typename _Context,
typename... _Args>
4334 template<
typename _Visitor,
typename _Ctx>
4335 _GLIBCXX_CONSTEXPR_FORMAT
decltype(
auto)
4336 __visit_format_arg(_Visitor&&, basic_format_arg<_Ctx>);
4338 template<
typename _Ch,
typename _Tp>
4340 __to_arg_t_enum() noexcept;
4344 template<typename _Context>
4345 class basic_format_arg
4347 using _CharT =
typename _Context::char_type;
4350 using handle = __format::_Arg_value<_Context>::handle;
4352 [[__gnu__::__always_inline__]]
4353 _GLIBCXX_CONSTEXPR_FORMAT
4354 basic_format_arg() noexcept : _M_type(__format::_Arg_none) { }
4356 [[nodiscard,__gnu__::__always_inline__]]
4357 explicit _GLIBCXX_CONSTEXPR_FORMAT
operator bool() const noexcept
4358 {
return _M_type != __format::_Arg_none; }
4360#if __cpp_lib_format >= 202306L
4361 template<
typename _Visitor>
4362 _GLIBCXX_CONSTEXPR_FORMAT
decltype(
auto)
4363 visit(
this basic_format_arg __arg, _Visitor&& __vis)
4366 template<
typename _Res,
typename _Visitor>
4367 _GLIBCXX_CONSTEXPR_FORMAT _Res
4368 visit(
this basic_format_arg __arg, _Visitor&& __vis)
4373 template<
typename _Ctx>
4374 friend class basic_format_args;
4376 template<
typename _Ctx,
typename... _Args>
4377 friend class __format::_Arg_store;
4379 static_assert(is_trivially_copyable_v<__format::_Arg_value<_Context>>);
4381 __format::_Arg_value<_Context> _M_val;
4382 __format::_Arg_t _M_type;
4387 template<
typename _Tp>
4388 static consteval auto
4391 using _Td = remove_const_t<_Tp>;
4392 if constexpr (is_same_v<_Td, bool>)
4393 return type_identity<bool>();
4394 else if constexpr (is_same_v<_Td, _CharT>)
4395 return type_identity<_CharT>();
4396 else if constexpr (is_same_v<_Td, char> && is_same_v<_CharT, wchar_t>)
4397 return type_identity<_CharT>();
4398#ifdef __SIZEOF_INT128__
4399 else if constexpr (is_same_v<_Td, __int128>)
4400 return type_identity<__int128>();
4401 else if constexpr (is_same_v<_Td, unsigned __int128>)
4402 return type_identity<unsigned __int128>();
4404 else if constexpr (__is_signed_integer<_Td>::value)
4406 if constexpr (
sizeof(_Td) <=
sizeof(int))
4407 return type_identity<int>();
4408 else if constexpr (
sizeof(_Td) <=
sizeof(
long long))
4409 return type_identity<long long>();
4411 else if constexpr (__is_unsigned_integer<_Td>::value)
4413 if constexpr (
sizeof(_Td) <=
sizeof(unsigned))
4414 return type_identity<unsigned>();
4415 else if constexpr (
sizeof(_Td) <=
sizeof(
unsigned long long))
4416 return type_identity<unsigned long long>();
4418 else if constexpr (is_same_v<_Td, float>)
4419 return type_identity<float>();
4420 else if constexpr (is_same_v<_Td, double>)
4421 return type_identity<double>();
4422#ifndef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
4423 else if constexpr (is_same_v<_Td, long double>)
4424 return type_identity<long double>();
4426 else if constexpr (is_same_v<_Td, __ibm128>)
4427 return type_identity<__ibm128>();
4428 else if constexpr (is_same_v<_Td, __ieee128>)
4429 return type_identity<__ieee128>();
4431#if defined(__SIZEOF_FLOAT128__) && _GLIBCXX_FORMAT_F128
4432 else if constexpr (is_same_v<_Td, __float128>)
4433 return type_identity<__float128>();
4435#if defined(__STDCPP_BFLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
4436 else if constexpr (is_same_v<_Td, __format::__bflt16_t>)
4437 return type_identity<__format::__bflt16_t>();
4439#if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
4440 else if constexpr (is_same_v<_Td, _Float16>)
4441 return type_identity<_Float16>();
4443#if defined(__FLT32_DIG__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
4444 else if constexpr (is_same_v<_Td, _Float32>)
4445 return type_identity<_Float32>();
4447#if defined(__FLT64_DIG__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
4448 else if constexpr (is_same_v<_Td, _Float64>)
4449 return type_identity<_Float64>();
4451 else if constexpr (__is_specialization_of<_Td, basic_string_view>
4452 || __is_specialization_of<_Td, basic_string>)
4454 if constexpr (is_same_v<typename _Td::value_type, _CharT>)
4455 return type_identity<basic_string_view<_CharT>>();
4457 return type_identity<handle>();
4459 else if constexpr (is_same_v<decay_t<_Td>,
const _CharT*>)
4460 return type_identity<const _CharT*>();
4461 else if constexpr (is_same_v<decay_t<_Td>, _CharT*>)
4462 return type_identity<const _CharT*>();
4463 else if constexpr (is_void_v<remove_pointer_t<_Td>>)
4464 return type_identity<const void*>();
4465 else if constexpr (is_same_v<_Td, nullptr_t>)
4466 return type_identity<const void*>();
4468 return type_identity<handle>();
4472 template<
typename _Tp>
4473 using _Normalize =
typename decltype(_S_to_arg_type<_Tp>())::type;
4476 template<
typename _Tp>
4477 static consteval __format::_Arg_t
4480 using namespace __format;
4481 if constexpr (is_same_v<_Tp, bool>)
4483 else if constexpr (is_same_v<_Tp, _CharT>)
4485 else if constexpr (is_same_v<_Tp, int>)
4487 else if constexpr (is_same_v<_Tp, unsigned>)
4489 else if constexpr (is_same_v<_Tp, long long>)
4491 else if constexpr (is_same_v<_Tp, unsigned long long>)
4493 else if constexpr (is_same_v<_Tp, float>)
4495 else if constexpr (is_same_v<_Tp, double>)
4497#ifndef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
4498 else if constexpr (is_same_v<_Tp, long double>)
4502 else if constexpr (is_same_v<_Tp, __ibm128>)
4504 else if constexpr (is_same_v<_Tp, __ieee128>)
4505 return _Arg_ieee128;
4507#if defined(__SIZEOF_FLOAT128__) && _GLIBCXX_FORMAT_F128
4508 else if constexpr (is_same_v<_Tp, __float128>)
4509 return _Arg_float128;
4511#if defined(__STDCPP_BFLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
4512 else if constexpr (is_same_v<_Tp, __format::__bflt16_t>)
4515#if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
4516 else if constexpr (is_same_v<_Tp, _Float16>)
4519#if defined(__FLT32_DIG__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
4520 else if constexpr (is_same_v<_Tp, _Float32>)
4523#if defined(__FLT64_DIG__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
4524 else if constexpr (is_same_v<_Tp, _Float64>)
4527 else if constexpr (is_same_v<_Tp, const _CharT*>)
4529 else if constexpr (is_same_v<_Tp, basic_string_view<_CharT>>)
4531 else if constexpr (is_same_v<_Tp, const void*>)
4533#ifdef __SIZEOF_INT128__
4534 else if constexpr (is_same_v<_Tp, __int128>)
4536 else if constexpr (is_same_v<_Tp, unsigned __int128>)
4539 else if constexpr (is_same_v<_Tp, handle>)
4543 template<
typename _Tp>
4544 _GLIBCXX_CONSTEXPR_FORMAT
void
4545 _M_set(_Tp __v)
noexcept
4547 _M_type = _S_to_enum<_Tp>();
4551 template<
typename _Tp>
4552 requires __format::__formattable_with<_Tp, _Context>
4553 _GLIBCXX_CONSTEXPR_FORMAT
explicit
4554 basic_format_arg(_Tp& __v)
noexcept
4556 using _Td = _Normalize<_Tp>;
4557 if constexpr (is_same_v<_Td, basic_string_view<_CharT>>)
4558 _M_set(_Td{__v.data(), __v.size()});
4559 else if constexpr (is_same_v<remove_const_t<_Tp>,
char>
4560 && is_same_v<_CharT, wchar_t>)
4561 _M_set(
static_cast<_Td
>(
static_cast<unsigned char>(__v)));
4563 _M_set(
static_cast<_Td
>(__v));
4566 template<
typename _Ctx,
typename... _Argz>
4567 friend _GLIBCXX_CONSTEXPR_FORMAT
auto
4568 make_format_args(_Argz&...)
noexcept;
4570 template<
typename _Visitor,
typename _Ctx>
4571 friend _GLIBCXX_CONSTEXPR_FORMAT
decltype(
auto)
4572 visit_format_arg(_Visitor&& __vis, basic_format_arg<_Ctx>);
4574 template<
typename _Visitor,
typename _Ctx>
4575 friend _GLIBCXX_CONSTEXPR_FORMAT
decltype(
auto)
4576 __format::__visit_format_arg(_Visitor&&, basic_format_arg<_Ctx>);
4578 template<
typename _Ch,
typename _Tp>
4579 friend consteval __format::_Arg_t
4580 __format::__to_arg_t_enum() noexcept;
4582 [[__gnu__::__noinline__]]
4584 _M_handle_unrecognized() const;
4586 template<typename _Visitor>
4587 _GLIBCXX_CONSTEXPR_FORMAT decltype(auto)
4588 _M_visit(_Visitor&& __vis)
4592 using enum __format::_Arg_t;
4607#if __glibcxx_to_chars
4612#ifndef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
4615#if defined(__SIZEOF_FLOAT128__) && _GLIBCXX_FORMAT_F128
4625#if defined(__STDCPP_BFLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
4629#if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
4633#if defined(__FLT32_DIG__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
4637#if defined(__FLT64_DIG__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
4650#ifdef __SIZEOF_INT128__
4660 handle __h = _M_handle_unrecognized();
4665 template<
typename _Visitor>
4666 _GLIBCXX_CONSTEXPR_FORMAT
decltype(
auto)
4667 _M_visit_user(_Visitor&& __vis)
4669 return _M_visit([&__vis]<
typename _Tp>(_Tp& __val) ->
decltype(
auto)
4671 constexpr bool __user_facing = __is_one_of<_Tp,
4672 monostate, bool, _CharT,
4673 int,
unsigned int,
long long int,
unsigned long long int,
4674 float, double,
long double,
4675 const _CharT*, basic_string_view<_CharT>,
4676 const void*, handle>::value;
4677 if constexpr (__user_facing)
4688 template<
typename _Visitor,
typename _Context>
4689 _GLIBCXX26_DEPRECATED_SUGGEST(
"std::basic_format_arg::visit")
4690 inline _GLIBCXX_CONSTEXPR_FORMAT decltype(auto)
4691 visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg)
4697 template<
typename _Visitor,
typename _Ctx>
4698 inline _GLIBCXX_CONSTEXPR_FORMAT
decltype(
auto)
4699 __visit_format_arg(_Visitor&& __vis, basic_format_arg<_Ctx> __arg)
4702 struct _WidthPrecVisitor
4704 template<
typename _Tp>
4705 _GLIBCXX_CONSTEXPR_FORMAT
size_t
4706 operator()(_Tp& __arg)
const
4708 if constexpr (is_same_v<_Tp, monostate>)
4709 __format::__invalid_arg_id_in_format_string();
4713 else if constexpr (
sizeof(_Tp) <=
sizeof(
long long))
4717 if constexpr (__is_unsigned_integer<_Tp>::value)
4719 else if constexpr (__is_signed_integer<_Tp>::value)
4723 __throw_format_error(
"format error: argument used for width or "
4724 "precision must be a non-negative integer");
4728#pragma GCC diagnostic push
4729#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
4730 template<
typename _Context>
4731 inline _GLIBCXX_CONSTEXPR_FORMAT
size_t
4732 __int_from_arg(
const basic_format_arg<_Context>& __arg)
4733 {
return __format::__visit_format_arg(_WidthPrecVisitor(), __arg); }
4736 template<
int _Bits,
size_t _Nm>
4738 __pack_arg_types(
const array<_Arg_t, _Nm>& __types)
4740 __UINT64_TYPE__ __packed_types = 0;
4741 for (
auto __i = __types.rbegin(); __i != __types.rend(); ++__i)
4742 __packed_types = (__packed_types << _Bits) | (
unsigned)*__i;
4743 return __packed_types;
4748 template<
typename _Context>
4749 class basic_format_args
4751 static constexpr int _S_packed_type_bits = 5;
4752 static constexpr int _S_packed_type_mask = 0b11111;
4753 static constexpr int _S_max_packed_args = 12;
4755 static_assert( (unsigned)__format::_Arg_max_ <= (1u << _S_packed_type_bits) );
4757 template<
typename... _Args>
4758 using _Store = __format::_Arg_store<_Context, _Args...>;
4760 template<
typename _Ctx,
typename... _Args>
4761 friend class __format::_Arg_store;
4763 using uint64_t = __UINT64_TYPE__;
4764 using _Format_arg = basic_format_arg<_Context>;
4765 using _Format_arg_val = __format::_Arg_value<_Context>;
4771 uint64_t _M_packed_size : 4;
4772 uint64_t _M_unpacked_size : 60;
4775 const _Format_arg_val* _M_values;
4776 const _Format_arg* _M_args;
4779 _GLIBCXX_CONSTEXPR_FORMAT
size_t
4780 _M_size() const noexcept
4781 {
return _M_packed_size ? _M_packed_size : _M_unpacked_size; }
4783 _GLIBCXX_CONSTEXPR_FORMAT
typename __format::_Arg_t
4784 _M_type(
size_t __i)
const noexcept
4786 uint64_t __t = _M_unpacked_size >> (__i * _S_packed_type_bits);
4787 return static_cast<__format::_Arg_t
>(__t & _S_packed_type_mask);
4790 template<
typename _Ctx,
typename... _Args>
4791 friend _GLIBCXX_CONSTEXPR_FORMAT
auto
4792 make_format_args(_Args&...)
noexcept;
4795 template<
typename... _Args>
4796 static consteval array<__format::_Arg_t,
sizeof...(_Args)>
4798 {
return {_Format_arg::template _S_to_enum<_Args>()...}; }
4801 template<
typename... _Args>
4802 _GLIBCXX_CONSTEXPR_FORMAT
4803 basic_format_args(
const _Store<_Args...>& __store)
noexcept;
4805 [[nodiscard,__gnu__::__always_inline__]]
4806 _GLIBCXX_CONSTEXPR_FORMAT basic_format_arg<_Context>
4807 get(
size_t __i)
const noexcept
4809 basic_format_arg<_Context> __arg;
4810 if (__i < _M_packed_size)
4812 __arg._M_type = _M_type(__i);
4813 __arg._M_val = _M_values[__i];
4815 else if (_M_packed_size == 0 && __i < _M_unpacked_size)
4816 __arg = _M_args[__i];
4823 template<
typename _Context,
typename... _Args>
4824 basic_format_args(__format::_Arg_store<_Context, _Args...>)
4825 -> basic_format_args<_Context>;
4827 template<
typename _Context,
typename... _Args>
4828 _GLIBCXX_CONSTEXPR_FORMAT
auto
4829 make_format_args(_Args&... __fmt_args)
noexcept;
4832 template<
typename _Context,
typename... _Args>
4833 class __format::_Arg_store
4835 friend std::basic_format_args<_Context>;
4837 template<
typename _Ctx,
typename... _Argz>
4838 friend _GLIBCXX_CONSTEXPR_FORMAT
auto std::
4839#if _GLIBCXX_INLINE_VERSION
4842 make_format_args(_Argz&...)
noexcept;
4846 static constexpr bool _S_values_only
4847 =
sizeof...(_Args) <= basic_format_args<_Context>::_S_max_packed_args;
4850 = __conditional_t<_S_values_only,
4851 __format::_Arg_value<_Context>,
4852 basic_format_arg<_Context>>;
4854 _Element_t _M_args[
sizeof...(_Args)];
4856 template<
typename _Tp>
4857 static _GLIBCXX_CONSTEXPR_FORMAT _Element_t
4858 _S_make_elt(_Tp& __v)
4860 using _Tq = remove_const_t<_Tp>;
4861 using _CharT =
typename _Context::char_type;
4862 static_assert(is_default_constructible_v<formatter<_Tq, _CharT>>,
4863 "std::formatter must be specialized for the type "
4864 "of each format arg");
4865 using __format::__formattable_with;
4866 if constexpr (is_const_v<_Tp>)
4867 if constexpr (!__formattable_with<_Tp, _Context>)
4868 if constexpr (__formattable_with<_Tq, _Context>)
4869 static_assert(__formattable_with<_Tp, _Context>,
4870 "format arg must be non-const because its "
4871 "std::formatter specialization has a "
4872 "non-const reference parameter");
4873 basic_format_arg<_Context> __arg(__v);
4874 if constexpr (_S_values_only)
4875 return __arg._M_val;
4880 template<
typename... _Tp>
4881 requires (
sizeof...(_Tp) ==
sizeof...(_Args))
4882 [[__gnu__::__always_inline__]]
4883 _GLIBCXX_CONSTEXPR_FORMAT
4884 _Arg_store(_Tp&... __a) noexcept
4885 : _M_args{_S_make_elt(__a)...}
4889 template<
typename _Context>
4890 class __format::_Arg_store<_Context>
4893 template<
typename _Context>
4894 template<
typename... _Args>
4895 inline _GLIBCXX_CONSTEXPR_FORMAT
4896 basic_format_args<_Context>::
4897 basic_format_args(
const _Store<_Args...>& __store)
noexcept
4899 if constexpr (
sizeof...(_Args) == 0)
4902 _M_unpacked_size = 0;
4905 else if constexpr (
sizeof...(_Args) <= _S_max_packed_args)
4908 _M_packed_size =
sizeof...(_Args);
4911 = __format::__pack_arg_types<_S_packed_type_bits>(_S_types_to_pack<_Args...>());
4913 _M_values = __store._M_args;
4920 _M_unpacked_size =
sizeof...(_Args);
4922 _M_args = __store._M_args;
4927 template<
typename _Context = format_context,
typename... _Args>
4928 [[nodiscard,__gnu__::__always_inline__]]
4929 inline _GLIBCXX_CONSTEXPR_FORMAT
auto
4930 make_format_args(_Args&... __fmt_args)
noexcept
4932 using _Fmt_arg = basic_format_arg<_Context>;
4933 using _Store = __format::_Arg_store<_Context,
typename _Fmt_arg::template
4934 _Normalize<_Args>...>;
4935 return _Store(__fmt_args...);
4938#ifdef _GLIBCXX_USE_WCHAR_T
4940 template<
typename... _Args>
4941 [[nodiscard,__gnu__::__always_inline__]]
4942 inline _GLIBCXX_CONSTEXPR_FORMAT
auto
4943 make_wformat_args(_Args&... __args)
noexcept
4944 {
return std::make_format_args<wformat_context>(__args...); }
4950 template<
typename _Out,
typename _CharT,
typename _Context>
4951 _GLIBCXX_CONSTEXPR_FORMAT _Out
4952 __do_vformat_to(_Out, basic_string_view<_CharT>,
4953 const basic_format_args<_Context>&,
4954 const locale* =
nullptr);
4956 template<
typename _CharT>
struct __formatter_chrono;
4974 template<
typename _Out,
typename _CharT>
4977 class _GLIBCXX_NO_SPECIALIZATIONS basic_format_context
4979 static_assert( output_iterator<_Out, const _CharT&> );
4981 basic_format_args<basic_format_context> _M_args;
4983 __format::_Optional_locale _M_loc;
4985 _GLIBCXX_CONSTEXPR_FORMAT
4986 basic_format_context(basic_format_args<basic_format_context> __args,
4988 : _M_args(__args), _M_out(std::move(__out))
4991 _GLIBCXX_CONSTEXPR_FORMAT
4992 basic_format_context(basic_format_args<basic_format_context> __args,
4993 _Out __out,
const std::locale& __loc)
4994 : _M_args(__args), _M_out(std::move(__out)), _M_loc(__loc)
5000 basic_format_context(
const basic_format_context&) =
delete;
5001 basic_format_context& operator=(
const basic_format_context&) =
delete;
5003 template<
typename _Out2,
typename _CharT2,
typename _Context2>
5004 friend _GLIBCXX_CONSTEXPR_FORMAT _Out2
5005 __format::__do_vformat_to(_Out2, basic_string_view<_CharT2>,
5006 const basic_format_args<_Context2>&,
5009 friend __format::__formatter_chrono<_CharT>;
5012 ~basic_format_context() =
default;
5014 using iterator = _Out;
5015 using char_type = _CharT;
5016 template<
typename _Tp>
5017 using formatter_type = formatter<_Tp, _CharT>;
5020 _GLIBCXX_CONSTEXPR_FORMAT basic_format_arg<basic_format_context>
5021 arg(
size_t __id)
const noexcept
5022 {
return _M_args.get(__id); }
5025 std::locale locale() {
return _M_loc.value(); }
5028 _GLIBCXX_CONSTEXPR_FORMAT iterator
5031 _GLIBCXX_CONSTEXPR_FORMAT
void
5032 advance_to(iterator __it) { _M_out =
std::move(__it); }
5035#if _GLIBCXX_EXTERN_TEMPLATE
5038 extern template basic_format_arg<format_context>::handle
5039 basic_format_arg<format_context>::_M_handle_unrecognized()
const;
5040# ifdef _GLIBCXX_USE_WCHAR_T
5041 extern template basic_format_arg<wformat_context>::handle
5042 basic_format_arg<wformat_context>::_M_handle_unrecognized()
const;
5045 template<
typename _Context>
5046 typename basic_format_arg<_Context>::handle
5047 basic_format_arg<_Context>::_M_handle_unrecognized()
const
5052 __throw_format_error(
"format error: unrecognized argument type");
5064 template<
typename _CharT>
5067 using iterator =
typename basic_format_parse_context<_CharT>::iterator;
5069 struct _Parse_context : basic_format_parse_context<_CharT>
5071 using basic_format_parse_context<_CharT>::basic_format_parse_context;
5072 const _Arg_t* _M_types =
nullptr;
5076 _Scanner(basic_string_view<_CharT> __str,
size_t __nargs = (
size_t)-1)
5077 : _M_pc(__str, __nargs)
5080 constexpr iterator begin() const noexcept {
return _M_pc.begin(); }
5081 constexpr iterator end() const noexcept {
return _M_pc.end(); }
5086 basic_string_view<_CharT> __fmt = _M_fmt_str();
5088 if (__fmt.size() == 2 && __fmt[0] ==
'{' && __fmt[1] ==
'}')
5090 _M_pc.advance_to(begin() + 1);
5091 _M_format_arg(_M_pc.next_arg_id());
5095 size_t __lbr = __fmt.find(
'{');
5096 size_t __rbr = __fmt.find(
'}');
5098 while (__fmt.size())
5100 auto __cmp = __lbr <=> __rbr;
5104 _M_pc.advance_to(end());
5109 if (__lbr + 1 == __fmt.size()
5110 || (__rbr == __fmt.npos && __fmt[__lbr + 1] !=
'{'))
5111 __format::__unmatched_left_brace_in_format_string();
5112 const bool __is_escape = __fmt[__lbr + 1] ==
'{';
5113 iterator __last = begin() + __lbr + int(__is_escape);
5114 _M_on_chars(__last);
5115 _M_pc.advance_to(__last + 1);
5116 __fmt = _M_fmt_str();
5119 if (__rbr != __fmt.npos)
5121 __lbr = __fmt.find(
'{');
5125 _M_on_replacement_field();
5126 __fmt = _M_fmt_str();
5127 __lbr = __fmt.find(
'{');
5128 __rbr = __fmt.find(
'}');
5133 if (++__rbr == __fmt.size() || __fmt[__rbr] !=
'}')
5134 __format::__unmatched_right_brace_in_format_string();
5135 iterator __last = begin() + __rbr;
5136 _M_on_chars(__last);
5137 _M_pc.advance_to(__last + 1);
5138 __fmt = _M_fmt_str();
5139 if (__lbr != __fmt.npos)
5141 __rbr = __fmt.find(
'}');
5146 constexpr basic_string_view<_CharT>
5147 _M_fmt_str() const noexcept
5148 {
return {begin(), end()}; }
5150 constexpr virtual void _M_on_chars(iterator) { }
5152 constexpr void _M_on_replacement_field()
5154 auto __next = begin();
5158 __id = _M_pc.next_arg_id();
5159 else if (*__next ==
':')
5161 __id = _M_pc.next_arg_id();
5162 _M_pc.advance_to(++__next);
5166 auto [__i, __ptr] = __format::__parse_arg_id(begin(), end());
5167 if (!__ptr || !(*__ptr ==
'}' || *__ptr ==
':'))
5168 __format::__invalid_arg_id_in_format_string();
5169 _M_pc.check_arg_id(__id = __i);
5172 _M_pc.advance_to(++__ptr);
5175 _M_pc.advance_to(__ptr);
5177 _M_format_arg(__id);
5178 if (begin() == end() || *begin() !=
'}')
5179 __format::__unmatched_left_brace_in_format_string();
5180 _M_pc.advance_to(begin() + 1);
5183 constexpr virtual void _M_format_arg(
size_t __id) = 0;
5187 template<
typename _Out,
typename _CharT>
5188 class _Formatting_scanner :
public _Scanner<_CharT>
5191 _GLIBCXX_CONSTEXPR_FORMAT
5192 _Formatting_scanner(basic_format_context<_Out, _CharT>& __fc,
5193 basic_string_view<_CharT> __str)
5194 : _Scanner<_CharT>(__str), _M_fc(__fc)
5198 basic_format_context<_Out, _CharT>& _M_fc;
5200 using iterator =
typename _Scanner<_CharT>::iterator;
5203 _M_on_chars(iterator __last)
override
5205 basic_string_view<_CharT> __str(this->begin(), __last);
5206 _M_fc.advance_to(__format::__write(_M_fc.out(), __str));
5210 _M_format_arg(
size_t __id)
override
5212 using _Context = basic_format_context<_Out, _CharT>;
5213 using handle =
typename basic_format_arg<_Context>::handle;
5215 __format::__visit_format_arg([
this](
auto& __arg) {
5217 using _Formatter =
typename _Context::template formatter_type<_Type>;
5218 if constexpr (is_same_v<_Type, monostate>)
5219 __format::__invalid_arg_id_in_format_string();
5220 else if constexpr (is_same_v<_Type, handle>)
5221 __arg.format(this->_M_pc, this->_M_fc);
5222 else if constexpr (is_default_constructible_v<_Formatter>)
5225 this->_M_pc.advance_to(__f.parse(this->_M_pc));
5226 this->_M_fc.advance_to(__f.format(__arg, this->_M_fc));
5229 static_assert(__format::__formattable_with<_Type, _Context>);
5230 }, _M_fc.arg(__id));
5234 template<
typename _CharT,
typename _Tp>
5236 __to_arg_t_enum() noexcept
5238 using _Context = __format::__format_context<_CharT>;
5239 using _Fmt_arg = basic_format_arg<_Context>;
5240 using _NormalizedTp =
typename _Fmt_arg::template _Normalize<_Tp>;
5241 return _Fmt_arg::template _S_to_enum<_NormalizedTp>();
5245 template<
typename _CharT,
typename... _Args>
5246 class _Checking_scanner :
public _Scanner<_CharT>
5249 (is_default_constructible_v<formatter<_Args, _CharT>> && ...),
5250 "std::formatter must be specialized for each type being formatted");
5254 _Checking_scanner(basic_string_view<_CharT> __str)
5255 : _Scanner<_CharT>(__str, sizeof...(_Args))
5257#if __cpp_lib_format >= 202305L
5258 this->_M_pc._M_types = _M_types.data();
5264 _M_format_arg(
size_t __id)
override
5266 if constexpr (
sizeof...(_Args) != 0)
5268 if (__id <
sizeof...(_Args))
5270 _M_parse_format_spec<_Args...>(__id);
5274 __builtin_unreachable();
5277 template<
typename _Tp,
typename... _OtherArgs>
5279 _M_parse_format_spec(
size_t __id)
5283 formatter<_Tp, _CharT> __f;
5284 this->_M_pc.advance_to(__f.parse(this->_M_pc));
5286 else if constexpr (
sizeof...(_OtherArgs) != 0)
5287 _M_parse_format_spec<_OtherArgs...>(__id - 1);
5289 __builtin_unreachable();
5292#if __cpp_lib_format >= 202305L
5293 array<_Arg_t,
sizeof...(_Args)>
5294 _M_types{ { __format::__to_arg_t_enum<_CharT, _Args>()... } };
5298 template<typename _CharT, unsigned = __unicode::__literal_encoding_is_unicode<_CharT>()>
5299 _GLIBCXX_CONSTEXPR_FORMAT _Sink_iter<_CharT>
5300 __do_vformat_to(_Sink_iter<_CharT> __out, basic_string_view<_CharT> __fmt,
5301 __format_context<_CharT>& __ctx)
5303 if constexpr (is_same_v<_CharT, char>)
5305 if (__fmt.size() == 2 && __fmt[0] ==
'{' && __fmt[1] ==
'}')
5307 bool __done =
false;
5308 __format::__visit_format_arg([&](
auto& __arg) {
5309 using _Tp = remove_cvref_t<
decltype(__arg)>;
5310 if constexpr (is_same_v<_Tp, bool>)
5312 size_t __len = 4 + !__arg;
5313 const char* __chars[] = {
"false",
"true" };
5314 if (
auto __res = __out._M_reserve(__len))
5316 ranges::copy_n(__chars[__arg], __len, __res.get());
5317 __res._M_bump(__len);
5321 else if constexpr (is_same_v<_Tp, char>)
5323 if (
auto __res = __out._M_reserve(1))
5325 *__res.get() = __arg;
5330 else if constexpr (is_integral_v<_Tp>)
5332 make_unsigned_t<_Tp> __uval;
5333 const bool __neg = __arg < 0;
5335 __uval = make_unsigned_t<_Tp>(~__arg) + 1u;
5338 const auto __n = __detail::__to_chars_len(__uval);
5339 if (
auto __res = __out._M_reserve(__n + __neg))
5341 auto __ptr = __res.get();
5343 __detail::__to_chars_10_impl(__ptr + (
int)__neg, __n,
5345 __res._M_bump(__n + __neg);
5349 else if constexpr (is_convertible_v<_Tp, string_view>)
5351 string_view __sv = __arg;
5352 if (
auto __res = __out._M_reserve(__sv.size()))
5354 ranges::copy(__sv, __res.get());
5355 __res._M_bump(__sv.size());
5365 _Formatting_scanner<_Sink_iter<_CharT>, _CharT> __scanner(__ctx, __fmt);
5366 __scanner._M_scan();
5375#if __cplusplus <= 202002L && _GLIBCXX_EXTERN_TEMPLATE
5376 extern template _Sink_iter<char>
5377 __do_vformat_to<char, 1>(_Sink_iter<char>, string_view,
5379# ifdef _GLIBCXX_USE_WCHAR_T
5380 extern template _Sink_iter<wchar_t>
5381 __do_vformat_to<wchar_t, 1>(_Sink_iter<wchar_t>, wstring_view,
5386 template<
typename _Out,
typename _CharT,
typename _Context>
5387 inline _GLIBCXX_CONSTEXPR_FORMAT _Out
5388 __do_vformat_to(_Out __out, basic_string_view<_CharT> __fmt,
5389 const basic_format_args<_Context>& __args,
5390 const locale* __loc)
5392 if constexpr (is_same_v<_Out, _Sink_iter<_CharT>>)
5394 auto __ctx = __loc ==
nullptr
5395 ? _Context(__args, __out)
5396 : _Context(__args, __out, *__loc);
5397 return __format::__do_vformat_to(__out, __fmt, __ctx);
5399 else if constexpr (__contiguous_char_iter<_CharT, _Out>)
5401 _Ptr_sink<_CharT> __sink(__out);
5402 __format::__do_vformat_to(__sink.out(), __fmt, __args, __loc);
5403 return std::move(__sink)._M_finish(__out).out;
5407 _Iter_sink<_CharT, _Out> __sink(
std::move(__out));
5408 __format::__do_vformat_to(__sink.out(), __fmt, __args, __loc);
5409 return std::move(__sink)._M_finish().out;
5413 template<
typename _Out,
typename _CharT>
5414 inline _GLIBCXX_CONSTEXPR_FORMAT format_to_n_result<_Out>
5415 __do_vformat_to_n(_Out __out, iter_difference_t<_Out> __n,
5416 basic_string_view<_CharT> __fmt,
5417 const type_identity_t<
5418 basic_format_args<__format_context<_CharT>>>& __args,
5419 const locale* __loc =
nullptr)
5421 if constexpr (__contiguous_char_iter<_CharT, _Out>)
5423 _Ptr_sink<_CharT> __sink(__out, __n);
5424 __format::__do_vformat_to(__sink.out(), __fmt, __args, __loc);
5425 return std::move(__sink)._M_finish(__out);
5429 _Iter_sink<_CharT, _Out> __sink(
std::move(__out), __n);
5430 __format::__do_vformat_to(__sink.out(), __fmt, __args, __loc);
5435#pragma GCC diagnostic pop
5440#if __cpp_lib_format >= 202305L
5443 template<
typename _CharT>
5444 template<
typename... _Ts>
5446 basic_format_parse_context<_CharT>::
5447 __check_dynamic_spec(
size_t __id)
noexcept
5449 if (__id >= _M_num_args)
5450 __format::__invalid_arg_id_in_format_string();
5451 if constexpr (
sizeof...(_Ts) != 0)
5453 using _Parse_ctx = __format::_Scanner<_CharT>::_Parse_context;
5454 auto* __args =
static_cast<_Parse_ctx*
>(
this)->_M_types;
5459 auto __arg = __args[__id];
5460 __format::_Arg_t __types[] = {
5461 __format::__to_arg_t_enum<_CharT, _Ts>()...
5463 for (
auto __t : __types)
5467 __invalid_dynamic_spec(
"arg(id) type does not match");
5472 template<
typename _CharT,
typename... _Args>
5473 template<
typename _Tp>
5474 requires convertible_to<const _Tp&, basic_string_view<_CharT>>
5476 basic_format_string<_CharT, _Args...>::
5477 basic_format_string(
const _Tp& __s) noexcept
5480 __format::_Checking_scanner<_CharT, remove_cvref_t<_Args>...>
5482 __scanner._M_scan();
5487 template<
typename _Out>
requires output_iterator<_Out, const char&>
5488 [[__gnu__::__always_inline__]]
5489 inline _GLIBCXX_CONSTEXPR_FORMAT _Out
5490 vformat_to(_Out __out, string_view __fmt, format_args __args)
5491 {
return __format::__do_vformat_to(
std::move(__out), __fmt, __args); }
5493#ifdef _GLIBCXX_USE_WCHAR_T
5494 template<
typename _Out>
requires output_iterator<_Out, const wchar_t&>
5495 [[__gnu__::__always_inline__]]
5496 inline _GLIBCXX_CONSTEXPR_FORMAT _Out
5497 vformat_to(_Out __out, wstring_view __fmt, wformat_args __args)
5498 {
return __format::__do_vformat_to(
std::move(__out), __fmt, __args); }
5501 template<
typename _Out>
requires output_iterator<_Out, const char&>
5502 [[__gnu__::__always_inline__]]
5504 vformat_to(_Out __out,
const locale& __loc, string_view __fmt,
5507 return __format::__do_vformat_to(
std::move(__out), __fmt, __args, &__loc);
5510#ifdef _GLIBCXX_USE_WCHAR_T
5511 template<
typename _Out>
requires output_iterator<_Out, const wchar_t&>
5512 [[__gnu__::__always_inline__]]
5514 vformat_to(_Out __out,
const locale& __loc, wstring_view __fmt,
5515 wformat_args __args)
5517 return __format::__do_vformat_to(
std::move(__out), __fmt, __args, &__loc);
5522 inline _GLIBCXX_CONSTEXPR_FORMAT
string
5523 vformat(string_view __fmt, format_args __args)
5525 __format::_Str_sink<char> __buf;
5526 std::vformat_to(__buf.out(), __fmt, __args);
5530#ifdef _GLIBCXX_USE_WCHAR_T
5532 inline _GLIBCXX_CONSTEXPR_FORMAT wstring
5533 vformat(wstring_view __fmt, wformat_args __args)
5535 __format::_Str_sink<wchar_t> __buf;
5536 std::vformat_to(__buf.out(), __fmt, __args);
5543 vformat(
const locale& __loc, string_view __fmt, format_args __args)
5545 __format::_Str_sink<char> __buf;
5546 std::vformat_to(__buf.out(), __loc, __fmt, __args);
5550#ifdef _GLIBCXX_USE_WCHAR_T
5553 vformat(
const locale& __loc, wstring_view __fmt, wformat_args __args)
5555 __format::_Str_sink<wchar_t> __buf;
5556 std::vformat_to(__buf.out(), __loc, __fmt, __args);
5561 template<
typename... _Args>
5563 inline _GLIBCXX_CONSTEXPR_FORMAT
string
5564 format(format_string<_Args...> __fmt, _Args&&... __args)
5565 {
return std::vformat(__fmt.get(), std::make_format_args(__args...)); }
5567#ifdef _GLIBCXX_USE_WCHAR_T
5568 template<
typename... _Args>
5570 inline _GLIBCXX_CONSTEXPR_FORMAT wstring
5571 format(wformat_string<_Args...> __fmt, _Args&&... __args)
5572 {
return std::vformat(__fmt.get(), std::make_wformat_args(__args...)); }
5575 template<
typename... _Args>
5578 format(
const locale& __loc, format_string<_Args...> __fmt,
5581 return std::vformat(__loc, __fmt.get(),
5582 std::make_format_args(__args...));
5585#ifdef _GLIBCXX_USE_WCHAR_T
5586 template<
typename... _Args>
5589 format(
const locale& __loc, wformat_string<_Args...> __fmt,
5592 return std::vformat(__loc, __fmt.get(),
5593 std::make_wformat_args(__args...));
5597 template<
typename _Out,
typename... _Args>
5598 requires output_iterator<_Out, const char&>
5599 inline _GLIBCXX_CONSTEXPR_FORMAT _Out
5600 format_to(_Out __out, format_string<_Args...> __fmt, _Args&&... __args)
5602 return std::vformat_to(
std::move(__out), __fmt.get(),
5603 std::make_format_args(__args...));
5606#ifdef _GLIBCXX_USE_WCHAR_T
5607 template<
typename _Out,
typename... _Args>
5608 requires output_iterator<_Out, const wchar_t&>
5609 inline _GLIBCXX_CONSTEXPR_FORMAT _Out
5610 format_to(_Out __out, wformat_string<_Args...> __fmt, _Args&&... __args)
5612 return std::vformat_to(
std::move(__out), __fmt.get(),
5613 std::make_wformat_args(__args...));
5617 template<
typename _Out,
typename... _Args>
5618 requires output_iterator<_Out, const char&>
5620 format_to(_Out __out,
const locale& __loc, format_string<_Args...> __fmt,
5623 return std::vformat_to(
std::move(__out), __loc, __fmt.get(),
5624 std::make_format_args(__args...));
5627#ifdef _GLIBCXX_USE_WCHAR_T
5628 template<
typename _Out,
typename... _Args>
5629 requires output_iterator<_Out, const wchar_t&>
5631 format_to(_Out __out,
const locale& __loc, wformat_string<_Args...> __fmt,
5634 return std::vformat_to(
std::move(__out), __loc, __fmt.get(),
5635 std::make_wformat_args(__args...));
5639 template<
typename _Out,
typename... _Args>
5640 requires output_iterator<_Out, const char&>
5641 inline _GLIBCXX_CONSTEXPR_FORMAT format_to_n_result<_Out>
5642 format_to_n(_Out __out, iter_difference_t<_Out> __n,
5643 format_string<_Args...> __fmt, _Args&&... __args)
5645 return __format::__do_vformat_to_n(
5647 std::make_format_args(__args...));
5650#ifdef _GLIBCXX_USE_WCHAR_T
5651 template<
typename _Out,
typename... _Args>
5652 requires output_iterator<_Out, const wchar_t&>
5653 inline _GLIBCXX_CONSTEXPR_FORMAT format_to_n_result<_Out>
5654 format_to_n(_Out __out, iter_difference_t<_Out> __n,
5655 wformat_string<_Args...> __fmt, _Args&&... __args)
5657 return __format::__do_vformat_to_n(
5659 std::make_wformat_args(__args...));
5663 template<
typename _Out,
typename... _Args>
5664 requires output_iterator<_Out, const char&>
5665 inline format_to_n_result<_Out>
5666 format_to_n(_Out __out, iter_difference_t<_Out> __n,
const locale& __loc,
5667 format_string<_Args...> __fmt, _Args&&... __args)
5669 return __format::__do_vformat_to_n(
5671 std::make_format_args(__args...), &__loc);
5674#ifdef _GLIBCXX_USE_WCHAR_T
5675 template<
typename _Out,
typename... _Args>
5676 requires output_iterator<_Out, const wchar_t&>
5677 inline format_to_n_result<_Out>
5678 format_to_n(_Out __out, iter_difference_t<_Out> __n,
const locale& __loc,
5679 wformat_string<_Args...> __fmt, _Args&&... __args)
5681 return __format::__do_vformat_to_n(
5683 std::make_wformat_args(__args...), &__loc);
5691 template<
typename _CharT>
5692 class _Counting_sink final :
public _Ptr_sink<_CharT>
5695 _GLIBCXX_CONSTEXPR_FORMAT
5696 _Counting_sink() : _Ptr_sink<_CharT>(nullptr, 0) { }
5698 [[__gnu__::__always_inline__]]
5699 _GLIBCXX_CONSTEXPR_FORMAT
size_t
5701 {
return this->_M_count + this->_M_used().size(); }
5704 template<
typename _CharT>
5705 class _Counting_sink :
public _Buf_sink<_CharT>
5707 size_t _M_count = 0;
5710 _M_overflow()
override
5712 if (!std::is_constant_evaluated())
5713 _M_count += this->_M_used().size();
5718 _Counting_sink() =
default;
5720 [[__gnu__::__always_inline__]]
5724 _Counting_sink::_M_overflow();
5732 template<
typename... _Args>
5734 inline _GLIBCXX_CONSTEXPR_FORMAT
size_t
5735 formatted_size(format_string<_Args...> __fmt, _Args&&... __args)
5737 __format::_Counting_sink<char> __buf;
5738 std::vformat_to(__buf.out(), __fmt.get(),
5739 std::make_format_args(__args...));
5740 return __buf.count();
5743#ifdef _GLIBCXX_USE_WCHAR_T
5744 template<
typename... _Args>
5746 inline _GLIBCXX_CONSTEXPR_FORMAT
size_t
5747 formatted_size(wformat_string<_Args...> __fmt, _Args&&... __args)
5749 __format::_Counting_sink<wchar_t> __buf;
5750 std::vformat_to(__buf.out(), __fmt.get(),
5751 std::make_wformat_args(__args...));
5752 return __buf.count();
5756 template<
typename... _Args>
5759 formatted_size(
const locale& __loc, format_string<_Args...> __fmt,
5762 __format::_Counting_sink<char> __buf;
5763 std::vformat_to(__buf.out(), __loc, __fmt.get(),
5764 std::make_format_args(__args...));
5765 return __buf.count();
5768#ifdef _GLIBCXX_USE_WCHAR_T
5769 template<
typename... _Args>
5772 formatted_size(
const locale& __loc, wformat_string<_Args...> __fmt,
5775 __format::_Counting_sink<wchar_t> __buf;
5776 std::vformat_to(__buf.out(), __loc, __fmt.get(),
5777 std::make_wformat_args(__args...));
5778 return __buf.count();
5782#if __glibcxx_format_ranges
5784 template<typename _Tp>
5785 consteval range_format
5788 using _Ref = ranges::range_reference_t<_Tp>;
5789 if constexpr (is_same_v<remove_cvref_t<_Ref>, _Tp>)
5790 return range_format::disabled;
5791 else if constexpr (
requires {
typename _Tp::key_type; })
5793 if constexpr (
requires {
typename _Tp::mapped_type; })
5795 using _Up = remove_cvref_t<_Ref>;
5796 if constexpr (__is_pair<_Up>)
5797 return range_format::map;
5798 else if constexpr (__is_specialization_of<_Up, tuple>)
5799 if constexpr (tuple_size_v<_Up> == 2)
5800 return range_format::map;
5802 return range_format::set;
5805 return range_format::sequence;
5810 template<ranges::input_range _Rg>
requires same_as<_Rg, remove_cvref_t<_Rg>>
5811 constexpr range_format format_kind<_Rg> = __fmt_kind<_Rg>();
5816 template<
typename _CharT,
typename _Out,
typename _Callback>
5817 _GLIBCXX_CONSTEXPR_FORMAT
5818 typename basic_format_context<_Out, _CharT>::iterator
5819 __format_padded(basic_format_context<_Out, _CharT>& __fc,
5820 const _Spec<_CharT>& __spec,
5823 if constexpr (is_same_v<_Out, _Drop_iter<_CharT>>)
5829 static_assert(is_same_v<_Out, _Sink_iter<_CharT>>);
5831 const size_t __padwidth = __spec._M_get_width(__fc);
5832 if (__padwidth == 0)
5833 return __call(__fc);
5837 _GLIBCXX_CONSTEXPR_FORMAT
5838 _Restore_out(basic_format_context<_Sink_iter<_CharT>, _CharT>& __fc)
5839 : _M_ctx(std::
addressof(__fc)), _M_out(__fc.out())
5842 _GLIBCXX_CONSTEXPR_FORMAT
void
5844 { _M_ctx =
nullptr; }
5846 _GLIBCXX_CONSTEXPR_FORMAT
5850 _M_ctx->advance_to(_M_out);
5854 basic_format_context<_Sink_iter<_CharT>, _CharT>* _M_ctx;
5855 _Sink_iter<_CharT> _M_out;
5858 _Restore_out __restore(__fc);
5859 _Padding_sink<_Sink_iter<_CharT>, _CharT> __sink(__fc.out(), __padwidth);
5860 __fc.advance_to(__sink.out());
5862 __fc.advance_to(__sink._M_finish(__spec._M_align, __spec._M_fill));
5863 __restore._M_disarm();
5868 template<
size_t _Pos,
typename _Tp,
typename _CharT>
5869 struct __indexed_formatter_storage
5876 basic_format_parse_context<_CharT> __pc({});
5877 if (_M_formatter.parse(__pc) != __pc.end())
5878 __format::__failed_to_parse_format_spec();
5881 template<
typename _Out>
5882 _GLIBCXX_CONSTEXPR_FORMAT
void
5883 _M_format(__maybe_const<_Tp, _CharT>& __elem,
5884 basic_format_context<_Out, _CharT>& __fc,
5885 basic_string_view<_CharT> __sep)
const
5887 if constexpr (_Pos != 0)
5888 __fc.advance_to(__format::__write(__fc.out(), __sep));
5889 __fc.advance_to(_M_formatter.format(__elem, __fc));
5892 [[__gnu__::__always_inline__]]
5896 if constexpr (__has_debug_format<formatter<_Tp, _CharT>>)
5897 _M_formatter.set_debug_format();
5901 formatter<_Tp, _CharT> _M_formatter;
5904 template<
typename _CharT,
typename... _Tps>
5905 class __tuple_formatter
5907 using _String_view = basic_string_view<_CharT>;
5908 using _Seps = __format::_Separators<_CharT>;
5912 set_separator(basic_string_view<_CharT> __sep)
noexcept
5916 set_brackets(basic_string_view<_CharT> __open,
5917 basic_string_view<_CharT> __close)
noexcept
5925 constexpr typename basic_format_parse_context<_CharT>::iterator
5926 parse(basic_format_parse_context<_CharT>& __pc)
5928 auto __first = __pc.begin();
5929 const auto __last = __pc.end();
5930 __format::_Spec<_CharT> __spec{};
5932 auto __finished = [&]
5934 if (__first != __last && *__first !=
'}')
5938 _M_felems._M_parse();
5939 _M_felems.set_debug_format();
5946 __first = __spec._M_parse_fill_and_align(__first, __last,
"{:");
5950 __first = __spec._M_parse_width(__first, __last, __pc);
5954 if (*__first ==
'n')
5957 _M_open = _M_close = _String_view();
5959 else if (*__first ==
'm')
5962 if constexpr (
sizeof...(_Tps) == 2)
5964 _M_sep = _Seps::_S_colon();
5965 _M_open = _M_close = _String_view();
5968 __throw_format_error(
"format error: 'm' specifier requires range"
5969 " of pair or tuple of two elements");
5975 __format::__failed_to_parse_format_spec();
5979 template<
typename _Tuple,
typename _Out,
size_t... _Ids>
5980 _GLIBCXX_CONSTEXPR_FORMAT
5981 typename basic_format_context<_Out, _CharT>::iterator
5982 _M_format(_Tuple& __tuple, index_sequence<_Ids...>,
5983 basic_format_context<_Out, _CharT>& __fc)
const
5984 {
return _M_format_elems(std::get<_Ids>(__tuple)..., __fc); }
5986 template<
typename _Out>
5987 _GLIBCXX_CONSTEXPR_FORMAT
5988 typename basic_format_context<_Out, _CharT>::iterator
5989 _M_format_elems(__maybe_const<_Tps, _CharT>&... __elems,
5990 basic_format_context<_Out, _CharT>& __fc)
const
5992 return __format::__format_padded(
5994 [
this, &__elems...](basic_format_context<_Out, _CharT>& __nfc)
5996 __nfc.advance_to(__format::__write(__nfc.out(), _M_open));
5997 _M_felems._M_format(__elems..., __nfc, _M_sep);
5998 return __format::__write(__nfc.out(), _M_close);
6003 template<
size_t... _Ids>
6004 struct __formatters_storage
6005 : __indexed_formatter_storage<_Ids, _Tps, _CharT>...
6007 template<
size_t _Id,
typename _Up>
6008 using _Base = __indexed_formatter_storage<_Id, _Up, _CharT>;
6013 (_Base<_Ids, _Tps>::_M_parse(), ...);
6016 template<
typename _Out>
6017 _GLIBCXX_CONSTEXPR_FORMAT
void
6018 _M_format(__maybe_const<_Tps, _CharT>&... __elems,
6019 basic_format_context<_Out, _CharT>& __fc,
6020 _String_view __sep)
const
6022 (_Base<_Ids, _Tps>::_M_format(__elems, __fc, __sep), ...);
6028 (_Base<_Ids, _Tps>::set_debug_format(), ...);
6032 template<
size_t... _Ids>
6033 static _GLIBCXX_CONSTEXPR_FORMAT
auto
6034 _S_create_storage(index_sequence<_Ids...>)
6035 -> __formatters_storage<_Ids...>;
6037 =
decltype(_S_create_storage(index_sequence_for<_Tps...>()));
6039 _Spec<_CharT> _M_spec{};
6040 _String_view _M_open = _Seps::_S_parens().substr(0, 1);
6041 _String_view _M_close = _Seps::_S_parens().substr(1, 1);
6042 _String_view _M_sep = _Seps::_S_comma();
6043 _Formatters _M_felems;
6046 template<
typename _Tp>
6047 concept __is_map_formattable
6048 = __is_pair<_Tp> || (__is_tuple_v<_Tp> && tuple_size_v<_Tp> == 2);
6054 template<__format::__
char _CharT, formattable<_CharT> _Fp,
6055 formattable<_CharT> _Sp>
6056 struct formatter<
pair<_Fp, _Sp>, _CharT>
6057 : __format::__tuple_formatter<_CharT, remove_cvref_t<_Fp>,
6058 remove_cvref_t<_Sp>>
6061 using __maybe_const_pair
6062 = __conditional_t<formattable<const _Fp, _CharT>
6063 && formattable<const _Sp, _CharT>,
6064 const pair<_Fp, _Sp>, pair<_Fp, _Sp>>;
6068 template<
typename _Out>
6069 _GLIBCXX_CONSTEXPR_FORMAT
6070 typename basic_format_context<_Out, _CharT>::iterator
6071 format(__maybe_const_pair& __p,
6072 basic_format_context<_Out, _CharT>& __fc)
const
6073 {
return this->_M_format_elems(__p.first, __p.second, __fc); }
6076#if __glibcxx_print >= 202406L
6079 template<
typename _Fp,
typename _Sp>
6080 constexpr bool enable_nonlocking_formatter_optimization<pair<_Fp, _Sp>>
6081 = enable_nonlocking_formatter_optimization<remove_cvref_t<_Fp>>
6082 && enable_nonlocking_formatter_optimization<remove_cvref_t<_Sp>>;
6085 template<__format::__
char _CharT, formattable<_CharT>... _Tps>
6086 struct formatter<tuple<_Tps...>, _CharT>
6087 : __format::__tuple_formatter<_CharT, remove_cvref_t<_Tps>...>
6090 using __maybe_const_tuple
6091 = __conditional_t<(formattable<const _Tps, _CharT> && ...),
6092 const tuple<_Tps...>, tuple<_Tps...>>;
6096 template<
typename _Out>
6097 _GLIBCXX_CONSTEXPR_FORMAT
6098 typename basic_format_context<_Out, _CharT>::iterator
6099 format(__maybe_const_tuple& __t,
6100 basic_format_context<_Out, _CharT>& __fc)
const
6101 {
return this->_M_format(__t, index_sequence_for<_Tps...>(), __fc); }
6104#if __glibcxx_print >= 202406L
6107 template<
typename... _Tps>
6108 constexpr bool enable_nonlocking_formatter_optimization<tuple<_Tps...>>
6109 = (enable_nonlocking_formatter_optimization<remove_cvref_t<_Tps>> && ...);
6113 template<
typename _Tp, __format::__
char _CharT>
6114 requires same_as<remove_cvref_t<_Tp>, _Tp> && formattable<_Tp, _CharT>
6115 class range_formatter
6117 using _String_view = basic_string_view<_CharT>;
6118 using _Seps = __format::_Separators<_CharT>;
6122 set_separator(basic_string_view<_CharT> __sep)
noexcept
6126 set_brackets(basic_string_view<_CharT> __open,
6127 basic_string_view<_CharT> __close)
noexcept
6133 constexpr formatter<_Tp, _CharT>&
6134 underlying() noexcept
6137 constexpr const formatter<_Tp, _CharT>&
6138 underlying() const noexcept
6143 constexpr typename basic_format_parse_context<_CharT>::iterator
6144 parse(basic_format_parse_context<_CharT>& __pc)
6146 auto __first = __pc.begin();
6147 const auto __last = __pc.end();
6148 __format::_Spec<_CharT> __spec{};
6149 bool __no_brace =
false;
6151 auto __finished = [&]
6152 {
return __first == __last || *__first ==
'}'; };
6154 auto __finalize = [&]
6160 auto __parse_val = [&](_String_view __nfs = _String_view())
6164 basic_format_parse_context<_CharT> __npc(__nfs);
6165 if (_M_fval.parse(__npc) != __npc.end())
6166 __format::__failed_to_parse_format_spec();
6167 if constexpr (__format::__has_debug_format<formatter<_Tp, _CharT>>)
6168 _M_fval.set_debug_format();
6169 return __finalize();
6173 return __parse_val();
6175 __first = __spec._M_parse_fill_and_align(__first, __last,
"{:");
6177 return __parse_val();
6179 __first = __spec._M_parse_width(__first, __last, __pc);
6181 return __parse_val();
6183 if (*__first ==
'?')
6186 __spec._M_debug =
true;
6187 if (__finished() || *__first !=
's')
6188 __throw_format_error(
"format error: '?' is allowed only in"
6189 " combination with 's'");
6192 if (*__first ==
's')
6195 if constexpr (same_as<_Tp, _CharT>)
6197 __spec._M_type = __format::_Pres_s;
6199 return __finalize();
6200 __throw_format_error(
"format error: element format specifier"
6201 " cannot be provided when 's' specifier is used");
6204 __throw_format_error(
"format error: 's' specifier requires"
6205 " range of character types");
6209 return __parse_val();
6211 if (*__first ==
'n')
6214 _M_open = _M_close = _String_view();
6219 return __parse_val();
6221 if (*__first ==
'm')
6223 _String_view __m(__first, 1);
6225 if constexpr (__format::__is_map_formattable<_Tp>)
6227 _M_sep = _Seps::_S_comma();
6230 _M_open = _Seps::_S_braces().substr(0, 1);
6231 _M_close = _Seps::_S_braces().substr(1, 1);
6234 return __parse_val(__m);
6235 __throw_format_error(
"format error: element format specifier"
6236 " cannot be provided when 'm' specifier is used");
6239 __throw_format_error(
"format error: 'm' specifier requires"
6240 " range of pairs or tuples of two elements");
6244 return __parse_val();
6246 if (*__first ==
':')
6248 __pc.advance_to(++__first);
6249 __first = _M_fval.parse(__pc);
6253 return __finalize();
6255 __format::__failed_to_parse_format_spec();
6260 template<ranges::input_range _Rg,
typename _Out>
6261 requires formattable<ranges::range_reference_t<_Rg>, _CharT> &&
6262 same_as<remove_cvref_t<ranges::range_reference_t<_Rg>>, _Tp>
6263 _GLIBCXX_CONSTEXPR_FORMAT
6264 typename basic_format_context<_Out, _CharT>::iterator
6265 format(_Rg&& __rg, basic_format_context<_Out, _CharT>& __fc)
const
6267 using _Range = remove_reference_t<_Rg>;
6268 if constexpr (ranges::contiguous_range<_Rg>)
6270 const span<__format::__maybe_const<_Tp, _CharT>>
6271 __spn(ranges::data(__rg),
size_t(ranges::distance(__rg)));
6272 return _M_format(__spn, __fc);
6274 else if constexpr (__format::__simply_formattable_range<_Range, _CharT>)
6275 return _M_format<const _Range>(__rg, __fc);
6277 return _M_format(__rg, __fc);
6281 template<ranges::input_range _Rg,
typename _Out>
6282 _GLIBCXX_CONSTEXPR_FORMAT
6283 typename basic_format_context<_Out, _CharT>::iterator
6284 _M_format(_Rg& __rg, basic_format_context<_Out, _CharT>& __fc)
const
6286 if constexpr (same_as<_Tp, _CharT>)
6287 if (_M_spec._M_type == __format::_Pres_s)
6289 __format::__formatter_str __fstr(_M_spec);
6290 return __fstr._M_format_range(__rg, __fc);
6292 return __format::__format_padded(
6294 [
this, &__rg](basic_format_context<_Out, _CharT>& __nfc)
6295 {
return _M_format_elems(__rg, __nfc); });
6299 template<ranges::input_range _Rg,
typename _Out>
6300 _GLIBCXX_CONSTEXPR_FORMAT
6301 typename basic_format_context<_Out, _CharT>::iterator
6302 _M_format_elems(_Rg& __rg,
6303 basic_format_context<_Out, _CharT>& __fc)
const
6305 auto __out = __format::__write(__fc.out(), _M_open);
6307 auto __first = ranges::begin(__rg);
6308 auto const __last = ranges::end(__rg);
6309 if (__first == __last)
6310 return __format::__write(__out, _M_close);
6312 __fc.advance_to(__out);
6313 __out = _M_fval.format(*__first, __fc);
6314 for (++__first; __first != __last; ++__first)
6316 __out = __format::__write(__out, _M_sep);
6317 __fc.advance_to(__out);
6318 __out = _M_fval.format(*__first, __fc);
6321 return __format::__write(__out, _M_close);
6324 __format::_Spec<_CharT> _M_spec{};
6325 _String_view _M_open = _Seps::_S_squares().substr(0, 1);
6326 _String_view _M_close = _Seps::_S_squares().substr(1, 1);
6327 _String_view _M_sep = _Seps::_S_comma();
6328 formatter<_Tp, _CharT> _M_fval;
6336 template<ranges::input_range _Rg, __format::__
char _CharT>
6337 requires (format_kind<_Rg> != range_format::disabled)
6338 && formattable<ranges::range_reference_t<_Rg>, _CharT>
6339 struct formatter<_Rg, _CharT>
6342 static const bool _S_range_format_is_string =
6343 (format_kind<_Rg> == range_format::string)
6344 || (format_kind<_Rg> == range_format::debug_string);
6345 using _Vt = remove_cvref_t<
6346 ranges::range_reference_t<
6347 __format::__maybe_const_range<_Rg, _CharT>>>;
6349 static consteval bool _S_is_correct()
6351 if constexpr (_S_range_format_is_string)
6352 static_assert(same_as<_Vt, _CharT>);
6356 static_assert(_S_is_correct());
6359 constexpr formatter() noexcept
6361 using _Seps = __format::_Separators<_CharT>;
6362 if constexpr (format_kind<_Rg> == range_format::map)
6364 static_assert(__format::__is_map_formattable<_Vt>);
6365 _M_under.set_brackets(_Seps::_S_braces().substr(0, 1),
6366 _Seps::_S_braces().substr(1, 1));
6367 _M_under.underlying().set_brackets({}, {});
6368 _M_under.underlying().set_separator(_Seps::_S_colon());
6370 else if constexpr (format_kind<_Rg> == range_format::set)
6371 _M_under.set_brackets(_Seps::_S_braces().substr(0, 1),
6372 _Seps::_S_braces().substr(1, 1));
6376 set_separator(basic_string_view<_CharT> __sep)
noexcept
6377 requires (format_kind<_Rg> == range_format::sequence)
6378 { _M_under.set_separator(__sep); }
6381 set_brackets(basic_string_view<_CharT> __open,
6382 basic_string_view<_CharT> __close)
noexcept
6383 requires (format_kind<_Rg> == range_format::sequence)
6384 { _M_under.set_brackets(__open, __close); }
6388 constexpr typename basic_format_parse_context<_CharT>::iterator
6389 parse(basic_format_parse_context<_CharT>& __pc)
6391 auto __res = _M_under.parse(__pc);
6392 if constexpr (format_kind<_Rg> == range_format::debug_string)
6393 _M_under.set_debug_format();
6399 template<
typename _Out>
6400 _GLIBCXX_CONSTEXPR_FORMAT
6401 typename basic_format_context<_Out, _CharT>::iterator
6402 format(__format::__maybe_const_range<_Rg, _CharT>& __rg,
6403 basic_format_context<_Out, _CharT>& __fc)
const
6405 if constexpr (_S_range_format_is_string)
6406 return _M_under._M_format_range(__rg, __fc);
6408 return _M_under.format(__rg, __fc);
6412 using _Formatter_under
6413 = __conditional_t<_S_range_format_is_string,
6414 __format::__formatter_str<_CharT>,
6415 range_formatter<_Vt, _CharT>>;
6416 _Formatter_under _M_under;
6419#if __glibcxx_print >= 202406L
6420 template<ranges::input_range _Rg>
6421 requires (format_kind<_Rg> != range_format::disabled)
6422 constexpr bool enable_nonlocking_formatter_optimization<_Rg> =
false;
6426#undef _GLIBCXX_WIDEN
6427#undef _GLIBCXX_CONSTEXPR_FORMAT
6429_GLIBCXX_END_NAMESPACE_VERSION
6432#pragma GCC diagnostic pop
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
_Tp arg(const complex< _Tp > &)
Return phase angle of z.
constexpr _Tp * to_address(_Tp *__ptr) noexcept
Obtain address referenced by a pointer to an object.
typename remove_reference< _Tp >::type remove_reference_t
Alias template for remove_reference.
pair(_T1, _T2) -> pair< _T1, _T2 >
Two pairs are equal iff their members are equal.
constexpr _Tp * addressof(_Tp &__r) noexcept
Returns the actual address of the object or function referenced by r, even in the presence of an over...
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
const _Facet & use_facet(const locale &__loc)
Return a facet.
basic_string< char > string
A string of char.
ISO C++ entities toplevel namespace is std.
chars_format
floating-point format for primitive numerical conversion
constexpr auto ssize(const _Container &__cont) noexcept(noexcept(__cont.size())) -> common_type_t< ptrdiff_t, make_signed_t< decltype(__cont.size())> >
Return the size of a container, as a signed integer.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.
A non-owning reference to a string.
Managing sequences of characters and character-like objects.
constexpr size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
constexpr void reserve(size_type __res_arg)
Attempt to preallocate enough memory for specified number of characters.
constexpr const _CharT * data() const noexcept
Return const pointer to contents.
constexpr basic_string substr(size_type __pos=0, size_type __n=npos) const
Get a substring.
constexpr void __resize_and_overwrite(size_type __n, _Operation __op)
Non-standard version of resize_and_overwrite for C++11 and above.
constexpr basic_string & append(const basic_string &__str)
Append a string to this string.
constexpr iterator insert(const_iterator __p, size_type __n, _CharT __c)
Insert multiple characters.
constexpr size_type capacity() const noexcept
constexpr bool empty() const noexcept
One of two subclasses of exception.
A standard container which offers fixed time access to individual elements in any order.