diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/stream/holder.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/stream/holder.h')
-rw-r--r-- | util/stream/holder.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/util/stream/holder.h b/util/stream/holder.h new file mode 100644 index 0000000000..c60a4e510c --- /dev/null +++ b/util/stream/holder.h @@ -0,0 +1,44 @@ +#pragma once + +#include <util/generic/ptr.h> + +#include <utility> +#include <type_traits> + +class IInputStream; +class IOutputStream; + +namespace NPrivate { + template <class Stream, bool isInput = std::is_base_of<IInputStream, Stream>::value> + struct TStreamBase { + using TType = IInputStream; + }; + + template <class Stream> + struct TStreamBase<Stream, false> { + using TType = IOutputStream; + }; + +} + +/** + * An ownership-gaining wrapper for proxy streams. + * + * Example usage: + * \code + * TCountingInput* input = new THoldingStream<TCountingInput>(new TStringInput(s)); + * \encode + * + * In this example, resulting counting input also owns a string input that it + * was constructed on top of. + */ +template <class Base, class StreamBase = typename ::NPrivate::TStreamBase<Base>::TType> +class THoldingStream: private THolder<StreamBase>, public Base { +public: + template <class... Args> + inline THoldingStream(THolder<StreamBase> stream, Args&&... args) + : THolder<StreamBase>(std::move(stream)) + , Base(this->Get(), std::forward<Args>(args)...) + { + } +}; |