diff options
author | zakarum <zakarum@yandex-team.ru> | 2022-02-10 16:49:34 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:34 +0300 |
commit | dbfeb17da4d5c610309076cffa8aeb7ac1da411c (patch) | |
tree | 974a315804a261fcebcb58c406172e40dc1a2bb7 /util/generic/maybe.h | |
parent | 62bad8df5b890e3012b8949bcf6d2e885ce8972c (diff) | |
download | ydb-dbfeb17da4d5c610309076cffa8aeb7ac1da411c.tar.gz |
Restoring authorship annotation for <zakarum@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic/maybe.h')
-rw-r--r-- | util/generic/maybe.h | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/util/generic/maybe.h b/util/generic/maybe.h index 34d21aebcd..28eeca88c6 100644 --- a/util/generic/maybe.h +++ b/util/generic/maybe.h @@ -49,7 +49,7 @@ private: static_assert(std::is_destructible<T>::value, "Instantiation of TMaybe with non-destructible type is ill-formed"); - template <class U> + template <class U> struct TConstructibleFromMaybeSomehow { public: static constexpr bool value = std::is_constructible<T, TMaybe<U, Policy>&>::value || @@ -61,8 +61,8 @@ private: std::is_convertible<TMaybe<U, Policy>&&, T>::value || std::is_convertible<const TMaybe<U, Policy>&&, T>::value; }; - - template <class U> + + template <class U> struct TAssignableFromMaybeSomehow { public: static constexpr bool value = TConstructibleFromMaybeSomehow<U>::value || @@ -71,7 +71,7 @@ private: std::is_assignable<T&, TMaybe<U, Policy>&&>::value || std::is_assignable<T&, const TMaybe<U, Policy>&&>::value; }; - + template <class U> struct TImplicitCopyCtor { public: @@ -180,35 +180,35 @@ public: template <class U, class = std::enable_if_t<TImplicitCopyCtor<U>::value>> TMaybe(const TMaybe<U, Policy>& right) { if (right.Defined()) { - new (Data()) T(right.GetRef()); + new (Data()) T(right.GetRef()); this->Defined_ = true; - } - } - + } + } + template <class U, std::enable_if_t<TExplicitCopyCtor<U>::value, bool> = false> explicit TMaybe(const TMaybe<U, Policy>& right) { if (right.Defined()) { - new (Data()) T(right.GetRef()); + new (Data()) T(right.GetRef()); this->Defined_ = true; - } - } - + } + } + template <class U, class = std::enable_if_t<TImplicitMoveCtor<U>::value>> TMaybe(TMaybe<U, Policy>&& right) noexcept(std::is_nothrow_constructible<T, U&&>::value) { if (right.Defined()) { - new (Data()) T(std::move(right.GetRef())); + new (Data()) T(std::move(right.GetRef())); this->Defined_ = true; - } - } - + } + } + template <class U, std::enable_if_t<TExplicitMoveCtor<U>::value, bool> = false> explicit TMaybe(TMaybe<U, Policy>&& right) noexcept(std::is_nothrow_constructible<T, U&&>::value) { if (right.Defined()) { - new (Data()) T(std::move(right.GetRef())); + new (Data()) T(std::move(right.GetRef())); this->Defined_ = true; - } - } - + } + } + template <class U = T, class = std::enable_if_t<TImplicitAnyCtor<U>::value>> constexpr TMaybe(U&& right) : TBase(TInPlace{}, std::forward<U>(right)) @@ -246,37 +246,37 @@ public: TMaybe&> operator=(const TMaybe<U, Policy>& right) { if (right.Defined()) { - if (Defined()) { + if (Defined()) { *Data() = right.GetRef(); - } else { - Init(right.GetRef()); - } - } else { - Clear(); - } - - return *this; - } - + } else { + Init(right.GetRef()); + } + } else { + Clear(); + } + + return *this; + } + template <class U> std::enable_if_t<TMoveAssignable<U>::value, TMaybe&> operator=(TMaybe<U, Policy>&& right) noexcept( std::is_nothrow_assignable<T&, U&&>::value&& std::is_nothrow_constructible<T, U&&>::value) { - if (right.Defined()) { - if (Defined()) { + if (right.Defined()) { + if (Defined()) { *Data() = std::move(right.GetRef()); - } else { - Init(std::move(right.GetRef())); - } - } else { - Clear(); - } - - return *this; - } - + } else { + Init(std::move(right.GetRef())); + } + } else { + Clear(); + } + + return *this; + } + template <typename... Args> T& ConstructInPlace(Args&&... args) { Clear(); |