diff options
author | richard <richard@yandex-team.ru> | 2022-02-10 16:52:06 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:52:06 +0300 |
commit | dd0a071a4202feb26c92240b37ecb9b884ca3849 (patch) | |
tree | ab7fbbf3253d4c0e2793218f09378908beb025fb /util | |
parent | 3d614c8de544db53c298060cd32d4119154be35a (diff) | |
download | ydb-dd0a071a4202feb26c92240b37ecb9b884ca3849.tar.gz |
Restoring authorship annotation for <richard@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util')
-rw-r--r-- | util/generic/algorithm.h | 22 | ||||
-rw-r--r-- | util/generic/algorithm_ut.cpp | 64 | ||||
-rw-r--r-- | util/generic/ptr.h | 2 |
3 files changed, 44 insertions, 44 deletions
diff --git a/util/generic/algorithm.h b/util/generic/algorithm.h index 34b58dba1c..badfb88993 100644 --- a/util/generic/algorithm.h +++ b/util/generic/algorithm.h @@ -126,20 +126,20 @@ static inline auto Find(C&& c, const T& v) { return std::find(begin(c), end(c), v); } -// FindPtr - return NULL if not found. Works for arrays, containers, iterators -template <class I, class T> -static inline auto FindPtr(I f, I l, const T& v) -> decltype(&*f) { - I found = Find(f, l, v); - return (found != l) ? &*found : nullptr; -} - -template <class C, class T> -static inline auto FindPtr(C&& c, const T& v) { +// FindPtr - return NULL if not found. Works for arrays, containers, iterators +template <class I, class T> +static inline auto FindPtr(I f, I l, const T& v) -> decltype(&*f) { + I found = Find(f, l, v); + return (found != l) ? &*found : nullptr; +} + +template <class C, class T> +static inline auto FindPtr(C&& c, const T& v) { using std::begin; using std::end; return FindPtr(begin(c), end(c), v); -} - +} + template <class I, class P> static inline I FindIf(I f, I l, P p) { return std::find_if(f, l, p); diff --git a/util/generic/algorithm_ut.cpp b/util/generic/algorithm_ut.cpp index a69f2657e7..8d732fcc0c 100644 --- a/util/generic/algorithm_ut.cpp +++ b/util/generic/algorithm_ut.cpp @@ -128,17 +128,17 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } template <class TTestConstPtr> - void TestFindPtrFoundValue(int j, TTestConstPtr root) { - if (j == 3) { - UNIT_ASSERT(root && *root == 3); - } else if (j == 4) { - UNIT_ASSERT(root == nullptr); - } else { - ythrow yexception() << "invalid param " << j; - } - } - - template <class TTestConstPtr> + void TestFindPtrFoundValue(int j, TTestConstPtr root) { + if (j == 3) { + UNIT_ASSERT(root && *root == 3); + } else if (j == 4) { + UNIT_ASSERT(root == nullptr); + } else { + ythrow yexception() << "invalid param " << j; + } + } + + template <class TTestConstPtr> void TestFindIfPtrFoundValue(int j, TTestConstPtr root) { if (j == 3) { UNIT_ASSERT(root == nullptr); @@ -158,7 +158,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { void operator=(const TVectorNoCopy&); }; - Y_UNIT_TEST(FindPtrTest) { + Y_UNIT_TEST(FindPtrTest) { TVectorNoCopy v; v.push_back(1); v.push_back(2); @@ -168,28 +168,28 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { const int array_const[3] = {1, 2, 3}; //test (const, non-const) * (iterator, vector, array) * (found, not found) variants. - // value '3' is in container, value '4' is not - for (int j = 3; j <= 4; ++j) { - TestFindPtrFoundValue<int*>(j, FindPtr(v, j)); - TestFindPtrFoundValue<int*>(j, FindPtr(v.begin(), v.end(), j)); - const TVectorNoCopy& q = v; - TestFindPtrFoundValue<const int*>(j, FindPtr(q, j)); - TestFindPtrFoundValue<const int*>(j, FindPtr(q.begin(), q.end(), j)); - TestFindPtrFoundValue<int*>(j, FindPtr(array, j)); - TestFindPtrFoundValue<const int*>(j, FindPtr(array_const, j)); - } - } - - Y_UNIT_TEST(FindIfPtrTest) { - TVectorNoCopy v; - v.push_back(1); - v.push_back(2); - v.push_back(3); - + // value '3' is in container, value '4' is not + for (int j = 3; j <= 4; ++j) { + TestFindPtrFoundValue<int*>(j, FindPtr(v, j)); + TestFindPtrFoundValue<int*>(j, FindPtr(v.begin(), v.end(), j)); + const TVectorNoCopy& q = v; + TestFindPtrFoundValue<const int*>(j, FindPtr(q, j)); + TestFindPtrFoundValue<const int*>(j, FindPtr(q.begin(), q.end(), j)); + TestFindPtrFoundValue<int*>(j, FindPtr(array, j)); + TestFindPtrFoundValue<const int*>(j, FindPtr(array_const, j)); + } + } + + Y_UNIT_TEST(FindIfPtrTest) { + TVectorNoCopy v; + v.push_back(1); + v.push_back(2); + v.push_back(3); + int array[3] = {1, 2, 3}; const int array_const[3] = {1, 2, 3}; - - //test (const, non-const) * (iterator, vector, array) * (found, not found) variants. + + //test (const, non-const) * (iterator, vector, array) * (found, not found) variants. // search, that 2*2 == 4, but there is no value 'x' in array that (x*x == 3) for (int j = 3; j <= 4; ++j) { TestFindIfPtrFoundValue<int*>(j, FindIfPtr(v, [j](int i) { return i * i == j; })); diff --git a/util/generic/ptr.h b/util/generic/ptr.h index 8c6c5f3ac0..19db0e3ec5 100644 --- a/util/generic/ptr.h +++ b/util/generic/ptr.h @@ -817,7 +817,7 @@ public: } template <class TT, class = TGuardConversion<T, TT>> - inline TSharedPtr(THolder<TT>&& t) { + inline TSharedPtr(THolder<TT>&& t) { Init(t); } |