Skip to content

update fmt::join to support more character types#4686

Open
Yancey2023 wants to merge 3 commits intofmtlib:masterfrom
Yancey2023:master
Open

update fmt::join to support more character types#4686
Yancey2023 wants to merge 3 commits intofmtlib:masterfrom
Yancey2023:master

Conversation

@Yancey2023
Copy link

@Yancey2023 Yancey2023 commented Feb 24, 2026

This PR brings more character type support for fmt::join.

Besides, implicit conversions of different character types may generate errors, so CI cannot pass. I also fix it.

/home/runner/work/fmt/fmt/include/fmt/base.h:1823:51: error: implicit conversion changes signedness: 'const char' to 'char16_t' [-Werror,-Wsign-conversion]
      for (size_t i = 0; i < count; ++i) out[i] = begin[i];
                                                ~ ^~~~~~~~

@Yancey2023 Yancey2023 marked this pull request as draft February 24, 2026 22:08
@Yancey2023 Yancey2023 marked this pull request as ready for review February 25, 2026 00:14
Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR

// A loop is faster than memcpy on small sizes.
T* out = ptr_ + size;
for (size_t i = 0; i < count; ++i) out[i] = begin[i];
for (size_t i = 0; i < count; ++i) out[i] = static_cast<T>(begin[i]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cast shouldn't be here because we shouldn't mix different code units.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I fix the issues mentioned in my PR if I don't do this?

template <typename Char> constexpr auto getsign(sign s) -> Char {
return static_cast<char>(((' ' << 24) | ('+' << 16) | ('-' << 8)) >>
(static_cast<int>(s) * 8));
return static_cast<Char>(static_cast<char>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't one cast be sufficient?

Copy link
Author

@Yancey2023 Yancey2023 Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does need to cast twice.

int -> char -> wchar_t

I have try to cast to wchar_t directly, but the result is error.

Comment on lines +162 to +169
template <typename T, typename S,
typename Char = typename decltype(detail::to_string_view(
std::declval<S>()))::value_type,
FMT_ENABLE_IF(detail::is_exotic_char<Char>::value)>
auto join(std::initializer_list<T> list, S&& sep)
-> join_view<const T*, const T*, Char> {
return {std::begin(list), std::end(list), detail::to_string_view(sep)};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is a questionable API and we should probably deprecated it. At the very least let's not touch it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants