aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorarkady-e1ppa <arkady-e1ppa@yandex-team.com>2024-06-11 22:01:04 +0300
committerarkady-e1ppa <arkady-e1ppa@yandex-team.com>2024-06-12 11:47:00 +0300
commit89f56e044a4f82c7e88fa15771beca2d5787c7c8 (patch)
treeadb31c52e55de4c2131cf15ca722e64b609b1a10 /library/cpp
parenta41bb65a80fdc183e427b6c337dbbc15776f1c92 (diff)
downloadydb-89f56e044a4f82c7e88fa15771beca2d5787c7c8.tar.gz
YT-21868: Delete unneeded ToString methods
e856aa45df227b86e8b121852d3774bb2504193b
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/yt/misc/optional.h6
-rw-r--r--library/cpp/yt/misc/source_location.cpp7
-rw-r--r--library/cpp/yt/misc/source_location.h3
-rw-r--r--library/cpp/yt/misc/strong_typedef.h7
-rw-r--r--library/cpp/yt/misc/variant-inl.h6
-rw-r--r--library/cpp/yt/misc/variant.cpp2
-rw-r--r--library/cpp/yt/misc/variant.h5
-rw-r--r--library/cpp/yt/string/format-inl.h16
-rw-r--r--library/cpp/yt/string/format_arg-inl.h7
-rw-r--r--library/cpp/yt/string/format_arg.h3
-rw-r--r--library/cpp/yt/string/string_builder-inl.h9
11 files changed, 25 insertions, 46 deletions
diff --git a/library/cpp/yt/misc/optional.h b/library/cpp/yt/misc/optional.h
index d5e3c07fbe..c5982af7bf 100644
--- a/library/cpp/yt/misc/optional.h
+++ b/library/cpp/yt/misc/optional.h
@@ -97,12 +97,6 @@ struct TStdOptionalTraits<std::optional<T>>
} // namespace NYT
template <class T>
-TString ToString(const std::optional<T>& nullable)
-{
- return nullable ? ToString(*nullable) : "<Null>";
-}
-
-template <class T>
struct THash<std::optional<T>>
{
size_t operator()(const std::optional<T>& nullable) const
diff --git a/library/cpp/yt/misc/source_location.cpp b/library/cpp/yt/misc/source_location.cpp
index 3fe45e23a7..37eb5edd53 100644
--- a/library/cpp/yt/misc/source_location.cpp
+++ b/library/cpp/yt/misc/source_location.cpp
@@ -10,7 +10,7 @@ namespace NYT {
#ifdef __cpp_lib_source_location
-void FormatValue(TStringBuilderBase* builder, const std::source_location& location, TStringBuf /*format*/)
+void FormatValue(TStringBuilderBase* builder, const std::source_location& location, TStringBuf /*spec*/)
{
if (location.file_name() != nullptr) {
builder->AppendFormat(
@@ -23,11 +23,6 @@ void FormatValue(TStringBuilderBase* builder, const std::source_location& locati
}
}
-TString ToString(const std::source_location& location)
-{
- return ToStringViaBuilder(location);
-}
-
#endif // __cpp_lib_source_location
////////////////////////////////////////////////////////////////////////////////
diff --git a/library/cpp/yt/misc/source_location.h b/library/cpp/yt/misc/source_location.h
index 38a6f83c80..43b2b86fcd 100644
--- a/library/cpp/yt/misc/source_location.h
+++ b/library/cpp/yt/misc/source_location.h
@@ -15,8 +15,7 @@ namespace NYT {
class TStringBuilderBase;
-void FormatValue(TStringBuilderBase* builder, const std::source_location& location, TStringBuf /*format*/);
-TString ToString(const std::source_location& location);
+void FormatValue(TStringBuilderBase* builder, const std::source_location& location, TStringBuf /*spec*/);
#endif // __cpp_lib_source_location
diff --git a/library/cpp/yt/misc/strong_typedef.h b/library/cpp/yt/misc/strong_typedef.h
index d47581701d..58d96ebd2c 100644
--- a/library/cpp/yt/misc/strong_typedef.h
+++ b/library/cpp/yt/misc/strong_typedef.h
@@ -56,13 +56,6 @@ public:
private:
T Underlying_;
-
- //! NB: Hidden friend definition to make this name accessible only via ADL.
- friend TString ToString(const TStrongTypedef& value)
- requires requires (T value) { { ToString(value) } -> std::same_as<TString>; }
- {
- return ToString(value.Underlying_);
- }
};
#define YT_DEFINE_STRONG_TYPEDEF(T, TUnderlying) \
diff --git a/library/cpp/yt/misc/variant-inl.h b/library/cpp/yt/misc/variant-inl.h
index 01f0e08593..4b0e04c92c 100644
--- a/library/cpp/yt/misc/variant-inl.h
+++ b/library/cpp/yt/misc/variant-inl.h
@@ -45,12 +45,6 @@ void FormatValue(TStringBuilderBase* builder, const std::variant<Ts...>& variant
NDetail::TVariantFormatter<0, Ts...>::Do(builder, variant, spec);
}
-template <class... Ts>
-TString ToString(const std::variant<Ts...>& variant)
-{
- return ToStringViaBuilder(variant);
-}
-
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT
diff --git a/library/cpp/yt/misc/variant.cpp b/library/cpp/yt/misc/variant.cpp
index be86affef8..df78563d0c 100644
--- a/library/cpp/yt/misc/variant.cpp
+++ b/library/cpp/yt/misc/variant.cpp
@@ -6,7 +6,7 @@ namespace NYT {
////////////////////////////////////////////////////////////////////////////////
-void FormatValue(TStringBuilderBase* builder, const std::monostate&, TStringBuf /*format*/)
+void FormatValue(TStringBuilderBase* builder, const std::monostate&, TStringBuf /*spec*/)
{
builder->AppendString(TStringBuf("<monostate>"));
}
diff --git a/library/cpp/yt/misc/variant.h b/library/cpp/yt/misc/variant.h
index 4ca977873e..9e8e122089 100644
--- a/library/cpp/yt/misc/variant.h
+++ b/library/cpp/yt/misc/variant.h
@@ -12,10 +12,7 @@ class TStringBuilderBase;
template <class... Ts>
void FormatValue(TStringBuilderBase* builder, const std::variant<Ts...>& variant, TStringBuf spec);
-void FormatValue(TStringBuilderBase* builder, const std::monostate&, TStringBuf /*format*/);
-
-template <class... Ts>
-TString ToString(const std::variant<Ts...>& variant);
+void FormatValue(TStringBuilderBase* builder, const std::monostate&, TStringBuf /*spec*/);
////////////////////////////////////////////////////////////////////////////////
diff --git a/library/cpp/yt/string/format-inl.h b/library/cpp/yt/string/format-inl.h
index acaa8f7011..8d0ef4de93 100644
--- a/library/cpp/yt/string/format-inl.h
+++ b/library/cpp/yt/string/format-inl.h
@@ -473,19 +473,19 @@ template <class T, class TPolicy>
void FormatValue(TStringBuilderBase* builder, const TMaybe<T, TPolicy>& value, TStringBuf spec);
// std::optional
-template <class T>
+template <CFormattable T>
void FormatValue(TStringBuilderBase* builder, const std::optional<T>& value, TStringBuf spec);
// std::pair
-template <class A, class B>
+template <CFormattable A, CFormattable B>
void FormatValue(TStringBuilderBase* builder, const std::pair<A, B>& value, TStringBuf spec);
// std::tuple
-template <class... Ts>
+template <CFormattable... Ts>
void FormatValue(TStringBuilderBase* builder, const std::tuple<Ts...>& value, TStringBuf spec);
// TEnumIndexedArray
-template <class E, class T>
+template <class E, CFormattable T>
void FormatValue(TStringBuilderBase* builder, const TEnumIndexedArray<E, T>& collection, TStringBuf spec);
// One-valued ranges
@@ -531,7 +531,7 @@ inline void FormatValue(TStringBuilderBase* builder, std::nullopt_t, TStringBuf
}
// std::optional: generic T
-template <class T>
+template <CFormattable T>
void FormatValue(TStringBuilderBase* builder, const std::optional<T>& value, TStringBuf spec)
{
if (value.has_value()) {
@@ -542,7 +542,7 @@ void FormatValue(TStringBuilderBase* builder, const std::optional<T>& value, TSt
}
// std::pair
-template <class A, class B>
+template <CFormattable A, CFormattable B>
void FormatValue(TStringBuilderBase* builder, const std::pair<A, B>& value, TStringBuf spec)
{
builder->AppendChar('{');
@@ -553,7 +553,7 @@ void FormatValue(TStringBuilderBase* builder, const std::pair<A, B>& value, TStr
}
// std::tuple
-template <class... Ts>
+template <CFormattable... Ts>
void FormatValue(TStringBuilderBase* builder, const std::tuple<Ts...>& value, TStringBuf spec)
{
builder->AppendChar('{');
@@ -571,7 +571,7 @@ void FormatValue(TStringBuilderBase* builder, const std::tuple<Ts...>& value, TS
}
// TEnumIndexedArray
-template <class E, class T>
+template <class E, CFormattable T>
void FormatValue(TStringBuilderBase* builder, const TEnumIndexedArray<E, T>& collection, TStringBuf spec)
{
builder->AppendChar('{');
diff --git a/library/cpp/yt/string/format_arg-inl.h b/library/cpp/yt/string/format_arg-inl.h
index 82a77a1249..e2f08e540d 100644
--- a/library/cpp/yt/string/format_arg-inl.h
+++ b/library/cpp/yt/string/format_arg-inl.h
@@ -27,6 +27,13 @@ constexpr bool IsNYTName()
return qualidName.find("NYT::") == 0;
}
+template <class T>
+constexpr bool IsStdName()
+{
+ constexpr auto qualidName = QualidName<T>();
+ return qualidName.find("std::") == 0;
+}
+
} // namespace NDetail
////////////////////////////////////////////////////////////////////////////////
diff --git a/library/cpp/yt/string/format_arg.h b/library/cpp/yt/string/format_arg.h
index da7d13a19b..6240059ed9 100644
--- a/library/cpp/yt/string/format_arg.h
+++ b/library/cpp/yt/string/format_arg.h
@@ -21,9 +21,6 @@ constexpr std::string_view QualidName();
template <class T>
constexpr bool IsNYTName();
-template <class T>
-concept CYtName = IsNYTName<T>();
-
} // namespace NDetail
////////////////////////////////////////////////////////////////////////////////
diff --git a/library/cpp/yt/string/string_builder-inl.h b/library/cpp/yt/string/string_builder-inl.h
index 683a241c9c..9fb3ae94f8 100644
--- a/library/cpp/yt/string/string_builder-inl.h
+++ b/library/cpp/yt/string/string_builder-inl.h
@@ -118,7 +118,7 @@ inline void TStringBuilder::DoReserve(size_t newLength)
////////////////////////////////////////////////////////////////////////////////
-inline void FormatValue(TStringBuilderBase* builder, const TStringBuilder& value, TStringBuf /*format*/)
+inline void FormatValue(TStringBuilderBase* builder, const TStringBuilder& value, TStringBuf /*spec*/)
{
builder->AppendString(value.GetBuffer());
}
@@ -165,14 +165,17 @@ TString ToStringIgnoringFormatValue(const T& t)
#include <util/string/cast.h>
-// util/string/cast.h extension for yt types only
+// util/string/cast.h extension for yt and std types only
// TODO(arkady-e1ppa): Abolish ::ToString in
// favour of either NYT::ToString or
// automatic formatting wherever it is needed.
namespace NPrivate {
template <class T>
- requires (NYT::NDetail::CYtName<T> && NYT::CFormattable<T>)
+ requires (
+ (NYT::NDetail::IsNYTName<T>() ||
+ NYT::NDetail::IsStdName<T>()) &&
+ NYT::CFormattable<T>)
struct TToString<T, false>
{
static TString Cvt(const T& t)