diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/generic/store_policy.h | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic/store_policy.h')
-rw-r--r-- | util/generic/store_policy.h | 138 |
1 files changed, 69 insertions, 69 deletions
diff --git a/util/generic/store_policy.h b/util/generic/store_policy.h index 148821c70c..04aa3ca108 100644 --- a/util/generic/store_policy.h +++ b/util/generic/store_policy.h @@ -1,75 +1,75 @@ -#pragma once - +#pragma once + #include <utility> -#include "ptr.h" - -template <class TBase, class TCounter> -struct TWithRefCount: public TBase, public TRefCounted<TWithRefCount<TBase, TCounter>, TCounter> { - template <typename... Args> - inline TWithRefCount(Args&&... args) +#include "ptr.h" + +template <class TBase, class TCounter> +struct TWithRefCount: public TBase, public TRefCounted<TWithRefCount<TBase, TCounter>, TCounter> { + template <typename... Args> + inline TWithRefCount(Args&&... args) : TBase(std::forward<Args>(args)...) - { - } -}; - -template <class T> -struct TPtrPolicy { + { + } +}; + +template <class T> +struct TPtrPolicy { inline TPtrPolicy(T* t) - : T_(t) - { - } - + : T_(t) + { + } + inline T* Ptr() noexcept { return T_; } - inline const T* Ptr() const noexcept { - return T_; - } - + inline const T* Ptr() const noexcept { + return T_; + } + T* T_; -}; - -template <class T> -struct TEmbedPolicy { - template <typename... Args> - inline TEmbedPolicy(Args&&... args) +}; + +template <class T> +struct TEmbedPolicy { + template <typename... Args> + inline TEmbedPolicy(Args&&... args) : T_(std::forward<Args>(args)...) - { - } - - inline T* Ptr() noexcept { - return &T_; - } - - inline const T* Ptr() const noexcept { - return &T_; - } - - T T_; -}; - -template <class T, class TCounter> -struct TRefPolicy { - using THelper = TWithRefCount<T, TCounter>; - - template <typename... Args> - inline TRefPolicy(Args&&... args) + { + } + + inline T* Ptr() noexcept { + return &T_; + } + + inline const T* Ptr() const noexcept { + return &T_; + } + + T T_; +}; + +template <class T, class TCounter> +struct TRefPolicy { + using THelper = TWithRefCount<T, TCounter>; + + template <typename... Args> + inline TRefPolicy(Args&&... args) : T_(new THelper(std::forward<Args>(args)...)) - { - } - - inline T* Ptr() noexcept { - return T_.Get(); - } - - inline const T* Ptr() const noexcept { - return T_.Get(); - } - - TIntrusivePtr<THelper> T_; -}; - + { + } + + inline T* Ptr() noexcept { + return T_.Get(); + } + + inline const T* Ptr() const noexcept { + return T_.Get(); + } + + TIntrusivePtr<THelper> T_; +}; + /** * Storage class that can be handy for implementing proxies / adaptors that can * accept both lvalues and rvalues. In the latter case it's often required to @@ -94,7 +94,7 @@ struct TRefPolicy { * Look at `Reversed` in `adaptor.h` for real example. */ template <class T, bool IsReference = std::is_reference<T>::value> -struct TAutoEmbedOrPtrPolicy: TPtrPolicy<std::remove_reference_t<T>> { +struct TAutoEmbedOrPtrPolicy: TPtrPolicy<std::remove_reference_t<T>> { using TBase = TPtrPolicy<std::remove_reference_t<T>>; TAutoEmbedOrPtrPolicy(T& reference) @@ -104,7 +104,7 @@ struct TAutoEmbedOrPtrPolicy: TPtrPolicy<std::remove_reference_t<T>> { }; template <class T> -struct TAutoEmbedOrPtrPolicy<T, false>: TEmbedPolicy<T> { +struct TAutoEmbedOrPtrPolicy<T, false>: TEmbedPolicy<T> { using TBase = TEmbedPolicy<T>; TAutoEmbedOrPtrPolicy(T&& object) @@ -113,8 +113,8 @@ struct TAutoEmbedOrPtrPolicy<T, false>: TEmbedPolicy<T> { } }; -template <class T> -using TAtomicRefPolicy = TRefPolicy<T, TAtomicCounter>; - -template <class T> -using TSimpleRefPolicy = TRefPolicy<T, TSimpleCounter>; +template <class T> +using TAtomicRefPolicy = TRefPolicy<T, TAtomicCounter>; + +template <class T> +using TSimpleRefPolicy = TRefPolicy<T, TSimpleCounter>; |