diff --git a/libcxx/include/__format/buffer.h b/libcxx/include/__format/buffer.h --- a/libcxx/include/__format/buffer.h +++ b/libcxx/include/__format/buffer.h @@ -17,9 +17,9 @@ #include <__algorithm/transform.h> #include <__algorithm/unwrap_iter.h> #include <__config> +#include <__format/concepts.h> #include <__format/enable_insertable.h> #include <__format/format_to_n_result.h> -#include <__format/formatter.h> // for __char_type TODO FMT Move the concept? #include <__iterator/back_insert_iterator.h> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> @@ -49,7 +49,7 @@ /// This helper is used together with the @ref back_insert_iterator to offer /// type-erasure for the formatting functions. This reduces the number to /// template instantiations. -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> class _LIBCPP_TEMPLATE_VIS __output_buffer { public: using value_type = _CharT; @@ -222,7 +222,7 @@ /// /// This storage is used when writing a single element to the output iterator /// is expensive. -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> class _LIBCPP_TEMPLATE_VIS __internal_storage { public: _LIBCPP_HIDE_FROM_ABI _CharT* __begin() { return __buffer_; } @@ -238,11 +238,11 @@ /// This requires the storage to be a contiguous buffer of \a _CharT. /// Since the output is directly written to the underlying storage this class /// is just an empty class. -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> class _LIBCPP_TEMPLATE_VIS __direct_storage {}; template -concept __enable_direct_output = __formatter::__char_type<_CharT> && +concept __enable_direct_output = __fmt_char_type<_CharT> && (same_as<_OutIt, _CharT*> #ifndef _LIBCPP_ENABLE_DEBUG_MODE || same_as<_OutIt, __wrap_iter<_CharT*>> @@ -250,7 +250,7 @@ ); /// Write policy for directly writing to the underlying output. -template +template class _LIBCPP_TEMPLATE_VIS __writer_direct { public: _LIBCPP_HIDE_FROM_ABI explicit __writer_direct(_OutIt __out_it) @@ -269,7 +269,7 @@ }; /// Write policy for copying the buffer to the output. -template +template class _LIBCPP_TEMPLATE_VIS __writer_iterator { public: _LIBCPP_HIDE_FROM_ABI explicit __writer_iterator(_OutIt __out_it) @@ -294,7 +294,7 @@ /// \ref __enable_insertable. template concept __insertable = - __enable_insertable<_Container> && __formatter::__char_type && + __enable_insertable<_Container> && __fmt_char_type && requires(_Container& __t, add_pointer_t __first, add_pointer_t __last) { __t.insert(__t.end(), __first, __last); }; @@ -340,7 +340,7 @@ }; /// The generic formatting buffer. -template +template requires(output_iterator<_OutIt, const _CharT&>) class _LIBCPP_TEMPLATE_VIS __format_buffer { using _Storage = @@ -376,7 +376,7 @@ /// /// Since \ref formatted_size only needs to know the size, the output itself is /// discarded. -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> class _LIBCPP_TEMPLATE_VIS __formatted_size_buffer { public: _LIBCPP_HIDE_FROM_ABI auto __make_output_iterator() { return __output_.__make_output_iterator(); } @@ -395,7 +395,7 @@ }; /// The base of a buffer that counts and limits the number of insertions. -template +template requires(output_iterator<_OutIt, const _CharT&>) struct _LIBCPP_TEMPLATE_VIS __format_to_n_buffer_base { using _Size = iter_difference_t<_OutIt>; @@ -425,7 +425,7 @@ /// /// This class limits the size available to the direct writer so it will not /// exceed the maximum number of code units. -template +template requires(output_iterator<_OutIt, const _CharT&>) class _LIBCPP_TEMPLATE_VIS __format_to_n_buffer_base<_OutIt, _CharT, true> { using _Size = iter_difference_t<_OutIt>; @@ -475,7 +475,7 @@ }; /// The buffer that counts and limits the number of insertions. -template +template requires(output_iterator<_OutIt, const _CharT&>) struct _LIBCPP_TEMPLATE_VIS __format_to_n_buffer final : public __format_to_n_buffer_base< _OutIt, _CharT, __enable_direct_output<_OutIt, _CharT>> { diff --git a/libcxx/include/__format/concepts.h b/libcxx/include/__format/concepts.h --- a/libcxx/include/__format/concepts.h +++ b/libcxx/include/__format/concepts.h @@ -25,6 +25,15 @@ #if _LIBCPP_STD_VER > 17 +/// The character type specializations of \ref formatter. +template +concept __fmt_char_type = + same_as<_CharT, char> +# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS + || same_as<_CharT, wchar_t> +# endif + ; + // The output iterator isn't specified. A formatter should accept any // output_iterator. This iterator is a minimal iterator to test the concept. // (Note testing for (w)format_context would be a valid choice, but requires diff --git a/libcxx/include/__format/formatter.h b/libcxx/include/__format/formatter.h --- a/libcxx/include/__format/formatter.h +++ b/libcxx/include/__format/formatter.h @@ -11,7 +11,6 @@ #define _LIBCPP___FORMAT_FORMATTER_H #include <__availability> -#include <__concepts/same_as.h> #include <__config> #include <__format/format_fwd.h> @@ -39,14 +38,6 @@ formatter& operator=(const formatter&) = delete; }; -namespace __formatter { - -/** The character types that formatters are specialized for. */ -template -concept __char_type = same_as<_CharT, char> || same_as<_CharT, wchar_t>; - -} // namespace __formatter - #endif //_LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__format/formatter_bool.h b/libcxx/include/__format/formatter_bool.h --- a/libcxx/include/__format/formatter_bool.h +++ b/libcxx/include/__format/formatter_bool.h @@ -14,8 +14,8 @@ #include <__availability> #include <__config> #include <__debug> +#include <__format/concepts.h> #include <__format/format_error.h> -#include <__format/format_fwd.h> #include <__format/format_parse_context.h> #include <__format/formatter.h> #include <__format/formatter_integral.h> @@ -35,7 +35,7 @@ #if _LIBCPP_STD_VER > 17 -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter { public: _LIBCPP_HIDE_FROM_ABI constexpr auto diff --git a/libcxx/include/__format/formatter_char.h b/libcxx/include/__format/formatter_char.h --- a/libcxx/include/__format/formatter_char.h +++ b/libcxx/include/__format/formatter_char.h @@ -13,7 +13,7 @@ #include <__availability> #include <__concepts/same_as.h> #include <__config> -#include <__format/format_fwd.h> +#include <__format/concepts.h> #include <__format/format_parse_context.h> #include <__format/formatter.h> #include <__format/formatter_integral.h> @@ -30,7 +30,7 @@ #if _LIBCPP_STD_VER > 17 -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT __formatter_char { public: _LIBCPP_HIDE_FROM_ABI constexpr auto diff --git a/libcxx/include/__format/formatter_floating_point.h b/libcxx/include/__format/formatter_floating_point.h --- a/libcxx/include/__format/formatter_floating_point.h +++ b/libcxx/include/__format/formatter_floating_point.h @@ -18,7 +18,7 @@ #include <__concepts/arithmetic.h> #include <__concepts/same_as.h> #include <__config> -#include <__format/format_fwd.h> +#include <__format/concepts.h> #include <__format/format_parse_context.h> #include <__format/formatter.h> #include <__format/formatter_integral.h> @@ -683,7 +683,7 @@ } // namespace __formatter -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS __formatter_floating_point { public: _LIBCPP_HIDE_FROM_ABI constexpr auto @@ -701,13 +701,13 @@ __format_spec::__parser<_CharT> __parser_; }; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_floating_point<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_floating_point<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_floating_point<_CharT> {}; diff --git a/libcxx/include/__format/formatter_integer.h b/libcxx/include/__format/formatter_integer.h --- a/libcxx/include/__format/formatter_integer.h +++ b/libcxx/include/__format/formatter_integer.h @@ -13,7 +13,7 @@ #include <__availability> #include <__concepts/arithmetic.h> #include <__config> -#include <__format/format_fwd.h> +#include <__format/concepts.h> #include <__format/format_parse_context.h> #include <__format/formatter.h> #include <__format/formatter_integral.h> @@ -30,7 +30,7 @@ #if _LIBCPP_STD_VER > 17 - template <__formatter::__char_type _CharT> + template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT __formatter_integer { public: @@ -59,43 +59,43 @@ }; // Signed integral types. -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> { }; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> {}; # ifndef _LIBCPP_HAS_NO_INT128 -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<__int128_t, _CharT> : public __formatter_integer<_CharT> {}; # endif // Unsigned integral types. -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_integer<_CharT> {}; # ifndef _LIBCPP_HAS_NO_INT128 -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<__uint128_t, _CharT> : public __formatter_integer<_CharT> {}; # endif diff --git a/libcxx/include/__format/formatter_integral.h b/libcxx/include/__format/formatter_integral.h --- a/libcxx/include/__format/formatter_integral.h +++ b/libcxx/include/__format/formatter_integral.h @@ -13,8 +13,8 @@ #include <__concepts/arithmetic.h> #include <__concepts/same_as.h> #include <__config> +#include <__format/concepts.h> #include <__format/format_error.h> -#include <__format/formatter.h> // for __char_type TODO FMT Move the concept? #include <__format/formatter_output.h> #include <__format/parser_std_format_spec.h> #include <__utility/unreachable.h> @@ -112,7 +112,7 @@ // Char // -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> _LIBCPP_HIDE_FROM_ABI auto __format_char( integral auto __value, output_iterator auto __out_it, diff --git a/libcxx/include/__format/formatter_pointer.h b/libcxx/include/__format/formatter_pointer.h --- a/libcxx/include/__format/formatter_pointer.h +++ b/libcxx/include/__format/formatter_pointer.h @@ -12,7 +12,7 @@ #include <__availability> #include <__config> -#include <__format/format_fwd.h> +#include <__format/concepts.h> #include <__format/format_parse_context.h> #include <__format/formatter.h> #include <__format/formatter_integral.h> @@ -29,7 +29,7 @@ #if _LIBCPP_STD_VER > 17 -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS __formatter_pointer { public: constexpr __formatter_pointer() { __parser_.__alignment_ = __format_spec::__alignment::__right; } @@ -56,13 +56,13 @@ // - struct formatter; // - template<> struct formatter; // - template<> struct formatter; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_pointer<_CharT> {}; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_pointer<_CharT> { }; -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_pointer<_CharT> {}; diff --git a/libcxx/include/__format/formatter_string.h b/libcxx/include/__format/formatter_string.h --- a/libcxx/include/__format/formatter_string.h +++ b/libcxx/include/__format/formatter_string.h @@ -12,7 +12,7 @@ #include <__availability> #include <__config> -#include <__format/format_fwd.h> +#include <__format/concepts.h> #include <__format/format_parse_context.h> #include <__format/formatter.h> #include <__format/formatter_output.h> @@ -29,7 +29,7 @@ #if _LIBCPP_STD_VER > 17 -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS __formatter_string { public: _LIBCPP_HIDE_FROM_ABI constexpr auto parse(basic_format_parse_context<_CharT>& __parse_ctx) @@ -47,7 +47,7 @@ }; // Formatter const char*. -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_string<_CharT> { using _Base = __formatter_string<_CharT>; @@ -80,7 +80,7 @@ }; // Formatter char*. -template <__formatter::__char_type _CharT> +template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<_CharT*, _CharT> : public formatter { using _Base = formatter; @@ -91,7 +91,7 @@ }; // Formatter char[]. -template <__formatter::__char_type _CharT, size_t _Size> +template <__fmt_char_type _CharT, size_t _Size> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<_CharT[_Size], _CharT> : public __formatter_string<_CharT> { using _Base = __formatter_string<_CharT>; @@ -102,7 +102,7 @@ }; // Formatter const char[]. -template <__formatter::__char_type _CharT, size_t _Size> +template <__fmt_char_type _CharT, size_t _Size> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter : public __formatter_string<_CharT> { using _Base = __formatter_string<_CharT>; @@ -113,7 +113,7 @@ }; // Formatter std::string. -template <__formatter::__char_type _CharT, class _Traits, class _Allocator> +template <__fmt_char_type _CharT, class _Traits, class _Allocator> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter, _CharT> : public __formatter_string<_CharT> { using _Base = __formatter_string<_CharT>; @@ -126,7 +126,7 @@ }; // Formatter std::string_view. -template <__formatter::__char_type _CharT, class _Traits> +template <__fmt_char_type _CharT, class _Traits> struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter, _CharT> : public __formatter_string<_CharT> { using _Base = __formatter_string<_CharT>;