Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions stl/inc/format
Original file line number Diff line number Diff line change
Expand Up @@ -1776,7 +1776,7 @@ struct _Format_arg_traits {
-> basic_string_view<_Char_type>; // not defined

template <class _Traits, class _Alloc>
static auto _Phony_basic_format_arg_constructor(const basic_string<_Char_type, _Traits, _Alloc>&)
static auto _Phony_basic_format_arg_constructor(basic_string<_Char_type, _Traits, _Alloc>)
Comment thread
StephanTLavavej marked this conversation as resolved.
Comment thread
StephanTLavavej marked this conversation as resolved.
Comment thread
StephanTLavavej marked this conversation as resolved.
-> basic_string_view<_Char_type>; // not defined

static auto _Phony_basic_format_arg_constructor(nullptr_t) -> const void*; // not defined
Expand Down Expand Up @@ -3286,10 +3286,15 @@ struct _Formatter_base {
_FormatCtx.arg(static_cast<size_t>(_Specs._Dynamic_precision_index)));
}

return _STD visit_format_arg(
_Arg_formatter<typename _FormatContext::iterator, _CharT>{
._Ctx = _STD addressof(_FormatCtx), ._Specs = _STD addressof(_Format_specs)},
basic_format_arg<_FormatContext>{_Val});
_Arg_formatter<typename _FormatContext::iterator, _CharT> _Arg_fmt{
._Ctx = _STD addressof(_FormatCtx), ._Specs = _STD addressof(_Format_specs)};

using _Storage_type = typename _Format_arg_traits<_FormatContext>::template _Storage_type<_Ty>;
if constexpr (is_same_v<typename basic_format_arg<_FormatContext>::handle, _Storage_type>) {
return _STD visit_format_arg(_Arg_fmt, basic_format_arg<_FormatContext>{_Val});
} else {
return _STD visit_format_arg(_Arg_fmt, basic_format_arg<_FormatContext>{static_cast<_Storage_type>(_Val)});
}
Comment thread
fsb4000 marked this conversation as resolved.
Outdated
}

private:
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/P0645R10_text_formatting_args/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cstdint>
#include <format>
#include <memory>
#include <string>
#include <string_view>
#include <type_traits>
#include <variant>
Expand Down Expand Up @@ -212,6 +213,9 @@ void test_format_arg_store() {
static_assert(sizeof(_Format_arg_index) == sizeof(size_t));
static_assert(is_same_v<_Format_arg_traits<format_context>::_Storage_type<void*>, const void*>);

static_assert(is_same_v<_Format_arg_traits<format_context>::_Storage_type<string>, string_view>);
static_assert(is_same_v<_Format_arg_traits<format_context>::_Storage_type<const string>, string_view>);

template <class Context>
void test_visit_monostate() {
assert(visit_format_arg(visitor<Context>, basic_format_arg<Context>()) == Arg_type::none);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,29 +172,35 @@ void test_format_family_overloads() {
template <class charT>
void test_custom_formattable_type() {
test_numeric_custom_formattable_type<int, charT>();
test_numeric_custom_formattable_type<long, charT>();
test_numeric_custom_formattable_type<long long, charT>();
test_numeric_custom_formattable_type<unsigned int, charT>();
test_numeric_custom_formattable_type<unsigned long, charT>();
test_numeric_custom_formattable_type<unsigned long long, charT>();
test_numeric_custom_formattable_type<short, charT>();
#ifdef _NATIVE_WCHAR_T_DEFINED
test_numeric_custom_formattable_type<unsigned short, charT>();
#endif
test_numeric_custom_formattable_type<float, charT>();
test_numeric_custom_formattable_type<double, charT>();
test_numeric_custom_formattable_type<long double, charT>();
}

template <class charT>
void test_mixed_custom_formattable_type() {
test_numeric_mixed_args_custom_formattable_type<int, charT>();
test_numeric_mixed_args_custom_formattable_type<long, charT>();
test_numeric_mixed_args_custom_formattable_type<long long, charT>();
test_numeric_mixed_args_custom_formattable_type<unsigned int, charT>();
test_numeric_mixed_args_custom_formattable_type<unsigned long, charT>();
test_numeric_mixed_args_custom_formattable_type<unsigned long long, charT>();
test_numeric_mixed_args_custom_formattable_type<short, charT>();
#ifdef _NATIVE_WCHAR_T_DEFINED
test_numeric_mixed_args_custom_formattable_type<unsigned short, charT>();
#endif
test_numeric_mixed_args_custom_formattable_type<float, charT>();
test_numeric_mixed_args_custom_formattable_type<double, charT>();
test_numeric_mixed_args_custom_formattable_type<long double, charT>();
}

int main() {
Expand Down