aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarkady-e1ppa <arkady-e1ppa@yandex-team.com>2024-09-18 11:07:37 +0300
committerarkady-e1ppa <arkady-e1ppa@yandex-team.com>2024-09-18 11:22:03 +0300
commitf4885374131a18b9906b7400d1d3e9485ae1f0aa (patch)
tree50fdf8adb8b9e783eb7e0170179481129c010df9
parent83fef1d88a43b7b54799dc70720adb5dbd2c9288 (diff)
downloadydb-f4885374131a18b9906b7400d1d3e9485ae1f0aa.tar.gz
remove cpp/yt/misc no longer depends on cpp/yt/string
commit_hash:429a843ed1a0e0fe3a5bc7d237f586b6671b8997
-rw-r--r--library/cpp/yt/misc/source_location.cpp33
-rw-r--r--library/cpp/yt/misc/source_location.h11
-rw-r--r--library/cpp/yt/misc/variant-inl.h50
-rw-r--r--library/cpp/yt/misc/variant.cpp16
-rw-r--r--library/cpp/yt/misc/variant.h13
-rw-r--r--library/cpp/yt/misc/ya.make1
-rw-r--r--library/cpp/yt/string/format-inl.h57
7 files changed, 56 insertions, 125 deletions
diff --git a/library/cpp/yt/misc/source_location.cpp b/library/cpp/yt/misc/source_location.cpp
index 598126f5a7..8d22d43636 100644
--- a/library/cpp/yt/misc/source_location.cpp
+++ b/library/cpp/yt/misc/source_location.cpp
@@ -1,32 +1,11 @@
#include "source_location.h"
-#include <library/cpp/yt/string/format.h>
-
#include <string.h>
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
-#ifdef __cpp_lib_source_location
-
-void FormatValue(TStringBuilderBase* builder, const std::source_location& location, TStringBuf /*spec*/)
-{
- if (location.file_name() != nullptr) {
- builder->AppendFormat(
- "%v:%v:%v",
- location.file_name(),
- location.line(),
- location.column());
- } else {
- builder->AppendString("<unknown>");
- }
-}
-
-#endif // __cpp_lib_source_location
-
-////////////////////////////////////////////////////////////////////////////////
-
const char* TSourceLocation::GetFileName() const
{
return FileName_;
@@ -70,18 +49,6 @@ bool TSourceLocation::operator==(const TSourceLocation& other) const
Line_ == other.Line_;
}
-void FormatValue(TStringBuilderBase* builder, const TSourceLocation& location, TStringBuf /*spec*/)
-{
- if (location.GetFileName() != nullptr) {
- builder->AppendFormat(
- "%v:%v",
- location.GetFileName(),
- location.GetLine());
- } else {
- builder->AppendString("<unknown>");
- }
-}
-
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT
diff --git a/library/cpp/yt/misc/source_location.h b/library/cpp/yt/misc/source_location.h
index 286527887a..7a47502262 100644
--- a/library/cpp/yt/misc/source_location.h
+++ b/library/cpp/yt/misc/source_location.h
@@ -10,15 +10,6 @@ namespace NYT {
////////////////////////////////////////////////////////////////////////////////
-class TStringBuilderBase;
-
-// TODO(dgolear): Drop when LLVM-14 is eradicated.
-#ifdef __cpp_lib_source_location
-void FormatValue(TStringBuilderBase* builder, const std::source_location& location, TStringBuf /*spec*/);
-#endif // __cpp_lib_source_location
-
-////////////////////////////////////////////////////////////////////////////////
-
class TSourceLocation
{
public:
@@ -47,8 +38,6 @@ private:
#define YT_CURRENT_SOURCE_LOCATION ::NYT::TSourceLocation(__FILE__, __LINE__)
#endif // __cpp_lib_source_location
-void FormatValue(TStringBuilderBase* builder, const TSourceLocation& location, TStringBuf spec);
-
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT
diff --git a/library/cpp/yt/misc/variant-inl.h b/library/cpp/yt/misc/variant-inl.h
deleted file mode 100644
index 4b0e04c92c..0000000000
--- a/library/cpp/yt/misc/variant-inl.h
+++ /dev/null
@@ -1,50 +0,0 @@
-#ifndef VARIANT_INL_H_
-#error "Direct inclusion of this file is not allowed, include variant.h"
-// For the sake of sane code completion.
-#include "variant.h"
-#endif
-
-#include <type_traits>
-
-namespace NYT {
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace NDetail {
-
-template <size_t Index, class... Ts>
-struct TVariantFormatter;
-
-template <size_t Index>
-struct TVariantFormatter<Index>
-{
- template <class TVariant>
- static void Do(TStringBuilderBase* /*builder*/, const TVariant& /*variant*/, TStringBuf /*spec*/)
- { }
-};
-
-template <size_t Index, class T, class... Ts>
-struct TVariantFormatter<Index, T, Ts...>
-{
- template <class TVariant>
- static void Do(TStringBuilderBase* builder, const TVariant& variant, TStringBuf spec)
- {
- if (variant.index() == Index) {
- FormatValue(builder, std::get<Index>(variant), spec);
- } else {
- TVariantFormatter<Index + 1, Ts...>::Do(builder, variant, spec);
- }
- }
-};
-
-} // namespace NDetail
-
-template <class... Ts>
-void FormatValue(TStringBuilderBase* builder, const std::variant<Ts...>& variant, TStringBuf spec)
-{
- NDetail::TVariantFormatter<0, Ts...>::Do(builder, variant, spec);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-} // namespace NYT
diff --git a/library/cpp/yt/misc/variant.cpp b/library/cpp/yt/misc/variant.cpp
deleted file mode 100644
index df78563d0c..0000000000
--- a/library/cpp/yt/misc/variant.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include "variant.h"
-
-#include <library/cpp/yt/string/string_builder.h>
-
-namespace NYT {
-
-////////////////////////////////////////////////////////////////////////////////
-
-void FormatValue(TStringBuilderBase* builder, const std::monostate&, TStringBuf /*spec*/)
-{
- builder->AppendString(TStringBuf("<monostate>"));
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-} // namespace NYT
diff --git a/library/cpp/yt/misc/variant.h b/library/cpp/yt/misc/variant.h
index 9e8e122089..7cc3d8ddda 100644
--- a/library/cpp/yt/misc/variant.h
+++ b/library/cpp/yt/misc/variant.h
@@ -7,15 +7,6 @@ namespace NYT {
////////////////////////////////////////////////////////////////////////////////
-class TStringBuilderBase;
-
-template <class... Ts>
-void FormatValue(TStringBuilderBase* builder, const std::variant<Ts...>& variant, TStringBuf spec);
-
-void FormatValue(TStringBuilderBase* builder, const std::monostate&, TStringBuf /*spec*/);
-
-////////////////////////////////////////////////////////////////////////////////
-
//! A concise way of creating a functor with an overloaded operator().
/*!
* Very useful for std::visit-ing variants. For example:
@@ -50,7 +41,3 @@ auto Visit(T&& variant, U&&... visitorOverloads)
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT
-
-#define VARIANT_INL_H_
-#include "variant-inl.h"
-#undef VARIANT_INL_H_
diff --git a/library/cpp/yt/misc/ya.make b/library/cpp/yt/misc/ya.make
index 841930aaa2..3135887e95 100644
--- a/library/cpp/yt/misc/ya.make
+++ b/library/cpp/yt/misc/ya.make
@@ -6,7 +6,6 @@ SRCS(
guid.cpp
source_location.cpp
thread_name.cpp
- variant.cpp
)
PEERDIR(
diff --git a/library/cpp/yt/string/format-inl.h b/library/cpp/yt/string/format-inl.h
index 67c8affa6e..2fe988f7d9 100644
--- a/library/cpp/yt/string/format-inl.h
+++ b/library/cpp/yt/string/format-inl.h
@@ -16,7 +16,7 @@
#include <library/cpp/yt/misc/concepts.h>
#include <library/cpp/yt/misc/enum.h>
-#include <library/cpp/yt/misc/wrapper_traits.h>
+#include <library/cpp/yt/misc/source_location.h>
#include <util/generic/maybe.h>
@@ -30,6 +30,10 @@
#include <filesystem>
#endif
+#ifdef __cpp_lib_source_location
+#include <source_location>
+#endif // __cpp_lib_source_location
+
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
@@ -592,6 +596,57 @@ inline void FormatValue(TStringBuilderBase* builder, const std::filesystem::path
}
#endif
+#ifdef __cpp_lib_source_location
+// std::source_location
+inline void FormatValue(TStringBuilderBase* builder, const std::source_location& location, TStringBuf /*spec*/)
+{
+ if (location.file_name() != nullptr) {
+ builder->AppendFormat(
+ "%v:%v:%v",
+ location.file_name(),
+ location.line(),
+ location.column());
+ } else {
+ builder->AppendString("<unknown>");
+ }
+}
+#endif // __cpp_lib_source_location
+
+// TSourceLocation
+inline void FormatValue(TStringBuilderBase* builder, const TSourceLocation& location, TStringBuf /*spec*/)
+{
+ if (location.GetFileName() != nullptr) {
+ builder->AppendFormat(
+ "%v:%v",
+ location.GetFileName(),
+ location.GetLine());
+ } else {
+ builder->AppendString("<unknown>");
+ }
+}
+
+// std::monostate
+inline void FormatValue(TStringBuilderBase* builder, const std::monostate&, TStringBuf /*spec*/)
+{
+ builder->AppendString(TStringBuf("<monostate>"));
+}
+
+// std::variant
+template <class... Ts>
+void FormatValue(TStringBuilderBase* builder, const std::variant<Ts...>& variant, TStringBuf spec)
+{
+ [&] <size_t... Ids> (std::index_sequence<Ids...>) {
+ ([&] {
+ if (variant.index() == Ids) {
+ FormatValue(builder, std::get<Ids>(variant), spec);
+ return false;
+ }
+
+ return true;
+ } () && ...);
+ } (std::index_sequence_for<Ts...>());
+}
+
// char
inline void FormatValue(TStringBuilderBase* builder, char value, TStringBuf spec)
{