diff options
author | swarmer <swarmer@yandex-team.com> | 2024-09-26 22:16:03 +0300 |
---|---|---|
committer | swarmer <swarmer@yandex-team.com> | 2024-09-26 22:36:37 +0300 |
commit | 69ce19dae9cc421f3d3a3b650e01b2f9bece79b5 (patch) | |
tree | b73fa8fbd2b795a54301e37aaaa6259811040823 /util/stream | |
parent | 9598e6ce746a6ae937ccc291c9c5e64db14ce62e (diff) | |
download | ydb-69ce19dae9cc421f3d3a3b650e01b2f9bece79b5.tar.gz |
check lifetime bound of output streams
commit_hash:17de7afe0f415c511e587b2f2607cbbc2348742e
Diffstat (limited to 'util/stream')
-rw-r--r-- | util/stream/format.h | 14 | ||||
-rw-r--r-- | util/stream/input.h | 2 | ||||
-rw-r--r-- | util/stream/output.h | 19 |
3 files changed, 18 insertions, 17 deletions
diff --git a/util/stream/format.h b/util/stream/format.h index 56c3083bbc..c6ee9c720f 100644 --- a/util/stream/format.h +++ b/util/stream/format.h @@ -67,7 +67,7 @@ namespace NFormatPrivate { }; template <typename T> - IOutputStream& operator<<(IOutputStream& o, const TLeftPad<T>& lp) { + IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, const TLeftPad<T>& lp) { TTempBuf buf; TMemoryOutput ss(buf.Data(), buf.Size()); ss << lp.Value; @@ -94,7 +94,7 @@ namespace NFormatPrivate { }; template <typename T> - IOutputStream& operator<<(IOutputStream& o, const TRightPad<T>& lp) { + IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, const TRightPad<T>& lp) { TTempBuf buf; TMemoryOutput ss(buf.Data(), buf.Size()); ss << lp.Value; @@ -123,7 +123,7 @@ namespace NFormatPrivate { using TUnsignedBaseNumber = TBaseNumber<std::make_unsigned_t<std::remove_cv_t<T>>, Base>; template <typename TStream, typename T, size_t Base> - TStream& ToStreamImpl(TStream& stream, const TBaseNumber<T, Base>& value) { + TStream& ToStreamImpl(TStream& stream Y_LIFETIME_BOUND, const TBaseNumber<T, Base>& value) { char buf[8 * sizeof(T) + 1]; /* Add 1 for sign. */ TStringBuf str(buf, IntToString<Base>(value.Value, buf, sizeof(buf))); @@ -149,12 +149,12 @@ namespace NFormatPrivate { } template <typename T, size_t Base> - IOutputStream& operator<<(IOutputStream& stream, const TBaseNumber<T, Base>& value) { + IOutputStream& operator<<(IOutputStream& stream Y_LIFETIME_BOUND, const TBaseNumber<T, Base>& value) { return ToStreamImpl(stream, value); } template <typename T, size_t Base> - std::ostream& operator<<(std::ostream& stream, const TBaseNumber<T, Base>& value) { + std::ostream& operator<<(std::ostream& stream Y_LIFETIME_BOUND, const TBaseNumber<T, Base>& value) { return ToStreamImpl(stream, value); } @@ -169,7 +169,7 @@ namespace NFormatPrivate { }; template <typename Char, size_t Base> - IOutputStream& operator<<(IOutputStream& os, const TBaseText<Char, Base>& text) { + IOutputStream& operator<<(IOutputStream& os Y_LIFETIME_BOUND, const TBaseText<Char, Base>& text) { for (size_t i = 0; i < text.Text.size(); ++i) { if (i != 0) { os << ' '; @@ -190,7 +190,7 @@ namespace NFormatPrivate { }; template <typename T> - IOutputStream& operator<<(IOutputStream& o, const TFloatPrecision<T>& prec) { + IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, const TFloatPrecision<T>& prec) { char buf[512]; size_t count = FloatToString(prec.Value, buf, sizeof(buf), prec.Mode, prec.NDigits); o << TStringBuf(buf, count); diff --git a/util/stream/input.h b/util/stream/input.h index b1facec254..c64159b28c 100644 --- a/util/stream/input.h +++ b/util/stream/input.h @@ -256,7 +256,7 @@ void In(IInputStream& in, T& value); * @see operator<<(IOutputStream&, T&) */ template <typename T> -inline IInputStream& operator>>(IInputStream& in, T& value) { +inline IInputStream& operator>>(IInputStream& in Y_LIFETIME_BOUND, T& value) { In<T>(in, value); return in; } diff --git a/util/stream/output.h b/util/stream/output.h index 1f903a655a..8acd66a4ba 100644 --- a/util/stream/output.h +++ b/util/stream/output.h @@ -7,6 +7,7 @@ #include <util/generic/string.h> #include <util/generic/strbuf.h> #include <util/generic/typetraits.h> +#include <util/system/compiler.h> #include <type_traits> @@ -207,54 +208,54 @@ void Out<const wchar16*>(IOutputStream& o, const wchar16* w); template <> void Out<const wchar32*>(IOutputStream& o, const wchar32* w); -static inline IOutputStream& operator<<(IOutputStream& o, TStreamManipulator m) { +static inline IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, TStreamManipulator m) { m(o); return o; } -static inline IOutputStream& operator<<(IOutputStream& o, const char* t) { +static inline IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, const char* t) { Out<const char*>(o, t); return o; } -static inline IOutputStream& operator<<(IOutputStream& o, char* t) { +static inline IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, char* t) { Out<const char*>(o, t); return o; } template <class T> -static inline std::enable_if_t<std::is_scalar<T>::value, IOutputStream&> operator<<(IOutputStream& o, T t) { +static inline std::enable_if_t<std::is_scalar<T>::value, IOutputStream&> operator<<(IOutputStream& o Y_LIFETIME_BOUND, T t) { Out<T>(o, t); return o; } template <class T> -static inline std::enable_if_t<!std::is_scalar<T>::value, IOutputStream&> operator<<(IOutputStream& o, const T& t) { +static inline std::enable_if_t<!std::is_scalar<T>::value, IOutputStream&> operator<<(IOutputStream& o Y_LIFETIME_BOUND, const T& t) { Out<T>(o, t); return o; } -static inline IOutputStream& operator<<(IOutputStream& o, const wchar16* t) { +static inline IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, const wchar16* t) { Out<const wchar16*>(o, t); return o; } -static inline IOutputStream& operator<<(IOutputStream& o, wchar16* t) { +static inline IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, wchar16* t) { Out<const wchar16*>(o, t); return o; } -static inline IOutputStream& operator<<(IOutputStream& o, const wchar32* t) { +static inline IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, const wchar32* t) { Out<const wchar32*>(o, t); return o; } -static inline IOutputStream& operator<<(IOutputStream& o, wchar32* t) { +static inline IOutputStream& operator<<(IOutputStream& o Y_LIFETIME_BOUND, wchar32* t) { Out<const wchar32*>(o, t); return o; } |