diff options
Diffstat (limited to 'libstdc++-v3/include/bits')
-rw-r--r-- | libstdc++-v3/include/bits/chrono_io.h | 912 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/formatfwd.h | 26 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/ranges_algo.h | 64 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_algo.h | 4 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_construct.h | 72 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_tempbuf.h | 2 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_uninitialized.h | 48 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/version.def | 8 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/version.h | 10 |
9 files changed, 806 insertions, 340 deletions
diff --git a/libstdc++-v3/include/bits/chrono_io.h b/libstdc++-v3/include/bits/chrono_io.h index c5c5e4b..abbf4efc 100644 --- a/libstdc++-v3/include/bits/chrono_io.h +++ b/libstdc++-v3/include/bits/chrono_io.h @@ -238,6 +238,108 @@ namespace __format operator|=(_ChronoParts& __x, _ChronoParts __y) noexcept { return __x = __x | __y; } + template<typename _CharT> + struct _ChronoFormats + { + using _String_view = basic_string_view<_CharT>; + + static consteval + _String_view + _S_ftz() noexcept + { return _GLIBCXX_WIDEN("%F %T %Z"); } + + static consteval + _String_view + _S_ft() noexcept + { return _S_ftz().substr(0, 5); } + + static consteval + _String_view + _S_f() noexcept + { return _S_ftz().substr(0, 2); } + + static consteval + _String_view + _S_t() noexcept + { return _S_ftz().substr(3, 2); } + + static consteval + _String_view + _S_ymd() noexcept + { return _GLIBCXX_WIDEN("%Y/%b/%d"); } + + static consteval + _String_view + _S_ym() noexcept + { return _S_ymd().substr(0, 5); } + + static consteval + _String_view + _S_md() noexcept + { return _S_ymd().substr(3); } + + static consteval + _String_view + _S_y() noexcept + { return _S_ymd().substr(0, 2); } + + static consteval + _String_view + _S_m() noexcept + { return _S_ymd().substr(3, 2); } + + static consteval + _String_view + _S_d() noexcept + { return _S_ymd().substr(6, 2); } + + static consteval + _String_view + _S_ymwi() noexcept + // %\0 is extension for handling weekday index + { return _String_view(_GLIBCXX_WIDEN("%Y/%b/%a[%\0]"), 12); } + + static consteval + _String_view + _S_mwi() noexcept + { return _S_ymwi().substr(3); } + + static consteval + _String_view + _S_wi() noexcept + { return _S_ymwi().substr(6); } + + static consteval + _String_view + _S_w() noexcept + { return _S_ymwi().substr(6, 2); } + + static consteval + _String_view + _S_ymwl() noexcept + { return _GLIBCXX_WIDEN("%Y/%b/%a[last]"); } + + static consteval + _String_view + _S_mwl() noexcept + { return _S_ymwl().substr(3); } + + static consteval + _String_view + _S_wl() noexcept + { return _S_ymwl().substr(6); } + + static consteval + _String_view + _S_yml() noexcept + { return _GLIBCXX_WIDEN("%Y/%b/last"); } + + static consteval + _String_view + _S_ml() noexcept + { return _S_yml().substr(3); } + }; + // TODO rename this to chrono::__formatter? or chrono::__detail::__formatter? template<typename _CharT> struct __formatter_chrono @@ -245,14 +347,22 @@ namespace __format using __string_view = basic_string_view<_CharT>; using __string = basic_string<_CharT>; + __formatter_chrono() = default; + + constexpr explicit + __formatter_chrono(_ChronoSpec<_CharT> __spec) noexcept + : _M_spec(__spec) + { } + template<typename _ParseContext> constexpr typename _ParseContext::iterator - _M_parse(_ParseContext& __pc, _ChronoParts __parts) + _M_parse(_ParseContext& __pc, _ChronoParts __parts, + const _ChronoSpec<_CharT>& __def = {}) { auto __first = __pc.begin(); auto __last = __pc.end(); - _ChronoSpec<_CharT> __spec{}; + _ChronoSpec<_CharT> __spec = __def; auto __finalize = [this, &__spec] { _M_spec = __spec; @@ -285,6 +395,7 @@ namespace __format return __first; } + __spec._M_localized = false; __first = __spec._M_parse_locale(__first, __last); if (__finished()) return __first; @@ -306,6 +417,9 @@ namespace __format // Parse chrono-specs in [first,last), checking each conversion-spec // against __parts (so fail for %Y if no year in parts). // Save range in __spec._M_chrono_specs. + __spec._M_debug = false; + __spec._M_locale_specific = true; + __spec._M_chrono_specs = __string_view(); const auto __chrono_specs = __first++; // Skip leading '%' if (*__chrono_specs != '%') @@ -492,14 +606,12 @@ namespace __format // that we instantiate fewer different specializations. Similar to // _Sink_iter for std::format. Replace each _S_year, _S_day etc. with // member functions of that type. + // pre: !_M_spec._M_chrono_specs.empty() template<typename _Tp, typename _FormatContext> typename _FormatContext::iterator _M_format(const _Tp& __t, _FormatContext& __fc, bool __is_neg = false) const { - if (_M_spec._M_chrono_specs.empty()) - return _M_format_to_ostream(__t, __fc, __is_neg); - #if defined _GLIBCXX_USE_NL_LANGINFO_L && __CHAR_BIT__ == 8 // _GLIBCXX_RESOLVE_LIB_DEFECTS // 3565. Handling of encodings in localized formatting @@ -562,6 +674,10 @@ namespace __format _CharT __c = *__first++; switch (__c) { + // %\0 is extension for handling weekday index + case '\0': + __out = _M_wi(__t, std::move(__out), __fc); + break; case 'a': case 'A': __out = _M_a_A(__t, std::move(__out), __fc, __c == 'A'); @@ -572,7 +688,10 @@ namespace __format __out = _M_b_B(__t, std::move(__out), __fc, __c == 'B'); break; case 'c': - __out = _M_c(__t, std::move(__out), __fc, __mod == 'E'); + case 'r': + case 'x': + case 'X': + __out = _M_c_r_x_X(__t, std::move(__out), __fc, __c, __mod); break; case 'C': case 'y': @@ -623,9 +742,6 @@ namespace __format __throw_format_error("chrono format error: argument is " "not a duration"); break; - case 'r': - __out = _M_r(__t, __print_sign(), __fc); - break; case 'R': case 'T': __out = _M_R_T(__t, __print_sign(), __fc, __c == 'T'); @@ -643,12 +759,6 @@ namespace __format __out = _M_U_V_W(__t, std::move(__out), __fc, __c, __mod == 'O'); break; - case 'x': - __out = _M_x(__t, std::move(__out), __fc, __mod == 'E'); - break; - case 'X': - __out = _M_X(__t, __print_sign(), __fc, __mod == 'E'); - break; case 'z': __out = _M_z(__t, std::move(__out), __fc, (bool)__mod); break; @@ -694,6 +804,24 @@ namespace __format return std::move(__out); } + // Format duration for empty chrono-specs, e.g. "{}" (C++20 [time.format] p6). + template<typename _Rep, typename _Period, typename _FormatContext> + typename _FormatContext::iterator + _M_format_to_ostream(const chrono::duration<_Rep, _Period>& __d, + bool __is_neg, _FormatContext& __fc) const + { + basic_ostringstream<_CharT> __os; + __os.imbue(_M_locale(__fc)); + + if (__is_neg) [[unlikely]] + __os << _S_plus_minus[1]; + __os << __d; + + auto __str = std::move(__os).str(); + return __format::__write_padded_as_spec(__str, __str.size(), + __fc, _M_spec); + } + _ChronoSpec<_CharT> _M_spec; private: @@ -708,82 +836,6 @@ namespace __format return __fc.locale(); } - // Format for empty chrono-specs, e.g. "{}" (C++20 [time.format] p6). - // TODO: consider moving body of every operator<< into this function - // and use std::format("{}", t) to implement those operators. That - // would avoid std::format("{}", t) calling operator<< which calls - // std::format again. - template<typename _Tp, typename _FormatContext> - typename _FormatContext::iterator - _M_format_to_ostream(const _Tp& __t, _FormatContext& __fc, - bool __is_neg) const - { - using ::std::chrono::__detail::__utc_leap_second; - using ::std::chrono::__detail::__local_time_fmt; - - basic_ostringstream<_CharT> __os; - __os.imbue(_M_locale(__fc)); - - if constexpr (__is_specialization_of<_Tp, __local_time_fmt>) - { - // Format as "{:L%F %T}" - auto __days = chrono::floor<chrono::days>(__t._M_time); - __os << chrono::year_month_day(__days) << ' ' - << chrono::hh_mm_ss(__t._M_time - __days); - - // For __local_time_fmt the __is_neg flags says whether to - // append " %Z" to the result. - if (__is_neg) - { - if (!__t._M_abbrev) [[unlikely]] - __format::__no_timezone_available(); - else if constexpr (is_same_v<_CharT, char>) - __os << ' ' << *__t._M_abbrev; - else - { - __os << L' '; - for (char __c : *__t._M_abbrev) - __os << __c; - } - } - } - else - { - if constexpr (__is_specialization_of<_Tp, __utc_leap_second>) - __os << __t._M_date << ' ' << __t._M_time; - else if constexpr (chrono::__is_time_point_v<_Tp>) - { - // Need to be careful here because not all specializations - // of chrono::sys_time can be written to an ostream. - // For the specializations of time_point that can be - // formatted with an empty chrono-specs, either it's a - // sys_time with period greater or equal to days: - if constexpr (is_convertible_v<_Tp, chrono::sys_days>) - __os << _S_date(__t); - // Or a local_time with period greater or equal to days: - else if constexpr (is_convertible_v<_Tp, chrono::local_days>) - __os << _S_date(__t); - else // Or it's formatted as "{:L%F %T}": - { - auto __days = chrono::floor<chrono::days>(__t); - __os << chrono::year_month_day(__days) << ' ' - << chrono::hh_mm_ss(__t - __days); - } - } - else - { - if constexpr (chrono::__is_duration_v<_Tp>) - if (__is_neg) [[unlikely]] - __os << _S_plus_minus[1]; - __os << __t; - } - } - - auto __str = std::move(__os).str(); - return __format::__write_padded_as_spec(__str, __str.size(), - __fc, _M_spec); - } - static constexpr const _CharT* _S_chars = _GLIBCXX_WIDEN("0123456789:/ +-{}"); static constexpr _CharT _S_colon = _S_chars[10]; @@ -818,6 +870,22 @@ namespace __format template<typename _Tp, typename _FormatContext> typename _FormatContext::iterator + _M_wi(const _Tp& __t, typename _FormatContext::iterator __out, + _FormatContext& __ctx) const + { + // %\0 Extension to format weekday index, used only by empty format spec + unsigned __wi = _S_weekday_index(__t); + + _CharT __buf[3]; + __out = __format::__write(std::move(__out), _S_str_d1(__buf, __wi)); + if (_M_spec._M_debug && (__wi < 1 || __wi > 5)) + __out = __format::__write(std::move(__out), + __string_view(_GLIBCXX_WIDEN(" is not a valid index"))); + return std::move(__out); + } + + template<typename _Tp, typename _FormatContext> + typename _FormatContext::iterator _M_a_A(const _Tp& __t, typename _FormatContext::iterator __out, _FormatContext& __ctx, bool __full) const { @@ -825,7 +893,16 @@ namespace __format // %A Locale's full weekday name. chrono::weekday __wd = _S_weekday(__t); if (!__wd.ok()) - __throw_format_error("format error: invalid weekday"); + { + if (!_M_spec._M_debug) + __throw_format_error("format error: invalid weekday"); + + _CharT __buf[3]; + __out = __format::__write(std::move(__out), + _S_str_d1(__buf, __wd.c_encoding())); + return __format::__write(std::move(__out), + __string_view(_GLIBCXX_WIDEN(" is not a valid weekday"))); + } locale __loc = _M_locale(__ctx); const auto& __tp = use_facet<__timepunct<_CharT>>(__loc); @@ -847,7 +924,17 @@ namespace __format // %B Locale's full month name. chrono::month __m = _S_month(__t); if (!__m.ok()) - __throw_format_error("format error: invalid month"); + { + if (!_M_spec._M_debug) + __throw_format_error("format error: invalid month"); + + _CharT __buf[3]; + __out = __format::__write(std::move(__out), + _S_str_d1(__buf, (unsigned)__m)); + return __format::__write(std::move(__out), + __string_view(_GLIBCXX_WIDEN(" is not a valid month"))); + } + locale __loc = _M_locale(__ctx); const auto& __tp = use_facet<__timepunct<_CharT>>(__loc); const _CharT* __months[12]; @@ -861,11 +948,16 @@ namespace __format template<typename _Tp, typename _FormatContext> typename _FormatContext::iterator - _M_c(const _Tp& __t, typename _FormatContext::iterator __out, - _FormatContext& __ctx, bool __mod = false) const + _M_c_r_x_X(const _Tp& __t, typename _FormatContext::iterator __out, + _FormatContext& __ctx, _CharT __conv, _CharT __mod) const { // %c Locale's date and time representation. // %Ec Locale's alternate date and time representation. + // %r Locale's 12-hour clock time. + // %x Locale's date rep + // %Ex Locale's alternative date representation. + // %X Locale's time rep + // %EX Locale's alternative time representation. using namespace chrono; using ::std::chrono::__detail::__utc_leap_second; @@ -899,23 +991,30 @@ namespace __format __tm.tm_zone = const_cast<char*>("UTC"); #endif - auto __d = _S_days(__t); // Either sys_days or local_days. - using _TDays = decltype(__d); - const year_month_day __ymd(__d); - const auto __y = __ymd.year(); - const auto __hms = _S_hms(__t); + if (__conv == 'c' || __conv == 'x') + { + auto __d = _S_days(__t); // Either sys_days or local_days. + using _TDays = decltype(__d); + const year_month_day __ymd(__d); + const auto __y = __ymd.year(); + + __tm.tm_year = (int)__y - 1900; + __tm.tm_yday = (__d - _TDays(__y/January/1)).count(); + __tm.tm_mon = (unsigned)__ymd.month() - 1; + __tm.tm_mday = (unsigned)__ymd.day(); + __tm.tm_wday = weekday(__d).c_encoding(); + } - __tm.tm_year = (int)__y - 1900; - __tm.tm_yday = (__d - _TDays(__y/January/1)).count(); - __tm.tm_mon = (unsigned)__ymd.month() - 1; - __tm.tm_mday = (unsigned)__ymd.day(); - __tm.tm_wday = weekday(__d).c_encoding(); - __tm.tm_hour = __hms.hours().count(); - __tm.tm_min = __hms.minutes().count(); - __tm.tm_sec = __hms.seconds().count(); - - return _M_locale_fmt(std::move(__out), _M_locale(__ctx), __tm, 'c', - __mod ? 'E' : '\0'); + if (__conv != 'x') + { + const auto __hms = _S_hms(__t); + __tm.tm_hour = __hms.hours().count(); + __tm.tm_min = __hms.minutes().count(); + __tm.tm_sec = __hms.seconds().count(); + } + + return _M_locale_fmt(std::move(__out), _M_locale(__ctx), __tm, + __conv, __mod); } template<typename _Tp, typename _FormatContext> @@ -974,7 +1073,11 @@ namespace __format } __out = __format::__write(std::move(__out), __sv); } - return std::move(__out); + + if (_M_spec._M_debug && __conv == 'Y' && !__y.ok()) [[unlikely]] + __out = __format::__write(std::move(__out), + __string_view(_GLIBCXX_WIDEN(" is not a valid year"))); + return __out; } template<typename _Tp, typename _FormatContext> @@ -1039,7 +1142,12 @@ namespace __format __buf[0] = _S_space; __sv = {__buf, 2}; } - return __format::__write(std::move(__out), __sv); + + __out = __format::__write(std::move(__out), __sv); + if (_M_spec._M_debug && !__d.ok()) [[unlikely]] + __out = __format::__write(std::move(__out), + __string_view(_GLIBCXX_WIDEN(" is not a valid day"))); + return std::move(__out); } template<typename _Tp, typename _FormatContext> @@ -1076,6 +1184,10 @@ namespace __format _S_fill_two_digits(__buf + 9, __di); __out = __format::__write(std::move(__out), __sv); } + + if (_M_spec._M_debug && !__ymd.ok()) + __out = __format::__write(std::move(__out), + __string_view(_GLIBCXX_WIDEN(" is not a valid date"))); return std::move(__out); } @@ -1243,25 +1355,6 @@ namespace __format template<typename _Tp, typename _FormatContext> typename _FormatContext::iterator - _M_r(const _Tp& __tt, typename _FormatContext::iterator __out, - _FormatContext& __ctx) const - { - // %r locale's 12-hour clock time. - auto __t = _S_floor_seconds(__tt); - locale __loc = _M_locale(__ctx); - const auto& __tp = use_facet<__timepunct<_CharT>>(__loc); - const _CharT* __ampm_fmt; - __tp._M_am_pm_format(&__ampm_fmt); - basic_string<_CharT> __fmt(_S_empty_spec); - __fmt.insert(1u, 1u, _S_colon); - __fmt.insert(2u, __ampm_fmt); - using _FmtStr = _Runtime_format_string<_CharT>; - return _M_write(std::move(__out), __loc, - std::format(__loc, _FmtStr(__fmt), __t)); - } - - template<typename _Tp, typename _FormatContext> - typename _FormatContext::iterator _M_R_T(const _Tp& __t, typename _FormatContext::iterator __out, _FormatContext& __ctx, bool __secs) const { @@ -1441,53 +1534,6 @@ namespace __format template<typename _Tp, typename _FormatContext> typename _FormatContext::iterator - _M_x(const _Tp& __t, typename _FormatContext::iterator __out, - _FormatContext& __ctx, bool __mod = false) const - { - // %x Locale's date rep - // %Ex Locale's alternative date representation. - locale __loc = _M_locale(__ctx); - const auto& __tp = use_facet<__timepunct<_CharT>>(__loc); - const _CharT* __date_reps[2]; - __tp._M_date_formats(__date_reps); - const _CharT* __rep = __date_reps[__mod]; - if (!*__rep) - return _M_D(__t, std::move(__out), __ctx); - - basic_string<_CharT> __fmt(_S_empty_spec); - __fmt.insert(1u, 1u, _S_colon); - __fmt.insert(2u, __rep); - using _FmtStr = _Runtime_format_string<_CharT>; - return _M_write(std::move(__out), __loc, - std::format(__loc, _FmtStr(__fmt), __t)); - } - - template<typename _Tp, typename _FormatContext> - typename _FormatContext::iterator - _M_X(const _Tp& __tt, typename _FormatContext::iterator __out, - _FormatContext& __ctx, bool __mod = false) const - { - // %X Locale's time rep - // %EX Locale's alternative time representation. - auto __t = _S_floor_seconds(__tt); - locale __loc = _M_locale(__ctx); - const auto& __tp = use_facet<__timepunct<_CharT>>(__loc); - const _CharT* __time_reps[2]; - __tp._M_time_formats(__time_reps); - const _CharT* __rep = __time_reps[__mod]; - if (!*__rep) - return _M_R_T(__t, std::move(__out), __ctx, true); - - basic_string<_CharT> __fmt(_S_empty_spec); - __fmt.insert(1u, 1u, _S_colon); - __fmt.insert(2u, __rep); - using _FmtStr = _Runtime_format_string<_CharT>; - return _M_write(std::move(__out), __loc, - std::format(__loc, _FmtStr(__fmt), __t)); - } - - template<typename _Tp, typename _FormatContext> - typename _FormatContext::iterator _M_z(const _Tp& __t, typename _FormatContext::iterator __out, _FormatContext&, bool __mod = false) const { @@ -1757,6 +1803,20 @@ namespace __format return weekday(_S_days(__t)); } + template<typename _Tp> + static unsigned + _S_weekday_index(const _Tp& __t) + { + using namespace ::std::chrono; + + if constexpr (is_same_v<_Tp, weekday_indexed>) + return __t.index(); + else if constexpr (requires { __t.weekday_indexed(); }) + return __t.weekday_indexed().index(); + else + return ((unsigned)_S_day(__t) + 6) / 7; + } + // Remove subsecond precision from a time_point. template<typename _Tp> static auto @@ -1801,6 +1861,84 @@ namespace __format } }; +#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI + template<typename _CharT> + struct __formatter_chrono_info + { + constexpr typename basic_format_parse_context<_CharT>::iterator + parse(basic_format_parse_context<_CharT>& __pc) + { return _M_f._M_parse(__pc, _ChronoParts(), {}); } + + template<typename _Info, typename _Out> + typename basic_format_context<_Out, _CharT>::iterator + format(const _Info& __i, + basic_format_context<_Out, _CharT>& __fc) const + { + // n.b. only acceptable chrono-spec for info is one containing + // only whitespaces and %%, that do not depend on formatted object. + if (!_M_f._M_spec._M_chrono_specs.empty()) [[unlikely]] + return _M_f._M_format(chrono::day(1), __fc); + + const size_t __padwidth = _M_f._M_spec._M_get_width(__fc); + if (__padwidth == 0) + return _M_format_to(__fc.out(), __i); + + _Padding_sink<_Out, _CharT> __sink(__fc.out(), __padwidth); + _M_format_to(__sink.out(), __i); + return __sink._M_finish(_M_f._M_spec._M_align, _M_f._M_spec._M_fill); + } + + private: + template<typename _Out> + _Out + _M_format_to(_Out __out, const chrono::sys_info& __si) const + { + using _FmtStr = _Runtime_format_string<_CharT>; + // n.b. only decimal separator is locale dependent for specifiers + // used below, as sys_info uses seconds and minutes duration, the + // output is locale-independent. + constexpr auto* __fs + = _GLIBCXX_WIDEN("[{0:%F %T},{1:%F %T},{2:%T},{3:%Q%q},{0:%Z}]"); + const chrono::local_seconds __lb(__si.begin.time_since_epoch()); + return std::format_to(std::move(__out), _FmtStr(__fs), + chrono::local_time_format(__lb, &__si.abbrev), + __si.end, __si.offset, __si.save); + } + + template<typename _Out> + _Out + _M_format_to(_Out __out, const chrono::local_info& __li) const + { + *__out = _Separators<_CharT>::_S_squares()[0]; + ++__out; + if (__li.result == chrono::local_info::unique) + __out = _M_format_to(std::move(__out), __li.first); + else + { + basic_string_view<_CharT> __sv; + if (__li.result == chrono::local_info::nonexistent) + __sv =_GLIBCXX_WIDEN("nonexistent"); + else + __sv = _GLIBCXX_WIDEN("ambiguous"); + __out = __format::__write(std::move(__out), __sv); + + __sv = _GLIBCXX_WIDEN(" local time between "); + __out = __format::__write(std::move(__out), __sv); + __out = _M_format_to(std::move(__out), __li.first); + + __sv = _GLIBCXX_WIDEN(" and "); + __out = __format::__write(std::move(__out), __sv); + __out = _M_format_to(std::move(__out), __li.second); + } + *__out = _Separators<_CharT>::_S_squares()[1]; + ++__out; + return std::move(__out); + } + + __formatter_chrono<_CharT> _M_f; + }; +#endif + } // namespace __format /// @endcond @@ -1812,7 +1950,7 @@ namespace __format parse(basic_format_parse_context<_CharT>& __pc) { using namespace __format; - auto __it = _M_f._M_parse(__pc, _Duration|_TimeOfDay); + auto __it = _M_f._M_parse(__pc, _Duration|_TimeOfDay, __defSpec); if constexpr (!is_floating_point_v<_Rep>) if (_M_f._M_spec._M_prec_kind != __format::_WP_none) __throw_format_error("format error: invalid precision for duration"); @@ -1834,16 +1972,37 @@ namespace __format using _URep = make_unsigned_t<_Rep>; auto __ucnt = -static_cast<_URep>(__d.count()); auto __ud = chrono::duration<_URep, _Period>(__ucnt); - return _M_f._M_format(__ud, __fc, true); + return _M_format(__ud, true, __fc); } else - return _M_f._M_format(-__d, __fc, true); + return _M_format(-__d, true, __fc); } - return _M_f._M_format(__d, __fc, false); + return _M_format(__d, false, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_localized = !is_integral_v<_Rep>; + if constexpr (is_integral_v<_Rep>) + __res._M_chrono_specs = _GLIBCXX_WIDEN("%Q%q"); + return __res; + }(); + + template<typename _Rep2, typename _Out> + typename basic_format_context<_Out, _CharT>::iterator + _M_format(const chrono::duration<_Rep2, _Period>& __d, + bool __is_neg, + basic_format_context<_Out, _CharT>& __fc) const + { + if constexpr (!is_integral_v<_Rep>) + if (_M_f._M_spec._M_chrono_specs.empty()) + return _M_f._M_format_to_ostream(__d, __is_neg, __fc); + return _M_f._M_format(__d, __fc, __is_neg); + } + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<__format::__char _CharT> @@ -1851,7 +2010,7 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_Day); } + { return _M_f._M_parse(__pc, __format::_Day, __defSpec); } template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator @@ -1860,7 +2019,15 @@ namespace __format { return _M_f._M_format(__t, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_debug = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_d(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<__format::__char _CharT> @@ -1868,7 +2035,7 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_Month); } + { return _M_f._M_parse(__pc, __format::_Month, __defSpec); } template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator @@ -1877,7 +2044,17 @@ namespace __format { return _M_f._M_format(__t, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_debug = true; + __res._M_localized = true; + __res._M_locale_specific = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_m(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<__format::__char _CharT> @@ -1885,7 +2062,7 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_Year); } + { return _M_f._M_parse(__pc, __format::_Year, __defSpec); } template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator @@ -1894,7 +2071,15 @@ namespace __format { return _M_f._M_format(__t, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_debug = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_y(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<__format::__char _CharT> @@ -1902,7 +2087,7 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_Weekday); } + { return _M_f._M_parse(__pc, __format::_Weekday, __defSpec); } template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator @@ -1911,7 +2096,17 @@ namespace __format { return _M_f._M_format(__t, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_debug = true; + __res._M_localized = true; + __res._M_locale_specific = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_w(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<__format::__char _CharT> @@ -1919,7 +2114,7 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_Weekday); } + { return _M_f._M_parse(__pc, __format::_Weekday, __defSpec); } template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator @@ -1928,7 +2123,17 @@ namespace __format { return _M_f._M_format(__t, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_debug = true; + __res._M_localized = true; + __res._M_locale_specific = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_wi(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<__format::__char _CharT> @@ -1936,7 +2141,7 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_Weekday); } + { return _M_f._M_parse(__pc, __format::_Weekday, __defSpec); } template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator @@ -1945,7 +2150,17 @@ namespace __format { return _M_f._M_format(__t, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_debug = true; + __res._M_localized = true; + __res._M_locale_specific = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_wl(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<__format::__char _CharT> @@ -1953,7 +2168,10 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_Month|__format::_Day); } + { + return _M_f._M_parse(__pc, __format::_Month|__format::_Day, + __defSpec); + } template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator @@ -1962,7 +2180,17 @@ namespace __format { return _M_f._M_format(__t, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_debug = true; + __res._M_localized = true; + __res._M_locale_specific = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_md(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<__format::__char _CharT> @@ -1970,7 +2198,10 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_Month|__format::_Day); } + { + return _M_f._M_parse(__pc, __format::_Month|__format::_Day, + __defSpec); + } template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator @@ -1979,7 +2210,17 @@ namespace __format { return _M_f._M_format(__t, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_debug = true; + __res._M_localized = true; + __res._M_locale_specific = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_ml(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<__format::__char _CharT> @@ -1987,7 +2228,10 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday); } + { + return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday, + __defSpec); + } template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator @@ -1996,7 +2240,17 @@ namespace __format { return _M_f._M_format(__t, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_debug = true; + __res._M_localized = true; + __res._M_locale_specific = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_mwi(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<__format::__char _CharT> @@ -2004,7 +2258,10 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday); } + { + return _M_f._M_parse(__pc, __format::_Month|__format::_Weekday, + __defSpec); + } template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator @@ -2013,7 +2270,17 @@ namespace __format { return _M_f._M_format(__t, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_debug = true; + __res._M_localized = true; + __res._M_locale_specific = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_mwl(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<__format::__char _CharT> @@ -2021,7 +2288,10 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_Year|__format::_Month); } + { + return _M_f._M_parse(__pc, __format::_Year|__format::_Month, + __defSpec); + } template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator @@ -2030,7 +2300,17 @@ namespace __format { return _M_f._M_format(__t, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_debug = true; + __res._M_localized = true; + __res._M_locale_specific = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_ym(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<__format::__char _CharT> @@ -2038,7 +2318,7 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_Date); } + { return _M_f._M_parse(__pc, __format::_Date, __defSpec); } template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator @@ -2047,7 +2327,15 @@ namespace __format { return _M_f._M_format(__t, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_debug = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_f(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<__format::__char _CharT> @@ -2055,7 +2343,7 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_Date); } + { return _M_f._M_parse(__pc, __format::_Date, __defSpec); } template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator @@ -2064,7 +2352,17 @@ namespace __format { return _M_f._M_format(__t, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_debug = true; + __res._M_localized = true; + __res._M_locale_specific = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_yml(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<__format::__char _CharT> @@ -2072,7 +2370,7 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_Date); } + { return _M_f._M_parse(__pc, __format::_Date, __defSpec); } template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator @@ -2081,7 +2379,17 @@ namespace __format { return _M_f._M_format(__t, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_debug = true; + __res._M_localized = true; + __res._M_locale_specific = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_ymwi(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<__format::__char _CharT> @@ -2089,7 +2397,7 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_Date); } + { return _M_f._M_parse(__pc, __format::_Date, __defSpec); } template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator @@ -2098,7 +2406,17 @@ namespace __format { return _M_f._M_format(__t, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_debug = true; + __res._M_localized = true; + __res._M_locale_specific = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_ymwl(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<typename _Rep, typename _Period, __format::__char _CharT> @@ -2106,7 +2424,7 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_TimeOfDay); } + { return _M_f._M_parse(__pc, __format::_TimeOfDay, __defSpec); } template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator @@ -2115,7 +2433,15 @@ namespace __format { return _M_f._M_format(__t, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_localized = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_t(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; #if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI @@ -2124,16 +2450,16 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_ChronoParts{}); } + { return _M_f.parse(__pc); } template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator format(const chrono::sys_info& __i, basic_format_context<_Out, _CharT>& __fc) const - { return _M_f._M_format(__i, __fc); } + { return _M_f.format(__i, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + __format::__formatter_chrono_info<_CharT> _M_f; }; template<__format::__char _CharT> @@ -2141,16 +2467,16 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_ChronoParts{}); } + { return _M_f.parse(__pc); } template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator format(const chrono::local_info& __i, basic_format_context<_Out, _CharT>& __fc) const - { return _M_f._M_format(__i, __fc); } + { return _M_f.format(__i, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + __format::__formatter_chrono_info<_CharT> _M_f; }; #endif @@ -2160,7 +2486,7 @@ namespace __format constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) { - auto __next = _M_f._M_parse(__pc, __format::_ZonedDateTime); + auto __next = _M_f._M_parse(__pc, __format::_ZonedDateTime, __defSpec); if constexpr (!__stream_insertable) if (_M_f._M_spec._M_chrono_specs.empty()) __format::__invalid_chrono_spec(); // chrono-specs can't be empty @@ -2178,7 +2504,22 @@ namespace __format = requires (basic_ostream<_CharT>& __os, chrono::sys_time<_Duration> __t) { __os << __t; }; - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + if constexpr (!__stream_insertable) + return __res; + else if constexpr (is_convertible_v<_Duration, chrono::days>) + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_f(); + else + { + __res._M_localized = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_ft(); + } + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<typename _Duration, __format::__char _CharT> @@ -2187,11 +2528,11 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_ZonedDateTime); } + { return _M_f._M_parse(__pc, __format::_ZonedDateTime, __defSpec); } template<typename _Out> - typename basic_format_context<_Out, _CharT>::iterator - format(const chrono::utc_time<_Duration>& __t, + typename basic_format_context<_Out, _CharT>::iterator + format(const chrono::utc_time<_Duration>& __t, basic_format_context<_Out, _CharT>& __fc) const { // Adjust by removing leap seconds to get equivalent sys_time. @@ -2212,7 +2553,15 @@ namespace __format private: friend formatter<chrono::__detail::__utc_leap_second<_Duration>, _CharT>; - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_localized = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_ft(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<typename _Duration, __format::__char _CharT> @@ -2221,11 +2570,11 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_ZonedDateTime); } + { return _M_f._M_parse(__pc, __format::_ZonedDateTime, __defSpec); } template<typename _Out> - typename basic_format_context<_Out, _CharT>::iterator - format(const chrono::tai_time<_Duration>& __t, + typename basic_format_context<_Out, _CharT>::iterator + format(const chrono::tai_time<_Duration>& __t, basic_format_context<_Out, _CharT>& __fc) const { // Convert to __local_time_fmt with abbrev "TAI" and offset 0s. @@ -2243,7 +2592,15 @@ namespace __format } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_localized = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_ft(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<typename _Duration, __format::__char _CharT> @@ -2252,11 +2609,11 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_ZonedDateTime); } + { return _M_f._M_parse(__pc, __format::_ZonedDateTime, __defSpec); } template<typename _Out> - typename basic_format_context<_Out, _CharT>::iterator - format(const chrono::gps_time<_Duration>& __t, + typename basic_format_context<_Out, _CharT>::iterator + format(const chrono::gps_time<_Duration>& __t, basic_format_context<_Out, _CharT>& __fc) const { // Convert to __local_time_fmt with abbrev "GPS" and offset 0s. @@ -2274,7 +2631,15 @@ namespace __format } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_localized = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_ft(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<typename _Duration, __format::__char _CharT> @@ -2282,11 +2647,11 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_ZonedDateTime); } + { return _M_f._M_parse(__pc, __format::_ZonedDateTime, __defSpec); } template<typename _Out> - typename basic_format_context<_Out, _CharT>::iterator - format(const chrono::file_time<_Duration>& __t, + typename basic_format_context<_Out, _CharT>::iterator + format(const chrono::file_time<_Duration>& __t, basic_format_context<_Out, _CharT>& __fc) const { using namespace chrono; @@ -2294,24 +2659,45 @@ namespace __format } private: - __format::__formatter_chrono<_CharT> _M_f; - }; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_localized = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_ft(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; + }; template<typename _Duration, __format::__char _CharT> struct formatter<chrono::local_time<_Duration>, _CharT> { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_DateTime); } + { return _M_f._M_parse(__pc, __format::_DateTime, __defSpec); } template<typename _Out> - typename basic_format_context<_Out, _CharT>::iterator - format(const chrono::local_time<_Duration>& __t, + typename basic_format_context<_Out, _CharT>::iterator + format(const chrono::local_time<_Duration>& __t, basic_format_context<_Out, _CharT>& __fc) const { return _M_f._M_format(__t, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + if constexpr (is_convertible_v<_Duration, chrono::days>) + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_f(); + else + { + __res._M_localized = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_ft(); + } + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; template<typename _Duration, __format::__char _CharT> @@ -2319,16 +2705,24 @@ namespace __format { constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc) - { return _M_f._M_parse(__pc, __format::_ZonedDateTime); } + { return _M_f._M_parse(__pc, __format::_ZonedDateTime, __defSpec); } template<typename _Out> - typename basic_format_context<_Out, _CharT>::iterator - format(const chrono::__detail::__local_time_fmt<_Duration>& __t, + typename basic_format_context<_Out, _CharT>::iterator + format(const chrono::__detail::__local_time_fmt<_Duration>& __t, basic_format_context<_Out, _CharT>& __fc) const - { return _M_f._M_format(__t, __fc, /* use %Z for {} */ true); } + { return _M_f._M_format(__t, __fc); } private: - __format::__formatter_chrono<_CharT> _M_f; + static constexpr __format::_ChronoSpec<_CharT> __defSpec = [] + { + __format::_ChronoSpec<_CharT> __res{}; + __res._M_localized = true; + __res._M_chrono_specs = __format::_ChronoFormats<_CharT>::_S_ftz(); + return __res; + }(); + + __format::__formatter_chrono<_CharT> _M_f{__defSpec}; }; #if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI @@ -2337,8 +2731,8 @@ namespace __format : formatter<chrono::__detail::__local_time_fmt_for<_Duration>, _CharT> { template<typename _Out> - typename basic_format_context<_Out, _CharT>::iterator - format(const chrono::zoned_time<_Duration, _TimeZonePtr>& __tp, + typename basic_format_context<_Out, _CharT>::iterator + format(const chrono::zoned_time<_Duration, _TimeZonePtr>& __tp, basic_format_context<_Out, _CharT>& __fc) const { using _Ltf = chrono::__detail::__local_time_fmt_for<_Duration>; @@ -2358,8 +2752,8 @@ namespace __format : formatter<chrono::utc_time<_Duration>, _CharT> { template<typename _Out> - typename basic_format_context<_Out, _CharT>::iterator - format(const chrono::__detail::__utc_leap_second<_Duration>& __t, + typename basic_format_context<_Out, _CharT>::iterator + format(const chrono::__detail::__utc_leap_second<_Duration>& __t, basic_format_context<_Out, _CharT>& __fc) const { return this->_M_f._M_format(__t, __fc); } }; @@ -2944,15 +3338,7 @@ namespace __detail basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const sys_info& __i) { - // n.b. only decimal separator is locale dependent for specifiers - // used below, as sys_info uses seconds and minutes duration, the - // output is locale-independent. - constexpr auto* __fs - = _GLIBCXX_WIDEN("[{0:%F %T},{1:%F %T},{2:%T},{3:%Q%q},{0:%Z}]"); - local_seconds __lb(__i.begin.time_since_epoch()); - __os << std::format(__fs, local_time_format(__lb, &__i.abbrev), - __i.end, __i.offset, __i.save); - return __os; + return __os << std::format(__os.getloc(), _GLIBCXX_WIDEN("{}"), __i); } /// Writes a local_info object to an ostream in an unspecified format. diff --git a/libstdc++-v3/include/bits/formatfwd.h b/libstdc++-v3/include/bits/formatfwd.h index 777e629..314b55d 100644 --- a/libstdc++-v3/include/bits/formatfwd.h +++ b/libstdc++-v3/include/bits/formatfwd.h @@ -162,6 +162,32 @@ namespace __format using __maybe_const = __conditional_t<formattable<const _Tp, _CharT>, const _Tp, _Tp>; } + + // [format.range], formatting of ranges + // [format.range.fmtkind], variable template format_kind + enum class range_format { + disabled, + map, + set, + sequence, + string, + debug_string + }; + + /** @brief A constant determining how a range should be formatted. + * + * The primary template of `std::format_kind` cannot be instantiated. + * There is a partial specialization for input ranges and you can + * specialize the variable template for your own cv-unqualified types + * that satisfy the `ranges::input_range` concept. + * + * @since C++23 + */ + template<typename _Rg> + constexpr auto format_kind = []{ + static_assert(false, "cannot use primary template of 'std::format_kind'"); + return type_identity<_Rg>{}; + }(); #endif // format_ranges _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h index a62c3cd..5aca6e8 100644 --- a/libstdc++-v3/include/bits/ranges_algo.h +++ b/libstdc++-v3/include/bits/ranges_algo.h @@ -47,28 +47,60 @@ namespace ranges { namespace __detail { + template<typename _Fp> + using __by_ref_or_value_fn + = __conditional_t<is_scalar_v<_Fp> || is_empty_v<_Fp>, _Fp, _Fp&>; + template<typename _Comp, typename _Proj> - constexpr auto + struct _Comp_proj + { + [[no_unique_address]] __by_ref_or_value_fn<_Comp> _M_comp; + [[no_unique_address]] __by_ref_or_value_fn<_Proj> _M_proj; + + constexpr + _Comp_proj(_Comp& __comp, _Proj& __proj) + : _M_comp(__comp), _M_proj(__proj) + { } + + template<typename _Tp, typename _Up> + constexpr bool + operator()(_Tp&& __x, _Up&& __y) + { + return std::__invoke(_M_comp, + std::__invoke(_M_proj, std::forward<_Tp>(__x)), + std::__invoke(_M_proj, std::forward<_Up>(__y))); + } + }; + + template<typename _Comp, typename _Proj> + constexpr _Comp_proj<_Comp, _Proj> __make_comp_proj(_Comp& __comp, _Proj& __proj) + { return {__comp, __proj}; } + + template<typename _Pred, typename _Proj> + struct _Pred_proj { - return [&] (auto&& __lhs, auto&& __rhs) -> bool { - using _TL = decltype(__lhs); - using _TR = decltype(__rhs); - return std::__invoke(__comp, - std::__invoke(__proj, std::forward<_TL>(__lhs)), - std::__invoke(__proj, std::forward<_TR>(__rhs))); - }; - } + [[no_unique_address]] __by_ref_or_value_fn<_Pred> _M_pred; + [[no_unique_address]] __by_ref_or_value_fn<_Proj> _M_proj; + + constexpr + _Pred_proj(_Pred& __pred, _Proj& __proj) + : _M_pred(__pred), _M_proj(__proj) + { } + + template<typename _Tp> + constexpr bool + operator()(_Tp&& __x) + { + return std::__invoke(_M_pred, + std::__invoke(_M_proj, std::forward<_Tp>(__x))); + } + }; template<typename _Pred, typename _Proj> - constexpr auto + constexpr _Pred_proj<_Pred, _Proj> __make_pred_proj(_Pred& __pred, _Proj& __proj) - { - return [&] <typename _Tp> (_Tp&& __arg) -> bool { - return std::__invoke(__pred, - std::__invoke(__proj, std::forward<_Tp>(__arg))); - }; - } + { return {__pred, __proj}; } } // namespace __detail struct __all_of_fn diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index 98c2249..3f4674d 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -2511,7 +2511,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) // [first,middle) and [middle,last). _TmpBuf __buf(__first, std::min(__len1, __len2)); - if (__builtin_expect(__buf.size() == __buf.requested_size(), true)) + if (__builtin_expect(__buf.size() == __buf._M_requested_size(), true)) std::__merge_adaptive (__first, __middle, __last, __len1, __len2, __buf.begin(), __comp); else if (__builtin_expect(__buf.begin() == 0, false)) @@ -5024,7 +5024,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO // so the buffer only needs to fit half the range at once. _TmpBuf __buf(__first, (__last - __first + 1) / 2); - if (__builtin_expect(__buf.requested_size() == __buf.size(), true)) + if (__builtin_expect(__buf._M_requested_size() == __buf.size(), true)) std::__stable_sort_adaptive(__first, __first + _DistanceType(__buf.size()), __last, __buf.begin(), __comp); diff --git a/libstdc++-v3/include/bits/stl_construct.h b/libstdc++-v3/include/bits/stl_construct.h index 23b8fb7..217a041 100644 --- a/libstdc++-v3/include/bits/stl_construct.h +++ b/libstdc++-v3/include/bits/stl_construct.h @@ -82,7 +82,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if constexpr (__cplusplus > 201703L && is_array_v<_Tp>) { for (auto& __x : *__location) - std::destroy_at(std::__addressof(__x)); + std::destroy_at(std::addressof(__x)); } else __location->~_Tp(); @@ -123,7 +123,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Construct(_Tp* __p, _Args&&... __args) { #if __cpp_constexpr_dynamic_alloc // >= C++20 - if (std::__is_constant_evaluated()) + if (std::is_constant_evaluated()) { // Allow std::_Construct to be used in constant expressions. std::construct_at(__p, std::forward<_Args>(__args)...); @@ -181,6 +181,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION for (; __first != __last; ++__first) std::_Destroy(std::__addressof(*__first)); } + + template<typename _ForwardIterator, typename _Size> + static _GLIBCXX20_CONSTEXPR _ForwardIterator + __destroy_n(_ForwardIterator __first, _Size __count) + { + for (; __count > 0; (void)++__first, --__count) + std::_Destroy(std::__addressof(*__first)); + return __first; + } }; template<> @@ -189,6 +198,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _ForwardIterator> static void __destroy(_ForwardIterator, _ForwardIterator) { } + + template<typename _ForwardIterator, typename _Size> + static _ForwardIterator + __destroy_n(_ForwardIterator __first, _Size __count) + { + std::advance(__first, __count); + return __first; + } }; #endif @@ -204,16 +221,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef typename iterator_traits<_ForwardIterator>::value_type _Value_type; #if __cplusplus >= 201103L - // A deleted destructor is trivial, this ensures we reject such types: - static_assert(is_destructible<_Value_type>::value, - "value type is destructible"); - if constexpr (!__has_trivial_destructor(_Value_type)) + if constexpr (!is_trivially_destructible<_Value_type>::value) for (; __first != __last; ++__first) - std::_Destroy(std::__addressof(*__first)); + std::_Destroy(std::addressof(*__first)); #if __cpp_constexpr_dynamic_alloc // >= C++20 - else if (std::__is_constant_evaluated()) + else if (std::is_constant_evaluated()) for (; __first != __last; ++__first) - std::destroy_at(std::__addressof(*__first)); + std::destroy_at(std::addressof(*__first)); #endif #else std::_Destroy_aux<__has_trivial_destructor(_Value_type)>:: @@ -221,33 +235,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif } -#if __cplusplus < 201103L - template<bool> - struct _Destroy_n_aux - { - template<typename _ForwardIterator, typename _Size> - static _GLIBCXX20_CONSTEXPR _ForwardIterator - __destroy_n(_ForwardIterator __first, _Size __count) - { - for (; __count > 0; (void)++__first, --__count) - std::_Destroy(std::__addressof(*__first)); - return __first; - } - }; - - template<> - struct _Destroy_n_aux<true> - { - template<typename _ForwardIterator, typename _Size> - static _ForwardIterator - __destroy_n(_ForwardIterator __first, _Size __count) - { - std::advance(__first, __count); - return __first; - } - }; -#endif - /** * Destroy a range of objects. If the value_type of the object has * a trivial destructor, the compiler should optimize all of this @@ -260,22 +247,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef typename iterator_traits<_ForwardIterator>::value_type _Value_type; #if __cplusplus >= 201103L - // A deleted destructor is trivial, this ensures we reject such types: - static_assert(is_destructible<_Value_type>::value, - "value type is destructible"); - if constexpr (!__has_trivial_destructor(_Value_type)) + if constexpr (!is_trivially_destructible<_Value_type>::value) for (; __count > 0; (void)++__first, --__count) - std::_Destroy(std::__addressof(*__first)); + std::_Destroy(std::addressof(*__first)); #if __cpp_constexpr_dynamic_alloc // >= C++20 - else if (std::__is_constant_evaluated()) + else if (std::is_constant_evaluated()) for (; __count > 0; (void)++__first, --__count) - std::destroy_at(std::__addressof(*__first)); + std::destroy_at(std::addressof(*__first)); #endif else std::advance(__first, __count); return __first; #else - return std::_Destroy_n_aux<__has_trivial_destructor(_Value_type)>:: + return std::_Destroy_aux<__has_trivial_destructor(_Value_type)>:: __destroy_n(__first, __count); #endif } diff --git a/libstdc++-v3/include/bits/stl_tempbuf.h b/libstdc++-v3/include/bits/stl_tempbuf.h index 7a7619e..8cc7b11 100644 --- a/libstdc++-v3/include/bits/stl_tempbuf.h +++ b/libstdc++-v3/include/bits/stl_tempbuf.h @@ -227,7 +227,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Returns the size requested by the constructor; may be >size(). size_type - requested_size() const + _M_requested_size() const { return _M_original_len; } /// As per Table mumble. diff --git a/libstdc++-v3/include/bits/stl_uninitialized.h b/libstdc++-v3/include/bits/stl_uninitialized.h index b1428db..f4b26cc 100644 --- a/libstdc++-v3/include/bits/stl_uninitialized.h +++ b/libstdc++-v3/include/bits/stl_uninitialized.h @@ -118,7 +118,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ~_UninitDestroyGuard() { if (__builtin_expect(_M_cur != 0, 0)) +#if __cplusplus == 201703L + // std::uninitialized_{value,default}{,_n} can construct array types, + // but std::_Destroy cannot handle them until C++20 (PR 120397). + _S_destroy(_M_first, *_M_cur); +#else std::_Destroy(_M_first, *_M_cur); +#endif } _GLIBCXX20_CONSTEXPR @@ -129,6 +135,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION private: _UninitDestroyGuard(const _UninitDestroyGuard&); + +#if __cplusplus == 201703L + template<typename _Iter> + static void + _S_destroy(_Iter __first, _Iter __last) + { + using _ValT = typename iterator_traits<_Iter>::value_type; + if constexpr (is_array<_ValT>::value) + for (; __first != __last; ++__first) + _S_destroy(*__first, *__first + extent<_ValT>::value); + else + std::_Destroy(__first, __last); + } +#endif }; // This is the default implementation of std::uninitialized_copy. @@ -839,7 +859,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _UninitDestroyGuard<_ForwardIterator> __guard(__first); for (; __first != __last; ++__first) - std::_Construct(std::__addressof(*__first)); + std::_Construct(std::addressof(*__first)); __guard.release(); } }; @@ -856,7 +876,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return; typename iterator_traits<_ForwardIterator>::value_type* __val - = std::__addressof(*__first); + = std::addressof(*__first); std::_Construct(__val); if (++__first != __last) std::fill(__first, __last, *__val); @@ -873,7 +893,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _UninitDestroyGuard<_ForwardIterator> __guard(__first); for (; __n > 0; --__n, (void) ++__first) - std::_Construct(std::__addressof(*__first)); + std::_Construct(std::addressof(*__first)); __guard.release(); return __first; } @@ -890,7 +910,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (__n > 0) { typename iterator_traits<_ForwardIterator>::value_type* __val - = std::__addressof(*__first); + = std::addressof(*__first); std::_Construct(__val); ++__first; __first = std::fill_n(__first, __n - 1, *__val); @@ -955,7 +975,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __alloc); typedef __gnu_cxx::__alloc_traits<_Allocator> __traits; for (; __first != __last; ++__first) - __traits::construct(__alloc, std::__addressof(*__first)); + __traits::construct(__alloc, std::addressof(*__first)); __guard.release(); } @@ -980,7 +1000,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __alloc); typedef __gnu_cxx::__alloc_traits<_Allocator> __traits; for (; __n > 0; --__n, (void) ++__first) - __traits::construct(__alloc, std::__addressof(*__first)); + __traits::construct(__alloc, std::addressof(*__first)); __guard.release(); return __first; } @@ -1007,7 +1027,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _UninitDestroyGuard<_ForwardIterator> __guard(__first); for (; __first != __last; ++__first) - std::_Construct_novalue(std::__addressof(*__first)); + std::_Construct_novalue(std::addressof(*__first)); __guard.release(); } }; @@ -1033,7 +1053,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _UninitDestroyGuard<_ForwardIterator> __guard(__first); for (; __n > 0; --__n, (void) ++__first) - std::_Construct_novalue(std::__addressof(*__first)); + std::_Construct_novalue(std::addressof(*__first)); __guard.release(); return __first; } @@ -1089,7 +1109,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _UninitDestroyGuard<_ForwardIterator> __guard(__result); for (; __n > 0; --__n, (void) ++__first, ++__result) - std::_Construct(std::__addressof(*__result), *__first); + std::_Construct(std::addressof(*__result), *__first); __guard.release(); return __result; } @@ -1112,7 +1132,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _UninitDestroyGuard<_ForwardIterator> __guard(__result); for (; __n > 0; --__n, (void) ++__first, ++__result) - std::_Construct(std::__addressof(*__result), *__first); + std::_Construct(std::addressof(*__result), *__first); __guard.release(); return {__first, __result}; } @@ -1276,11 +1296,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION noexcept(noexcept(std::allocator_traits<_Allocator>::construct(__alloc, __dest, std::move(*__orig))) && noexcept(std::allocator_traits<_Allocator>::destroy( - __alloc, std::__addressof(*__orig)))) + __alloc, std::addressof(*__orig)))) { typedef std::allocator_traits<_Allocator> __traits; __traits::construct(__alloc, __dest, std::move(*__orig)); - __traits::destroy(__alloc, std::__addressof(*__orig)); + __traits::destroy(__alloc, std::addressof(*__orig)); } // This class may be specialized for specific types. @@ -1308,8 +1328,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION "relocation is only possible for values of the same type"); _ForwardIterator __cur = __result; for (; __first != __last; ++__first, (void)++__cur) - std::__relocate_object_a(std::__addressof(*__cur), - std::__addressof(*__first), __alloc); + std::__relocate_object_a(std::addressof(*__cur), + std::addressof(*__first), __alloc); return __cur; } diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 7cf62e9..880586e 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -852,6 +852,14 @@ ftms = { }; ftms = { + name = optional_range_support; + values = { + v = 202406; + cxxmin = 26; + }; +}; + +ftms = { name = destroying_delete; values = { v = 201806; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index 9f4cf9a..4300adb 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -955,6 +955,16 @@ #endif /* !defined(__cpp_lib_optional) && defined(__glibcxx_want_optional) */ #undef __glibcxx_want_optional +#if !defined(__cpp_lib_optional_range_support) +# if (__cplusplus > 202302L) +# define __glibcxx_optional_range_support 202406L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_optional_range_support) +# define __cpp_lib_optional_range_support 202406L +# endif +# endif +#endif /* !defined(__cpp_lib_optional_range_support) && defined(__glibcxx_want_optional_range_support) */ +#undef __glibcxx_want_optional_range_support + #if !defined(__cpp_lib_destroying_delete) # if (__cplusplus >= 202002L) && (__cpp_impl_destroying_delete) # define __glibcxx_destroying_delete 201806L |