aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/iterator
diff options
context:
space:
mode:
authorthegeorg <thegeorg@yandex-team.ru>2022-02-10 16:45:12 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:12 +0300
commit49116032d905455a7b1c994e4a696afc885c1e71 (patch)
treebe835aa92c6248212e705f25388ebafcf84bc7a1 /library/cpp/iterator
parent4e839db24a3bbc9f1c610c43d6faaaa99824dcca (diff)
downloadydb-49116032d905455a7b1c994e4a696afc885c1e71.tar.gz
Restoring authorship annotation for <thegeorg@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/iterator')
-rw-r--r--library/cpp/iterator/cartesian_product.h6
-rw-r--r--library/cpp/iterator/concatenate.h6
-rw-r--r--library/cpp/iterator/enumerate.h6
-rw-r--r--library/cpp/iterator/filtering.h8
-rw-r--r--library/cpp/iterator/iterate_keys.cpp2
-rw-r--r--library/cpp/iterator/iterate_keys.h26
-rw-r--r--library/cpp/iterator/iterate_values.cpp2
-rw-r--r--library/cpp/iterator/iterate_values.h26
-rw-r--r--library/cpp/iterator/mapped.h28
-rw-r--r--library/cpp/iterator/ut/filtering_ut.cpp74
-rw-r--r--library/cpp/iterator/ut/functools_ut.cpp234
-rw-r--r--library/cpp/iterator/ut/iterate_keys_ut.cpp74
-rw-r--r--library/cpp/iterator/ut/iterate_values_ut.cpp212
-rw-r--r--library/cpp/iterator/ut/mapped_ut.cpp114
-rw-r--r--library/cpp/iterator/ut/ya.make16
-rw-r--r--library/cpp/iterator/ya.make4
-rw-r--r--library/cpp/iterator/zip.h8
17 files changed, 423 insertions, 423 deletions
diff --git a/library/cpp/iterator/cartesian_product.h b/library/cpp/iterator/cartesian_product.h
index b1855ebddb..3ef70339a2 100644
--- a/library/cpp/iterator/cartesian_product.h
+++ b/library/cpp/iterator/cartesian_product.h
@@ -82,9 +82,9 @@ namespace NPrivate {
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;
+ using value_type = typename TIterator::value_type;
+ using reference = typename TIterator::reference;
+ using const_reference = typename TIterator::reference;
TIterator begin() const {
bool isEmpty = !((std::begin(*std::get<I>(Holders_).Ptr()) != std::end(*std::get<I>(Holders_).Ptr())) && ...);
diff --git a/library/cpp/iterator/concatenate.h b/library/cpp/iterator/concatenate.h
index 728b7c2703..64d2cd451a 100644
--- a/library/cpp/iterator/concatenate.h
+++ b/library/cpp/iterator/concatenate.h
@@ -101,9 +101,9 @@ namespace NPrivate {
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;
+ using value_type = typename TIterator::value_type;
+ using reference = typename TIterator::reference;
+ using const_reference = typename TIterator::reference;
TIterator begin() const {
TIterator iterator{TIteratorState{std::begin(*std::get<I>(Holders_).Ptr())...}, 0, &Holders_};
diff --git a/library/cpp/iterator/enumerate.h b/library/cpp/iterator/enumerate.h
index aacef79c98..2c83fb41bf 100644
--- a/library/cpp/iterator/enumerate.h
+++ b/library/cpp/iterator/enumerate.h
@@ -54,9 +54,9 @@ namespace NPrivate {
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;
+ using value_type = typename TIterator::value_type;
+ using reference = typename TIterator::reference;
+ using const_reference = typename TIterator::reference;
TIterator begin() const {
return {0, std::begin(*Storage_.Ptr())};
diff --git a/library/cpp/iterator/filtering.h b/library/cpp/iterator/filtering.h
index b0d0720b62..c28e3bc6c4 100644
--- a/library/cpp/iterator/filtering.h
+++ b/library/cpp/iterator/filtering.h
@@ -64,13 +64,13 @@ class TFilteringRange {
using TRawIterator = decltype(std::begin(std::declval<TContainer&>()));
using TConditionWrapper = std::reference_wrapper<std::remove_reference_t<TCondition>>;
public:
- //TODO: make TIterator typedef private
+ //TODO: make TIterator typedef private
using TIterator = TFilteringIterator<TRawIterator, TConditionWrapper>;
-
+
using iterator = TIterator;
using const_iterator = TIterator;
- using value_type = typename TIterator::value_type;
- using reference = typename TIterator::reference;
+ using value_type = typename TIterator::value_type;
+ using reference = typename TIterator::reference;
TFilteringRange(TContainer&& container, TCondition&& predicate)
: Container(std::forward<TContainer>(container))
diff --git a/library/cpp/iterator/iterate_keys.cpp b/library/cpp/iterator/iterate_keys.cpp
index 609afd08da..6556d39af7 100644
--- a/library/cpp/iterator/iterate_keys.cpp
+++ b/library/cpp/iterator/iterate_keys.cpp
@@ -1 +1 @@
-#include "iterate_keys.h"
+#include "iterate_keys.h"
diff --git a/library/cpp/iterator/iterate_keys.h b/library/cpp/iterator/iterate_keys.h
index 0915d0040d..75362a6bd6 100644
--- a/library/cpp/iterator/iterate_keys.h
+++ b/library/cpp/iterator/iterate_keys.h
@@ -1,13 +1,13 @@
-#pragma once
-
-#include "mapped.h"
-
-template<typename TMapping>
-auto IterateKeys(TMapping&& map) {
- return ::MakeMappedRange(
- std::forward<TMapping>(map),
- [](const auto& x) -> decltype((x.first)) {
- return x.first;
- }
- );
-}
+#pragma once
+
+#include "mapped.h"
+
+template<typename TMapping>
+auto IterateKeys(TMapping&& map) {
+ return ::MakeMappedRange(
+ std::forward<TMapping>(map),
+ [](const auto& x) -> decltype((x.first)) {
+ return x.first;
+ }
+ );
+}
diff --git a/library/cpp/iterator/iterate_values.cpp b/library/cpp/iterator/iterate_values.cpp
index 40b0eb3ae5..5607e58ecb 100644
--- a/library/cpp/iterator/iterate_values.cpp
+++ b/library/cpp/iterator/iterate_values.cpp
@@ -1 +1 @@
-#include "iterate_values.h"
+#include "iterate_values.h"
diff --git a/library/cpp/iterator/iterate_values.h b/library/cpp/iterator/iterate_values.h
index 4997ea6300..ac6f2f04ce 100644
--- a/library/cpp/iterator/iterate_values.h
+++ b/library/cpp/iterator/iterate_values.h
@@ -1,13 +1,13 @@
-#pragma once
-
-#include "mapped.h"
-
-template<typename TMapping>
-auto IterateValues(TMapping&& map) {
- return ::MakeMappedRange(
- std::forward<TMapping>(map),
- [](auto& x) -> decltype((x.second)) {
- return x.second;
- }
- );
-}
+#pragma once
+
+#include "mapped.h"
+
+template<typename TMapping>
+auto IterateValues(TMapping&& map) {
+ return ::MakeMappedRange(
+ std::forward<TMapping>(map),
+ [](auto& x) -> decltype((x.second)) {
+ return x.second;
+ }
+ );
+}
diff --git a/library/cpp/iterator/mapped.h b/library/cpp/iterator/mapped.h
index 9733ee58ab..6c5e763184 100644
--- a/library/cpp/iterator/mapped.h
+++ b/library/cpp/iterator/mapped.h
@@ -17,10 +17,10 @@ namespace NIteratorPrivate {
template <class TIterator, class TMapper>
class TMappedIterator {
-protected:
+protected:
using TSelf = TMappedIterator<TIterator, TMapper>;
using TSrcPointerType = typename std::iterator_traits<TIterator>::reference;
- using TValue = typename std::invoke_result_t<TMapper, TSrcPointerType>;
+ using TValue = typename std::invoke_result_t<TMapper, TSrcPointerType>;
public:
using difference_type = std::ptrdiff_t;
using value_type = TValue;
@@ -31,7 +31,7 @@ public:
TMappedIterator(TIterator it, TMapper mapper)
: Iter(it)
- , Mapper(std::move(mapper))
+ , Mapper(std::move(mapper))
{
}
@@ -99,14 +99,14 @@ protected:
using TContainerStorage = TAutoEmbedOrPtrPolicy<TContainer>;
using TMapperStorage = TAutoEmbedOrPtrPolicy<TMapper>;
using TMapperWrapper = std::reference_wrapper<std::remove_reference_t<TMapper>>;
- using TInternalIterator = decltype(std::begin(std::declval<TContainer&>()));
- using TIterator = TMappedIterator<TInternalIterator, TMapperWrapper>;
+ using TInternalIterator = decltype(std::begin(std::declval<TContainer&>()));
+ using TIterator = TMappedIterator<TInternalIterator, TMapperWrapper>;
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;
+ 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))
@@ -114,11 +114,11 @@ public:
{
}
- TIterator begin() const {
+ TIterator begin() const {
return {std::begin(*Container.Ptr()), {*Mapper.Ptr()}};
}
- TIterator end() const {
+ TIterator end() const {
return {std::end(*Container.Ptr()), {*Mapper.Ptr()}};
}
@@ -135,8 +135,8 @@ protected:
template <class TContainer, class TMapper>
class TRandomAccessMappedRange : public TInputMappedRange<TContainer, TMapper> {
using TBase = TInputMappedRange<TContainer, TMapper>;
- using TInternalIterator = typename TBase::TInternalIterator;
- using TIterator = typename TBase::TIterator;
+ using TInternalIterator = typename TBase::TInternalIterator;
+ using TIterator = typename TBase::TIterator;
public:
using iterator = typename TBase::iterator;
using const_iterator = typename TBase::const_iterator;
diff --git a/library/cpp/iterator/ut/filtering_ut.cpp b/library/cpp/iterator/ut/filtering_ut.cpp
index cd03e7ef83..60c2044698 100644
--- a/library/cpp/iterator/ut/filtering_ut.cpp
+++ b/library/cpp/iterator/ut/filtering_ut.cpp
@@ -1,41 +1,41 @@
-#include <library/cpp/iterator/filtering.h>
+#include <library/cpp/iterator/filtering.h>
-#include <library/cpp/testing/gtest/gtest.h>
+#include <library/cpp/testing/gtest/gtest.h>
-#include <util/generic/vector.h>
-
-using namespace testing;
-
-TEST(Filtering, TFilteringRangeTest) {
- const TVector<int> x = {1, 2, 3, 4, 5};
-
- EXPECT_THAT(
- MakeFilteringRange(
- x,
- [](int x) { return x % 2 == 0; }
- ),
- ElementsAre(2, 4)
- );
-}
-
-TEST(Filtering, TEmptyFilteringRangeTest) {
- TVector<int> x = {1, 2, 3, 4, 5};
- EXPECT_THAT(
- MakeFilteringRange(
- x,
- [](int x) { return x > 100; }
- ),
- ElementsAre()
- );
-}
-
-TEST(Filtering, TMutableFilteringRangeTest) {
- TVector<int> x = {1, 2, 3, 4, 5};
- for (auto& y : MakeFilteringRange(x, [](int x) { return x % 2 == 0; })) {
- y = 7;
+#include <util/generic/vector.h>
+
+using namespace testing;
+
+TEST(Filtering, TFilteringRangeTest) {
+ const TVector<int> x = {1, 2, 3, 4, 5};
+
+ EXPECT_THAT(
+ MakeFilteringRange(
+ x,
+ [](int x) { return x % 2 == 0; }
+ ),
+ ElementsAre(2, 4)
+ );
+}
+
+TEST(Filtering, TEmptyFilteringRangeTest) {
+ TVector<int> x = {1, 2, 3, 4, 5};
+ EXPECT_THAT(
+ MakeFilteringRange(
+ x,
+ [](int x) { return x > 100; }
+ ),
+ ElementsAre()
+ );
+}
+
+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)
- );
+ EXPECT_THAT(
+ x,
+ ElementsAre(1, 7, 3, 7, 5)
+ );
}
diff --git a/library/cpp/iterator/ut/functools_ut.cpp b/library/cpp/iterator/ut/functools_ut.cpp
index 496a2a9747..2dee9a55c8 100644
--- a/library/cpp/iterator/ut/functools_ut.cpp
+++ b/library/cpp/iterator/ut/functools_ut.cpp
@@ -1,6 +1,6 @@
-#include <library/cpp/iterator/functools.h>
+#include <library/cpp/iterator/functools.h>
-#include <library/cpp/testing/gtest/gtest.h>
+#include <library/cpp/testing/gtest/gtest.h>
#include <util/generic/vector.h>
#include <util/generic/xrange.h>
@@ -58,17 +58,17 @@ using namespace NFuncTools;
auto it3 = std::move(it);
Y_UNUSED(it3);
Y_UNUSED(*it3);
- EXPECT_TRUE(it3 == it3);
- EXPECT_FALSE(it3 != it3);
+ EXPECT_TRUE(it3 == it3);
+ EXPECT_FALSE(it3 != it3);
// const TIterator
const auto it4 = it3;
Y_UNUSED(*it4);
- EXPECT_TRUE(it4 == it4);
- EXPECT_FALSE(it4 != it4);
- EXPECT_TRUE(it3 == it4);
- EXPECT_TRUE(it4 == it3);
- EXPECT_FALSE(it3 != it4);
- EXPECT_FALSE(it4 != it3);
+ EXPECT_TRUE(it4 == it4);
+ EXPECT_FALSE(it4 != it4);
+ EXPECT_TRUE(it3 == it4);
+ EXPECT_TRUE(it4 == it3);
+ EXPECT_FALSE(it3 != it4);
+ EXPECT_FALSE(it4 != it3);
}
auto it = container.begin();
@@ -118,57 +118,57 @@ using namespace NFuncTools;
}
- TEST(FuncTools, CompileRange) {
+ TEST(FuncTools, CompileRange) {
TestViewCompileability(Range(19));
TestViewCompileability(Range(10, 19));
TestViewCompileability(Range(10, 19, 2));
}
- TEST(FuncTools, Enumerate) {
- TVector<size_t> a = {1, 2, 4};
- TVector<size_t> b;
- TVector<size_t> c = {1};
+ TEST(FuncTools, Enumerate) {
+ TVector<size_t> a = {1, 2, 4};
+ TVector<size_t> b;
+ TVector<size_t> c = {1};
for (auto& v : {a, b, c}) {
- size_t j = 0;
+ size_t j = 0;
FOR_DISPATCH_2(i, x, Enumerate(v)) {
- EXPECT_EQ(v[i], x);
- EXPECT_EQ(i, j++);
- EXPECT_LT(i, v.size());
+ EXPECT_EQ(v[i], x);
+ EXPECT_EQ(i, j++);
+ EXPECT_LT(i, v.size());
}
- EXPECT_EQ(j, v.size());
+ EXPECT_EQ(j, v.size());
}
- TVector<size_t> d = {0, 0, 0};
+ TVector<size_t> d = {0, 0, 0};
FOR_DISPATCH_2(i, x, Enumerate(d)) {
x = i;
}
- EXPECT_THAT(
- d,
- testing::ElementsAre(0u, 1u, 2u)
- );
+ EXPECT_THAT(
+ d,
+ testing::ElementsAre(0u, 1u, 2u)
+ );
}
- TEST(FuncTools, EnumerateTemporary) {
- TVector<size_t> a = {1, 2, 4};
- TVector<size_t> b;
- TVector<size_t> c = {1};
+ TEST(FuncTools, EnumerateTemporary) {
+ TVector<size_t> a = {1, 2, 4};
+ TVector<size_t> b;
+ TVector<size_t> c = {1};
for (auto& v : {a, b, c}) {
- size_t j = 0;
+ size_t j = 0;
FOR_DISPATCH_2(i, x, Enumerate(TVector(v))) {
- EXPECT_EQ(v[i], x);
- EXPECT_EQ(i, j++);
- EXPECT_LT(i, v.size());
+ EXPECT_EQ(v[i], x);
+ EXPECT_EQ(i, j++);
+ EXPECT_LT(i, v.size());
}
- EXPECT_EQ(j, v.size());
+ EXPECT_EQ(j, v.size());
}
- FOR_DISPATCH_2(i, x, Enumerate(TVector<size_t>{1, 2, 3})) {
- EXPECT_EQ(i + 1, x);
+ FOR_DISPATCH_2(i, x, Enumerate(TVector<size_t>{1, 2, 3})) {
+ EXPECT_EQ(i + 1, x);
}
}
- TEST(FuncTools, CompileEnumerate) {
+ TEST(FuncTools, CompileEnumerate) {
auto container = std::vector{1, 2, 3};
TestViewCompileability(Enumerate(container));
const auto constContainer = std::vector{1, 2, 3};
@@ -180,13 +180,13 @@ using namespace NFuncTools;
FOR_DISPATCH_2(i, x, Enumerate(MakeMinimalisticContainer())) {
res.push_back({i, x});
}
- EXPECT_EQ(res, (std::vector<std::pair<int, int>>{
+ EXPECT_EQ(res, (std::vector<std::pair<int, int>>{
{0, 0}, {1, 1}, {2, 2},
}));
}
- TEST(FuncTools, Zip) {
- TVector<std::pair<TVector<size_t>, TVector<size_t>>> ts = {
+ TEST(FuncTools, Zip) {
+ TVector<std::pair<TVector<size_t>, TVector<size_t>>> ts = {
{{1, 2, 3}, {4, 5, 6}},
{{1, 2, 3}, {4, 5, 6, 7}},
{{1, 2, 3, 4}, {4, 5, 6}},
@@ -194,28 +194,28 @@ using namespace NFuncTools;
};
FOR_DISPATCH_2(a, b, ts) {
- size_t k = 0;
+ size_t k = 0;
FOR_DISPATCH_2(i, j, Zip(a, b)) {
- EXPECT_EQ(++k, i);
- EXPECT_EQ(i + 3, j);
+ EXPECT_EQ(++k, i);
+ EXPECT_EQ(i + 3, j);
}
- EXPECT_EQ(k, Min(a.size(), b.size()));
+ EXPECT_EQ(k, Min(a.size(), b.size()));
}
}
- TEST(FuncTools, ZipReference) {
+ TEST(FuncTools, ZipReference) {
TVector a = {0, 1, 2};
TVector b = {2, 1, 0, -1};
FOR_DISPATCH_2(ai, bi, Zip(a, b)) {
ai = bi;
}
- EXPECT_THAT(
- a,
- testing::ElementsAre(2u, 1u, 0u)
- );
+ EXPECT_THAT(
+ a,
+ testing::ElementsAre(2u, 1u, 0u)
+ );
}
- TEST(FuncTools, Zip3) {
+ TEST(FuncTools, Zip3) {
TVector<std::tuple<TVector<i32>, TVector<i32>, TVector<i32>>> ts = {
{{1, 2, 3}, {4, 5, 6}, {11, 3}},
{{1, 2, 3}, {4, 5, 6, 7}, {9, 0}},
@@ -235,11 +235,11 @@ using namespace NFuncTools;
f.push_back({ai, bi, ci});
}
- EXPECT_EQ(e, f);
+ EXPECT_EQ(e, f);
}
}
- TEST(FuncTools, CompileZip) {
+ TEST(FuncTools, CompileZip) {
auto container = std::vector{1, 2, 3};
TestViewCompileability(Zip(container));
TestViewCompileability(Zip(container, container, container));
@@ -252,12 +252,12 @@ using namespace NFuncTools;
FOR_DISPATCH_2(a, b, Zip(MakeMinimalisticContainer(), container)) {
res.push_back({a, b});
}
- EXPECT_EQ(res, (std::vector<std::pair<int, int>>{
+ EXPECT_EQ(res, (std::vector<std::pair<int, int>>{
{0, 1}, {1, 2}, {2, 3},
}));
}
- TEST(FuncTools, Filter) {
+ TEST(FuncTools, Filter) {
TVector<TVector<i32>> ts = {
{},
{1},
@@ -282,11 +282,11 @@ using namespace NFuncTools;
c.push_back(x);
}
- EXPECT_EQ(b, c);
+ EXPECT_EQ(b, c);
}
}
- TEST(FuncTools, CompileFilter) {
+ TEST(FuncTools, CompileFilter) {
auto container = std::vector{1, 2, 3};
auto isOdd = [](int x) { return bool(x & 1); };
TestViewCompileability(Filter(isOdd, container));
@@ -294,7 +294,7 @@ using namespace NFuncTools;
TestViewCompileability(Filter(isOdd, arrayContainer));
}
- TEST(FuncTools, Map) {
+ TEST(FuncTools, Map) {
TVector<TVector<i32>> ts = {
{},
{1},
@@ -315,7 +315,7 @@ using namespace NFuncTools;
c.push_back(x);
}
- EXPECT_EQ(b, c);
+ EXPECT_EQ(b, c);
}
TVector floats = {1.4, 4.1, 13.9};
@@ -329,11 +329,11 @@ using namespace NFuncTools;
for (auto i : Map<float>(Map<int>(floats))) {
resFloat.push_back(i);
}
- EXPECT_EQ(ints, res);
- EXPECT_EQ(roundedFloats, resFloat);
+ EXPECT_EQ(ints, res);
+ EXPECT_EQ(roundedFloats, resFloat);
}
- TEST(FuncTools, CompileMap) {
+ TEST(FuncTools, CompileMap) {
auto container = std::vector{1, 2, 3};
auto sqr = [](int x) { return x * x; };
TestViewCompileability(Map(sqr, container));
@@ -341,25 +341,25 @@ using namespace NFuncTools;
TestViewCompileability(Map(sqr, arrayContainer));
}
- TEST(FuncTools, MapRandomAccess) {
+ TEST(FuncTools, MapRandomAccess) {
auto sqr = [](int x) { return x * x; };
{
auto container = std::vector{1, 2, 3};
auto mapped = Map(sqr, container);
- static_assert(
- std::is_same_v<decltype(mapped)::iterator::iterator_category, std::random_access_iterator_tag>
- );
+ static_assert(
+ std::is_same_v<decltype(mapped)::iterator::iterator_category, std::random_access_iterator_tag>
+ );
}
{
auto container = std::set<int>{1, 2, 3};
auto mapped = Map(sqr, container);
- static_assert(
- std::is_same_v<decltype(mapped)::iterator::iterator_category, std::input_iterator_tag>
- );
+ static_assert(
+ std::is_same_v<decltype(mapped)::iterator::iterator_category, std::input_iterator_tag>
+ );
}
}
- TEST(FuncTools, CartesianProduct) {
+ TEST(FuncTools, CartesianProduct) {
TVector<std::pair<TVector<i32>, TVector<i32>>> ts = {
{{1, 2, 3}, {4, 5, 6}},
{{1, 2, 3}, {4, 5, 6, 7}},
@@ -381,7 +381,7 @@ using namespace NFuncTools;
d.push_back({ai, bi});
}
- EXPECT_EQ(c, d);
+ EXPECT_EQ(c, d);
}
{
@@ -390,12 +390,12 @@ using namespace NFuncTools;
FOR_DISPATCH_2(gi, i, CartesianProduct(g, h)) {
gi.push_back(i);
}
- EXPECT_EQ(g[0], h);
- EXPECT_EQ(g[1], h);
+ EXPECT_EQ(g[0], h);
+ EXPECT_EQ(g[1], h);
}
}
- TEST(FuncTools, CartesianProduct3) {
+ TEST(FuncTools, CartesianProduct3) {
TVector<std::tuple<TVector<i32>, TVector<i32>, TVector<i32>>> ts = {
{{1, 2, 3}, {4, 5, 6}, {11, 3}},
{{1, 2, 3}, {4, 5, 6, 7}, {9}},
@@ -419,11 +419,11 @@ using namespace NFuncTools;
f.push_back({ai, bi, ci});
}
- EXPECT_EQ(e, f);
+ EXPECT_EQ(e, f);
}
}
- TEST(FuncTools, CompileCartesianProduct) {
+ TEST(FuncTools, CompileCartesianProduct) {
auto container = std::vector{1, 2, 3};
TestViewCompileability(CartesianProduct(container, container));
const auto constContainer = std::vector{1, 2, 3};
@@ -435,14 +435,14 @@ using namespace NFuncTools;
FOR_DISPATCH_2(a, b, CartesianProduct(MakeMinimalisticContainer(), MakeMinimalisticContainer())) {
res.push_back({a, b});
}
- EXPECT_EQ(res, (std::vector<std::pair<int, int>>{
+ EXPECT_EQ(res, (std::vector<std::pair<int, int>>{
{0, 0}, {0, 1}, {0, 2},
{1, 0}, {1, 1}, {1, 2},
{2, 0}, {2, 1}, {2, 2},
}));
}
- TEST(FuncTools, Concatenate2) {
+ TEST(FuncTools, Concatenate2) {
TVector<std::pair<TVector<i32>, TVector<i32>>> ts = {
{{1, 2, 3}, {4, 5, 6}},
{{1, 2, 3}, {4, 5, 6, 7}},
@@ -465,7 +465,7 @@ using namespace NFuncTools;
d.push_back(x);
}
- EXPECT_EQ(c, d);
+ EXPECT_EQ(c, d);
}
{
@@ -474,11 +474,11 @@ using namespace NFuncTools;
for (auto x : Concatenate(a, TVector<i32>{5, 6})) {
c.push_back(x);
}
- EXPECT_EQ(c, (TVector<i32>{1, 2, 3, 4, 5, 6}));
+ EXPECT_EQ(c, (TVector<i32>{1, 2, 3, 4, 5, 6}));
}
}
- TEST(FuncTools, CompileConcatenate) {
+ TEST(FuncTools, CompileConcatenate) {
auto container = std::vector{1, 2, 3};
TestViewCompileability(Concatenate(container, container));
const auto constContainer = std::vector{1, 2, 3};
@@ -490,42 +490,42 @@ using namespace NFuncTools;
for (auto a : Concatenate(MakeMinimalisticContainer(), MakeMinimalisticContainer())) {
res.push_back(a);
}
- EXPECT_EQ(res, (std::vector{0, 1, 2, 0, 1, 2}));
+ EXPECT_EQ(res, (std::vector{0, 1, 2, 0, 1, 2}));
}
- TEST(FuncTools, Combo) {
- FOR_DISPATCH_2(i, j, Enumerate(xrange(10u))) {
- EXPECT_EQ(i, j);
+ TEST(FuncTools, Combo) {
+ FOR_DISPATCH_2(i, j, Enumerate(xrange(10u))) {
+ EXPECT_EQ(i, j);
}
- FOR_DISPATCH_2(i, jk, Enumerate(Enumerate(xrange(10u)))) {
- EXPECT_EQ(i, std::get<0>(jk));
- EXPECT_EQ(std::get<0>(jk), std::get<1>(jk));
+ FOR_DISPATCH_2(i, jk, Enumerate(Enumerate(xrange(10u)))) {
+ EXPECT_EQ(i, std::get<0>(jk));
+ EXPECT_EQ(std::get<0>(jk), std::get<1>(jk));
}
- TVector<size_t> a = {0, 1, 2};
+ TVector<size_t> a = {0, 1, 2};
FOR_DISPATCH_2(i, j, Enumerate(Reversed(a))) {
- EXPECT_EQ(i, 2 - j);
+ EXPECT_EQ(i, 2 - j);
}
FOR_DISPATCH_2(i, j, Enumerate(Map<float>(a))) {
- EXPECT_EQ(i, (size_t)j);
+ EXPECT_EQ(i, (size_t)j);
}
FOR_DISPATCH_2(i, j, Zip(a, Map<float>(a))) {
- EXPECT_EQ(i, (size_t)j);
+ EXPECT_EQ(i, (size_t)j);
}
auto mapper = [](auto&& x) {
return std::get<0>(x) + std::get<1>(x);
};
FOR_DISPATCH_2(i, j, Zip(a, Map(mapper, Zip(a, a)))) {
- EXPECT_EQ(j, 2 * i);
+ EXPECT_EQ(j, 2 * i);
}
}
- TEST(FuncTools, CopyIterator) {
+ TEST(FuncTools, CopyIterator) {
TVector a = {1, 2, 3, 4};
TVector b = {4, 5, 6, 7};
@@ -544,12 +544,12 @@ using namespace NFuncTools;
auto iterable = Enumerate(a);
testIterator(std::begin(iterable),
[](auto p2, auto p3, auto p4) {
- EXPECT_EQ(std::get<0>(p2), 1u);
- EXPECT_EQ(std::get<1>(p2), 2);
- EXPECT_EQ(std::get<0>(p3), 2u);
- EXPECT_EQ(std::get<1>(p3), 3);
- EXPECT_EQ(std::get<0>(p4), 3u);
- EXPECT_EQ(std::get<1>(p4), 4);
+ EXPECT_EQ(std::get<0>(p2), 1u);
+ EXPECT_EQ(std::get<1>(p2), 2);
+ EXPECT_EQ(std::get<0>(p3), 2u);
+ EXPECT_EQ(std::get<1>(p3), 3);
+ EXPECT_EQ(std::get<0>(p4), 3u);
+ EXPECT_EQ(std::get<1>(p4), 4);
});
}
@@ -557,9 +557,9 @@ using namespace NFuncTools;
auto iterable = Map([](i32 x) { return x*x; }, a);
testIterator(std::begin(iterable),
[](auto p2, auto p3, auto p4) {
- EXPECT_EQ(p2, 4);
- EXPECT_EQ(p3, 9);
- EXPECT_EQ(p4, 16);
+ EXPECT_EQ(p2, 4);
+ EXPECT_EQ(p3, 9);
+ EXPECT_EQ(p4, 16);
});
}
@@ -567,12 +567,12 @@ using namespace NFuncTools;
auto iterable = Zip(a, b);
testIterator(std::begin(iterable),
[](auto p2, auto p3, auto p4) {
- EXPECT_EQ(std::get<0>(p2), 2);
- EXPECT_EQ(std::get<1>(p2), 5);
- EXPECT_EQ(std::get<0>(p3), 3);
- EXPECT_EQ(std::get<1>(p3), 6);
- EXPECT_EQ(std::get<0>(p4), 4);
- EXPECT_EQ(std::get<1>(p4), 7);
+ EXPECT_EQ(std::get<0>(p2), 2);
+ EXPECT_EQ(std::get<1>(p2), 5);
+ EXPECT_EQ(std::get<0>(p3), 3);
+ EXPECT_EQ(std::get<1>(p3), 6);
+ EXPECT_EQ(std::get<0>(p4), 4);
+ EXPECT_EQ(std::get<1>(p4), 7);
});
}
@@ -581,9 +581,9 @@ using namespace NFuncTools;
auto iterable = Filter([](i32 x) { return !(x & 1); }, c);
testIterator(std::begin(iterable),
[](auto p2, auto p3, auto p4) {
- EXPECT_EQ(p2, 4);
- EXPECT_EQ(p3, 6);
- EXPECT_EQ(p4, 8);
+ EXPECT_EQ(p2, 4);
+ EXPECT_EQ(p3, 6);
+ EXPECT_EQ(p4, 8);
});
}
@@ -592,12 +592,12 @@ using namespace NFuncTools;
// (0, 2), (0, 3), (1, 2), (1, 3)
testIterator(std::begin(iterable),
[](auto p2, auto p3, auto p4) {
- EXPECT_EQ(std::get<0>(p2), 0);
- EXPECT_EQ(std::get<1>(p2), 3);
- EXPECT_EQ(std::get<0>(p3), 1);
- EXPECT_EQ(std::get<1>(p3), 2);
- EXPECT_EQ(std::get<0>(p4), 1);
- EXPECT_EQ(std::get<1>(p4), 3);
+ EXPECT_EQ(std::get<0>(p2), 0);
+ EXPECT_EQ(std::get<1>(p2), 3);
+ EXPECT_EQ(std::get<0>(p3), 1);
+ EXPECT_EQ(std::get<1>(p3), 2);
+ EXPECT_EQ(std::get<0>(p4), 1);
+ EXPECT_EQ(std::get<1>(p4), 3);
});
}
}
diff --git a/library/cpp/iterator/ut/iterate_keys_ut.cpp b/library/cpp/iterator/ut/iterate_keys_ut.cpp
index b5058c379d..49eb866b6e 100644
--- a/library/cpp/iterator/ut/iterate_keys_ut.cpp
+++ b/library/cpp/iterator/ut/iterate_keys_ut.cpp
@@ -1,37 +1,37 @@
-#include <library/cpp/iterator/iterate_keys.h>
-
-#include <library/cpp/testing/gtest/gtest.h>
-
-#include <map>
-
-using namespace testing;
-
-TEST(IterateKeys, ConstMappingIteration) {
- const std::map<int, int> squares{
- {1, 1},
- {2, 4},
- {3, 9},
- };
- EXPECT_THAT(
- IterateKeys(squares),
- ElementsAre(1, 2, 3)
- );
-}
-
-TEST(IterateKeys, ConstMultiMappingIteration) {
- const std::multimap<int, int> primesBelow{
- {2, 2},
- {5, 3},
- {5, 5},
- {11, 7},
- {11, 11},
- {23, 13},
- {23, 17},
- {23, 23},
- };
-
- EXPECT_THAT(
- IterateKeys(primesBelow),
- ElementsAre(2, 5, 5, 11, 11, 23, 23, 23)
- );
-}
+#include <library/cpp/iterator/iterate_keys.h>
+
+#include <library/cpp/testing/gtest/gtest.h>
+
+#include <map>
+
+using namespace testing;
+
+TEST(IterateKeys, ConstMappingIteration) {
+ const std::map<int, int> squares{
+ {1, 1},
+ {2, 4},
+ {3, 9},
+ };
+ EXPECT_THAT(
+ IterateKeys(squares),
+ ElementsAre(1, 2, 3)
+ );
+}
+
+TEST(IterateKeys, ConstMultiMappingIteration) {
+ const std::multimap<int, int> primesBelow{
+ {2, 2},
+ {5, 3},
+ {5, 5},
+ {11, 7},
+ {11, 11},
+ {23, 13},
+ {23, 17},
+ {23, 23},
+ };
+
+ EXPECT_THAT(
+ IterateKeys(primesBelow),
+ ElementsAre(2, 5, 5, 11, 11, 23, 23, 23)
+ );
+}
diff --git a/library/cpp/iterator/ut/iterate_values_ut.cpp b/library/cpp/iterator/ut/iterate_values_ut.cpp
index b8940bded7..ed099e560d 100644
--- a/library/cpp/iterator/ut/iterate_values_ut.cpp
+++ b/library/cpp/iterator/ut/iterate_values_ut.cpp
@@ -1,106 +1,106 @@
-#include <library/cpp/iterator/iterate_values.h>
-
-#include <library/cpp/testing/gtest/gtest.h>
-
-#include <util/generic/algorithm.h>
-
-#include <map>
-#include <unordered_map>
-
-using namespace testing;
-
-TEST(IterateValues, ConstMappingIteration) {
- const std::map<int, int> squares{
- {1, 1},
- {2, 4},
- {3, 9},
- };
- EXPECT_THAT(
- IterateValues(squares),
- ElementsAre(1, 4, 9)
- );
-
- const std::unordered_map<int, int> roots{
- {49, 7},
- {36, 6},
- {25, 5},
- };
- EXPECT_THAT(
- IterateValues(roots),
- UnorderedElementsAre(5, 6, 7)
- );
-
- const std::map<int, std::string> translations{
- {1, "one"},
- {2, "two"},
- {3, "three"},
- };
- EXPECT_EQ(
- Accumulate(IterateValues(translations), std::string{}),
- "onetwothree"
- );
-}
-
-TEST(IterateValues, NonConstMappingIteration) {
- std::map<int, int> squares{
- {1, 1},
- {2, 4},
- {3, 9},
- };
- for (auto& value: IterateValues(squares)) {
- value *= value;
- }
- EXPECT_THAT(
- IterateValues(squares),
- ElementsAre(1, 16, 81)
- );
-}
-
-TEST(IterateValues, ConstMultiMappingIteration) {
- const std::multimap<int, int> primesBelow{
- {2, 2},
- {5, 3},
- {5, 5},
- {11, 7},
- {11, 11},
- {23, 13},
- {23, 17},
- {23, 23},
- };
-
- EXPECT_THAT(
- IterateValues(primesBelow),
- ElementsAre(2, 3, 5, 7, 11, 13, 17, 23)
- );
- auto [begin, end] = primesBelow.equal_range(11);
- EXPECT_EQ(std::distance(begin, end), 2);
- EXPECT_THAT(
- IterateValues(std::vector(begin, end)),
- ElementsAre(7, 11)
- );
-}
-
-TEST(IterateValues, ConstUnorderedMultiMappingIteration) {
- const std::unordered_multimap<int, int> primesBelow{
- {2, 2},
- {5, 3},
- {5, 5},
- {11, 7},
- {11, 11},
- {23, 13},
- {23, 17},
- {23, 23},
- };
-
- EXPECT_THAT(
- IterateValues(primesBelow),
- UnorderedElementsAre(2, 3, 5, 7, 11, 13, 17, 23)
- );
-
- auto [begin, end] = primesBelow.equal_range(11);
- EXPECT_EQ(std::distance(begin, end), 2);
- EXPECT_THAT(
- IterateValues(std::vector(begin, end)),
- UnorderedElementsAre(7, 11)
- );
-}
+#include <library/cpp/iterator/iterate_values.h>
+
+#include <library/cpp/testing/gtest/gtest.h>
+
+#include <util/generic/algorithm.h>
+
+#include <map>
+#include <unordered_map>
+
+using namespace testing;
+
+TEST(IterateValues, ConstMappingIteration) {
+ const std::map<int, int> squares{
+ {1, 1},
+ {2, 4},
+ {3, 9},
+ };
+ EXPECT_THAT(
+ IterateValues(squares),
+ ElementsAre(1, 4, 9)
+ );
+
+ const std::unordered_map<int, int> roots{
+ {49, 7},
+ {36, 6},
+ {25, 5},
+ };
+ EXPECT_THAT(
+ IterateValues(roots),
+ UnorderedElementsAre(5, 6, 7)
+ );
+
+ const std::map<int, std::string> translations{
+ {1, "one"},
+ {2, "two"},
+ {3, "three"},
+ };
+ EXPECT_EQ(
+ Accumulate(IterateValues(translations), std::string{}),
+ "onetwothree"
+ );
+}
+
+TEST(IterateValues, NonConstMappingIteration) {
+ std::map<int, int> squares{
+ {1, 1},
+ {2, 4},
+ {3, 9},
+ };
+ for (auto& value: IterateValues(squares)) {
+ value *= value;
+ }
+ EXPECT_THAT(
+ IterateValues(squares),
+ ElementsAre(1, 16, 81)
+ );
+}
+
+TEST(IterateValues, ConstMultiMappingIteration) {
+ const std::multimap<int, int> primesBelow{
+ {2, 2},
+ {5, 3},
+ {5, 5},
+ {11, 7},
+ {11, 11},
+ {23, 13},
+ {23, 17},
+ {23, 23},
+ };
+
+ EXPECT_THAT(
+ IterateValues(primesBelow),
+ ElementsAre(2, 3, 5, 7, 11, 13, 17, 23)
+ );
+ auto [begin, end] = primesBelow.equal_range(11);
+ EXPECT_EQ(std::distance(begin, end), 2);
+ EXPECT_THAT(
+ IterateValues(std::vector(begin, end)),
+ ElementsAre(7, 11)
+ );
+}
+
+TEST(IterateValues, ConstUnorderedMultiMappingIteration) {
+ const std::unordered_multimap<int, int> primesBelow{
+ {2, 2},
+ {5, 3},
+ {5, 5},
+ {11, 7},
+ {11, 11},
+ {23, 13},
+ {23, 17},
+ {23, 23},
+ };
+
+ EXPECT_THAT(
+ IterateValues(primesBelow),
+ UnorderedElementsAre(2, 3, 5, 7, 11, 13, 17, 23)
+ );
+
+ auto [begin, end] = primesBelow.equal_range(11);
+ EXPECT_EQ(std::distance(begin, end), 2);
+ EXPECT_THAT(
+ IterateValues(std::vector(begin, end)),
+ UnorderedElementsAre(7, 11)
+ );
+}
diff --git a/library/cpp/iterator/ut/mapped_ut.cpp b/library/cpp/iterator/ut/mapped_ut.cpp
index 77b5d7c2f6..440cd37945 100644
--- a/library/cpp/iterator/ut/mapped_ut.cpp
+++ b/library/cpp/iterator/ut/mapped_ut.cpp
@@ -1,61 +1,61 @@
-#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) {
- TVector<int> x = {1, 2, 3, 4, 5};
- auto it = MakeMappedIterator(x.begin(), [](int x) { return x + 7; });
-
- EXPECT_EQ(*it, 8);
- EXPECT_EQ(it[2], 10);
-}
-
-TEST(TIterator, TMappedRangeTest) {
- TVector<int> x = {1, 2, 3, 4, 5};
-
- EXPECT_THAT(
- MakeMappedRange(
- x,
- [](int x) { return x + 3; }
- ),
- ElementsAre(4, 5, 6, 7, 8)
- );
-}
-
-//TODO: replace with dedicated IterateKeys / IterateValues methods
-TEST(TIterator, TMutableMappedRangeTest) {
- TMap<int, int> points = {{1, 2}, {3, 4}};
-
- EXPECT_THAT(
- MakeMappedRange(
- points.begin(), points.end(),
- [](TMap<int, int>::value_type& kv) -> int& { return kv.second; }
- ),
- ElementsAre(2, 4)
- );
-}
-
-TEST(TIterator, TOwningMappedMethodTest) {
- auto range = MakeMappedRange(
- TVector<std::pair<int, int>>{std::make_pair(1, 2), std::make_pair(3, 4)},
- [](auto& point) -> int& {
- return point.first;
+#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) {
+ TVector<int> x = {1, 2, 3, 4, 5};
+ auto it = MakeMappedIterator(x.begin(), [](int x) { return x + 7; });
+
+ EXPECT_EQ(*it, 8);
+ EXPECT_EQ(it[2], 10);
+}
+
+TEST(TIterator, TMappedRangeTest) {
+ TVector<int> x = {1, 2, 3, 4, 5};
+
+ EXPECT_THAT(
+ MakeMappedRange(
+ x,
+ [](int x) { return x + 3; }
+ ),
+ ElementsAre(4, 5, 6, 7, 8)
+ );
+}
+
+//TODO: replace with dedicated IterateKeys / IterateValues methods
+TEST(TIterator, TMutableMappedRangeTest) {
+ TMap<int, int> points = {{1, 2}, {3, 4}};
+
+ EXPECT_THAT(
+ MakeMappedRange(
+ points.begin(), points.end(),
+ [](TMap<int, int>::value_type& kv) -> int& { return kv.second; }
+ ),
+ ElementsAre(2, 4)
+ );
+}
+
+TEST(TIterator, TOwningMappedMethodTest) {
+ auto range = MakeMappedRange(
+ 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;
- EXPECT_EQ(range[0], 2);
- (*range.begin()) += 1;
- EXPECT_EQ(range[0], 3);
- for (int& y : range) {
- y += 7;
+ );
+ EXPECT_EQ(range[0], 1);
+ range[0] += 1;
+ EXPECT_EQ(range[0], 2);
+ (*range.begin()) += 1;
+ EXPECT_EQ(range[0], 3);
+ for (int& y : range) {
+ y += 7;
}
- EXPECT_EQ(*range.begin(), 10);
- EXPECT_EQ(*(range.begin() + 1), 10);
+ 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 ed9b08aa7e..601e5663b9 100644
--- a/library/cpp/iterator/ut/ya.make
+++ b/library/cpp/iterator/ut/ya.make
@@ -1,17 +1,17 @@
-GTEST()
+GTEST()
+
+PEERDIR(
+ library/cpp/iterator
+)
-PEERDIR(
- library/cpp/iterator
-)
-
OWNER(g:util)
SRCS(
filtering_ut.cpp
functools_ut.cpp
- iterate_keys_ut.cpp
- iterate_values_ut.cpp
- mapped_ut.cpp
+ iterate_keys_ut.cpp
+ iterate_values_ut.cpp
+ mapped_ut.cpp
zip_ut.cpp
)
diff --git a/library/cpp/iterator/ya.make b/library/cpp/iterator/ya.make
index c8723354b1..1ba1ffb411 100644
--- a/library/cpp/iterator/ya.make
+++ b/library/cpp/iterator/ya.make
@@ -6,8 +6,8 @@ SRCS(
cartesian_product.cpp
concatenate.cpp
enumerate.cpp
- iterate_keys.cpp
- iterate_values.cpp
+ iterate_keys.cpp
+ iterate_values.cpp
filtering.cpp
functools.cpp
mapped.cpp
diff --git a/library/cpp/iterator/zip.h b/library/cpp/iterator/zip.h
index 5ba1c6cb0b..ac12ed35fe 100644
--- a/library/cpp/iterator/zip.h
+++ b/library/cpp/iterator/zip.h
@@ -49,7 +49,7 @@ namespace NPrivate {
using value_type = TValue;
using pointer = TValue*;
using reference = TValue&;
- using const_reference = const TValue&;
+ using const_reference = const TValue&;
using iterator_category = std::input_iterator_tag;
TValue operator*() {
@@ -85,9 +85,9 @@ namespace NPrivate {
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::const_reference;
+ using value_type = typename TIterator::value_type;
+ using reference = typename TIterator::reference;
+ using const_reference = typename TIterator::const_reference;
TIterator begin() const {
return {TIteratorState{std::begin(*std::get<I>(Holders_).Ptr())...}};