diff options
author | dgolear <dgolear@yandex-team.com> | 2024-05-21 01:03:40 +0300 |
---|---|---|
committer | dgolear <dgolear@yandex-team.com> | 2024-05-21 01:15:41 +0300 |
commit | a92a0d80c339ed6f70624dffa79288e61b72e941 (patch) | |
tree | 14ae8539e97846150a92530242efeb4b5b5fc08e /library/cpp | |
parent | 52107f6c22b7a6a09f394b920b18b6bae386ceb7 (diff) | |
download | ydb-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.cpp | 26 | ||||
-rw-r--r-- | library/cpp/yt/misc/source_location.h | 18 |
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: |