diff options
Diffstat (limited to 'libcxx/include/format')
-rw-r--r-- | libcxx/include/format | 93 |
1 files changed, 42 insertions, 51 deletions
diff --git a/libcxx/include/format b/libcxx/include/format index bf51edd91ece..60197d24523f 100644 --- a/libcxx/include/format +++ b/libcxx/include/format @@ -36,13 +36,13 @@ namespace std { // [format.functions], formatting functions template<class... Args> - string format(format-string<Args...> fmt, const Args&... args); + string format(format-string<Args...> fmt, Args&&... args); template<class... Args> - wstring format(wformat-string<Args...> fmt, const Args&... args); + wstring format(wformat-string<Args...> fmt, Args&&... args); template<class... Args> - string format(const locale& loc, format-string<Args...> fmt, const Args&... args); + string format(const locale& loc, format-string<Args...> fmt, Args&&... args); template<class... Args> - wstring format(const locale& loc, wformat-string<Args...> fmt, const Args&... args); + wstring format(const locale& loc, wformat-string<Args...> fmt, Args&&... args); string vformat(string_view fmt, format_args args); wstring vformat(wstring_view fmt, wformat_args args); @@ -50,13 +50,13 @@ namespace std { wstring vformat(const locale& loc, wstring_view fmt, wformat_args args); template<class Out, class... Args> - Out format_to(Out out, format-string<Args...> fmt, const Args&... args); + Out format_to(Out out, format-string<Args...> fmt, Args&&... args); template<class Out, class... Args> - Out format_to(Out out, wformat-string<Args...> fmt, const Args&... args); + Out format_to(Out out, wformat-string<Args...> fmt, Args&&... args); template<class Out, class... Args> - Out format_to(Out out, const locale& loc, format-string<Args...> fmt, const Args&... args); + Out format_to(Out out, const locale& loc, format-string<Args...> fmt, Args&&... args); template<class Out, class... Args> - Out format_to(Out out, const locale& loc, wformat-string<Args...> fmt, const Args&... args); + Out format_to(Out out, const locale& loc, wformat-string<Args...> fmt, Args&&... args); template<class Out> Out vformat_to(Out out, string_view fmt, format_args args); @@ -75,27 +75,27 @@ namespace std { }; template<class Out, class... Args> format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n, - format-string<Args...> fmt, const Args&... args); + format-string<Args...> fmt, Args&&... args); template<class Out, class... Args> format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n, - wformat-string<Args...> fmt, const Args&... args); + wformat-string<Args...> fmt, Args&&... args); template<class Out, class... Args> format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n, const locale& loc, format-string<Args...> fmt, - const Args&... args); + Args&&... args); template<class Out, class... Args> format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n, const locale& loc, wformat-string<Args...> fmt, - const Args&... args); + Args&&... args); template<class... Args> - size_t formatted_size(format-string<Args...> fmt, const Args&... args); + size_t formatted_size(format-string<Args...> fmt, Args&&... args); template<class... Args> - size_t formatted_size(wformat-string<Args...> fmt, const Args&... args); + size_t formatted_size(wformat-string<Args...> fmt, Args&&... args); template<class... Args> - size_t formatted_size(const locale& loc, format-string<Args...> fmt, const Args&... args); + size_t formatted_size(const locale& loc, format-string<Args...> fmt, Args&&... args); template<class... Args> - size_t formatted_size(const locale& loc, wformat-string<Args...> fmt, const Args&... args); + size_t formatted_size(const locale& loc, wformat-string<Args...> fmt, Args&&... args); // [format.formatter], formatter template<class T, class charT = char> struct formatter; @@ -117,10 +117,10 @@ namespace std { template<class Context = format_context, class... Args> format-arg-store<Context, Args...> - make_format_args(const Args&... args); + make_format_args(Args&&... args); template<class... Args> format-arg-store<wformat_context, Args...> - make_wformat_args(const Args&... args); + make_wformat_args(Args&&... args); // [format.error], class format_error class format_error; @@ -190,26 +190,15 @@ using format_args = basic_format_args<format_context>; using wformat_args = basic_format_args<wformat_context>; #endif -// TODO FMT This helper wrapper can probably be removed after P2418 has been -// implemented. -template <class _Context, class... _Args> -_LIBCPP_HIDE_FROM_ABI __format_arg_store<_Context, _Args...> -__make_format_args(_Args&&... __args) { - return _VSTD::__format_arg_store<_Context, _Args...>( - _VSTD::forward<_Args>(__args)...); -} - -// TODO FMT After P2418 specify the return type instead of using auto. template <class _Context = format_context, class... _Args> -_LIBCPP_HIDE_FROM_ABI auto make_format_args(const _Args&... __args) { - return _VSTD::__make_format_args<_Context>(__args...); +_LIBCPP_HIDE_FROM_ABI __format_arg_store<_Context, _Args...> make_format_args(_Args&&... __args) { + return _VSTD::__format_arg_store<_Context, _Args...>(__args...); } #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -// TODO FMT After P2418 specify the return type instead of using auto. template <class... _Args> -_LIBCPP_HIDE_FROM_ABI auto make_wformat_args(const _Args&... __args) { - return _VSTD::make_format_args<wformat_context>(__args...); +_LIBCPP_HIDE_FROM_ABI __format_arg_store<wformat_context, _Args...> make_wformat_args(_Args&&... __args) { + return _VSTD::__format_arg_store<wformat_context, _Args...>(__args...); } #endif @@ -387,6 +376,7 @@ __handle_replacement_field(const _CharT* __begin, const _CharT* __end, __format::__parse_number_result __r = __format::__parse_arg_id(__begin, __end, __parse_ctx); + bool __parse = *__r.__ptr == _CharT(':'); switch (*__r.__ptr) { case _CharT(':'): // The arg-id has a format-specifier, advance the input to the format-spec. @@ -406,7 +396,7 @@ __handle_replacement_field(const _CharT* __begin, const _CharT* __end, if (__type == __arg_t::__handle) __ctx.__handle(__r.__value).__parse(__parse_ctx); else - __format::__compile_time_visit_format_arg(__parse_ctx, __ctx, __type); + __format::__compile_time_visit_format_arg(__parse_ctx, __ctx, __type); } else _VSTD::visit_format_arg( [&](auto __arg) { @@ -416,7 +406,8 @@ __handle_replacement_field(const _CharT* __begin, const _CharT* __end, __arg.format(__parse_ctx, __ctx); else { formatter<decltype(__arg), _CharT> __formatter; - __parse_ctx.advance_to(__formatter.parse(__parse_ctx)); + if (__parse) + __parse_ctx.advance_to(__formatter.parse(__parse_ctx)); __ctx.advance_to(__formatter.format(__arg, __ctx)); } }, @@ -563,7 +554,7 @@ vformat_to(_OutIt __out_it, wstring_view __fmt, wformat_args __args) { template <output_iterator<const char&> _OutIt, class... _Args> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt -format_to(_OutIt __out_it, __format_string_t<_Args...> __fmt, const _Args&... __args) { +format_to(_OutIt __out_it, __format_string_t<_Args...> __fmt, _Args&&... __args) { return _VSTD::vformat_to(_VSTD::move(__out_it), __fmt.__str_, _VSTD::make_format_args(__args...)); } @@ -571,7 +562,7 @@ format_to(_OutIt __out_it, __format_string_t<_Args...> __fmt, const _Args&... __ #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS template <output_iterator<const wchar_t&> _OutIt, class... _Args> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt -format_to(_OutIt __out_it, __wformat_string_t<_Args...> __fmt, const _Args&... __args) { +format_to(_OutIt __out_it, __wformat_string_t<_Args...> __fmt, _Args&&... __args) { return _VSTD::vformat_to(_VSTD::move(__out_it), __fmt.__str_, _VSTD::make_wformat_args(__args...)); } @@ -595,14 +586,14 @@ vformat(wstring_view __fmt, wformat_args __args) { template <class... _Args> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string format(__format_string_t<_Args...> __fmt, - const _Args&... __args) { + _Args&&... __args) { return _VSTD::vformat(__fmt.__str_, _VSTD::make_format_args(__args...)); } #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS template <class... _Args> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring -format(__wformat_string_t<_Args...> __fmt, const _Args&... __args) { +format(__wformat_string_t<_Args...> __fmt, _Args&&... __args) { return _VSTD::vformat(__fmt.__str_, _VSTD::make_wformat_args(__args...)); } #endif @@ -619,7 +610,7 @@ _LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> __vformat_to_n(_OutIt __out_it, template <output_iterator<const char&> _OutIt, class... _Args> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt> -format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, __format_string_t<_Args...> __fmt, const _Args&... __args) { +format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, __format_string_t<_Args...> __fmt, _Args&&... __args) { return _VSTD::__vformat_to_n<format_context>(_VSTD::move(__out_it), __n, __fmt.__str_, _VSTD::make_format_args(__args...)); } @@ -627,7 +618,7 @@ format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, __format_string_t<_A template <output_iterator<const wchar_t&> _OutIt, class... _Args> _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt> format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, __wformat_string_t<_Args...> __fmt, - const _Args&... __args) { + _Args&&... __args) { return _VSTD::__vformat_to_n<wformat_context>(_VSTD::move(__out_it), __n, __fmt.__str_, _VSTD::make_wformat_args(__args...)); } #endif @@ -642,14 +633,14 @@ _LIBCPP_HIDE_FROM_ABI size_t __vformatted_size(basic_string_view<_CharT> __fmt, template <class... _Args> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t -formatted_size(__format_string_t<_Args...> __fmt, const _Args&... __args) { +formatted_size(__format_string_t<_Args...> __fmt, _Args&&... __args) { return _VSTD::__vformatted_size(__fmt.__str_, basic_format_args{_VSTD::make_format_args(__args...)}); } #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS template <class... _Args> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t -formatted_size(__wformat_string_t<_Args...> __fmt, const _Args&... __args) { +formatted_size(__wformat_string_t<_Args...> __fmt, _Args&&... __args) { return _VSTD::__vformatted_size(__fmt.__str_, basic_format_args{_VSTD::make_wformat_args(__args...)}); } #endif @@ -694,7 +685,7 @@ _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt v template <output_iterator<const char&> _OutIt, class... _Args> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt -format_to(_OutIt __out_it, locale __loc, __format_string_t<_Args...> __fmt, const _Args&... __args) { +format_to(_OutIt __out_it, locale __loc, __format_string_t<_Args...> __fmt, _Args&&... __args) { return _VSTD::vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt.__str_, _VSTD::make_format_args(__args...)); } @@ -702,7 +693,7 @@ format_to(_OutIt __out_it, locale __loc, __format_string_t<_Args...> __fmt, cons #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS template <output_iterator<const wchar_t&> _OutIt, class... _Args> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt -format_to(_OutIt __out_it, locale __loc, __wformat_string_t<_Args...> __fmt, const _Args&... __args) { +format_to(_OutIt __out_it, locale __loc, __wformat_string_t<_Args...> __fmt, _Args&&... __args) { return _VSTD::vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt.__str_, _VSTD::make_wformat_args(__args...)); } @@ -729,7 +720,7 @@ vformat(locale __loc, wstring_view __fmt, wformat_args __args) { template <class... _Args> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string format(locale __loc, __format_string_t<_Args...> __fmt, - const _Args&... __args) { + _Args&&... __args) { return _VSTD::vformat(_VSTD::move(__loc), __fmt.__str_, _VSTD::make_format_args(__args...)); } @@ -737,7 +728,7 @@ _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string f #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS template <class... _Args> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring -format(locale __loc, __wformat_string_t<_Args...> __fmt, const _Args&... __args) { +format(locale __loc, __wformat_string_t<_Args...> __fmt, _Args&&... __args) { return _VSTD::vformat(_VSTD::move(__loc), __fmt.__str_, _VSTD::make_wformat_args(__args...)); } @@ -757,7 +748,7 @@ _LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> __vformat_to_n(_OutIt __out_it, template <output_iterator<const char&> _OutIt, class... _Args> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt> format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, locale __loc, __format_string_t<_Args...> __fmt, - const _Args&... __args) { + _Args&&... __args) { return _VSTD::__vformat_to_n<format_context>(_VSTD::move(__out_it), __n, _VSTD::move(__loc), __fmt.__str_, _VSTD::make_format_args(__args...)); } @@ -766,7 +757,7 @@ format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, locale __loc, __form template <output_iterator<const wchar_t&> _OutIt, class... _Args> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt> format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, locale __loc, __wformat_string_t<_Args...> __fmt, - const _Args&... __args) { + _Args&&... __args) { return _VSTD::__vformat_to_n<wformat_context>(_VSTD::move(__out_it), __n, _VSTD::move(__loc), __fmt.__str_, _VSTD::make_wformat_args(__args...)); } @@ -783,14 +774,14 @@ _LIBCPP_HIDE_FROM_ABI size_t __vformatted_size(locale __loc, basic_string_view<_ template <class... _Args> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t -formatted_size(locale __loc, __format_string_t<_Args...> __fmt, const _Args&... __args) { +formatted_size(locale __loc, __format_string_t<_Args...> __fmt, _Args&&... __args) { return _VSTD::__vformatted_size(_VSTD::move(__loc), __fmt.__str_, basic_format_args{_VSTD::make_format_args(__args...)}); } #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS template <class... _Args> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t -formatted_size(locale __loc, __wformat_string_t<_Args...> __fmt, const _Args&... __args) { +formatted_size(locale __loc, __wformat_string_t<_Args...> __fmt, _Args&&... __args) { return _VSTD::__vformatted_size(_VSTD::move(__loc), __fmt.__str_, basic_format_args{_VSTD::make_wformat_args(__args...)}); } #endif |