diff options
author | mikari <mikari@yandex-team.ru> | 2022-02-10 16:48:47 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:47 +0300 |
commit | 2e0ed5ad2d70bf924ccd3cbbfab508784ab36325 (patch) | |
tree | c407f44de8fd4579bf0ceffc822d243ff76cfd26 /library/cpp/iterator | |
parent | ab32245a89d56835833808c7e644b3da277d7085 (diff) | |
download | ydb-2e0ed5ad2d70bf924ccd3cbbfab508784ab36325.tar.gz |
Restoring authorship annotation for <mikari@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/iterator')
-rw-r--r-- | library/cpp/iterator/mapped.h | 60 | ||||
-rw-r--r-- | library/cpp/iterator/ut/mapped_ut.cpp | 2 |
2 files changed, 31 insertions, 31 deletions
diff --git a/library/cpp/iterator/mapped.h b/library/cpp/iterator/mapped.h index 6c5e763184..1bc2663bb7 100644 --- a/library/cpp/iterator/mapped.h +++ b/library/cpp/iterator/mapped.h @@ -29,7 +29,7 @@ public: using iterator_category = std::conditional_t<NIteratorPrivate::HasRandomAccess<TIterator>(), std::random_access_iterator_tag, std::input_iterator_tag>; - TMappedIterator(TIterator it, TMapper mapper) + TMappedIterator(TIterator it, TMapper mapper) : Iter(it) , Mapper(std::move(mapper)) { @@ -89,11 +89,11 @@ public: private: TIterator Iter; - TMapper Mapper; + TMapper Mapper; }; -template <class TContainer, class TMapper> +template <class TContainer, class TMapper> class TInputMappedRange { protected: using TContainerStorage = TAutoEmbedOrPtrPolicy<TContainer>; @@ -101,27 +101,27 @@ protected: using TMapperWrapper = std::reference_wrapper<std::remove_reference_t<TMapper>>; using TInternalIterator = decltype(std::begin(std::declval<TContainer&>())); using TIterator = TMappedIterator<TInternalIterator, TMapperWrapper>; -public: +public: using iterator = TIterator; using const_iterator = TIterator; using value_type = typename TIterator::value_type; using reference = typename TIterator::reference; using const_reference = typename TIterator::reference; - + TInputMappedRange(TContainer&& container, TMapper&& mapper) : Container(std::forward<TContainer>(container)) , Mapper(std::forward<TMapper>(mapper)) - { - } - + { + } + TIterator begin() const { return {std::begin(*Container.Ptr()), {*Mapper.Ptr()}}; - } - + } + TIterator end() const { return {std::end(*Container.Ptr()), {*Mapper.Ptr()}}; - } - + } + bool empty() const { return std::begin(*Container.Ptr()) == std::end(*Container.Ptr()); } @@ -130,7 +130,7 @@ protected: mutable TContainerStorage Container; mutable TMapperStorage Mapper; }; - + template <class TContainer, class TMapper> class TRandomAccessMappedRange : public TInputMappedRange<TContainer, TMapper> { @@ -150,36 +150,36 @@ public: TRandomAccessMappedRange(TContainer&& container, TMapper&& mapper) : TBase(std::forward<TContainer>(container), std::forward<TMapper>(mapper)) { - } - + } + using TBase::begin; using TBase::end; using TBase::empty; - size_type size() const { + size_type size() const { return std::end(*this->Container.Ptr()) - std::begin(*this->Container.Ptr()); - } - - const_reference operator[](size_t at) const { + } + + const_reference operator[](size_t at) const { Y_ASSERT(at < this->size()); - + return *(this->begin() + at); - } - - reference operator[](size_t at) { + } + + reference operator[](size_t at) { Y_ASSERT(at < this->size()); - + return *(this->begin() + at); - } -}; - + } +}; + template <class TIterator, class TMapper> -TMappedIterator<TIterator, TMapper> MakeMappedIterator(TIterator iter, TMapper mapper) { - return {iter, mapper}; +TMappedIterator<TIterator, TMapper> MakeMappedIterator(TIterator iter, TMapper mapper) { + return {iter, mapper}; } template <class TIterator, class TMapper> -auto MakeMappedRange(TIterator begin, TIterator end, TMapper mapper) { +auto MakeMappedRange(TIterator begin, TIterator end, TMapper mapper) { return MakeIteratorRange(MakeMappedIterator(begin, mapper), MakeMappedIterator(end, mapper)); } diff --git a/library/cpp/iterator/ut/mapped_ut.cpp b/library/cpp/iterator/ut/mapped_ut.cpp index 440cd37945..b073361be2 100644 --- a/library/cpp/iterator/ut/mapped_ut.cpp +++ b/library/cpp/iterator/ut/mapped_ut.cpp @@ -55,7 +55,7 @@ TEST(TIterator, TOwningMappedMethodTest) { for (int& y : range) { y += 7; } - + EXPECT_EQ(*range.begin(), 10); EXPECT_EQ(*(range.begin() + 1), 10); } |