diff options
author | epar <epar@yandex-team.ru> | 2022-02-10 16:50:02 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:02 +0300 |
commit | 904f1af50fdd9aae658a7b5688b5a497044c4584 (patch) | |
tree | 5fc4555525a8451ec9e74fde574490f4c72c8fc5 /util/generic | |
parent | 9473a88c91129dfe21343af486bebb93a0b33291 (diff) | |
download | ydb-904f1af50fdd9aae658a7b5688b5a497044c4584.tar.gz |
Restoring authorship annotation for <epar@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic')
-rw-r--r-- | util/generic/adaptor.cpp | 2 | ||||
-rw-r--r-- | util/generic/adaptor.h | 38 | ||||
-rw-r--r-- | util/generic/adaptor_ut.cpp | 118 |
3 files changed, 79 insertions, 79 deletions
diff --git a/util/generic/adaptor.cpp b/util/generic/adaptor.cpp index 1909857ba5..04bf3d54cb 100644 --- a/util/generic/adaptor.cpp +++ b/util/generic/adaptor.cpp @@ -1 +1 @@ -#include "adaptor.h" +#include "adaptor.h" diff --git a/util/generic/adaptor.h b/util/generic/adaptor.h index b88a65fc81..e04f7b12d2 100644 --- a/util/generic/adaptor.h +++ b/util/generic/adaptor.h @@ -1,9 +1,9 @@ -#pragma once - +#pragma once + #include "store_policy.h" -#include "typetraits.h" - -namespace NPrivate { +#include "typetraits.h" + +namespace NPrivate { template <class Range> class TReverseRangeStorage { public: @@ -11,7 +11,7 @@ namespace NPrivate { : Base_(std::forward<Range>(range)) { } - + decltype(auto) Base() const { return *Base_.Ptr(); } @@ -44,8 +44,8 @@ namespace NPrivate { auto begin() const { return Base().rbegin(); - } - + } + auto end() const { return Base().rend(); } @@ -70,23 +70,23 @@ namespace NPrivate { auto begin() const { using std::end; return std::make_reverse_iterator(end(Base())); - } - + } + auto end() const { using std::begin; return std::make_reverse_iterator(begin(Base())); - } - + } + auto begin() { using std::end; return std::make_reverse_iterator(end(Base())); - } - + } + auto end() { using std::begin; return std::make_reverse_iterator(begin(Base())); - } - }; + } + }; template <class Range> class TReverseRange: public TReverseRangeBase<Range> { @@ -119,8 +119,8 @@ namespace NPrivate { return end(Base()); } }; -} - +} + /** * Provides a reverse view into the provided container. * @@ -137,4 +137,4 @@ namespace NPrivate { template <class Range> constexpr ::NPrivate::TReverseRange<Range> Reversed(Range&& range) { return ::NPrivate::TReverseRange<Range>(std::forward<Range>(range)); -} +} diff --git a/util/generic/adaptor_ut.cpp b/util/generic/adaptor_ut.cpp index 721f849f93..793e22c2c7 100644 --- a/util/generic/adaptor_ut.cpp +++ b/util/generic/adaptor_ut.cpp @@ -1,80 +1,80 @@ -#include "adaptor.h" -#include "yexception.h" - +#include "adaptor.h" +#include "yexception.h" + #include <library/cpp/testing/unittest/registar.h> - + struct TOnCopy: yexception { -}; - +}; + struct TOnMove: yexception { -}; - -struct TState { - explicit TState() { - } - - TState(const TState&) { - ythrow TOnCopy(); - } - - TState(TState&&) { - ythrow TOnMove(); - } - - void operator=(const TState&) { - ythrow TOnCopy(); - } - - void rbegin() const { - } - - void rend() const { - } -}; - +}; + +struct TState { + explicit TState() { + } + + TState(const TState&) { + ythrow TOnCopy(); + } + + TState(TState&&) { + ythrow TOnMove(); + } + + void operator=(const TState&) { + ythrow TOnCopy(); + } + + void rbegin() const { + } + + void rend() const { + } +}; + Y_UNIT_TEST_SUITE(TReverseAdaptor) { Y_UNIT_TEST(ReadTest) { TVector<int> cont = {1, 2, 3}; TVector<int> etalon = {3, 2, 1}; - size_t idx = 0; - for (const auto& x : Reversed(cont)) { - UNIT_ASSERT_VALUES_EQUAL(etalon[idx++], x); - } + size_t idx = 0; + for (const auto& x : Reversed(cont)) { + UNIT_ASSERT_VALUES_EQUAL(etalon[idx++], x); + } idx = 0; for (const auto& x : Reversed(std::move(cont))) { UNIT_ASSERT_VALUES_EQUAL(etalon[idx++], x); } - } - + } + Y_UNIT_TEST(WriteTest) { TVector<int> cont = {1, 2, 3}; TVector<int> etalon = {3, 6, 9}; - size_t idx = 0; - for (auto& x : Reversed(cont)) { - x *= x + idx++; - } - idx = 0; - for (auto& x : cont) { - UNIT_ASSERT_VALUES_EQUAL(etalon[idx++], x); - } - } - + size_t idx = 0; + for (auto& x : Reversed(cont)) { + x *= x + idx++; + } + idx = 0; + for (auto& x : cont) { + UNIT_ASSERT_VALUES_EQUAL(etalon[idx++], x); + } + } + Y_UNIT_TEST(InnerTypeTest) { using TStub = TVector<int>; - TStub stub; - const TStub cstub; - - using namespace NPrivate; + TStub stub; + const TStub cstub; + + using namespace NPrivate; UNIT_ASSERT_TYPES_EQUAL(decltype(Reversed(stub)), TReverseRange<TStub&>); UNIT_ASSERT_TYPES_EQUAL(decltype(Reversed(cstub)), TReverseRange<const TStub&>); - } - + } + Y_UNIT_TEST(CopyMoveTest) { - TState lvalue; - const TState clvalue; - UNIT_ASSERT_NO_EXCEPTION(Reversed(lvalue)); - UNIT_ASSERT_NO_EXCEPTION(Reversed(clvalue)); - } + TState lvalue; + const TState clvalue; + UNIT_ASSERT_NO_EXCEPTION(Reversed(lvalue)); + UNIT_ASSERT_NO_EXCEPTION(Reversed(clvalue)); + } Y_UNIT_TEST(ReverseX2Test) { TVector<int> cont = {1, 2, 3}; @@ -121,4 +121,4 @@ Y_UNIT_TEST_SUITE(TReverseAdaptor) { UNIT_ASSERT_VALUES_EQUAL(etalon2[idx++], x); } } -} +} |