aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authordgolear <dgolear@yandex-team.com>2024-05-21 01:03:40 +0300
committerdgolear <dgolear@yandex-team.com>2024-05-21 01:15:41 +0300
commita92a0d80c339ed6f70624dffa79288e61b72e941 (patch)
tree14ae8539e97846150a92530242efeb4b5b5fc08e /library/cpp
parent52107f6c22b7a6a09f394b920b18b6bae386ceb7 (diff)
downloadydb-a92a0d80c339ed6f70624dffa79288e61b72e941.tar.gz
YT: Add FormatValue for std::source_location
YTORM-1057 0aa4ceb80d984a15c92a69f242ecf517b3c7a07c
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/yt/misc/source_location.cpp26
-rw-r--r--library/cpp/yt/misc/source_location.h18
2 files changed, 44 insertions, 0 deletions
diff --git a/library/cpp/yt/misc/source_location.cpp b/library/cpp/yt/misc/source_location.cpp
index 8d22d43636..3fe45e23a7 100644
--- a/library/cpp/yt/misc/source_location.cpp
+++ b/library/cpp/yt/misc/source_location.cpp
@@ -1,11 +1,37 @@
#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 /*format*/)
+{
+ if (location.file_name() != nullptr) {
+ builder->AppendFormat(
+ "%v:%v:%v",
+ location.file_name(),
+ location.line(),
+ location.column());
+ } else {
+ builder->AppendString("<unknown>");
+ }
+}
+
+TString ToString(const std::source_location& location)
+{
+ return ToStringViaBuilder(location);
+}
+
+#endif // __cpp_lib_source_location
+
+////////////////////////////////////////////////////////////////////////////////
+
const char* TSourceLocation::GetFileName() const
{
return FileName_;
diff --git a/library/cpp/yt/misc/source_location.h b/library/cpp/yt/misc/source_location.h
index 84213eea70..38a6f83c80 100644
--- a/library/cpp/yt/misc/source_location.h
+++ b/library/cpp/yt/misc/source_location.h
@@ -1,9 +1,27 @@
#pragma once
+#include <util/generic/string.h>
+
+#ifdef __cpp_lib_source_location
+#include <source_location>
+#endif // __cpp_lib_source_location
+
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
+// TODO(dgolear): Drop when LLVM-14 is eradicated.
+#ifdef __cpp_lib_source_location
+
+class TStringBuilderBase;
+
+void FormatValue(TStringBuilderBase* builder, const std::source_location& location, TStringBuf /*format*/);
+TString ToString(const std::source_location& location);
+
+#endif // __cpp_lib_source_location
+
+////////////////////////////////////////////////////////////////////////////////
+
class TSourceLocation
{
public: