diff options
author | arkady-e1ppa <arkady-e1ppa@yandex-team.com> | 2024-09-18 11:07:37 +0300 |
---|---|---|
committer | arkady-e1ppa <arkady-e1ppa@yandex-team.com> | 2024-09-18 11:22:03 +0300 |
commit | f4885374131a18b9906b7400d1d3e9485ae1f0aa (patch) | |
tree | 50fdf8adb8b9e783eb7e0170179481129c010df9 /library/cpp/yt/string/format-inl.h | |
parent | 83fef1d88a43b7b54799dc70720adb5dbd2c9288 (diff) | |
download | ydb-f4885374131a18b9906b7400d1d3e9485ae1f0aa.tar.gz |
remove cpp/yt/misc no longer depends on cpp/yt/string
commit_hash:429a843ed1a0e0fe3a5bc7d237f586b6671b8997
Diffstat (limited to 'library/cpp/yt/string/format-inl.h')
-rw-r--r-- | library/cpp/yt/string/format-inl.h | 57 |
1 files changed, 56 insertions, 1 deletions
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) { |