Fix formatting of some nested ranges
This commit is contained in:
parent
3eb3aef575
commit
e7875ae0fa
@ -482,7 +482,8 @@ struct range_formatter<
|
||||
for (; it != end; ++it) {
|
||||
if (i > 0) out = detail::copy_str<Char>(separator_, out);
|
||||
ctx.advance_to(out);
|
||||
out = underlying_.format(mapper.map(*it), ctx);
|
||||
auto&& item = *it;
|
||||
out = underlying_.format(mapper.map(item), ctx);
|
||||
++i;
|
||||
}
|
||||
out = detail::copy_str<Char>(closing_bracket_, out);
|
||||
|
@ -7,13 +7,19 @@
|
||||
|
||||
#include "fmt/ranges.h"
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <numeric>
|
||||
#include <queue>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#if FMT_HAS_INCLUDE(<ranges>)
|
||||
# include <ranges>
|
||||
#endif
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 601
|
||||
@ -378,6 +384,17 @@ struct cpp20_only_range {
|
||||
};
|
||||
|
||||
static_assert(std::input_iterator<cpp20_only_range::iterator>);
|
||||
|
||||
# ifdef __cpp_lib_ranges_iota
|
||||
TEST(ranges_test, nested_ranges) {
|
||||
auto l = std::list{1, 2, 3};
|
||||
auto r = std::views::iota(0, 3) | std::views::transform([&l](auto i) {
|
||||
return std::views::take(std::ranges::subrange(l), i);
|
||||
}) |
|
||||
std::views::transform(std::views::reverse);
|
||||
EXPECT_EQ(fmt::format("{}", r), "[[], [1], [2, 1]]");
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
|
||||
TEST(ranges_test, join_sentinel) {
|
||||
|
Loading…
Reference in New Issue
Block a user