diff options
author | mstebelev <mstebelev@yandex-team.ru> | 2022-02-10 16:47:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:17 +0300 |
commit | 93e9e4639b6ee2afbdf45cf3927cea6d340e19b0 (patch) | |
tree | 9814fbd1c3effac9b8377c5d604b367b14e2db55 /library/cpp/iterator | |
parent | 5a176099114d03d5669e95a55a3a514bd24dd8b1 (diff) | |
download | ydb-93e9e4639b6ee2afbdf45cf3927cea6d340e19b0.tar.gz |
Restoring authorship annotation for <mstebelev@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/iterator')
-rw-r--r-- | library/cpp/iterator/filtering.h | 124 | ||||
-rw-r--r-- | library/cpp/iterator/mapped.h | 152 | ||||
-rw-r--r-- | library/cpp/iterator/ut/filtering_ut.cpp | 8 | ||||
-rw-r--r-- | library/cpp/iterator/ut/mapped_ut.cpp | 12 | ||||
-rw-r--r-- | library/cpp/iterator/ut/ya.make | 14 | ||||
-rw-r--r-- | library/cpp/iterator/ya.make | 8 |
6 files changed, 159 insertions, 159 deletions
diff --git a/library/cpp/iterator/filtering.h b/library/cpp/iterator/filtering.h index c99428b5f1..c28e3bc6c4 100644 --- a/library/cpp/iterator/filtering.h +++ b/library/cpp/iterator/filtering.h @@ -1,61 +1,61 @@ -#pragma once - +#pragma once + #include <util/generic/iterator_range.h> #include <util/generic/store_policy.h> -#include <iterator> - - -template <class TIterator, class TCondition> -class TFilteringIterator { -public: - using TSelf = TFilteringIterator<TIterator, TCondition>; - - using difference_type = typename std::iterator_traits<TIterator>::difference_type; - using value_type = typename std::iterator_traits<TIterator>::value_type; - using reference = typename std::iterator_traits<TIterator>::reference; - using pointer = typename std::iterator_traits<TIterator>::pointer; - using iterator_category = std::forward_iterator_tag; - - TFilteringIterator(TIterator it, TIterator last, const TCondition& condition) - : Iter(it) - , Last(last) +#include <iterator> + + +template <class TIterator, class TCondition> +class TFilteringIterator { +public: + using TSelf = TFilteringIterator<TIterator, TCondition>; + + using difference_type = typename std::iterator_traits<TIterator>::difference_type; + using value_type = typename std::iterator_traits<TIterator>::value_type; + using reference = typename std::iterator_traits<TIterator>::reference; + using pointer = typename std::iterator_traits<TIterator>::pointer; + using iterator_category = std::forward_iterator_tag; + + TFilteringIterator(TIterator it, TIterator last, const TCondition& condition) + : Iter(it) + , Last(last) , Condition(condition) - { - Grep(); - } - - TSelf& operator++() { - ++Iter; - Grep(); - return *this; - } - - decltype(auto) operator*() const { - return *Iter; - } - - pointer operator->() const { - return &*Iter; - } - - bool operator==(const TSelf& other) const { - return Iter == other.Iter; - } - bool operator!=(const TSelf& other) const { - return Iter != other.Iter; - } - -private: - void Grep() { - while (Iter != Last && !Condition(*Iter)) { - ++Iter; - } - } - TIterator Iter; - TIterator Last; - TCondition Condition; -}; - + { + Grep(); + } + + TSelf& operator++() { + ++Iter; + Grep(); + return *this; + } + + decltype(auto) operator*() const { + return *Iter; + } + + pointer operator->() const { + return &*Iter; + } + + bool operator==(const TSelf& other) const { + return Iter == other.Iter; + } + bool operator!=(const TSelf& other) const { + return Iter != other.Iter; + } + +private: + void Grep() { + while (Iter != Last && !Condition(*Iter)) { + ++Iter; + } + } + TIterator Iter; + TIterator Last; + TCondition Condition; +}; + template <class TContainer, class TCondition> class TFilteringRange { @@ -91,12 +91,12 @@ private: }; -template <class TIterator, class TCondition> -auto MakeFilteringRange(TIterator begin, TIterator end, const TCondition& condition) { - return MakeIteratorRange(TFilteringIterator<TIterator, TCondition>(begin, end, condition), TFilteringIterator<TIterator, TCondition>(end, end, condition)); -} - -template <class TContainer, class TCondition> +template <class TIterator, class TCondition> +auto MakeFilteringRange(TIterator begin, TIterator end, const TCondition& condition) { + return MakeIteratorRange(TFilteringIterator<TIterator, TCondition>(begin, end, condition), TFilteringIterator<TIterator, TCondition>(end, end, condition)); +} + +template <class TContainer, class TCondition> auto MakeFilteringRange(TContainer&& container, TCondition&& condition) { return TFilteringRange<TContainer, TCondition>(std::forward<TContainer>(container), std::forward<TCondition>(condition)); -} +} diff --git a/library/cpp/iterator/mapped.h b/library/cpp/iterator/mapped.h index 255ebb1803..6c5e763184 100644 --- a/library/cpp/iterator/mapped.h +++ b/library/cpp/iterator/mapped.h @@ -1,8 +1,8 @@ -#pragma once - -#include <util/generic/iterator_range.h> +#pragma once + +#include <util/generic/iterator_range.h> #include <util/generic/store_policy.h> - + #include <iterator> @@ -15,83 +15,83 @@ namespace NIteratorPrivate { }; -template <class TIterator, class TMapper> -class TMappedIterator { +template <class TIterator, class TMapper> +class TMappedIterator { protected: - using TSelf = TMappedIterator<TIterator, TMapper>; - using TSrcPointerType = typename std::iterator_traits<TIterator>::reference; + using TSelf = TMappedIterator<TIterator, TMapper>; + using TSrcPointerType = typename std::iterator_traits<TIterator>::reference; using TValue = typename std::invoke_result_t<TMapper, TSrcPointerType>; public: - using difference_type = std::ptrdiff_t; - using value_type = TValue; - using reference = TValue&; - using pointer = std::remove_reference_t<TValue>*; + using difference_type = std::ptrdiff_t; + using value_type = TValue; + using reference = TValue&; + using pointer = std::remove_reference_t<TValue>*; using iterator_category = std::conditional_t<NIteratorPrivate::HasRandomAccess<TIterator>(), std::random_access_iterator_tag, std::input_iterator_tag>; - + TMappedIterator(TIterator it, TMapper mapper) - : Iter(it) + : Iter(it) , Mapper(std::move(mapper)) - { - } - - TSelf& operator++() { - ++Iter; - return *this; - } - TSelf& operator--() { - --Iter; - return *this; - } + { + } + + TSelf& operator++() { + ++Iter; + return *this; + } + TSelf& operator--() { + --Iter; + return *this; + } TValue operator*() { return Mapper((*Iter)); } - TValue operator*() const { - return Mapper((*Iter)); - } - - pointer operator->() const { - return &(Mapper((*Iter))); - } - - TValue operator[](difference_type n) const { - return Mapper(*(Iter + n)); - } - TSelf& operator+=(difference_type n) { - Iter += n; - return *this; - } - TSelf& operator-=(difference_type n) { - Iter -= n; - return *this; - } - TSelf operator+(difference_type n) const { - return TSelf(Iter + n, Mapper); - } + TValue operator*() const { + return Mapper((*Iter)); + } + + pointer operator->() const { + return &(Mapper((*Iter))); + } + + TValue operator[](difference_type n) const { + return Mapper(*(Iter + n)); + } + TSelf& operator+=(difference_type n) { + Iter += n; + return *this; + } + TSelf& operator-=(difference_type n) { + Iter -= n; + return *this; + } + TSelf operator+(difference_type n) const { + return TSelf(Iter + n, Mapper); + } TSelf operator-(difference_type n) const { return TSelf(Iter - n, Mapper); } - difference_type operator-(const TSelf& other) const { - return Iter - other.Iter; - } - bool operator==(const TSelf& other) const { - return Iter == other.Iter; - } - bool operator!=(const TSelf& other) const { - return Iter != other.Iter; - } - bool operator>(const TSelf& other) const { - return Iter > other.Iter; - } - bool operator<(const TSelf& other) const { - return Iter < other.Iter; - } - -private: - TIterator Iter; + difference_type operator-(const TSelf& other) const { + return Iter - other.Iter; + } + bool operator==(const TSelf& other) const { + return Iter == other.Iter; + } + bool operator!=(const TSelf& other) const { + return Iter != other.Iter; + } + bool operator>(const TSelf& other) const { + return Iter > other.Iter; + } + bool operator<(const TSelf& other) const { + return Iter < other.Iter; + } + +private: + TIterator Iter; TMapper Mapper; -}; - +}; + template <class TContainer, class TMapper> class TInputMappedRange { @@ -173,21 +173,21 @@ public: } }; -template <class TIterator, class TMapper> +template <class TIterator, class TMapper> TMappedIterator<TIterator, TMapper> MakeMappedIterator(TIterator iter, TMapper mapper) { return {iter, mapper}; -} - -template <class TIterator, class TMapper> +} + +template <class TIterator, class TMapper> auto MakeMappedRange(TIterator begin, TIterator end, TMapper mapper) { - return MakeIteratorRange(MakeMappedIterator(begin, mapper), MakeMappedIterator(end, mapper)); -} - -template <class TContainer, class TMapper> + return MakeIteratorRange(MakeMappedIterator(begin, mapper), MakeMappedIterator(end, mapper)); +} + +template <class TContainer, class TMapper> auto MakeMappedRange(TContainer&& container, TMapper&& mapper) { if constexpr (NIteratorPrivate::HasRandomAccess<decltype(std::begin(container))>()) { return TRandomAccessMappedRange<TContainer, TMapper>(std::forward<TContainer>(container), std::forward<TMapper>(mapper)); } else { return TInputMappedRange<TContainer, TMapper>(std::forward<TContainer>(container), std::forward<TMapper>(mapper)); } -} +} diff --git a/library/cpp/iterator/ut/filtering_ut.cpp b/library/cpp/iterator/ut/filtering_ut.cpp index 1837e1e280..60c2044698 100644 --- a/library/cpp/iterator/ut/filtering_ut.cpp +++ b/library/cpp/iterator/ut/filtering_ut.cpp @@ -1,7 +1,7 @@ #include <library/cpp/iterator/filtering.h> - + #include <library/cpp/testing/gtest/gtest.h> - + #include <util/generic/vector.h> using namespace testing; @@ -33,9 +33,9 @@ TEST(Filtering, TMutableFilteringRangeTest) { TVector<int> x = {1, 2, 3, 4, 5}; for (auto& y : MakeFilteringRange(x, [](int x) { return x % 2 == 0; })) { y = 7; - } + } EXPECT_THAT( x, ElementsAre(1, 7, 3, 7, 5) ); -} +} diff --git a/library/cpp/iterator/ut/mapped_ut.cpp b/library/cpp/iterator/ut/mapped_ut.cpp index 94b686c119..440cd37945 100644 --- a/library/cpp/iterator/ut/mapped_ut.cpp +++ b/library/cpp/iterator/ut/mapped_ut.cpp @@ -1,10 +1,10 @@ #include <library/cpp/iterator/mapped.h> - + #include <library/cpp/testing/gtest/gtest.h> - + #include <util/generic/map.h> #include <util/generic/vector.h> - + using namespace testing; TEST(TIterator, TMappedIteratorTest) { @@ -45,7 +45,7 @@ TEST(TIterator, TOwningMappedMethodTest) { TVector<std::pair<int, int>>{std::make_pair(1, 2), std::make_pair(3, 4)}, [](auto& point) -> int& { return point.first; - } + } ); EXPECT_EQ(range[0], 1); range[0] += 1; @@ -54,8 +54,8 @@ TEST(TIterator, TOwningMappedMethodTest) { EXPECT_EQ(range[0], 3); for (int& y : range) { y += 7; - } + } EXPECT_EQ(*range.begin(), 10); EXPECT_EQ(*(range.begin() + 1), 10); -} +} diff --git a/library/cpp/iterator/ut/ya.make b/library/cpp/iterator/ut/ya.make index 1a457541b4..601e5663b9 100644 --- a/library/cpp/iterator/ut/ya.make +++ b/library/cpp/iterator/ut/ya.make @@ -1,18 +1,18 @@ GTEST() - + PEERDIR( library/cpp/iterator ) OWNER(g:util) - -SRCS( - filtering_ut.cpp + +SRCS( + filtering_ut.cpp functools_ut.cpp iterate_keys_ut.cpp iterate_values_ut.cpp mapped_ut.cpp zip_ut.cpp -) - -END() +) + +END() diff --git a/library/cpp/iterator/ya.make b/library/cpp/iterator/ya.make index 226858b8c5..1ba1ffb411 100644 --- a/library/cpp/iterator/ya.make +++ b/library/cpp/iterator/ya.make @@ -1,7 +1,7 @@ OWNER(g:util) - -LIBRARY() - + +LIBRARY() + SRCS( cartesian_product.cpp concatenate.cpp @@ -14,6 +14,6 @@ SRCS( zip.cpp ) -END() +END() RECURSE_FOR_TESTS(ut) |