diff options
author | arkady-e1ppa <arkady-e1ppa@yandex-team.com> | 2024-11-18 14:48:05 +0300 |
---|---|---|
committer | arkady-e1ppa <arkady-e1ppa@yandex-team.com> | 2024-11-18 15:04:54 +0300 |
commit | 9e876c7c66440327e3bba353d37e99d68eabb0b9 (patch) | |
tree | b7daabaa3386ab7b1a783fad91da2f014f9354e7 /library/cpp/yt/string/format_string-inl.h | |
parent | 13bff9a72fbc1bd6a2643251982afcc3b4a7e93a (diff) | |
download | ydb-9e876c7c66440327e3bba353d37e99d68eabb0b9.tar.gz |
YT-23435: Parse format string at compile time
commit_hash:804530d1ee861ff42d7d8cad25d9f569b4feaacf
Diffstat (limited to 'library/cpp/yt/string/format_string-inl.h')
-rw-r--r-- | library/cpp/yt/string/format_string-inl.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/library/cpp/yt/string/format_string-inl.h b/library/cpp/yt/string/format_string-inl.h index a692d9648d..67f9bad45c 100644 --- a/library/cpp/yt/string/format_string-inl.h +++ b/library/cpp/yt/string/format_string-inl.h @@ -4,6 +4,8 @@ #include "format_string.h" #endif +#include <algorithm> + namespace NYT { //////////////////////////////////////////////////////////////////////////////// @@ -15,8 +17,13 @@ consteval TBasicFormatString<TArgs...>::TBasicFormatString(const T& fmt) : Format_(fmt) { CheckFormattability(); -#if !defined(NDEBUG) && !defined(YT_DISABLE_FORMAT_STATIC_ANALYSIS) - NDetail::TFormatAnalyser::ValidateFormat<std::remove_cvref_t<TArgs>...>(Format_); +#if !defined(YT_DISABLE_FORMAT_STATIC_ANALYSIS) + std::tie(Markers, Escapes) = NDetail::TFormatAnalyser::AnalyzeFormat<std::remove_cvref_t<TArgs>...>(Format_); +#else + std::ranges::fill_n(std::ranges::begin(Escapes), 1, -1); + if constexpr (sizeof...(TArgs) != 0) { + std::ranges::fill_n(std::ranges::begin(Markers), 1, std::tuple{0, 0}); + } #endif } @@ -46,6 +53,11 @@ template <class... TArgs> TBasicFormatString<TArgs...>::TBasicFormatString(TRuntimeFormat fmt) : Format_(fmt.Get()) { + std::ranges::fill_n(std::ranges::begin(Escapes), 1, -1); + if constexpr (sizeof...(TArgs) != 0) { + std::ranges::fill_n(std::ranges::begin(Markers), 1, std::tuple{0, 0}); + } + // NB(arkady-e1ppa): StaticFormat performs the // formattability check of the args in a way // that provides more useful information |