mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-16 22:19:40 +00:00
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) {
|
for (; it != end; ++it) {
|
||||||
if (i > 0) out = detail::copy_str<Char>(separator_, out);
|
if (i > 0) out = detail::copy_str<Char>(separator_, out);
|
||||||
ctx.advance_to(out);
|
ctx.advance_to(out);
|
||||||
out = underlying_.format(mapper.map(*it), ctx);
|
auto&& item = *it;
|
||||||
|
out = underlying_.format(mapper.map(item), ctx);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
out = detail::copy_str<Char>(closing_bracket_, out);
|
out = detail::copy_str<Char>(closing_bracket_, out);
|
||||||
|
@ -7,13 +7,19 @@
|
|||||||
|
|
||||||
#include "fmt/ranges.h"
|
#include "fmt/ranges.h"
|
||||||
|
|
||||||
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <numeric>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#if FMT_HAS_INCLUDE(<ranges>)
|
||||||
|
# include <ranges>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
#if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 601
|
#if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 601
|
||||||
@ -242,7 +248,7 @@ template <typename T> class non_const_only_range {
|
|||||||
explicit non_const_only_range(Args&&... args)
|
explicit non_const_only_range(Args&&... args)
|
||||||
: vec(std::forward<Args>(args)...) {}
|
: vec(std::forward<Args>(args)...) {}
|
||||||
|
|
||||||
auto begin() -> const_iterator{ return vec.begin(); }
|
auto begin() -> const_iterator { return vec.begin(); }
|
||||||
auto end() -> const_iterator { return vec.end(); }
|
auto end() -> const_iterator { return vec.end(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -360,7 +366,7 @@ struct cpp20_only_range {
|
|||||||
iterator() = default;
|
iterator() = default;
|
||||||
iterator(int i) : val(i) {}
|
iterator(int i) : val(i) {}
|
||||||
auto operator*() const -> int { return val; }
|
auto operator*() const -> int { return val; }
|
||||||
auto operator++() -> iterator&{
|
auto operator++() -> iterator& {
|
||||||
++val;
|
++val;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -378,6 +384,17 @@ struct cpp20_only_range {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static_assert(std::input_iterator<cpp20_only_range::iterator>);
|
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
|
# endif
|
||||||
|
|
||||||
TEST(ranges_test, join_sentinel) {
|
TEST(ranges_test, join_sentinel) {
|
||||||
|
Loading…
Reference in New Issue
Block a user