From a8aa70fb74ac6ba5b80f0e07291da1f4edcda551 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Sat, 11 Feb 2023 09:46:20 +0800 Subject: [PATCH 1/3] Make instantiation of `_Parse_format_string` lazy --- stl/inc/format | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/stl/inc/format b/stl/inc/format index 1e7feb962c5..7c01601b395 100644 --- a/stl/inc/format +++ b/stl/inc/format @@ -3417,8 +3417,10 @@ _NODISCARD auto make_wformat_args(_Args&&... _Vals) { return _Format_arg_store{_Vals...}; } -_EXPORT_STD template _OutputIt> -_OutputIt vformat_to(_OutputIt _Out, const string_view _Fmt, const format_args _Args) { +_EXPORT_STD template _OutputIt, + class _Sv = string_view> // lazy instantiation, see GH-1926 +_OutputIt vformat_to(_OutputIt _Out, const type_identity_t<_Sv> _Fmt, const format_args _Args) { + static_assert(is_same_v<_Sv, string_view>, "misspecified template argument"); if constexpr (is_same_v<_OutputIt, _Fmt_it>) { _Format_handler _Handler(_Out, _Fmt, _Args); _Parse_format_string(_Fmt, _Handler); @@ -3431,8 +3433,10 @@ _OutputIt vformat_to(_OutputIt _Out, const string_view _Fmt, const format_args _ } } -_EXPORT_STD template _OutputIt> -_OutputIt vformat_to(_OutputIt _Out, const wstring_view _Fmt, const wformat_args _Args) { +_EXPORT_STD template _OutputIt, + class _Sv = wstring_view> // lazy instantiation, see GH-1926 +_OutputIt vformat_to(_OutputIt _Out, const type_identity_t<_Sv> _Fmt, const wformat_args _Args) { + static_assert(is_same_v<_Sv, wstring_view>, "misspecified template argument"); if constexpr (is_same_v<_OutputIt, _Fmt_wit>) { _Format_handler _Handler(_Out, _Fmt, _Args); _Parse_format_string(_Fmt, _Handler); @@ -3445,8 +3449,10 @@ _OutputIt vformat_to(_OutputIt _Out, const wstring_view _Fmt, const wformat_args } } -_EXPORT_STD template _OutputIt> -_OutputIt vformat_to(_OutputIt _Out, const locale& _Loc, const string_view _Fmt, const format_args _Args) { +_EXPORT_STD template _OutputIt, + class _Sv = string_view> // lazy instantiation, see GH-1926 +_OutputIt vformat_to(_OutputIt _Out, const locale& _Loc, const type_identity_t<_Sv> _Fmt, const format_args _Args) { + static_assert(is_same_v<_Sv, string_view>, "misspecified template argument"); if constexpr (is_same_v<_OutputIt, _Fmt_it>) { _Format_handler _Handler(_Out, _Fmt, _Args, _Lazy_locale{_Loc}); _Parse_format_string(_Fmt, _Handler); @@ -3459,8 +3465,10 @@ _OutputIt vformat_to(_OutputIt _Out, const locale& _Loc, const string_view _Fmt, } } -_EXPORT_STD template _OutputIt> -_OutputIt vformat_to(_OutputIt _Out, const locale& _Loc, const wstring_view _Fmt, const wformat_args _Args) { +_EXPORT_STD template _OutputIt, + class _Sv = wstring_view> // lazy instantiation, see GH-1926 +_OutputIt vformat_to(_OutputIt _Out, const locale& _Loc, const type_identity_t<_Sv> _Fmt, const wformat_args _Args) { + static_assert(is_same_v<_Sv, wstring_view>, "misspecified template argument"); if constexpr (is_same_v<_OutputIt, _Fmt_wit>) { _Format_handler _Handler(_Out, _Fmt, _Args, _Lazy_locale{_Loc}); _Parse_format_string(_Fmt, _Handler); From b068cd4fddc7d2ed92a5a1ea42820cf5faef04d7 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Sun, 12 Feb 2023 00:34:46 -0800 Subject: [PATCH 2/3] Casey: try to avoid messing with the interface of `vformat_to` --- stl/inc/format | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/stl/inc/format b/stl/inc/format index 7c01601b395..fad0c7d4a9e 100644 --- a/stl/inc/format +++ b/stl/inc/format @@ -3417,65 +3417,65 @@ _NODISCARD auto make_wformat_args(_Args&&... _Vals) { return _Format_arg_store{_Vals...}; } -_EXPORT_STD template _OutputIt, - class _Sv = string_view> // lazy instantiation, see GH-1926 -_OutputIt vformat_to(_OutputIt _Out, const type_identity_t<_Sv> _Fmt, const format_args _Args) { - static_assert(is_same_v<_Sv, string_view>, "misspecified template argument"); +_EXPORT_STD template _OutputIt> +_OutputIt vformat_to(_OutputIt _Out, const string_view _Fmt, const format_args _Args) { + // Make `_Parse_format_string` type-dependent to defer instantiation: + using _Dependent_char = conditional_t, char, char>; if constexpr (is_same_v<_OutputIt, _Fmt_it>) { - _Format_handler _Handler(_Out, _Fmt, _Args); + _Format_handler<_Dependent_char> _Handler(_Out, _Fmt, _Args); _Parse_format_string(_Fmt, _Handler); return _Out; } else { _Fmt_iterator_buffer<_OutputIt, char> _Buf(_STD move(_Out)); - _Format_handler _Handler(_Fmt_it{_Buf}, _Fmt, _Args); + _Format_handler<_Dependent_char> _Handler(_Fmt_it{_Buf}, _Fmt, _Args); _Parse_format_string(_Fmt, _Handler); return _Buf._Out(); } } -_EXPORT_STD template _OutputIt, - class _Sv = wstring_view> // lazy instantiation, see GH-1926 -_OutputIt vformat_to(_OutputIt _Out, const type_identity_t<_Sv> _Fmt, const wformat_args _Args) { - static_assert(is_same_v<_Sv, wstring_view>, "misspecified template argument"); +_EXPORT_STD template _OutputIt> +_OutputIt vformat_to(_OutputIt _Out, const wstring_view _Fmt, const wformat_args _Args) { + // Make `_Parse_format_string` type-dependent to defer instantiation: + using _Dependent_char = conditional_t, wchar_t, wchar_t>; if constexpr (is_same_v<_OutputIt, _Fmt_wit>) { - _Format_handler _Handler(_Out, _Fmt, _Args); + _Format_handler<_Dependent_char> _Handler(_Out, _Fmt, _Args); _Parse_format_string(_Fmt, _Handler); return _Out; } else { _Fmt_iterator_buffer<_OutputIt, wchar_t> _Buf(_STD move(_Out)); - _Format_handler _Handler(_Fmt_wit{_Buf}, _Fmt, _Args); + _Format_handler<_Dependent_char> _Handler(_Fmt_wit{_Buf}, _Fmt, _Args); _Parse_format_string(_Fmt, _Handler); return _Buf._Out(); } } -_EXPORT_STD template _OutputIt, - class _Sv = string_view> // lazy instantiation, see GH-1926 -_OutputIt vformat_to(_OutputIt _Out, const locale& _Loc, const type_identity_t<_Sv> _Fmt, const format_args _Args) { - static_assert(is_same_v<_Sv, string_view>, "misspecified template argument"); +_EXPORT_STD template _OutputIt> +_OutputIt vformat_to(_OutputIt _Out, const locale& _Loc, const string_view _Fmt, const format_args _Args) { + // Make `_Parse_format_string` type-dependent to defer instantiation: + using _Dependent_char = conditional_t, char, char>; if constexpr (is_same_v<_OutputIt, _Fmt_it>) { - _Format_handler _Handler(_Out, _Fmt, _Args, _Lazy_locale{_Loc}); + _Format_handler<_Dependent_char> _Handler(_Out, _Fmt, _Args, _Lazy_locale{_Loc}); _Parse_format_string(_Fmt, _Handler); return _Out; } else { _Fmt_iterator_buffer<_OutputIt, char> _Buf(_STD move(_Out)); - _Format_handler _Handler(_Fmt_it{_Buf}, _Fmt, _Args, _Lazy_locale{_Loc}); + _Format_handler<_Dependent_char> _Handler(_Fmt_it{_Buf}, _Fmt, _Args, _Lazy_locale{_Loc}); _Parse_format_string(_Fmt, _Handler); return _Buf._Out(); } } -_EXPORT_STD template _OutputIt, - class _Sv = wstring_view> // lazy instantiation, see GH-1926 -_OutputIt vformat_to(_OutputIt _Out, const locale& _Loc, const type_identity_t<_Sv> _Fmt, const wformat_args _Args) { - static_assert(is_same_v<_Sv, wstring_view>, "misspecified template argument"); +_EXPORT_STD template _OutputIt> +_OutputIt vformat_to(_OutputIt _Out, const locale& _Loc, const wstring_view _Fmt, const wformat_args _Args) { + // Make `_Parse_format_string` type-dependent to defer instantiation: + using _Dependent_char = conditional_t, wchar_t, wchar_t>; if constexpr (is_same_v<_OutputIt, _Fmt_wit>) { - _Format_handler _Handler(_Out, _Fmt, _Args, _Lazy_locale{_Loc}); + _Format_handler<_Dependent_char> _Handler(_Out, _Fmt, _Args, _Lazy_locale{_Loc}); _Parse_format_string(_Fmt, _Handler); return _Out; } else { _Fmt_iterator_buffer<_OutputIt, wchar_t> _Buf(_STD move(_Out)); - _Format_handler _Handler(_Fmt_wit{_Buf}, _Fmt, _Args, _Lazy_locale{_Loc}); + _Format_handler<_Dependent_char> _Handler(_Fmt_wit{_Buf}, _Fmt, _Args, _Lazy_locale{_Loc}); _Parse_format_string(_Fmt, _Handler); return _Buf._Out(); } From c8ca089c296b0e72043411757914a7afaff02196 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Mon, 13 Feb 2023 00:22:27 +0800 Subject: [PATCH 3/3] Simplify `_Dependent_char` --- stl/inc/format | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stl/inc/format b/stl/inc/format index fad0c7d4a9e..9e3a41df7d1 100644 --- a/stl/inc/format +++ b/stl/inc/format @@ -3420,7 +3420,7 @@ _NODISCARD auto make_wformat_args(_Args&&... _Vals) { _EXPORT_STD template _OutputIt> _OutputIt vformat_to(_OutputIt _Out, const string_view _Fmt, const format_args _Args) { // Make `_Parse_format_string` type-dependent to defer instantiation: - using _Dependent_char = conditional_t, char, char>; + using _Dependent_char = decltype((void) _Out, char{}); if constexpr (is_same_v<_OutputIt, _Fmt_it>) { _Format_handler<_Dependent_char> _Handler(_Out, _Fmt, _Args); _Parse_format_string(_Fmt, _Handler); @@ -3436,7 +3436,7 @@ _OutputIt vformat_to(_OutputIt _Out, const string_view _Fmt, const format_args _ _EXPORT_STD template _OutputIt> _OutputIt vformat_to(_OutputIt _Out, const wstring_view _Fmt, const wformat_args _Args) { // Make `_Parse_format_string` type-dependent to defer instantiation: - using _Dependent_char = conditional_t, wchar_t, wchar_t>; + using _Dependent_char = decltype((void) _Out, wchar_t{}); if constexpr (is_same_v<_OutputIt, _Fmt_wit>) { _Format_handler<_Dependent_char> _Handler(_Out, _Fmt, _Args); _Parse_format_string(_Fmt, _Handler); @@ -3452,7 +3452,7 @@ _OutputIt vformat_to(_OutputIt _Out, const wstring_view _Fmt, const wformat_args _EXPORT_STD template _OutputIt> _OutputIt vformat_to(_OutputIt _Out, const locale& _Loc, const string_view _Fmt, const format_args _Args) { // Make `_Parse_format_string` type-dependent to defer instantiation: - using _Dependent_char = conditional_t, char, char>; + using _Dependent_char = decltype((void) _Out, char{}); if constexpr (is_same_v<_OutputIt, _Fmt_it>) { _Format_handler<_Dependent_char> _Handler(_Out, _Fmt, _Args, _Lazy_locale{_Loc}); _Parse_format_string(_Fmt, _Handler); @@ -3468,7 +3468,7 @@ _OutputIt vformat_to(_OutputIt _Out, const locale& _Loc, const string_view _Fmt, _EXPORT_STD template _OutputIt> _OutputIt vformat_to(_OutputIt _Out, const locale& _Loc, const wstring_view _Fmt, const wformat_args _Args) { // Make `_Parse_format_string` type-dependent to defer instantiation: - using _Dependent_char = conditional_t, wchar_t, wchar_t>; + using _Dependent_char = decltype((void) _Out, wchar_t{}); if constexpr (is_same_v<_OutputIt, _Fmt_wit>) { _Format_handler<_Dependent_char> _Handler(_Out, _Fmt, _Args, _Lazy_locale{_Loc}); _Parse_format_string(_Fmt, _Handler);