1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #pragma once
- #include "format_analyser.h"
- #include <util/generic/strbuf.h>
- #if (!__clang__ || __clang_major__ < 16)
- #define YT_DISABLE_FORMAT_STATIC_ANALYSIS
- #endif
- namespace NYT {
- ////////////////////////////////////////////////////////////////////////////////
- // Explicitly create TRuntimeFormat if you wish to
- // use runtime/non-literal value as format.
- class TRuntimeFormat
- {
- public:
- explicit TRuntimeFormat(TStringBuf fmt);
- TStringBuf Get() const noexcept;
- private:
- TStringBuf Format_;
- };
- // This class used to properly bind to
- // string literals and allow compile-time parsing/checking
- // of those. If you need a runtime format, use TRuntimeFormat.
- template <class... TArgs>
- class TBasicFormatString
- {
- public:
- // Can be used to perform compile-time check of format.
- template <class T>
- requires std::constructible_from<std::string_view, T>
- consteval TBasicFormatString(const T& fmt);
- TBasicFormatString(TRuntimeFormat fmt);
- TStringBuf Get() const noexcept;
- static consteval void CheckFormattability();
- // Data used for compile-time slicing of the format string.
- NDetail::TFormatAnalyser::TMarkerLocations<TArgs...> Markers = {};
- NDetail::TFormatAnalyser::TEscapeLocations Escapes = {};
- private:
- std::string_view Format_;
- template <class T>
- static void CrashCompilerClassIsNotFormattable();
- };
- // Used to properly infer template arguments in Format.
- template <class... TArgs>
- using TFormatString = TBasicFormatString<std::type_identity_t<TArgs>...>;
- ////////////////////////////////////////////////////////////////////////////////
- template <class T>
- concept CStringLiteral = requires (T& t) {
- [] (const char*) { } (t);
- };
- ////////////////////////////////////////////////////////////////////////////////
- } // namespace NYT
- #define FORMAT_STRING_INL_H_
- #include "format_string-inl.h"
- #undef FORMAT_STRING_INL_H_
|