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 | |
parent | 62bad8df5b890e3012b8949bcf6d2e885ce8972c (diff) | |
download | ydb-dbfeb17da4d5c610309076cffa8aeb7ac1da411c.tar.gz |
Restoring authorship annotation for <zakarum@yandex-team.ru>. Commit 1 of 2.
-rw-r--r-- | library/cpp/regex/pcre/regexp.cpp | 12 | ||||
-rw-r--r-- | util/generic/maybe.h | 86 | ||||
-rw-r--r-- | util/generic/maybe_ut.cpp | 274 |
3 files changed, 186 insertions, 186 deletions
diff --git a/library/cpp/regex/pcre/regexp.cpp b/library/cpp/regex/pcre/regexp.cpp index 575c09cee4..1bcd071e87 100644 --- a/library/cpp/regex/pcre/regexp.cpp +++ b/library/cpp/regex/pcre/regexp.cpp @@ -213,20 +213,20 @@ void TRegExBase::Compile(const TString& re, int cflags) { } int TRegExBase::Exec(const char* str, regmatch_t pmatch[], int eflags, int nmatches) const { - if (!Impl) - ythrow yexception() << "!Regular expression is not compiled"; + if (!Impl) + ythrow yexception() << "!Regular expression is not compiled"; return Impl->Exec(str, pmatch, eflags, nmatches); } int TRegExBase::GetCompileOptions() const { - if (!Impl) - ythrow yexception() << "!Regular expression is not compiled"; + if (!Impl) + ythrow yexception() << "!Regular expression is not compiled"; return Impl->CompileOptions; } TString TRegExBase::GetRegExpr() const { - if (!Impl) - ythrow yexception() << "!Regular expression is not compiled"; + if (!Impl) + ythrow yexception() << "!Regular expression is not compiled"; return Impl->RegExpr; } 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(); diff --git a/util/generic/maybe_ut.cpp b/util/generic/maybe_ut.cpp index 2c1a425c5e..d1abd3eafe 100644 --- a/util/generic/maybe_ut.cpp +++ b/util/generic/maybe_ut.cpp @@ -808,162 +808,162 @@ Y_UNIT_TEST_SUITE(TMaybeTest) { output << TMaybe<int>(42); UNIT_ASSERT_EQUAL("42", s); } - + Y_UNIT_TEST(TestMaybeCovarianceImplicit) { - struct TestStruct { - TestStruct(int value) - : Value_(value) + struct TestStruct { + TestStruct(int value) + : Value_(value) { } - - operator int() const { - return Value_; - } - - static TMaybe<int> Unwrap(TMaybe<TestStruct> testStructMaybe) { - return testStructMaybe; - } - - int Value_; - }; - - TMaybe<int> testMaybeFull = TestStruct::Unwrap(TMaybe<int>(42)); - UNIT_ASSERT(testMaybeFull.Defined()); - UNIT_ASSERT_EQUAL(testMaybeFull.GetRef(), 42); - - TMaybe<int> testMaybeEmpty = TestStruct::Unwrap(TMaybe<int>()); - UNIT_ASSERT(!testMaybeEmpty.Defined()); - } - + + operator int() const { + return Value_; + } + + static TMaybe<int> Unwrap(TMaybe<TestStruct> testStructMaybe) { + return testStructMaybe; + } + + int Value_; + }; + + TMaybe<int> testMaybeFull = TestStruct::Unwrap(TMaybe<int>(42)); + UNIT_ASSERT(testMaybeFull.Defined()); + UNIT_ASSERT_EQUAL(testMaybeFull.GetRef(), 42); + + TMaybe<int> testMaybeEmpty = TestStruct::Unwrap(TMaybe<int>()); + UNIT_ASSERT(!testMaybeEmpty.Defined()); + } + Y_UNIT_TEST(TestMaybeCovarianceExplicit) { - struct TestStruct { - explicit TestStruct(int value) - : Value_(value) + struct TestStruct { + explicit TestStruct(int value) + : Value_(value) { } - int Value_; - }; - - TMaybe<TestStruct> testStructMaybeFull(TMaybe<int>(42)); - UNIT_ASSERT(testStructMaybeFull.Defined()); - UNIT_ASSERT_EQUAL(testStructMaybeFull.GetRef().Value_, 42); - - TMaybe<int> empty; - TMaybe<TestStruct> testStructMaybeEmpty(empty); - UNIT_ASSERT(!testStructMaybeEmpty.Defined()); - } - + int Value_; + }; + + TMaybe<TestStruct> testStructMaybeFull(TMaybe<int>(42)); + UNIT_ASSERT(testStructMaybeFull.Defined()); + UNIT_ASSERT_EQUAL(testStructMaybeFull.GetRef().Value_, 42); + + TMaybe<int> empty; + TMaybe<TestStruct> testStructMaybeEmpty(empty); + UNIT_ASSERT(!testStructMaybeEmpty.Defined()); + } + Y_UNIT_TEST(TestMaybeCovarianceAssign) { - struct TestStruct { - explicit TestStruct(int value) - : Value_(value) + struct TestStruct { + explicit TestStruct(int value) + : Value_(value) { } - TestStruct& operator=(int value) { - Value_ = value; - return *this; - } - int Value_; - }; - - TMaybe<TestStruct> testStructMaybe(Nothing()); - UNIT_ASSERT(!testStructMaybe.Defined()); - - testStructMaybe = TMaybe<int>(42); - UNIT_ASSERT(testStructMaybe.Defined()); - UNIT_ASSERT_EQUAL(testStructMaybe.GetRef().Value_, 42); - - testStructMaybe = TMaybe<int>(23); - UNIT_ASSERT(testStructMaybe.Defined()); - UNIT_ASSERT_EQUAL(testStructMaybe.GetRef().Value_, 23); - - testStructMaybe = TMaybe<int>(); - UNIT_ASSERT(!testStructMaybe.Defined()); - } - + TestStruct& operator=(int value) { + Value_ = value; + return *this; + } + int Value_; + }; + + TMaybe<TestStruct> testStructMaybe(Nothing()); + UNIT_ASSERT(!testStructMaybe.Defined()); + + testStructMaybe = TMaybe<int>(42); + UNIT_ASSERT(testStructMaybe.Defined()); + UNIT_ASSERT_EQUAL(testStructMaybe.GetRef().Value_, 42); + + testStructMaybe = TMaybe<int>(23); + UNIT_ASSERT(testStructMaybe.Defined()); + UNIT_ASSERT_EQUAL(testStructMaybe.GetRef().Value_, 23); + + testStructMaybe = TMaybe<int>(); + UNIT_ASSERT(!testStructMaybe.Defined()); + } + Y_UNIT_TEST(TestMaybeCovarianceNonTrivial) { - struct TestStruct { - enum { - FromValue, - FromMaybe, - }; - TestStruct(int value) - : Value_(value) - , From_(FromValue) + struct TestStruct { + enum { + FromValue, + FromMaybe, + }; + TestStruct(int value) + : Value_(value) + , From_(FromValue) { } - TestStruct(TMaybe<int> value) - : Value_(value.Defined() ? value.GetRef() : 0) - , From_(FromMaybe) + TestStruct(TMaybe<int> value) + : Value_(value.Defined() ? value.GetRef() : 0) + , From_(FromMaybe) { } - int Value_; - int From_; - }; - - TMaybe<TestStruct> testStructFromMaybe(TMaybe<int>(42)); - UNIT_ASSERT(testStructFromMaybe.Defined()); - UNIT_ASSERT_EQUAL(testStructFromMaybe.GetRef().From_, TestStruct::FromMaybe); - UNIT_ASSERT_EQUAL(testStructFromMaybe.GetRef().Value_, 42); - - TMaybe<int> empty; - TMaybe<TestStruct> testStructFromEmptyMaybe(empty); - UNIT_ASSERT(testStructFromEmptyMaybe.Defined()); - UNIT_ASSERT_EQUAL(testStructFromEmptyMaybe.GetRef().From_, TestStruct::FromMaybe); - UNIT_ASSERT_EQUAL(testStructFromEmptyMaybe.GetRef().Value_, 0); - - TMaybe<TestStruct> testStructFromValue(23); - UNIT_ASSERT(testStructFromValue.Defined()); - UNIT_ASSERT_EQUAL(testStructFromValue.GetRef().From_, TestStruct::FromValue); - UNIT_ASSERT_EQUAL(testStructFromValue.GetRef().Value_, 23); - } - + int Value_; + int From_; + }; + + TMaybe<TestStruct> testStructFromMaybe(TMaybe<int>(42)); + UNIT_ASSERT(testStructFromMaybe.Defined()); + UNIT_ASSERT_EQUAL(testStructFromMaybe.GetRef().From_, TestStruct::FromMaybe); + UNIT_ASSERT_EQUAL(testStructFromMaybe.GetRef().Value_, 42); + + TMaybe<int> empty; + TMaybe<TestStruct> testStructFromEmptyMaybe(empty); + UNIT_ASSERT(testStructFromEmptyMaybe.Defined()); + UNIT_ASSERT_EQUAL(testStructFromEmptyMaybe.GetRef().From_, TestStruct::FromMaybe); + UNIT_ASSERT_EQUAL(testStructFromEmptyMaybe.GetRef().Value_, 0); + + TMaybe<TestStruct> testStructFromValue(23); + UNIT_ASSERT(testStructFromValue.Defined()); + UNIT_ASSERT_EQUAL(testStructFromValue.GetRef().From_, TestStruct::FromValue); + UNIT_ASSERT_EQUAL(testStructFromValue.GetRef().Value_, 23); + } + Y_UNIT_TEST(TestMaybeCovarianceNonTrivialAssign) { - struct TestStruct { - enum { - FromValue, - FromMaybe, - }; - TestStruct(int value) - : Value_(value) - , From_(FromValue) + struct TestStruct { + enum { + FromValue, + FromMaybe, + }; + TestStruct(int value) + : Value_(value) + , From_(FromValue) { } - TestStruct(TMaybe<int> value) - : Value_(value.Defined() ? value.GetRef() : 0) - , From_(FromMaybe) + TestStruct(TMaybe<int> value) + : Value_(value.Defined() ? value.GetRef() : 0) + , From_(FromMaybe) { } - TestStruct& operator=(int value) { - Value_ = value; - From_ = FromValue; - return *this; - } - TestStruct& operator=(TMaybe<int> value) { - Value_ = value.Defined() ? value.GetRef() : 0; - From_ = FromMaybe; - return *this; - } - int Value_; - int From_; - }; - - TMaybe<TestStruct> testStructMaybe(Nothing()); - testStructMaybe = TMaybe<int>(42); - UNIT_ASSERT(testStructMaybe.Defined()); - UNIT_ASSERT_EQUAL(testStructMaybe.GetRef().From_, TestStruct::FromMaybe); - UNIT_ASSERT_EQUAL(testStructMaybe.GetRef().Value_, 42); - - testStructMaybe = TMaybe<int>(); - UNIT_ASSERT(testStructMaybe.Defined()); - UNIT_ASSERT_EQUAL(testStructMaybe.GetRef().From_, TestStruct::FromMaybe); - UNIT_ASSERT_EQUAL(testStructMaybe.GetRef().Value_, 0); - - testStructMaybe = 23; - UNIT_ASSERT(testStructMaybe.Defined()); - UNIT_ASSERT_EQUAL(testStructMaybe.GetRef().From_, TestStruct::FromValue); - UNIT_ASSERT_EQUAL(testStructMaybe.GetRef().Value_, 23); - } + TestStruct& operator=(int value) { + Value_ = value; + From_ = FromValue; + return *this; + } + TestStruct& operator=(TMaybe<int> value) { + Value_ = value.Defined() ? value.GetRef() : 0; + From_ = FromMaybe; + return *this; + } + int Value_; + int From_; + }; + + TMaybe<TestStruct> testStructMaybe(Nothing()); + testStructMaybe = TMaybe<int>(42); + UNIT_ASSERT(testStructMaybe.Defined()); + UNIT_ASSERT_EQUAL(testStructMaybe.GetRef().From_, TestStruct::FromMaybe); + UNIT_ASSERT_EQUAL(testStructMaybe.GetRef().Value_, 42); + + testStructMaybe = TMaybe<int>(); + UNIT_ASSERT(testStructMaybe.Defined()); + UNIT_ASSERT_EQUAL(testStructMaybe.GetRef().From_, TestStruct::FromMaybe); + UNIT_ASSERT_EQUAL(testStructMaybe.GetRef().Value_, 0); + + testStructMaybe = 23; + UNIT_ASSERT(testStructMaybe.Defined()); + UNIT_ASSERT_EQUAL(testStructMaybe.GetRef().From_, TestStruct::FromValue); + UNIT_ASSERT_EQUAL(testStructMaybe.GetRef().Value_, 23); + } Y_UNIT_TEST(TestMaybeConvertion) { struct TSrc {}; |