parent
5de0bc1d4f
commit
c20874c28f
@ -3720,20 +3720,33 @@ struct arg_join : detail::view {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename It, typename Sentinel, typename Char>
|
template <typename It, typename Sentinel, typename Char>
|
||||||
struct formatter<arg_join<It, Sentinel, Char>, Char>
|
struct formatter<arg_join<It, Sentinel, Char>, Char> {
|
||||||
: formatter<typename std::iterator_traits<It>::value_type, Char> {
|
private:
|
||||||
|
using value_type = typename std::iterator_traits<It>::value_type;
|
||||||
|
using formatter_type =
|
||||||
|
conditional_t<has_formatter<value_type, format_context>::value,
|
||||||
|
formatter<value_type, Char>,
|
||||||
|
detail::fallback_formatter<value_type, Char>>;
|
||||||
|
|
||||||
|
formatter_type value_formatter_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
template <typename ParseContext>
|
||||||
|
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
|
||||||
|
return value_formatter_.parse(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename FormatContext>
|
template <typename FormatContext>
|
||||||
auto format(const arg_join<It, Sentinel, Char>& value, FormatContext& ctx)
|
auto format(const arg_join<It, Sentinel, Char>& value, FormatContext& ctx)
|
||||||
-> decltype(ctx.out()) {
|
-> decltype(ctx.out()) {
|
||||||
using base = formatter<typename std::iterator_traits<It>::value_type, Char>;
|
|
||||||
auto it = value.begin;
|
auto it = value.begin;
|
||||||
auto out = ctx.out();
|
auto out = ctx.out();
|
||||||
if (it != value.end) {
|
if (it != value.end) {
|
||||||
out = base::format(*it++, ctx);
|
out = value_formatter_.format(*it++, ctx);
|
||||||
while (it != value.end) {
|
while (it != value.end) {
|
||||||
out = detail::copy_str<Char>(value.sep.begin(), value.sep.end(), out);
|
out = detail::copy_str<Char>(value.sep.begin(), value.sep.end(), out);
|
||||||
ctx.advance_to(out);
|
ctx.advance_to(out);
|
||||||
out = base::format(*it++, ctx);
|
out = value_formatter_.format(*it++, ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
|
@ -188,6 +188,11 @@ TEST(OStreamTest, Join) {
|
|||||||
EXPECT_EQ("1, 2, 3", fmt::format("{}", fmt::join(v, v + 3, ", ")));
|
EXPECT_EQ("1, 2, 3", fmt::format("{}", fmt::join(v, v + 3, ", ")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(OStreamTest, JoinFallbackFormatter) {
|
||||||
|
auto strs = std::vector<TestString>{TestString("foo"), TestString("bar")};
|
||||||
|
EXPECT_EQ("foo, bar", fmt::format("{}", fmt::join(strs, ", ")));
|
||||||
|
}
|
||||||
|
|
||||||
#if FMT_USE_CONSTEXPR
|
#if FMT_USE_CONSTEXPR
|
||||||
TEST(OStreamTest, ConstexprString) {
|
TEST(OStreamTest, ConstexprString) {
|
||||||
EXPECT_EQ("42", format(FMT_STRING("{}"), std::string("42")));
|
EXPECT_EQ("42", format(FMT_STRING("{}"), std::string("42")));
|
||||||
|
Loading…
Reference in New Issue
Block a user