diff options
author | rus084 <rus084@yandex-team.com> | 2023-07-04 10:30:13 +0300 |
---|---|---|
committer | rus084 <rus084@yandex-team.com> | 2023-07-04 10:30:13 +0300 |
commit | 05e65abc4b8a3bee7da3888db0808aed846ee4ba (patch) | |
tree | bc05a896759ca30503576ce0b41327af254a0966 | |
parent | 6b1fffd64f2a49f05aa5beba087969c8df16f0d4 (diff) | |
download | ydb-05e65abc4b8a3bee7da3888db0808aed846ee4ba.tar.gz |
[util] add std::optional support to IOutputStream << operator
-rw-r--r-- | util/stream/output.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/util/stream/output.cpp b/util/stream/output.cpp index 40948fe925..a0ef0346de 100644 --- a/util/stream/output.cpp +++ b/util/stream/output.cpp @@ -19,6 +19,7 @@ #include <cstdio> #include <filesystem> #include <string_view> +#include <optional> #if defined(_win_) #include <io.h> @@ -251,6 +252,23 @@ void Out<TNullPtr>(IOutputStream& o, TTypeTraits<TNullPtr>::TFuncParam) { o << TStringBuf("nullptr"); } +#define DEF_OPTIONAL(TYPE) \ + template <> \ + void Out<std::optional<TYPE>>(IOutputStream & o, const std::optional<TYPE>& value) { \ + if (value) { \ + o << *value; \ + } else { \ + o << "(NULL)"; \ + } \ + } + +DEF_OPTIONAL(ui32); +DEF_OPTIONAL(i64); +DEF_OPTIONAL(ui64); +DEF_OPTIONAL(std::string); +DEF_OPTIONAL(TString); +DEF_OPTIONAL(TStringBuf); + #if defined(_android_) namespace { class TAndroidStdIOStreams { |