aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/string/format-inl.h
diff options
context:
space:
mode:
authorarkady-e1ppa <arkady-e1ppa@yandex-team.com>2024-06-13 16:50:14 +0300
committerarkady-e1ppa <arkady-e1ppa@yandex-team.com>2024-06-13 17:13:41 +0300
commit3a8a5fac5ba669fa5bed1ccd92e75bdfc6d30d21 (patch)
tree6282648de72746e2de7193e12ecc3ee7e4ad40f5 /library/cpp/yt/string/format-inl.h
parent3021b75cb7c16df7e4c99f77ef1509c72a79c876 (diff)
downloadydb-3a8a5fac5ba669fa5bed1ccd92e75bdfc6d30d21.tar.gz
YT-21868: Enable stat analysis in some other places
We slightly rework inner workings of stat analysis. For almost any sane use case the behavior is identical, but should compile a little faster. If you send string literals like `char[N]` or `const char*` make them constexpr. If you can't (e.g. `ex.what()` case) wrap it in `TStringBuf`, if you want the "by the book; 100% right" solution then wrap it in `TRuntimeFormat` instead. `SetRequestInfo` methods now statically checks the format. Only one error was found -- hooray! Some other internal stuff was added, a lot removed -- don't worry about it. You won't be able to see the difference 62050dfe8a9cedc1289f18e80397ff33a8e2ecdb
Diffstat (limited to 'library/cpp/yt/string/format-inl.h')
-rw-r--r--library/cpp/yt/string/format-inl.h46
1 files changed, 14 insertions, 32 deletions
diff --git a/library/cpp/yt/string/format-inl.h b/library/cpp/yt/string/format-inl.h
index 8d0ef4de93..1ff2d816c5 100644
--- a/library/cpp/yt/string/format-inl.h
+++ b/library/cpp/yt/string/format-inl.h
@@ -819,41 +819,23 @@ void RunFormatter(
////////////////////////////////////////////////////////////////////////////////
template <class... TArgs>
-void Format(TStringBuilderBase* builder, TStaticFormat<TArgs...> format, TArgs&&... args)
-{
- NYT::NDetail::TValueFormatter<0, TArgs...> formatter(args...);
- NYT::NDetail::RunFormatter(builder, format.Get(), formatter);
-}
-
-template <class... TArgs>
-void Format(TStringBuilderBase* builder, TRuntimeFormat format, TArgs&&... args)
-{
- // NB(arkady-e1ppa): StaticFormat performs the
- // formattability check of the args in a way
- // that provides more useful information
- // than a simple static_assert with conjunction.
- // Additionally, the latter doesn't work properly
- // for older clang version.
- static constexpr auto argsChecker = [] {
- TStaticFormat<TArgs...>::CheckFormattability();
- return 42;
- } ();
- Y_UNUSED(argsChecker);
-
- NYT::NDetail::TValueFormatter<0, TArgs...> formatter(args...);
- NYT::NDetail::RunFormatter(builder, format.Get(), formatter);
-}
-
-template <class... TArgs>
-TString Format(TStaticFormat<TArgs...> format, TArgs&&... args)
-{
- TStringBuilder builder;
- Format(&builder, format, std::forward<TArgs>(args)...);
- return builder.Flush();
+void Format(TStringBuilderBase* builder, TFormatString<TArgs...> format, TArgs&&... args)
+{
+ // NB(arkady-e1ppa): "if constexpr" is done in order to prevent
+ // compiler from emitting "No matching function to call"
+ // when arguments are not formattable.
+ // Compiler would crash in TFormatString ctor
+ // anyway (e.g. program would not compile) but
+ // for some reason it does look ahead and emits
+ // a second error.
+ if constexpr ((CFormattable<TArgs> && ...)) {
+ NYT::NDetail::TValueFormatter<0, TArgs...> formatter(args...);
+ NYT::NDetail::RunFormatter(builder, format.Get(), formatter);
+ }
}
template <class... TArgs>
-TString Format(TRuntimeFormat format, TArgs&&... args)
+TString Format(TFormatString<TArgs...> format, TArgs&&... args)
{
TStringBuilder builder;
Format(&builder, format, std::forward<TArgs>(args)...);