This partly reverts D133535 and enables CTAD for more parts in format.
Reviewed By: ldionne, #libc
Differential Revision: https://reviews.llvm.org/D135292
# endif
# endif
-// There are a handful of standard library types that are intended to support CTAD but don't need any
-// explicit deduction guides to do so. This macro is used to mark them as such, which suppresses the
-// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code with these classes.
+// There are a handful of public standard library types that are intended to
+// support CTAD but don't need any explicit deduction guides to do so. This
+// macro is used to mark them as such, which suppresses the
+// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code
+// with these classes.
#if _LIBCPP_STD_VER >= 17
-# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \
- template <class _Tag = void> \
- _ClassName(typename _Tag::__allow_ctad) -> _ClassName<_Tag>
+# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \
+ template <class ..._Tag> \
+ _ClassName(typename _Tag::__allow_ctad...) -> _ClassName<_Tag...>
#else
# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "")
#endif
_OutIt __out_it,
basic_format_args<basic_format_context<_OutIt, _CharT>> __args,
optional<_VSTD::locale>&& __loc = nullopt) {
- return _VSTD::basic_format_context<_OutIt, _CharT>(_VSTD::move(__out_it), __args,
- _VSTD::move(__loc));
+ return _VSTD::basic_format_context(_VSTD::move(__out_it), __args, _VSTD::move(__loc));
}
#else
template <class _OutIt, class _CharT>
__format_context_create(
_OutIt __out_it,
basic_format_args<basic_format_context<_OutIt, _CharT>> __args) {
- return _VSTD::basic_format_context<_OutIt, _CharT>(_VSTD::move(__out_it), __args);
+ return _VSTD::basic_format_context(_VSTD::move(__out_it), __args);
}
#endif
: __out_it_(_VSTD::move(__out_it)), __args_(__args) {}
#endif
};
+_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(basic_format_context);
#endif //_LIBCPP_STD_VER > 17
_LIBCPP_HIDE_FROM_ABI constexpr const _CharT*
__handle_replacement_field(const _CharT* __begin, const _CharT* __end,
_ParseCtx& __parse_ctx, _Ctx& __ctx) {
- __format::__parse_number_result<_CharT> __r =
- __format::__parse_arg_id(__begin, __end, __parse_ctx);
+ __format::__parse_number_result __r = __format::__parse_arg_id(__begin, __end, __parse_ctx);
bool __parse = *__r.__ptr == _CharT(':');
switch (*__r.__ptr) {
_OutIt __out_it, basic_string_view<_CharT> __fmt,
basic_format_args<basic_format_context<_FormatOutIt, _CharT>> __args) {
if constexpr (same_as<_OutIt, _FormatOutIt>)
- return _VSTD::__format::__vformat_to(
- basic_format_parse_context<_CharT>{__fmt, __args.__size()},
- _VSTD::__format_context_create(_VSTD::move(__out_it), __args));
+ return _VSTD::__format::__vformat_to(basic_format_parse_context{__fmt, __args.__size()},
+ _VSTD::__format_context_create(_VSTD::move(__out_it), __args));
else {
__format::__format_buffer<_OutIt, _CharT> __buffer{_VSTD::move(__out_it)};
- _VSTD::__format::__vformat_to(
- basic_format_parse_context<_CharT>{__fmt, __args.__size()},
- _VSTD::__format_context_create(__buffer.__make_output_iterator(),
- __args));
+ _VSTD::__format::__vformat_to(basic_format_parse_context{__fmt, __args.__size()},
+ _VSTD::__format_context_create(__buffer.__make_output_iterator(), __args));
return _VSTD::move(__buffer).__out_it();
}
}
basic_string_view<_CharT> __fmt,
basic_format_args<_Context> __args) {
__format::__format_to_n_buffer<_OutIt, _CharT> __buffer{_VSTD::move(__out_it), __n};
- _VSTD::__format::__vformat_to(basic_format_parse_context<_CharT>{__fmt, __args.__size()},
+ _VSTD::__format::__vformat_to(basic_format_parse_context{__fmt, __args.__size()},
_VSTD::__format_context_create(__buffer.__make_output_iterator(), __args));
return _VSTD::move(__buffer).__result();
}
template <class _CharT>
_LIBCPP_HIDE_FROM_ABI size_t __vformatted_size(basic_string_view<_CharT> __fmt, auto __args) {
__format::__formatted_size_buffer<_CharT> __buffer;
- _VSTD::__format::__vformat_to(basic_format_parse_context<_CharT>{__fmt, __args.__size()},
+ _VSTD::__format::__vformat_to(basic_format_parse_context{__fmt, __args.__size()},
_VSTD::__format_context_create(__buffer.__make_output_iterator(), __args));
return _VSTD::move(__buffer).__result();
}
basic_format_args<basic_format_context<_FormatOutIt, _CharT>> __args) {
if constexpr (same_as<_OutIt, _FormatOutIt>)
return _VSTD::__format::__vformat_to(
- basic_format_parse_context<_CharT>{__fmt, __args.__size()},
- _VSTD::__format_context_create(_VSTD::move(__out_it), __args,
- _VSTD::move(__loc)));
+ basic_format_parse_context{__fmt, __args.__size()},
+ _VSTD::__format_context_create(_VSTD::move(__out_it), __args, _VSTD::move(__loc)));
else {
__format::__format_buffer<_OutIt, _CharT> __buffer{_VSTD::move(__out_it)};
_VSTD::__format::__vformat_to(
- basic_format_parse_context<_CharT>{__fmt, __args.__size()},
- _VSTD::__format_context_create(__buffer.__make_output_iterator(),
- __args, _VSTD::move(__loc)));
+ basic_format_parse_context{__fmt, __args.__size()},
+ _VSTD::__format_context_create(__buffer.__make_output_iterator(), __args, _VSTD::move(__loc)));
return _VSTD::move(__buffer).__out_it();
}
}
basic_format_args<_Context> __args) {
__format::__format_to_n_buffer<_OutIt, _CharT> __buffer{_VSTD::move(__out_it), __n};
_VSTD::__format::__vformat_to(
- basic_format_parse_context<_CharT>{__fmt, __args.__size()},
+ basic_format_parse_context{__fmt, __args.__size()},
_VSTD::__format_context_create(__buffer.__make_output_iterator(), __args, _VSTD::move(__loc)));
return _VSTD::move(__buffer).__result();
}
_LIBCPP_HIDE_FROM_ABI size_t __vformatted_size(locale __loc, basic_string_view<_CharT> __fmt, auto __args) {
__format::__formatted_size_buffer<_CharT> __buffer;
_VSTD::__format::__vformat_to(
- basic_format_parse_context<_CharT>{__fmt, __args.__size()},
+ basic_format_parse_context{__fmt, __args.__size()},
_VSTD::__format_context_create(__buffer.__make_output_iterator(), __args, _VSTD::move(__loc)));
return _VSTD::move(__buffer).__result();
}
size_t __next_arg_id_;
size_t __num_args_;
};
+_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(basic_format_parse_context);
using format_parse_context = basic_format_parse_context<char>;
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
};
template <class _CharT>
+__parse_number_result(const _CharT*, uint32_t) -> __parse_number_result<_CharT>;
+
+template <class _CharT>
_LIBCPP_HIDE_FROM_ABI constexpr __parse_number_result<_CharT>
__parse_number(const _CharT* __begin, const _CharT* __end);
if (__begin == __end)
__throw_format_error("End of input while parsing format-spec arg-id");
- __format::__parse_number_result<_CharT> __r =
- __format::__parse_arg_id(__begin, __end, __parse_ctx);
+ __format::__parse_number_result __r = __format::__parse_arg_id(__begin, __end, __parse_ctx);
if (__r.__ptr == __end || *__r.__ptr != _CharT('}'))
__throw_format_error("Invalid arg-id");
__throw_format_error("A format-spec width field shouldn't have a leading zero");
if (*__begin == _CharT('{')) {
- __format::__parse_number_result<_CharT> __r = __format_spec::__parse_arg_id(++__begin, __end, __parse_ctx);
+ __format::__parse_number_result __r = __format_spec::__parse_arg_id(++__begin, __end, __parse_ctx);
__width_as_arg_ = true;
__width_ = __r.__value;
__begin = __r.__ptr;
if (*__begin < _CharT('0') || *__begin > _CharT('9'))
return false;
- __format::__parse_number_result<_CharT> __r = __format::__parse_number(__begin, __end);
+ __format::__parse_number_result __r = __format::__parse_number(__begin, __end);
__width_ = __r.__value;
_LIBCPP_ASSERT(__width_ != 0, "A zero value isn't allowed and should be impossible, "
"due to validations in this function");
__throw_format_error("End of input while parsing format-spec precision");
if (*__begin == _CharT('{')) {
- __format::__parse_number_result<_CharT> __arg_id = __format_spec::__parse_arg_id(++__begin, __end, __parse_ctx);
+ __format::__parse_number_result __arg_id = __format_spec::__parse_arg_id(++__begin, __end, __parse_ctx);
__precision_as_arg_ = true;
__precision_ = __arg_id.__value;
__begin = __arg_id.__ptr;
if (*__begin < _CharT('0') || *__begin > _CharT('9'))
__throw_format_error("The format-spec precision field doesn't contain a value or arg-id");
- __format::__parse_number_result<_CharT> __r = __format::__parse_number(__begin, __end);
+ __format::__parse_number_result __r = __format::__parse_number(__begin, __end);
__precision_ = __r.__value;
__precision_as_arg_ = false;
__begin = __r.__ptr;
const _CharT* __last_;
};
+template <class _CharT>
+__column_width_result(size_t, const _CharT*) -> __column_width_result<_CharT>;
+
/// Since a column width can be two it's possible that the requested column
/// width can't be achieved. Depending on the intended usage the policy can be
/// selected.
}
ptrdiff_t __ascii_size = __it - __str.begin();
- __column_width_result<_CharT> __result =
+ __column_width_result __result =
__detail::__estimate_column_width_grapheme_clustering(__it, __str.end(), __maximum, __rounding);
__result.__width_ += __ascii_size;
std::basic_format_args<std::basic_format_context<OutIt, CharT>> args) {
{
std::basic_string<CharT> str[3];
- std::basic_format_context<OutIt, CharT> context =
- test_format_context_create(OutIt{str[0]}, args);
+ std::basic_format_context context = test_format_context_create(OutIt{str[0]}, args);
context.out() = CharT('a');
context.advance_to(OutIt{str[1]});
context.out() = CharT('b');
std::basic_format_args args = store;
std::basic_string<CharT> output;
- const std::basic_format_context<OutIt, CharT> context =
- test_format_context_create(OutIt{output}, args);
+ const std::basic_format_context context = test_format_context_create(OutIt{output}, args);
LIBCPP_ASSERT(args.__size() == 4);
ASSERT_NOEXCEPT(context.arg(0));
for (size_t i = 0, e = args.__size(); i != e; ++i) {
{
std::basic_string<CharT> output;
OutIt out_it{output};
- std::basic_format_context<OutIt, CharT> context = test_format_context_create(out_it, args);
+ std::basic_format_context context = test_format_context_create(out_it, args);
LIBCPP_ASSERT(args.__size() == 4);
assert(test_basic_format_arg(context.arg(0), true));
{
std::basic_string<CharT> output;
OutIt out_it{output};
- std::basic_format_context<OutIt, CharT> context = test_format_context_create(out_it, args, en_US);
+ std::basic_format_context context = test_format_context_create(out_it, args, en_US);
LIBCPP_ASSERT(args.__size() == 4);
assert(test_basic_format_arg(context.arg(0), true));
{
std::basic_string<CharT> output;
OutIt out_it{output};
- std::basic_format_context<OutIt, CharT> context = test_format_context_create(out_it, args, fr_FR);
+ std::basic_format_context context = test_format_context_create(out_it, args, fr_FR);
LIBCPP_ASSERT(args.__size() == 4);
assert(test_basic_format_arg(context.arg(0), true));
{
std::basic_string<CharT> output;
OutIt out_it{output};
- std::basic_format_context<OutIt, CharT> context = test_format_context_create(out_it, args, en_US);
+ std::basic_format_context context = test_format_context_create(out_it, args, en_US);
assert(args.__size() == 4);
assert(test_basic_format_arg(context.arg(0), true));
assert(test_basic_format_arg(context.arg(1), CharT('a')));
{
std::basic_string<CharT> output;
OutIt out_it{output};
- std::basic_format_context<OutIt, CharT> context = test_format_context_create(out_it, args, fr_FR);
+ std::basic_format_context context = test_format_context_create(out_it, args, fr_FR);
assert(args.__size() == 4);
assert(test_basic_format_arg(context.arg(0), true));
assert(test_basic_format_arg(context.arg(1), CharT('a')));
{
std::basic_string<CharT> str;
OutIt out_it{str};
- std::basic_format_context<OutIt, CharT> context = test_format_context_create(out_it, args);
+ std::basic_format_context context = test_format_context_create(out_it, args);
context.out() = CharT('a');
context.out() = CharT('b');
context.out() = CharT('c');
}
{
std::basic_string_view view{fmt};
- std::basic_format_parse_context<CharT> context(view);
+ std::basic_format_parse_context context(view);
context.advance_to(context.begin() + 1);
assert(std::to_address(context.begin()) == fmt + 1);
}
{
std::basic_string_view view{fmt};
- std::basic_format_parse_context<CharT> context(view);
+ std::basic_format_parse_context context(view);
assert(context.begin() == view.begin());
ASSERT_NOEXCEPT(context.begin());
}
static_assert(
!std::is_move_assignable_v<std::basic_format_parse_context<CharT> >);
- ASSERT_NOEXCEPT(
- std::basic_format_parse_context<CharT>{std::basic_string_view<CharT>{}});
- ASSERT_NOEXCEPT(
- std::basic_format_parse_context<CharT>{std::basic_string_view<CharT>{}, 42});
+ ASSERT_NOEXCEPT(std::basic_format_parse_context{std::basic_string_view<CharT>{}});
+ ASSERT_NOEXCEPT(std::basic_format_parse_context{std::basic_string_view<CharT>{}, 42});
{
std::basic_format_parse_context<CharT> context(fmt);
}
{
std::basic_string_view view{fmt};
- std::basic_format_parse_context<CharT> context(view);
+ std::basic_format_parse_context context(view);
assert(context.begin() == view.begin());
assert(context.end() == view.end());
}
}
{
std::basic_string_view view{fmt};
- std::basic_format_parse_context<CharT> context(view);
+ std::basic_format_parse_context context(view);
assert(context.end() == view.end());
ASSERT_NOEXCEPT(context.end());
}