Skip to content

Commit 6574e3b

Browse files
author
lukyan
committed
Fix MakeFormattableView
commit_hash:0e4b24c65451e75f168b456cd0d271ddebb7219d
1 parent 475f6be commit 6574e3b

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

library/cpp/yt/string/format-inl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,15 @@ typename TFormattableView<TRange, TFormatter>::TEnd TFormattableView<TRange, TFo
316316
}
317317

318318
template <class TRange, class TFormatter>
319-
TFormattableView<TRange, TFormatter> MakeFormattableView(
319+
TFormattableView<TRange, std::decay_t<TFormatter>> MakeFormattableView(
320320
const TRange& range,
321321
TFormatter&& formatter)
322322
{
323323
return TFormattableView<TRange, std::decay_t<TFormatter>>{range.begin(), range.end(), std::forward<TFormatter>(formatter)};
324324
}
325325

326326
template <class TRange, class TFormatter>
327-
TFormattableView<TRange, TFormatter> MakeShrunkFormattableView(
327+
TFormattableView<TRange, std::decay_t<TFormatter>> MakeShrunkFormattableView(
328328
const TRange& range,
329329
TFormatter&& formatter,
330330
size_t limit)

library/cpp/yt/string/format.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ struct TFormattableView
9191

9292
//! Annotates a given #range with #formatter to be applied to each item.
9393
template <class TRange, class TFormatter>
94-
TFormattableView<TRange, TFormatter> MakeFormattableView(
94+
TFormattableView<TRange, std::decay_t<TFormatter>> MakeFormattableView(
9595
const TRange& range,
9696
TFormatter&& formatter);
9797

9898
template <class TRange, class TFormatter>
99-
TFormattableView<TRange, TFormatter> MakeShrunkFormattableView(
99+
TFormattableView<TRange, std::decay_t<TFormatter>> MakeShrunkFormattableView(
100100
const TRange& range,
101101
TFormatter&& formatter,
102102
size_t limit);

library/cpp/yt/string/unittests/format_ut.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,19 @@ TEST(TFormatTest, LazyMultiValueFormatter)
267267
EXPECT_EQ("int: 1, string: hello, range: [1, 2, 3]", Format("%v", lazyFormatter));
268268
}
269269

270+
TEST(TFormatTest, ReusableLambdaFormatter)
271+
{
272+
auto formatter = [&] (auto* builder, int value) {
273+
builder->AppendFormat("%v", value);
274+
};
275+
276+
std::vector<int> range1{1, 2, 3};
277+
EXPECT_EQ("[1, 2, 3]", Format("%v", MakeFormattableView(range1, formatter)));
278+
279+
std::vector<int> range2{4, 5, 6};
280+
EXPECT_EQ("[4, 5, 6]", Format("%v", MakeFormattableView(range2, formatter)));
281+
}
282+
270283
TEST(TFormatTest, VectorArg)
271284
{
272285
std::vector<TString> params = {"a", "b", "c"};

0 commit comments

Comments
 (0)