diff options
author | arkady-e1ppa <arkady-e1ppa@yandex-team.com> | 2024-06-07 13:13:50 +0300 |
---|---|---|
committer | arkady-e1ppa <arkady-e1ppa@yandex-team.com> | 2024-06-07 13:27:39 +0300 |
commit | 327232940ecda2082cbcd9551049456522bbaffe (patch) | |
tree | b9a4b9604260773016c98f1560f59e2d06ce535e /library/cpp/config/domscheme.h | |
parent | 1924960f5dfa85e96d87306b3962f57862ab98c8 (diff) | |
download | ydb-327232940ecda2082cbcd9551049456522bbaffe.tar.gz |
YT-21868: Refactor NYT::Format
NYT::Format had several problems:
1. There are too many ways to enable printing of T. Not all are equally good. You could specialize TValueFormatter, you could write an overload of FormatValue, you could write an overload of ToString, you could write an overload of operator << for special stream or you could specialize the Out function.
2. If you attempt to print T which cannot be printed, you get a linker error without a proper source location which is very frustrating to work with.
3. There is no static analysis of format string performed even when it is possible.
4. If you write FormatValue overload, you still have to write ToString overload if you want to use this function (and people tend to use it quite a bit, since it is defined for util types and enums.
This pr addresses these issues to some extent. Relevant changes:
1. The only way to support NYT::Format is to define the FormatValue overload. Otherwise, you get a compile-time error.
2. Format overloads have changed: Now you have two options for general use:
```
TString Format(TStaticFormat<TArgs...> fmt, TArgs&&... args);
TString Format(TRuntimeFormat fmt, TArgs&&... args);
```
Either overload checks if TArg has a FormatValue overload. TStaticFormat performs a compile-time check of flags and the argument count. It binds to any string literal and constexpr string/string_view (and TStringBuf). TRuntimeFormat has to be mentioned explicitly. Otherwise, you will get a compile-time error for using runtime variable as a format.
3(!!!). Types which name begins with NYT:: have a specialization of ToString function which uses FormatValue. Thus, if you write class in namespace NYT and define FormatValue, you get ToString automatically. If your type is not from namespace enclosing NYT, you can just call NYT::ToString for the same effect. This limitation was caused by the fact, that we cannot review all of the external projects code which might inherit from stl classes or adopt some other questionable code practises which may completely break the dispatching mechanism of ToString due to the specialization (there were such cases). Proper documentation of this library will be added soon, so that this interaction is made known. This limitation might be lifted later
77beb68082e10aaf48be1842aad8aba63f26c1bd
Diffstat (limited to 'library/cpp/config/domscheme.h')
0 files changed, 0 insertions, 0 deletions