diff --git a/stl/inc/format b/stl/inc/format index e5a549e7749..0683f56dd28 100644 --- a/stl/inc/format +++ b/stl/inc/format @@ -2857,6 +2857,22 @@ _NODISCARD auto make_wformat_args(const _Args&... _Vals) { return _Format_arg_store{_Vals...}; } +template +struct _Basic_format_string { + basic_string_view<_CharT> _Str; + + // TRANSITION, consteval compiler support + template + requires convertible_to> constexpr _Basic_format_string(const _Ty& _Str_) + : _Str{_Str_} {} +}; + +template +using _Fmt_string = _Basic_format_string...>; + +template +using _Fmt_wstring = _Basic_format_string...>; + template _OutputIt> _OutputIt vformat_to(_OutputIt _Out, const string_view _Fmt, const format_args _Args) { if constexpr (is_same_v<_OutputIt, _Fmt_it>) { @@ -2914,23 +2930,23 @@ _OutputIt vformat_to(_OutputIt _Out, const locale& _Loc, const wstring_view _Fmt } template _OutputIt, class... _Types> -_OutputIt format_to(_OutputIt _Out, const string_view _Fmt, const _Types&... _Args) { - return _STD vformat_to(_STD move(_Out), _Fmt, _STD make_format_args(_Args...)); +_OutputIt format_to(_OutputIt _Out, const _Fmt_string<_Types...> _Fmt, const _Types&... _Args) { + return _STD vformat_to(_STD move(_Out), _Fmt._Str, _STD make_format_args(_Args...)); } template _OutputIt, class... _Types> -_OutputIt format_to(_OutputIt _Out, const wstring_view _Fmt, const _Types&... _Args) { - return _STD vformat_to(_STD move(_Out), _Fmt, _STD make_wformat_args(_Args...)); +_OutputIt format_to(_OutputIt _Out, const _Fmt_wstring<_Types...> _Fmt, const _Types&... _Args) { + return _STD vformat_to(_STD move(_Out), _Fmt._Str, _STD make_wformat_args(_Args...)); } template _OutputIt, class... _Types> -_OutputIt format_to(_OutputIt _Out, const locale& _Loc, const string_view _Fmt, const _Types&... _Args) { - return _STD vformat_to(_STD move(_Out), _Loc, _Fmt, _STD make_format_args(_Args...)); +_OutputIt format_to(_OutputIt _Out, const locale& _Loc, const _Fmt_string<_Types...> _Fmt, const _Types&... _Args) { + return _STD vformat_to(_STD move(_Out), _Loc, _Fmt._Str, _STD make_format_args(_Args...)); } template _OutputIt, class... _Types> -_OutputIt format_to(_OutputIt _Out, const locale& _Loc, const wstring_view _Fmt, const _Types&... _Args) { - return _STD vformat_to(_STD move(_Out), _Loc, _Fmt, _STD make_wformat_args(_Args...)); +_OutputIt format_to(_OutputIt _Out, const locale& _Loc, const _Fmt_wstring<_Types...> _Fmt, const _Types&... _Args) { + return _STD vformat_to(_STD move(_Out), _Loc, _Fmt._Str, _STD make_wformat_args(_Args...)); } _NODISCARD inline string vformat(const string_view _Fmt, const format_args _Args) { @@ -2962,23 +2978,23 @@ _NODISCARD inline wstring vformat(const locale& _Loc, const wstring_view _Fmt, c } template -_NODISCARD string format(const string_view _Fmt, const _Types&... _Args) { - return _STD vformat(_Fmt, _STD make_format_args(_Args...)); +_NODISCARD string format(const _Fmt_string<_Types...> _Fmt, const _Types&... _Args) { + return _STD vformat(_Fmt._Str, _STD make_format_args(_Args...)); } template -_NODISCARD wstring format(const wstring_view _Fmt, const _Types&... _Args) { - return _STD vformat(_Fmt, _STD make_wformat_args(_Args...)); +_NODISCARD wstring format(const _Fmt_wstring<_Types...> _Fmt, const _Types&... _Args) { + return _STD vformat(_Fmt._Str, _STD make_wformat_args(_Args...)); } template -_NODISCARD string format(const locale& _Loc, const string_view _Fmt, const _Types&... _Args) { - return _STD vformat(_Loc, _Fmt, _STD make_format_args(_Args...)); +_NODISCARD string format(const locale& _Loc, const _Fmt_string<_Types...> _Fmt, const _Types&... _Args) { + return _STD vformat(_Loc, _Fmt._Str, _STD make_format_args(_Args...)); } template -_NODISCARD wstring format(const locale& _Loc, const wstring_view _Fmt, const _Types&... _Args) { - return _STD vformat(_Loc, _Fmt, _STD make_wformat_args(_Args...)); +_NODISCARD wstring format(const locale& _Loc, const _Fmt_wstring<_Types...> _Fmt, const _Types&... _Args) { + return _STD vformat(_Loc, _Fmt._Str, _STD make_wformat_args(_Args...)); } template @@ -2988,62 +3004,62 @@ struct format_to_n_result { }; template _OutputIt, class... _Types> -format_to_n_result<_OutputIt> format_to_n( - _OutputIt _Out, const iter_difference_t<_OutputIt> _Max, const string_view _Fmt, const _Types&... _Args) { +format_to_n_result<_OutputIt> format_to_n(_OutputIt _Out, const iter_difference_t<_OutputIt> _Max, + const _Fmt_string<_Types...> _Fmt, const _Types&... _Args) { _Fmt_iterator_buffer<_OutputIt, char, _Fmt_fixed_buffer_traits> _Buf(_STD move(_Out), _Max); - _STD vformat_to(_Fmt_it{_Buf}, _Fmt, _STD make_format_args(_Args...)); + _STD vformat_to(_Fmt_it{_Buf}, _Fmt._Str, _STD make_format_args(_Args...)); return {.out = _Buf._Out(), .size = _Buf._Count()}; } template _OutputIt, class... _Types> -format_to_n_result<_OutputIt> format_to_n( - _OutputIt _Out, const iter_difference_t<_OutputIt> _Max, const wstring_view _Fmt, const _Types&... _Args) { +format_to_n_result<_OutputIt> format_to_n(_OutputIt _Out, const iter_difference_t<_OutputIt> _Max, + const _Fmt_wstring<_Types...> _Fmt, const _Types&... _Args) { _Fmt_iterator_buffer<_OutputIt, wchar_t, _Fmt_fixed_buffer_traits> _Buf(_STD move(_Out), _Max); - _STD vformat_to(_Fmt_wit{_Buf}, _Fmt, _STD make_wformat_args(_Args...)); + _STD vformat_to(_Fmt_wit{_Buf}, _Fmt._Str, _STD make_wformat_args(_Args...)); return {.out = _Buf._Out(), .size = _Buf._Count()}; } template _OutputIt, class... _Types> format_to_n_result<_OutputIt> format_to_n(_OutputIt _Out, const iter_difference_t<_OutputIt> _Max, const locale& _Loc, - const string_view _Fmt, const _Types&... _Args) { + const _Fmt_string<_Types...> _Fmt, const _Types&... _Args) { _Fmt_iterator_buffer<_OutputIt, char, _Fmt_fixed_buffer_traits> _Buf(_STD move(_Out), _Max); - _STD vformat_to(_Fmt_it{_Buf}, _Loc, _Fmt, _STD make_format_args(_Args...)); + _STD vformat_to(_Fmt_it{_Buf}, _Loc, _Fmt._Str, _STD make_format_args(_Args...)); return {.out = _Buf._Out(), .size = _Buf._Count()}; } template _OutputIt, class... _Types> format_to_n_result<_OutputIt> format_to_n(_OutputIt _Out, const iter_difference_t<_OutputIt> _Max, const locale& _Loc, - const wstring_view _Fmt, const _Types&... _Args) { + const _Fmt_wstring<_Types...> _Fmt, const _Types&... _Args) { _Fmt_iterator_buffer<_OutputIt, wchar_t, _Fmt_fixed_buffer_traits> _Buf(_STD move(_Out), _Max); - _STD vformat_to(_Fmt_wit{_Buf}, _Loc, _Fmt, _STD make_wformat_args(_Args...)); + _STD vformat_to(_Fmt_wit{_Buf}, _Loc, _Fmt._Str, _STD make_wformat_args(_Args...)); return {.out = _Buf._Out(), .size = _Buf._Count()}; } template -_NODISCARD size_t formatted_size(const string_view _Fmt, const _Types&... _Args) { +_NODISCARD size_t formatted_size(const _Fmt_string<_Types...> _Fmt, const _Types&... _Args) { _Fmt_counting_buffer _Buf; - _STD vformat_to(_Fmt_it{_Buf}, _Fmt, _STD make_format_args(_Args...)); + _STD vformat_to(_Fmt_it{_Buf}, _Fmt._Str, _STD make_format_args(_Args...)); return _Buf._Count(); } template -_NODISCARD size_t formatted_size(const wstring_view _Fmt, const _Types&... _Args) { +_NODISCARD size_t formatted_size(const _Fmt_wstring<_Types...> _Fmt, const _Types&... _Args) { _Fmt_counting_buffer _Buf; - _STD vformat_to(_Fmt_wit{_Buf}, _Fmt, _STD make_wformat_args(_Args...)); + _STD vformat_to(_Fmt_wit{_Buf}, _Fmt._Str, _STD make_wformat_args(_Args...)); return _Buf._Count(); } template -_NODISCARD size_t formatted_size(const locale& _Loc, const string_view _Fmt, const _Types&... _Args) { +_NODISCARD size_t formatted_size(const locale& _Loc, const _Fmt_string<_Types...> _Fmt, const _Types&... _Args) { _Fmt_counting_buffer _Buf; - _STD vformat_to(_Fmt_it{_Buf}, _Loc, _Fmt, _STD make_format_args(_Args...)); + _STD vformat_to(_Fmt_it{_Buf}, _Loc, _Fmt._Str, _STD make_format_args(_Args...)); return _Buf._Count(); } template -_NODISCARD size_t formatted_size(const locale& _Loc, const wstring_view _Fmt, const _Types&... _Args) { +_NODISCARD size_t formatted_size(const locale& _Loc, const _Fmt_wstring<_Types...> _Fmt, const _Types&... _Args) { _Fmt_counting_buffer _Buf; - _STD vformat_to(_Fmt_wit{_Buf}, _Loc, _Fmt, _STD make_wformat_args(_Args...)); + _STD vformat_to(_Fmt_wit{_Buf}, _Loc, _Fmt._Str, _STD make_wformat_args(_Args...)); return _Buf._Count(); }