Extending fmt::join to support C++20-only ranges. (#2549)

This commit is contained in:
Barry Revzin
2021-10-16 10:02:03 -07:00
committed by GitHub
parent f5371a75f4
commit 7aca36bca4
2 changed files with 48 additions and 3 deletions
+10 -3
View File
@@ -2748,7 +2748,12 @@ using arg_join FMT_DEPRECATED_ALIAS = join_view<It, Sentinel, Char>;
template <typename It, typename Sentinel, typename Char>
struct formatter<join_view<It, Sentinel, Char>, Char> {
private:
using value_type = typename std::iterator_traits<It>::value_type;
using value_type =
#ifdef __cpp_lib_ranges
std::iter_value_t<It>;
#else
typename std::iterator_traits<It>::value_type;
#endif
using context = buffer_context<Char>;
using mapper = detail::arg_mapper<context>;
@@ -2782,11 +2787,13 @@ struct formatter<join_view<It, Sentinel, Char>, Char> {
auto it = value.begin;
auto out = ctx.out();
if (it != value.end) {
out = value_formatter_.format(map(*it++), ctx);
out = value_formatter_.format(map(*it), ctx);
++it;
while (it != value.end) {
out = detail::copy_str<Char>(value.sep.begin(), value.sep.end(), out);
ctx.advance_to(out);
out = value_formatter_.format(map(*it++), ctx);
out = value_formatter_.format(map(*it), ctx);
++it;
}
}
return out;