aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlukyan <lukyan@yandex-team.com>2025-04-16 22:43:47 +0300
committerlukyan <lukyan@yandex-team.com>2025-04-16 22:59:26 +0300
commit6574e3bb8e463246106d483ba72fdf2d6d32cbdc (patch)
tree00eb6688be5b9f85810730a1b078189ad6cd42c2
parent475f6be41dd8364cd4726086ee21d6ad3215964d (diff)
downloadydb-6574e3bb8e463246106d483ba72fdf2d6d32cbdc.tar.gz
Fix MakeFormattableView
commit_hash:0e4b24c65451e75f168b456cd0d271ddebb7219d
-rw-r--r--library/cpp/yt/string/format-inl.h4
-rw-r--r--library/cpp/yt/string/format.h4
-rw-r--r--library/cpp/yt/string/unittests/format_ut.cpp13
3 files changed, 17 insertions, 4 deletions
diff --git a/library/cpp/yt/string/format-inl.h b/library/cpp/yt/string/format-inl.h
index 01214399e8e..5b49fc5925c 100644
--- a/library/cpp/yt/string/format-inl.h
+++ b/library/cpp/yt/string/format-inl.h
@@ -316,7 +316,7 @@ typename TFormattableView<TRange, TFormatter>::TEnd TFormattableView<TRange, TFo
}
template <class TRange, class TFormatter>
-TFormattableView<TRange, TFormatter> MakeFormattableView(
+TFormattableView<TRange, std::decay_t<TFormatter>> MakeFormattableView(
const TRange& range,
TFormatter&& formatter)
{
@@ -324,7 +324,7 @@ TFormattableView<TRange, TFormatter> MakeFormattableView(
}
template <class TRange, class TFormatter>
-TFormattableView<TRange, TFormatter> MakeShrunkFormattableView(
+TFormattableView<TRange, std::decay_t<TFormatter>> MakeShrunkFormattableView(
const TRange& range,
TFormatter&& formatter,
size_t limit)
diff --git a/library/cpp/yt/string/format.h b/library/cpp/yt/string/format.h
index d15127fae05..fa45f39e5ac 100644
--- a/library/cpp/yt/string/format.h
+++ b/library/cpp/yt/string/format.h
@@ -91,12 +91,12 @@ struct TFormattableView
//! Annotates a given #range with #formatter to be applied to each item.
template <class TRange, class TFormatter>
-TFormattableView<TRange, TFormatter> MakeFormattableView(
+TFormattableView<TRange, std::decay_t<TFormatter>> MakeFormattableView(
const TRange& range,
TFormatter&& formatter);
template <class TRange, class TFormatter>
-TFormattableView<TRange, TFormatter> MakeShrunkFormattableView(
+TFormattableView<TRange, std::decay_t<TFormatter>> MakeShrunkFormattableView(
const TRange& range,
TFormatter&& formatter,
size_t limit);
diff --git a/library/cpp/yt/string/unittests/format_ut.cpp b/library/cpp/yt/string/unittests/format_ut.cpp
index e2e23c737c2..a6c5ef6837f 100644
--- a/library/cpp/yt/string/unittests/format_ut.cpp
+++ b/library/cpp/yt/string/unittests/format_ut.cpp
@@ -267,6 +267,19 @@ TEST(TFormatTest, LazyMultiValueFormatter)
EXPECT_EQ("int: 1, string: hello, range: [1, 2, 3]", Format("%v", lazyFormatter));
}
+TEST(TFormatTest, ReusableLambdaFormatter)
+{
+ auto formatter = [&] (auto* builder, int value) {
+ builder->AppendFormat("%v", value);
+ };
+
+ std::vector<int> range1{1, 2, 3};
+ EXPECT_EQ("[1, 2, 3]", Format("%v", MakeFormattableView(range1, formatter)));
+
+ std::vector<int> range2{4, 5, 6};
+ EXPECT_EQ("[4, 5, 6]", Format("%v", MakeFormattableView(range2, formatter)));
+}
+
TEST(TFormatTest, VectorArg)
{
std::vector<TString> params = {"a", "b", "c"};