From 1ab8f0ba994f29591c64a8081118aa7d4249c0f7 Mon Sep 17 00:00:00 2001 From: Patrick Stewart Date: Tue, 13 Apr 2021 13:27:12 +0100 Subject: [PATCH] Support char*_t in fmt::join --- include/fmt/format.h | 23 ++++++----------------- include/fmt/ranges.h | 26 +++++++------------------- 2 files changed, 13 insertions(+), 36 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 32b42dd5..c735c6c0 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3753,14 +3753,9 @@ struct formatter, Char> { Returns an object that formats the iterator range `[begin, end)` with elements separated by `sep`. */ -template -arg_join join(It begin, Sentinel end, string_view sep) { - return {begin, end, sep}; -} - -template -arg_join join(It begin, Sentinel end, wstring_view sep) { - return {begin, end, sep}; +template +arg_join> join(It begin, Sentinel end, const S& sep) { + return {begin, end, to_string_view(sep)}; } /** @@ -3779,15 +3774,9 @@ arg_join join(It begin, Sentinel end, wstring_view sep) { // Output: "01, 02, 03" \endrst */ -template -arg_join, detail::sentinel_t, char> join( - Range&& range, string_view sep) { - return join(std::begin(range), std::end(range), sep); -} - -template -arg_join, detail::sentinel_t, wchar_t> join( - Range&& range, wstring_view sep) { +template +arg_join, detail::sentinel_t, char_t> join( + Range&& range, const S& sep) { return join(std::begin(range), std::end(range), sep); } diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 0ebf9652..df029496 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -427,16 +427,10 @@ struct formatter, Char> { // Output: "1, a" \endrst */ -template -FMT_CONSTEXPR tuple_arg_join join(const std::tuple& tuple, - string_view sep) { - return {tuple, sep}; -} - -template -FMT_CONSTEXPR tuple_arg_join join(const std::tuple& tuple, - wstring_view sep) { - return {tuple, sep}; +template +FMT_CONSTEXPR tuple_arg_join, T...> join(const std::tuple& tuple, + const S& sep) { + return {tuple, to_string_view(sep)}; } /** @@ -450,15 +444,9 @@ FMT_CONSTEXPR tuple_arg_join join(const std::tuple& tuple, // Output: "1, 2, 3" \endrst */ -template -arg_join join(std::initializer_list list, - string_view sep) { - return join(std::begin(list), std::end(list), sep); -} - -template -arg_join join(std::initializer_list list, - wstring_view sep) { +template +arg_join> join(std::initializer_list list, + const S& sep) { return join(std::begin(list), std::end(list), sep); }