diff options
author | Vlad Yaroslavlev <vladon@vladon.com> | 2022-02-10 16:46:23 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:23 +0300 |
commit | 706b83ed7de5a473436620367af31fc0ceecde07 (patch) | |
tree | 103305d30dec77e8f6367753367f59b3cd68f9f1 /util/generic | |
parent | 918e8a1574070d0ec733f0b76cfad8f8892ad2e5 (diff) | |
download | ydb-706b83ed7de5a473436620367af31fc0ceecde07.tar.gz |
Restoring authorship annotation for Vlad Yaroslavlev <vladon@vladon.com>. Commit 1 of 2.
Diffstat (limited to 'util/generic')
91 files changed, 2142 insertions, 2142 deletions
diff --git a/util/generic/adaptor_ut.cpp b/util/generic/adaptor_ut.cpp index 721f849f93..3ce6437add 100644 --- a/util/generic/adaptor_ut.cpp +++ b/util/generic/adaptor_ut.cpp @@ -34,8 +34,8 @@ struct TState { Y_UNIT_TEST_SUITE(TReverseAdaptor) { Y_UNIT_TEST(ReadTest) { - TVector<int> cont = {1, 2, 3}; - TVector<int> etalon = {3, 2, 1}; + 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); @@ -47,8 +47,8 @@ Y_UNIT_TEST_SUITE(TReverseAdaptor) { } Y_UNIT_TEST(WriteTest) { - TVector<int> cont = {1, 2, 3}; - TVector<int> etalon = {3, 6, 9}; + TVector<int> cont = {1, 2, 3}; + TVector<int> etalon = {3, 6, 9}; size_t idx = 0; for (auto& x : Reversed(cont)) { x *= x + idx++; @@ -60,7 +60,7 @@ Y_UNIT_TEST_SUITE(TReverseAdaptor) { } Y_UNIT_TEST(InnerTypeTest) { - using TStub = TVector<int>; + using TStub = TVector<int>; TStub stub; const TStub cstub; diff --git a/util/generic/algorithm.h b/util/generic/algorithm.h index badfb88993..12fd914c15 100644 --- a/util/generic/algorithm.h +++ b/util/generic/algorithm.h @@ -487,13 +487,13 @@ static inline Val InnerProduct(It1 begin1, It1 end1, It2 begin2, Val val, BinOp1 return std::inner_product(begin1, end1, begin2, val, binOp1, binOp2); } -template <typename TVectorType> -static inline typename TVectorType::value_type InnerProduct(const TVectorType& lhs, const TVectorType& rhs, typename TVectorType::value_type val = typename TVectorType::value_type()) { +template <typename TVectorType> +static inline typename TVectorType::value_type InnerProduct(const TVectorType& lhs, const TVectorType& rhs, typename TVectorType::value_type val = typename TVectorType::value_type()) { return std::inner_product(lhs.begin(), lhs.end(), rhs.begin(), val); } -template <typename TVectorType, typename BinOp1, typename BinOp2> -static inline typename TVectorType::value_type InnerProduct(const TVectorType& lhs, const TVectorType& rhs, typename TVectorType::value_type val, BinOp1 binOp1, BinOp2 binOp2) { +template <typename TVectorType, typename BinOp1, typename BinOp2> +static inline typename TVectorType::value_type InnerProduct(const TVectorType& lhs, const TVectorType& rhs, typename TVectorType::value_type val, BinOp1 binOp1, BinOp2 binOp2) { return std::inner_product(lhs.begin(), lhs.end(), rhs.begin(), val, binOp1, binOp2); } diff --git a/util/generic/algorithm_ut.cpp b/util/generic/algorithm_ut.cpp index 8d732fcc0c..45f35b7ca7 100644 --- a/util/generic/algorithm_ut.cpp +++ b/util/generic/algorithm_ut.cpp @@ -2,7 +2,7 @@ #include "algorithm.h" #include "strbuf.h" -#include "string.h" +#include "string.h" static auto isOne = [](char c) { return c == '1'; }; @@ -59,7 +59,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { struct TStrokaNoCopy: TString { public: TStrokaNoCopy(const char* p) - : TString(p) + : TString(p) { } @@ -80,11 +80,11 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT_VALUES_EQUAL(CountOf(0x61, 'a', 'b', 'c', 0x61), 2); UNIT_ASSERT_VALUES_EQUAL(CountOf(0x61, 'a', 'b', 'c', 0x61ll), 2); - // TString and const char * - UNIT_ASSERT_VALUES_EQUAL(CountOf(TString("xyz"), "123", "poi"), 0); - UNIT_ASSERT_VALUES_EQUAL(CountOf(TString("xyz"), "123", "poi", "xyz"), 1); + // TString and const char * + UNIT_ASSERT_VALUES_EQUAL(CountOf(TString("xyz"), "123", "poi"), 0); + UNIT_ASSERT_VALUES_EQUAL(CountOf(TString("xyz"), "123", "poi", "xyz"), 1); - // TString and TStringBuf + // TString and TStringBuf UNIT_ASSERT_VALUES_EQUAL(CountOf(TString("xyz"), TStringBuf("123"), TStringBuf("poi")), 0); UNIT_ASSERT_VALUES_EQUAL(CountOf(TString("xyz"), TStringBuf("123"), TStringBuf("poi"), TStringBuf("xyz")), @@ -94,10 +94,10 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT_VALUES_EQUAL(CountOf(TStringBuf("xyz"), "123", "poi"), 0); UNIT_ASSERT_VALUES_EQUAL(CountOf(TStringBuf("xyz"), "123", "poi", "xyz"), 1); - // TStringBuf and TString + // TStringBuf and TString UNIT_ASSERT_VALUES_EQUAL(CountOf(TStringBuf("xyz"), TString("123"), TString("poi")), 0); UNIT_ASSERT_VALUES_EQUAL(CountOf(TStringBuf("xyz"), TString("123"), TString("poi"), - TString("xyz")), + TString("xyz")), 1); } @@ -221,7 +221,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT_EQUAL(2, FindIndex(array, 3)); UNIT_ASSERT_EQUAL(NPOS, FindIndex(array, 42)); - TVector<int> empty; + TVector<int> empty; UNIT_ASSERT_EQUAL(NPOS, FindIndex(empty, 0)); } @@ -249,33 +249,33 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { Y_UNIT_TEST(SortUniqueTest) { { - TVector<TString> v; + TVector<TString> v; SortUnique(v); - UNIT_ASSERT_EQUAL(v, TVector<TString>()); + UNIT_ASSERT_EQUAL(v, TVector<TString>()); } { const char* ar[] = {"345", "3", "123", "2", "23", "3", "2"}; - TVector<TString> v(ar, ar + Y_ARRAY_SIZE(ar)); + TVector<TString> v(ar, ar + Y_ARRAY_SIZE(ar)); SortUnique(v); const char* suAr[] = {"123", "2", "23", "3", "345"}; - TVector<TString> suV(suAr, suAr + Y_ARRAY_SIZE(suAr)); + TVector<TString> suV(suAr, suAr + Y_ARRAY_SIZE(suAr)); UNIT_ASSERT_EQUAL(v, suV); } } Y_UNIT_TEST(EraseTest) { - TVector<int> data = {5, 4, 3, 2, 1, 0}; - TVector<int> expected = {5, 4, 2, 1, 0}; + TVector<int> data = {5, 4, 3, 2, 1, 0}; + TVector<int> expected = {5, 4, 2, 1, 0}; Erase(data, 3); UNIT_ASSERT_EQUAL(data, expected); } Y_UNIT_TEST(EraseIfTest) { - TVector<int> data = {5, 4, 3, 2, 1, 0}; - TVector<int> expected = {2, 1, 0}; + TVector<int> data = {5, 4, 3, 2, 1, 0}; + TVector<int> expected = {2, 1, 0}; EraseIf(data, [](int i) { return i >= 3; }); UNIT_ASSERT_EQUAL(data, expected); } @@ -314,14 +314,14 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { Y_UNIT_TEST(NthElementTest) { { - TVector<TString> v; + TVector<TString> v; NthElement(v.begin(), v.begin(), v.end()); - UNIT_ASSERT_EQUAL(v, TVector<TString>()); + UNIT_ASSERT_EQUAL(v, TVector<TString>()); } { int data[] = {3, 2, 1, 4, 6, 5, 7, 9, 8}; - TVector<int> testVector(data, data + Y_ARRAY_SIZE(data)); + TVector<int> testVector(data, data + Y_ARRAY_SIZE(data)); size_t medianInd = testVector.size() / 2; @@ -334,7 +334,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { { const char* data[] = {"3", "234", "1231", "333", "545345", "11", "111", "55", "66"}; - TVector<TString> testVector(data, data + Y_ARRAY_SIZE(data)); + TVector<TString> testVector(data, data + Y_ARRAY_SIZE(data)); size_t medianInd = testVector.size() / 2; NthElement(testVector.begin(), testVector.begin() + medianInd, testVector.end()); @@ -350,7 +350,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { Y_UNIT_TEST(BinarySearchTest) { { - TVector<TString> v; + TVector<TString> v; bool test = BinarySearch(v.begin(), v.end(), "test"); UNIT_ASSERT_EQUAL(test, false); } @@ -366,7 +366,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } { - TVector<size_t> data = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; + TVector<size_t> data = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; bool test = BinarySearch(data.begin(), data.end(), (size_t)9, TGreater<size_t>()); UNIT_ASSERT_EQUAL(test, true); @@ -381,8 +381,8 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { Y_UNIT_TEST(EqualRangeTest) { { - TVector<TString> v; - using PairOfVector = std::pair<TVector<TString>::iterator, TVector<TString>::iterator>; + TVector<TString> v; + using PairOfVector = std::pair<TVector<TString>::iterator, TVector<TString>::iterator>; PairOfVector tmp = EqualRange(v.begin(), v.end(), "tmp"); UNIT_ASSERT_EQUAL(tmp.first, tmp.second); @@ -400,15 +400,15 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } { - TVector<size_t> data = {9, 9, 8, 8, 8, 5, 4, 3, 3, 0, 0}; + TVector<size_t> data = {9, 9, 8, 8, 8, 5, 4, 3, 3, 0, 0}; - using PairOfVector = std::pair<TVector<size_t>::iterator, TVector<size_t>::iterator>; + using PairOfVector = std::pair<TVector<size_t>::iterator, TVector<size_t>::iterator>; PairOfVector tmp = EqualRange(data.begin(), data.end(), 8, TGreater<size_t>()); UNIT_ASSERT_EQUAL(tmp.first - data.begin(), 2); UNIT_ASSERT_EQUAL(tmp.second - tmp.first, 3); - using PairOfVectorReverse = std::pair<TVector<size_t>::reverse_iterator, TVector<size_t>::reverse_iterator>; + using PairOfVectorReverse = std::pair<TVector<size_t>::reverse_iterator, TVector<size_t>::reverse_iterator>; PairOfVectorReverse tmpR = EqualRange(data.rbegin(), data.rend(), (size_t)0); UNIT_ASSERT_EQUAL(tmpR.first, data.rbegin()); @@ -417,15 +417,15 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } Y_UNIT_TEST(IsSortedTest) { - TVector<int> v0; + TVector<int> v0; UNIT_ASSERT_VALUES_EQUAL(IsSorted(v0.begin(), v0.end()), true); - TVector<int> v1 = {1, 2, 3, 4, 5, 5, 5, 6, 6, 7, 8}; + TVector<int> v1 = {1, 2, 3, 4, 5, 5, 5, 6, 6, 7, 8}; UNIT_ASSERT_VALUES_EQUAL(IsSorted(v1.begin(), v1.end()), true); UNIT_ASSERT_VALUES_EQUAL(IsSorted(v1.begin(), v1.end(), TLess<int>()), true); UNIT_ASSERT_VALUES_EQUAL(IsSorted(v1.begin(), v1.end(), TGreater<int>()), false); - TVector<int> v2 = {1, 2, 1}; + TVector<int> v2 = {1, 2, 1}; UNIT_ASSERT_VALUES_EQUAL(IsSorted(v2.begin(), v2.end()), false); UNIT_ASSERT_VALUES_EQUAL(IsSorted(v2.begin(), v2.end(), TLess<int>()), false); UNIT_ASSERT_VALUES_EQUAL(IsSorted(v2.begin(), v2.end(), TGreater<int>()), false); @@ -502,35 +502,35 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } Y_UNIT_TEST(SortByTest) { - TVector<int> collection = {10, 2, 7}; + TVector<int> collection = {10, 2, 7}; SortBy(collection, [](int x) { return -x; }); - TVector<int> expected = {10, 7, 2}; + TVector<int> expected = {10, 7, 2}; UNIT_ASSERT_VALUES_EQUAL(collection, expected); } Y_UNIT_TEST(StableSortByTest) { - TVector<int> collection = {404, 101, 106, 203, 102, 205, 401}; + TVector<int> collection = {404, 101, 106, 203, 102, 205, 401}; StableSortBy(collection, [](int x) { return x / 100; }); - TVector<int> expected = {101, 106, 102, 203, 205, 404, 401}; + TVector<int> expected = {101, 106, 102, 203, 205, 404, 401}; UNIT_ASSERT_VALUES_EQUAL(collection, expected); } Y_UNIT_TEST(SortUniqueByTest) { - TVector<int> collection = {404, 101, 101, 203, 101, 203, 404}; + TVector<int> collection = {404, 101, 101, 203, 101, 203, 404}; StableSortUniqueBy(collection, [](int x) { return x / 100; }); - TVector<int> expected = {101, 203, 404}; + TVector<int> expected = {101, 203, 404}; UNIT_ASSERT_VALUES_EQUAL(collection, expected); } Y_UNIT_TEST(StableSortUniqueByTest) { - TVector<int> collection = {404, 101, 106, 203, 102, 205, 401}; + TVector<int> collection = {404, 101, 106, 203, 102, 205, 401}; StableSortUniqueBy(collection, [](int x) { return x / 100; }); - TVector<int> expected = {101, 203, 404}; + TVector<int> expected = {101, 203, 404}; UNIT_ASSERT_VALUES_EQUAL(collection, expected); } Y_UNIT_TEST(IotaTest) { - TVector<int> v(10); + TVector<int> v(10); Iota(v.begin(), v.end(), 0); UNIT_ASSERT_VALUES_EQUAL(v[0], 0); @@ -546,10 +546,10 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { Y_UNIT_TEST(CopyNTest) { int data[] = {1, 2, 3, 4, 8, 7, 6, 5}; const size_t vSize = 10; - TVector<int> result(10, 0); + TVector<int> result(10, 0); size_t toCopy = 5; - TVector<int>::iterator iter = CopyN(data, toCopy, result.begin()); + TVector<int>::iterator iter = CopyN(data, toCopy, result.begin()); UNIT_ASSERT_VALUES_EQUAL(iter - result.begin(), toCopy); UNIT_ASSERT_VALUES_EQUAL(result.size(), 10); for (size_t idx = 0; idx < toCopy; ++idx) { @@ -579,9 +579,9 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { const size_t count = 9; int data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; const size_t vSize = 10; - TVector<int> v(vSize, 0); + TVector<int> v(vSize, 0); - TVector<int>::iterator iter = CopyIf(data, data + count, v.begin(), [](int x) { return !(x % 3); }); + TVector<int>::iterator iter = CopyIf(data, data + count, v.begin(), [](int x) { return !(x % 3); }); UNIT_ASSERT_VALUES_EQUAL(v.size(), vSize); UNIT_ASSERT_VALUES_EQUAL(iter - v.begin(), 3); v.resize(iter - v.begin()); @@ -591,7 +591,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } Y_UNIT_TEST(MinMaxElementTest) { - TVector<int> v(10); + TVector<int> v(10); Iota(v.begin(), v.end(), 0); UNIT_ASSERT_EQUAL(*MinMaxElement(v.begin(), v.end()).first, 0); UNIT_ASSERT_EQUAL(*MinMaxElement(v.begin(), v.end()).second, 9); @@ -607,9 +607,9 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT_EQUAL(p1.first, 5); UNIT_ASSERT_EQUAL(p1.second, 12); - std::pair<TString, TString> p2 = MinMax(TString("test"), TString("data")); - UNIT_ASSERT_EQUAL(p2.first, TString("data")); - UNIT_ASSERT_EQUAL(p2.second, TString("test")); + std::pair<TString, TString> p2 = MinMax(TString("test"), TString("data")); + UNIT_ASSERT_EQUAL(p2.first, TString("data")); + UNIT_ASSERT_EQUAL(p2.second, TString("test")); } Y_UNIT_TEST(TestMaxElementBy) { @@ -618,7 +618,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { return x * x; }), 5); - const TVector<int> vec(array, array + Y_ARRAY_SIZE(array)); + const TVector<int> vec(array, array + Y_ARRAY_SIZE(array)); UNIT_ASSERT_VALUES_EQUAL(*MaxElementBy(vec, [](int x) { return -1.0 * x; }), 1); @@ -634,8 +634,8 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { auto singleElementSequence = {'z'}; UNIT_ASSERT_VALUES_EQUAL(*MaxElementBy(singleElementSequence, identity), 'z'); - const TString strings[] = {"one", "two", "three", "four"}; - UNIT_ASSERT_STRINGS_EQUAL(*MaxElementBy(strings, [](TString s) { return s.size(); }), "three"); + const TString strings[] = {"one", "two", "three", "four"}; + UNIT_ASSERT_STRINGS_EQUAL(*MaxElementBy(strings, [](TString s) { return s.size(); }), "three"); } Y_UNIT_TEST(TestMinElementBy) { @@ -644,7 +644,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { return 'a' + x; }), 1); - const TVector<int> vec(std::begin(array), std::end(array)); + const TVector<int> vec(std::begin(array), std::end(array)); UNIT_ASSERT_VALUES_EQUAL(*MinElementBy(vec, [](int x) { return -x; }), 5); @@ -660,7 +660,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { auto singleElementSequence = {'z'}; UNIT_ASSERT_VALUES_EQUAL(*MinElementBy(singleElementSequence, identity), 'z'); - const TVector<TStringBuf> strings = {"one", "two", "three", "four"}; + const TVector<TStringBuf> strings = {"one", "two", "three", "four"}; auto stringLength = [](TStringBuf s) { return s.size(); }; @@ -669,12 +669,12 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } Y_UNIT_TEST(MaxElementByReturnsEndForEmptyRange) { - const TVector<int> empty; + const TVector<int> empty; UNIT_ASSERT_EQUAL(MaxElementBy(empty, [](int) { return 0; }), empty.end()); } Y_UNIT_TEST(MaxElementByDoesntCallFunctorForEmptyRange) { - const TVector<int> empty; + const TVector<int> empty; auto functor = [](int) { UNIT_ASSERT(false); return 0; @@ -683,12 +683,12 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } Y_UNIT_TEST(MinElementByReturnsEndForEmptyRange) { - const TVector<int> empty; + const TVector<int> empty; UNIT_ASSERT_EQUAL(MinElementBy(empty, [](int) { return 0; }), empty.end()); } Y_UNIT_TEST(MinElementByDoesntCallFunctorForEmptyRange) { - const TVector<int> empty; + const TVector<int> empty; auto functor = [](int) { UNIT_ASSERT(false); return 0; @@ -764,7 +764,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT_EQUAL(FindIf(array, [](int x) { return x == 1; }), begin(array)); UNIT_ASSERT_EQUAL(FindIf(array, [](int x) { return x > 5; }), end(array)); - TVector<int> vector = {1, 2, 3, 4, 5}; + TVector<int> vector = {1, 2, 3, 4, 5}; UNIT_ASSERT_EQUAL(FindIf(vector, [](int x) { return x == 1; }), begin(vector)); UNIT_ASSERT_EQUAL(FindIf(vector, [](int x) { return x > 5; }), end(vector)); @@ -773,7 +773,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { *iter = 5; // Compilability test. Check if the returned iterator is const. Should not compile - const TVector<int> constVector = {1, 2, 3, 4, 5}; + const TVector<int> constVector = {1, 2, 3, 4, 5}; auto constIter = FindIf(constVector, [](int x) { return x == 1; }); Y_UNUSED(constIter); // *constIter = 5; @@ -798,7 +798,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } Y_UNIT_TEST(TestLowerBoundBy) { - using TIntPairs = TVector<std::pair<i32, i32>>; + using TIntPairs = TVector<std::pair<i32, i32>>; auto data = TIntPairs{{1, 5}, {3, 2}, {3, 4}, {8, 0}, {5, 4}}; auto getKey = [](const auto& x) { return x.second; }; @@ -818,7 +818,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } Y_UNIT_TEST(TestUpperBoundBy) { - using TIntPairs = TVector<std::pair<i32, i32>>; + using TIntPairs = TVector<std::pair<i32, i32>>; auto data = TIntPairs{{1, 5}, {3, 2}, {3, 4}, {8, 0}, {5, 4}}; auto getKey = [](const auto& x) { return x.second; }; diff --git a/util/generic/array_ref_ut.cpp b/util/generic/array_ref_ut.cpp index 4c8eaf7135..a8588f65ec 100644 --- a/util/generic/array_ref_ut.cpp +++ b/util/generic/array_ref_ut.cpp @@ -1,7 +1,7 @@ -#include "array_ref.h" - +#include "array_ref.h" + #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(TestArrayRef) { Y_UNIT_TEST(TestDefaultConstructor) { TArrayRef<int> defaulted; @@ -65,10 +65,10 @@ Y_UNIT_TEST_SUITE(TestArrayRef) { UNIT_ASSERT(iterator != r.end()); UNIT_ASSERT_VALUES_EQUAL(i, *iterator); ++iterator; - } + } UNIT_ASSERT(iterator == r.end()); } - + Y_UNIT_TEST(TestReverseIterators) { const int x[] = {1, 2, 3}; const TArrayRef<const int> rx{x}; @@ -80,8 +80,8 @@ Y_UNIT_TEST_SUITE(TestArrayRef) { UNIT_ASSERT_VALUES_EQUAL(*i, 1); ++i; UNIT_ASSERT_EQUAL(i, rx.crend()); - } - + } + Y_UNIT_TEST(TestConstIterators) { int x[] = {1, 2, 3}; TArrayRef<int> rx{x}; @@ -121,16 +121,16 @@ Y_UNIT_TEST_SUITE(TestArrayRef) { Y_UNIT_TEST(TestCreatingFromStringLiteral) { TConstArrayRef<char> knownSizeRef("123", 3); - size_t ret = 0; - + size_t ret = 0; + for (char ch : knownSizeRef) { - ret += ch - '0'; - } - - UNIT_ASSERT_VALUES_EQUAL(ret, 6); + ret += ch - '0'; + } + + UNIT_ASSERT_VALUES_EQUAL(ret, 6); UNIT_ASSERT_VALUES_EQUAL(knownSizeRef.size(), 3); UNIT_ASSERT_VALUES_EQUAL(knownSizeRef.at(0), '1'); - + /* * When TArrayRef is being constructed from string literal, * trailing zero will be added into it. @@ -138,7 +138,7 @@ Y_UNIT_TEST_SUITE(TestArrayRef) { TConstArrayRef<char> autoSizeRef("456"); UNIT_ASSERT_VALUES_EQUAL(autoSizeRef[0], '4'); UNIT_ASSERT_VALUES_EQUAL(autoSizeRef[3], '\0'); - } + } Y_UNIT_TEST(TestEqualityOperator) { static constexpr size_t size = 5; @@ -174,10 +174,10 @@ Y_UNIT_TEST_SUITE(TestArrayRef) { auto fc = [](TArrayRef<const int>) {}; auto fm = [](TArrayRef<int>) {}; - fc(TVector<int>({1})); + fc(TVector<int>({1})); - const TVector<int> ac = {1}; - TVector<int> am = {1}; + const TVector<int> ac = {1}; + TVector<int> am = {1}; fc(ac); fc(am); @@ -319,4 +319,4 @@ Y_UNIT_TEST_SUITE(TestArrayRef) { const TVector<int> constData; Foo(MakeConstArrayRef(constData)); } -} +} diff --git a/util/generic/benchmark/fastclp2/main.cpp b/util/generic/benchmark/fastclp2/main.cpp index 49277db077..bd01f97d23 100644 --- a/util/generic/benchmark/fastclp2/main.cpp +++ b/util/generic/benchmark/fastclp2/main.cpp @@ -19,7 +19,7 @@ namespace { } } - TVector<T> Examples; + TVector<T> Examples; }; } diff --git a/util/generic/benchmark/log2/main.cpp b/util/generic/benchmark/log2/main.cpp index 969f09a309..61dcafa319 100644 --- a/util/generic/benchmark/log2/main.cpp +++ b/util/generic/benchmark/log2/main.cpp @@ -11,7 +11,7 @@ namespace { template <typename T, size_t N> struct TExamplesHolder { - TVector<T> Examples; + TVector<T> Examples; TExamplesHolder() : Examples(N) diff --git a/util/generic/benchmark/rotate_bits/main.cpp b/util/generic/benchmark/rotate_bits/main.cpp index 057edbe864..31019f1508 100644 --- a/util/generic/benchmark/rotate_bits/main.cpp +++ b/util/generic/benchmark/rotate_bits/main.cpp @@ -25,7 +25,7 @@ namespace { } } - TVector<TExample<T>> Examples; + TVector<TExample<T>> Examples; }; } diff --git a/util/generic/benchmark/sort/main.cpp b/util/generic/benchmark/sort/main.cpp index d58f491f4d..fce7ef06ef 100644 --- a/util/generic/benchmark/sort/main.cpp +++ b/util/generic/benchmark/sort/main.cpp @@ -5,7 +5,7 @@ #include <util/generic/xrange.h> Y_CPU_BENCHMARK(Sort1, iface) { - TVector<int> x = {1}; + TVector<int> x = {1}; for (const auto i : xrange(iface.Iterations())) { Y_UNUSED(i); @@ -14,7 +14,7 @@ Y_CPU_BENCHMARK(Sort1, iface) { } Y_CPU_BENCHMARK(Sort2, iface) { - TVector<int> x = {2, 1}; + TVector<int> x = {2, 1}; for (const auto i : xrange(iface.Iterations())) { Y_UNUSED(i); @@ -23,7 +23,7 @@ Y_CPU_BENCHMARK(Sort2, iface) { } Y_CPU_BENCHMARK(Sort4, iface) { - TVector<int> x = {4, 3, 2, 1}; + TVector<int> x = {4, 3, 2, 1}; for (const auto i : xrange(iface.Iterations())) { Y_UNUSED(i); @@ -32,7 +32,7 @@ Y_CPU_BENCHMARK(Sort4, iface) { } Y_CPU_BENCHMARK(Sort16, iface) { - TVector<int> x = {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; + TVector<int> x = {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; for (const auto i : xrange(iface.Iterations())) { Y_UNUSED(i); @@ -41,7 +41,7 @@ Y_CPU_BENCHMARK(Sort16, iface) { } Y_CPU_BENCHMARK(StableSort1, iface) { - TVector<int> x = {1}; + TVector<int> x = {1}; for (const auto i : xrange(iface.Iterations())) { Y_UNUSED(i); @@ -50,7 +50,7 @@ Y_CPU_BENCHMARK(StableSort1, iface) { } Y_CPU_BENCHMARK(StableSort2, iface) { - TVector<int> x = {2, 1}; + TVector<int> x = {2, 1}; for (const auto i : xrange(iface.Iterations())) { Y_UNUSED(i); @@ -59,7 +59,7 @@ Y_CPU_BENCHMARK(StableSort2, iface) { } Y_CPU_BENCHMARK(StableSort4, iface) { - TVector<int> x = {4, 3, 2, 1}; + TVector<int> x = {4, 3, 2, 1}; for (const auto i : xrange(iface.Iterations())) { Y_UNUSED(i); @@ -68,7 +68,7 @@ Y_CPU_BENCHMARK(StableSort4, iface) { } Y_CPU_BENCHMARK(StableSort16, iface) { - TVector<int> x = {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; + TVector<int> x = {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; for (const auto i : xrange(iface.Iterations())) { Y_UNUSED(i); diff --git a/util/generic/benchmark/vector_count_ctor/f.cpp b/util/generic/benchmark/vector_count_ctor/f.cpp index b89e351ba7..f758faf808 100644 --- a/util/generic/benchmark/vector_count_ctor/f.cpp +++ b/util/generic/benchmark/vector_count_ctor/f.cpp @@ -8,7 +8,7 @@ void CreateYvector(const size_t size, const size_t count) { for (size_t i = 0; i < count; ++i) { NBench::Clobber(); - TVector<ui8> v(size); + TVector<ui8> v(size); NBench::Escape(v.data()); NBench::Clobber(); } diff --git a/util/generic/bitmap.h b/util/generic/bitmap.h index f77d182460..ca82f88bc6 100644 --- a/util/generic/bitmap.h +++ b/util/generic/bitmap.h @@ -25,7 +25,7 @@ namespace NBitMapPrivate { // better than intrinsics without -mpopcnt template <typename T> - static unsigned CountBitsPrivate(T v) noexcept { + static unsigned CountBitsPrivate(T v) noexcept { return static_cast<unsigned>(ByteSums(v) >> 56); } diff --git a/util/generic/bitops.h b/util/generic/bitops.h index 2db15fc59b..11d3b78f3d 100644 --- a/util/generic/bitops.h +++ b/util/generic/bitops.h @@ -14,7 +14,7 @@ namespace NBitOps { namespace NPrivate { template <unsigned N, typename T> struct TClp2Helper { - static Y_FORCE_INLINE T Calc(T t) noexcept { + static Y_FORCE_INLINE T Calc(T t) noexcept { const T prev = TClp2Helper<N / 2, T>::Calc(t); return prev | (prev >> N); @@ -23,7 +23,7 @@ namespace NBitOps { template <typename T> struct TClp2Helper<0u, T> { - static Y_FORCE_INLINE T Calc(T t) noexcept { + static Y_FORCE_INLINE T Calc(T t) noexcept { return t - 1; } }; @@ -58,24 +58,24 @@ namespace NBitOps { } #if defined(__GNUC__) - inline unsigned GetValueBitCountImpl(unsigned int value) noexcept { + inline unsigned GetValueBitCountImpl(unsigned int value) noexcept { Y_ASSERT(value); // because __builtin_clz* have undefined result for zero. return std::numeric_limits<unsigned int>::digits - __builtin_clz(value); } - inline unsigned GetValueBitCountImpl(unsigned long value) noexcept { + inline unsigned GetValueBitCountImpl(unsigned long value) noexcept { Y_ASSERT(value); // because __builtin_clz* have undefined result for zero. return std::numeric_limits<unsigned long>::digits - __builtin_clzl(value); } - inline unsigned GetValueBitCountImpl(unsigned long long value) noexcept { + inline unsigned GetValueBitCountImpl(unsigned long long value) noexcept { Y_ASSERT(value); // because __builtin_clz* have undefined result for zero. return std::numeric_limits<unsigned long long>::digits - __builtin_clzll(value); } #else /// Stupid realization for non-GCC. Can use BSR from x86 instructions set. template <typename T> - inline unsigned GetValueBitCountImpl(T value) noexcept { + inline unsigned GetValueBitCountImpl(T value) noexcept { Y_ASSERT(value); // because __builtin_clz* have undefined result for zero. unsigned result = 1; // result == 0 - impossible value, see Y_ASSERT(). value >>= 1; @@ -89,24 +89,24 @@ namespace NBitOps { #endif #if defined(__GNUC__) - inline unsigned CountTrailingZeroBitsImpl(unsigned int value) noexcept { + inline unsigned CountTrailingZeroBitsImpl(unsigned int value) noexcept { Y_ASSERT(value); // because __builtin_ctz* have undefined result for zero. return __builtin_ctz(value); } - inline unsigned CountTrailingZeroBitsImpl(unsigned long value) noexcept { + inline unsigned CountTrailingZeroBitsImpl(unsigned long value) noexcept { Y_ASSERT(value); // because __builtin_ctz* have undefined result for zero. return __builtin_ctzl(value); } - inline unsigned CountTrailingZeroBitsImpl(unsigned long long value) noexcept { + inline unsigned CountTrailingZeroBitsImpl(unsigned long long value) noexcept { Y_ASSERT(value); // because __builtin_ctz* have undefined result for zero. return __builtin_ctzll(value); } #else /// Stupid realization for non-GCC. Can use BSF from x86 instructions set. template <typename T> - inline unsigned CountTrailingZeroBitsImpl(T value) noexcept { + inline unsigned CountTrailingZeroBitsImpl(T value) noexcept { Y_ASSERT(value); // because __builtin_ctz* have undefined result for zero. unsigned result = 0; while (!(value & 1)) { @@ -206,7 +206,7 @@ namespace NBitOps { * Result is undefined for `t == 0`. */ template <typename T> -static inline T FastClp2(T t) noexcept { +static inline T FastClp2(T t) noexcept { Y_ASSERT(t > 0); using TCvt = typename ::TUnsignedInts::template TSelectBy<TSizeOfPredicate<sizeof(T)>::template TResult>::type; return 1 + ::NBitOps::NPrivate::TClp2Helper<sizeof(TCvt) * 4, T>::Calc(static_cast<TCvt>(t)); @@ -224,7 +224,7 @@ Y_CONST_FUNCTION constexpr bool IsPowerOf2(T v) noexcept { * Returns the number of leading 0-bits in `value`, starting at the most significant bit position. */ template <typename T> -static inline unsigned GetValueBitCount(T value) noexcept { +static inline unsigned GetValueBitCount(T value) noexcept { Y_ASSERT(value > 0); using TCvt = typename ::TUnsignedInts::template TSelectBy<TSizeOfPredicate<sizeof(T)>::template TResult>::type; return ::NBitOps::NPrivate::GetValueBitCountImpl(static_cast<TCvt>(value)); @@ -234,7 +234,7 @@ static inline unsigned GetValueBitCount(T value) noexcept { * Returns the number of trailing 0-bits in `value`, starting at the least significant bit position */ template <typename T> -static inline unsigned CountTrailingZeroBits(T value) noexcept { +static inline unsigned CountTrailingZeroBits(T value) noexcept { Y_ASSERT(value > 0); using TCvt = typename ::TUnsignedInts::template TSelectBy<TSizeOfPredicate<sizeof(T)>::template TResult>::type; return ::NBitOps::NPrivate::CountTrailingZeroBitsImpl(static_cast<TCvt>(value)); diff --git a/util/generic/bt_exception.h b/util/generic/bt_exception.h index 018d2bc89a..12333e0c4b 100644 --- a/util/generic/bt_exception.h +++ b/util/generic/bt_exception.h @@ -15,7 +15,7 @@ public: BT_.Capture(); } - const TBackTrace* BackTrace() const noexcept override { + const TBackTrace* BackTrace() const noexcept override { return &BT_; } diff --git a/util/generic/buffer.cpp b/util/generic/buffer.cpp index b92697e1d0..70f0539d04 100644 --- a/util/generic/buffer.cpp +++ b/util/generic/buffer.cpp @@ -89,11 +89,11 @@ void TBuffer::Realloc(size_t len) { Len_ = len; } -TBuffer::~TBuffer() { +TBuffer::~TBuffer() { y_deallocate(Data_); } -void TBuffer::AsString(TString& s) { +void TBuffer::AsString(TString& s) { s.assign(Data(), Size()); Clear(); } diff --git a/util/generic/buffer.h b/util/generic/buffer.h index 9576467404..f2b29a61b6 100644 --- a/util/generic/buffer.h +++ b/util/generic/buffer.h @@ -35,18 +35,18 @@ public: return *this; } - ~TBuffer(); + ~TBuffer(); - inline void Clear() noexcept { + inline void Clear() noexcept { Pos_ = 0; } - inline void EraseBack(size_t n) noexcept { + inline void EraseBack(size_t n) noexcept { Y_ASSERT(n <= Pos_); Pos_ -= n; } - inline void Reset() noexcept { + inline void Reset() noexcept { TBuffer().Swap(*this); } @@ -59,24 +59,24 @@ public: Assign(b, e - b); } - inline char* Data() noexcept { + inline char* Data() noexcept { return Data_; } - inline const char* Data() const noexcept { + inline const char* Data() const noexcept { return Data_; } - inline char* Pos() noexcept { + inline char* Pos() noexcept { return Data_ + Pos_; } - inline const char* Pos() const noexcept { + inline const char* Pos() const noexcept { return Data_ + Pos_; } /// Used space in bytes (do not mix with Capacity!) - inline size_t Size() const noexcept { + inline size_t Size() const noexcept { return Pos_; } @@ -84,11 +84,11 @@ public: return !Size(); } - inline explicit operator bool() const noexcept { + inline explicit operator bool() const noexcept { return Size(); } - inline size_t Avail() const noexcept { + inline size_t Avail() const noexcept { return Len_ - Pos_; } @@ -170,7 +170,7 @@ public: Pos_ = len; } - inline size_t Capacity() const noexcept { + inline size_t Capacity() const noexcept { return Len_; } @@ -193,7 +193,7 @@ public: return Size(); } - inline void Swap(TBuffer& r) noexcept { + inline void Swap(TBuffer& r) noexcept { DoSwap(Data_, r.Data_); DoSwap(Len_, r.Len_); DoSwap(Pos_, r.Pos_); @@ -202,24 +202,24 @@ public: /* * after this call buffer becomes empty */ - void AsString(TString& s); + void AsString(TString& s); /* * iterator-like interface */ - inline TIterator Begin() noexcept { + inline TIterator Begin() noexcept { return Data(); } - inline TIterator End() noexcept { + inline TIterator End() noexcept { return Begin() + Size(); } - inline TConstIterator Begin() const noexcept { + inline TConstIterator Begin() const noexcept { return Data(); } - inline TConstIterator End() const noexcept { + inline TConstIterator End() const noexcept { return Begin() + Size(); } diff --git a/util/generic/buffer_ut.cpp b/util/generic/buffer_ut.cpp index 437d7122ec..ba4c2e94bb 100644 --- a/util/generic/buffer_ut.cpp +++ b/util/generic/buffer_ut.cpp @@ -1,7 +1,7 @@ #include <library/cpp/testing/unittest/registar.h> #include <util/system/datetime.h> -#include "string.h" +#include "string.h" #include "vector.h" #include "buffer.h" @@ -21,7 +21,7 @@ Y_UNIT_TEST_SUITE(TBufferTest) { const char data[] = "1234567890qwertyuiop"; TBuffer buf(13); - TString str; + TString str; for (size_t i = 0; i < 10; ++i) { for (size_t j = 0; j < sizeof(data) - 1; ++j) { @@ -91,11 +91,11 @@ Y_UNIT_TEST_SUITE(TBufferTest) { buf.Append('a'); UNIT_ASSERT_EQUAL(buf.Capacity(), 256); - TString tmp1 = "abcdef"; + TString tmp1 = "abcdef"; buf.Append(tmp1.data(), tmp1.size()); UNIT_ASSERT_EQUAL(buf.Capacity(), 256); - TString tmp2 = "30498290sfokdsflj2308w"; + TString tmp2 = "30498290sfokdsflj2308w"; buf.Resize(1020); buf.Append(tmp2.data(), tmp2.size()); UNIT_ASSERT_EQUAL(buf.Capacity(), 2048); @@ -104,7 +104,7 @@ Y_UNIT_TEST_SUITE(TBufferTest) { Y_UNIT_TEST(TestShrinkToFit) { TBuffer buf; - TString content = "some text"; + TString content = "some text"; buf.Append(content.data(), content.size()); UNIT_ASSERT_EQUAL(buf.Size(), 9); UNIT_ASSERT_EQUAL(buf.Capacity(), 16); @@ -134,13 +134,13 @@ Y_UNIT_TEST(TestAlignUp) { buf.AlignUp(4, '!'); UNIT_ASSERT(buf.Size() % 4 == 0); - UNIT_ASSERT_VALUES_EQUAL(TString(~buf, +buf), "some text!!!"); + UNIT_ASSERT_VALUES_EQUAL(TString(~buf, +buf), "some text!!!"); char addContent[] = "1234"; buf.Append(addContent, sizeof(addContent)); buf.AlignUp(4, 'X'); UNIT_ASSERT(buf.Size() % 4 == 0); - UNIT_ASSERT_VALUES_EQUAL(TString(~buf, +buf), "some text!!!1234"); + UNIT_ASSERT_VALUES_EQUAL(TString(~buf, +buf), "some text!!!1234"); } #endif @@ -164,7 +164,7 @@ Y_UNIT_TEST(TestSpeed) { } { - TVector<char> buf; + TVector<char> buf; t2 = MicroSeconds(); diff --git a/util/generic/cast.h b/util/generic/cast.h index 0d4a41f385..792de22368 100644 --- a/util/generic/cast.h +++ b/util/generic/cast.h @@ -143,7 +143,7 @@ inline std::enable_if_t<!::NPrivate::TSafelyConvertible<TSmall, TLarge>::Result, } template <class TSmallInt, class TLargeInt> -inline TSmallInt IntegerCast(TLargeInt largeInt) noexcept { +inline TSmallInt IntegerCast(TLargeInt largeInt) noexcept { try { return SafeIntegerCast<TSmallInt>(largeInt); } catch (const yexception& exc) { diff --git a/util/generic/deque.h b/util/generic/deque.h index 2dabaf3177..b32beaca00 100644 --- a/util/generic/deque.h +++ b/util/generic/deque.h @@ -9,7 +9,7 @@ #include <initializer_list> template <class T, class A> -class TDeque: public std::deque<T, TReboundAllocator<A, T>> { +class TDeque: public std::deque<T, TReboundAllocator<A, T>> { using TBase = std::deque<T, TReboundAllocator<A, T>>; public: diff --git a/util/generic/deque_ut.cpp b/util/generic/deque_ut.cpp index 93bf50fa92..1c522bc187 100644 --- a/util/generic/deque_ut.cpp +++ b/util/generic/deque_ut.cpp @@ -27,7 +27,7 @@ protected: UNIT_TEST_SUITE_REGISTRATION(TDequeTest); void TDequeTest::TestConstructorsAndAssignments() { - using container = TDeque<int>; + using container = TDeque<int>; container c1; c1.push_back(100); @@ -66,7 +66,7 @@ void TDequeTest::TestConstructorsAndAssignments() { } void TDequeTest::TestDeque1() { - TDeque<int> d; + TDeque<int> d; UNIT_ASSERT(!d); d.push_back(4); @@ -89,8 +89,8 @@ void TDequeTest::TestDeque1() { UNIT_ASSERT(d[2] == 25); //Some compile time tests: - TDeque<int>::iterator dit = d.begin(); - TDeque<int>::const_iterator cdit(d.begin()); + TDeque<int>::iterator dit = d.begin(); + TDeque<int>::const_iterator cdit(d.begin()); UNIT_ASSERT((dit - cdit) == 0); UNIT_ASSERT((cdit - dit) == 0); @@ -100,14 +100,14 @@ void TDequeTest::TestDeque1() { } void TDequeTest::TestInsert() { - TDeque<int> d; + TDeque<int> d; d.push_back(0); d.push_back(1); d.push_back(2); UNIT_ASSERT(d.size() == 3); - TDeque<int>::iterator dit; + TDeque<int>::iterator dit; //Insertion before begin: dit = d.insert(d.begin(), 3); @@ -177,8 +177,8 @@ void TDequeTest::TestInsert() { } void TDequeTest::TestAt() { - TDeque<int> d; - TDeque<int> const& cd = d; + TDeque<int> d; + TDeque<int> const& cd = d; d.push_back(10); UNIT_ASSERT(d.at(0) == 10); @@ -197,12 +197,12 @@ void TDequeTest::TestAt() { void TDequeTest::TestAutoRef() { int i; - TDeque<int> ref; + TDeque<int> ref; for (i = 0; i < 5; ++i) { ref.push_back(i); } - TDeque<TDeque<int>> d_d_int(1, ref); + TDeque<TDeque<int>> d_d_int(1, ref); d_d_int.push_back(d_d_int[0]); d_d_int.push_back(ref); d_d_int.push_back(d_d_int[0]); @@ -215,7 +215,7 @@ void TDequeTest::TestAutoRef() { } void TDequeTest::TestErase() { - TDeque<int> dint; + TDeque<int> dint; dint.push_back(3); dint.push_front(2); dint.push_back(4); @@ -224,7 +224,7 @@ void TDequeTest::TestErase() { dint.push_front(0); dint.push_back(6); - TDeque<int>::iterator it(dint.begin() + 1); + TDeque<int>::iterator it(dint.begin() + 1); UNIT_ASSERT(*it == 1); dint.erase(dint.begin()); diff --git a/util/generic/explicit_type_ut.cpp b/util/generic/explicit_type_ut.cpp index 50a745f090..f7cb501a35 100644 --- a/util/generic/explicit_type_ut.cpp +++ b/util/generic/explicit_type_ut.cpp @@ -17,7 +17,7 @@ public: template <class T, class Arg> struct TCallable: public TCallableBase { enum { - Result = sizeof(Test(std::declval<T>(), std::declval<Arg>(), 1)) == sizeof(TYes) + Result = sizeof(Test(std::declval<T>(), std::declval<Arg>(), 1)) == sizeof(TYes) }; }; diff --git a/util/generic/fastqueue.h b/util/generic/fastqueue.h index 1fee5b86f6..461dd52af3 100644 --- a/util/generic/fastqueue.h +++ b/util/generic/fastqueue.h @@ -35,7 +35,7 @@ public: return tmp->Obj; } - inline size_t Size() const noexcept { + inline size_t Size() const noexcept { return Size_; } @@ -43,7 +43,7 @@ public: return !this->Size(); } - inline explicit operator bool() const noexcept { + inline explicit operator bool() const noexcept { return !this->Empty(); } diff --git a/util/generic/flags_ut.cpp b/util/generic/flags_ut.cpp index 5377c6a058..a87d9eb920 100644 --- a/util/generic/flags_ut.cpp +++ b/util/generic/flags_ut.cpp @@ -93,7 +93,7 @@ Y_UNIT_TEST_SUITE(TFlagsTest) { Y_UNIT_TEST(TestHash) { ETest1 value0 = nullptr, value1 = Test1; - THashMap<ETest1, int> hash; + THashMap<ETest1, int> hash; hash[value0] = 0; hash[value1] = 1; diff --git a/util/generic/fuzz/vector/main.cpp b/util/generic/fuzz/vector/main.cpp index 0a0293f795..ed7eb43ad8 100644 --- a/util/generic/fuzz/vector/main.cpp +++ b/util/generic/fuzz/vector/main.cpp @@ -14,7 +14,7 @@ extern "C" int LLVMFuzzerTestOneInput(const ui8* data, size_t size) { TMemoryInput mi(data, size); try { - TVector<ui16> v; + TVector<ui16> v; while (mi.Avail()) { char cmd = Read<char>(mi); diff --git a/util/generic/fwd.h b/util/generic/fwd.h index 5cc2da40e5..7681b5df5c 100644 --- a/util/generic/fwd.h +++ b/util/generic/fwd.h @@ -53,46 +53,46 @@ class TRbTree; //containers template <class T, class A = std::allocator<T>> -class TVector; +class TVector; template <class T, class A = std::allocator<T>> -class TDeque; +class TDeque; -template <class T, class S = TDeque<T>> -class TQueue; +template <class T, class S = TDeque<T>> +class TQueue; -template <class T, class S = TVector<T>, class C = TLess<T>> -class TPriorityQueue; +template <class T, class S = TVector<T>, class C = TLess<T>> +class TPriorityQueue; template <class Key, class T, class HashFcn = THash<Key>, class EqualKey = TEqualTo<Key>, class Alloc = std::allocator<Key>> -class THashMap; +class THashMap; template <class Key, class T, class HashFcn = THash<Key>, class EqualKey = TEqualTo<Key>, class Alloc = std::allocator<Key>> -class THashMultiMap; +class THashMultiMap; template <class Value, class HashFcn = THash<Value>, class EqualKey = TEqualTo<Value>, class Alloc = std::allocator<Value>> -class THashSet; +class THashSet; template <class Value, class HashFcn = THash<Value>, class EqualKey = TEqualTo<Value>, class Alloc = std::allocator<Value>> -class THashMultiSet; +class THashMultiSet; template <class T, class A = std::allocator<T>> -class TList; +class TList; template <class K, class V, class Less = TLess<K>, class A = std::allocator<K>> -class TMap; +class TMap; template <class K, class V, class Less = TLess<K>, class A = std::allocator<K>> -class TMultiMap; +class TMultiMap; template <class K, class L = TLess<K>, class A = std::allocator<K>> -class TSet; +class TSet; template <class K, class L = TLess<K>, class A = std::allocator<K>> -class TMultiSet; +class TMultiSet; -template <class T, class S = TDeque<T>> -class TStack; +template <class T, class S = TDeque<T>> +class TStack; template <size_t BitCount, typename TChunkType = ui64> class TBitMap; diff --git a/util/generic/guid.cpp b/util/generic/guid.cpp index 8b907457bc..e85bcb28ba 100644 --- a/util/generic/guid.cpp +++ b/util/generic/guid.cpp @@ -1,6 +1,6 @@ #include "guid.h" #include "ylimits.h" -#include "string.h" +#include "string.h" #include <util/string/ascii.h> #include <util/string/builder.h> @@ -65,11 +65,11 @@ TGUID TGUID::CreateTimebased() { return result; } -TString GetGuidAsString(const TGUID& g) { +TString GetGuidAsString(const TGUID& g) { return g.AsGuidString(); } -TString CreateGuidAsString() { +TString CreateGuidAsString() { return TGUID::Create().AsGuidString(); } diff --git a/util/generic/guid.h b/util/generic/guid.h index 2bf6c8ad99..9212b3edb6 100644 --- a/util/generic/guid.h +++ b/util/generic/guid.h @@ -66,8 +66,8 @@ struct THash<TGUID> { }; void CreateGuid(TGUID* res); -TString GetGuidAsString(const TGUID& g); -TString CreateGuidAsString(); +TString GetGuidAsString(const TGUID& g); +TString CreateGuidAsString(); TGUID GetGuid(TStringBuf s); bool GetGuid(TStringBuf s, TGUID& result); diff --git a/util/generic/guid_ut.cpp b/util/generic/guid_ut.cpp index 048354ff39..6b9118851f 100644 --- a/util/generic/guid_ut.cpp +++ b/util/generic/guid_ut.cpp @@ -17,7 +17,7 @@ Y_UNIT_TEST_SUITE(TGuidTest) { struct TTest { TGUID G; - TString S; + TString S; }; Y_UNIT_TEST(Test1) { diff --git a/util/generic/hash.cpp b/util/generic/hash.cpp index a674ee4538..96b3b13981 100644 --- a/util/generic/hash.cpp +++ b/util/generic/hash.cpp @@ -3,9 +3,9 @@ #include <util/string/escape.h> #include <util/string/cast.h> -const void* const _yhashtable_empty_data[] = {(void*)3, nullptr, (void*)1}; +const void* const _yhashtable_empty_data[] = {(void*)3, nullptr, (void*)1}; -TString NPrivate::MapKeyToString(TStringBuf key) { +TString NPrivate::MapKeyToString(TStringBuf key) { constexpr size_t HASH_KEY_MAX_LENGTH = 500; try { return EscapeC(key.substr(0, HASH_KEY_MAX_LENGTH)); @@ -14,35 +14,35 @@ TString NPrivate::MapKeyToString(TStringBuf key) { } } -TString NPrivate::MapKeyToString(unsigned short key) { +TString NPrivate::MapKeyToString(unsigned short key) { return ToString(key); } -TString NPrivate::MapKeyToString(short key) { +TString NPrivate::MapKeyToString(short key) { return ToString(key); } -TString NPrivate::MapKeyToString(unsigned int key) { +TString NPrivate::MapKeyToString(unsigned int key) { return ToString(key); } -TString NPrivate::MapKeyToString(int key) { +TString NPrivate::MapKeyToString(int key) { return ToString(key); } -TString NPrivate::MapKeyToString(unsigned long key) { +TString NPrivate::MapKeyToString(unsigned long key) { return ToString(key); } -TString NPrivate::MapKeyToString(long key) { +TString NPrivate::MapKeyToString(long key) { return ToString(key); } -TString NPrivate::MapKeyToString(unsigned long long key) { +TString NPrivate::MapKeyToString(unsigned long long key) { return ToString(key); } -TString NPrivate::MapKeyToString(long long key) { +TString NPrivate::MapKeyToString(long long key) { return ToString(key); } diff --git a/util/generic/hash.h b/util/generic/hash.h index e46db21fa9..aa9981e9f1 100644 --- a/util/generic/hash.h +++ b/util/generic/hash.h @@ -29,40 +29,40 @@ struct TSelect1st { }; template <class Value> -struct __yhashtable_node { +struct __yhashtable_node { /** If the first bit is not set, then this is a pointer to the next node in * the list of nodes for the current bucket. Otherwise this is a pointer of - * type __yhashtable_node**, pointing back into the buckets array. + * type __yhashtable_node**, pointing back into the buckets array. * * This trick makes it possible to use only one node pointer in a hash table * iterator. */ - __yhashtable_node* next; + __yhashtable_node* next; /** Value stored in a node. */ Value val; - __yhashtable_node& operator=(const __yhashtable_node&) = delete; + __yhashtable_node& operator=(const __yhashtable_node&) = delete; }; template <class Value, class Key, class HashFcn, class ExtractKey, class EqualKey, class Alloc> -class THashTable; +class THashTable; template <class Key, class T, class HashFcn, class EqualKey, typename size_type_f> class sthash; template <class Value> -struct __yhashtable_iterator; +struct __yhashtable_iterator; template <class Value> -struct __yhashtable_const_iterator; +struct __yhashtable_const_iterator; template <class Value> -struct __yhashtable_iterator { - using iterator = __yhashtable_iterator<Value>; - using const_iterator = __yhashtable_const_iterator<Value>; - using node = __yhashtable_node<Value>; +struct __yhashtable_iterator { + using iterator = __yhashtable_iterator<Value>; + using const_iterator = __yhashtable_const_iterator<Value>; + using node = __yhashtable_node<Value>; using iterator_category = std::forward_iterator_tag; using value_type = Value; @@ -73,7 +73,7 @@ struct __yhashtable_iterator { node* cur; - explicit __yhashtable_iterator(node* n) + explicit __yhashtable_iterator(node* n) : cur(n) { } /*y*/ @@ -96,16 +96,16 @@ struct __yhashtable_iterator { bool IsEnd() const { return !cur; } - Y_FORCE_INLINE explicit operator bool() const noexcept { + Y_FORCE_INLINE explicit operator bool() const noexcept { return cur != nullptr; } }; template <class Value> -struct __yhashtable_const_iterator { - using iterator = __yhashtable_iterator<Value>; - using const_iterator = __yhashtable_const_iterator<Value>; - using node = __yhashtable_node<Value>; +struct __yhashtable_const_iterator { + using iterator = __yhashtable_iterator<Value>; + using const_iterator = __yhashtable_const_iterator<Value>; + using node = __yhashtable_node<Value>; using iterator_category = std::forward_iterator_tag; using value_type = Value; @@ -116,13 +116,13 @@ struct __yhashtable_const_iterator { const node* cur; - explicit __yhashtable_const_iterator(const node* n) + explicit __yhashtable_const_iterator(const node* n) : cur(n) { } - __yhashtable_const_iterator() { + __yhashtable_const_iterator() { } - __yhashtable_const_iterator(const iterator& it) + __yhashtable_const_iterator(const iterator& it) : cur(it.cur) { } @@ -143,7 +143,7 @@ struct __yhashtable_const_iterator { bool IsEnd() const { return !cur; } - Y_FORCE_INLINE explicit operator bool() const noexcept { + Y_FORCE_INLINE explicit operator bool() const noexcept { return cur != nullptr; } }; @@ -156,8 +156,8 @@ struct __yhashtable_const_iterator { template <class Alloc> class _allocator_base: private Alloc { public: - _allocator_base(const Alloc& other) - : Alloc(other) + _allocator_base(const Alloc& other) + : Alloc(other) { } @@ -177,12 +177,12 @@ public: }; /** - * Wrapper for an array of THashTable buckets. + * Wrapper for an array of THashTable buckets. * * Is better than vector for this particular use case. Main differences: * - Occupies one less word on stack. - * - Doesn't even try to initialize its elements. It is THashTable's responsibility. - * - Presents a better interface in relation to THashTable's marker element trick. + * - Doesn't even try to initialize its elements. It is THashTable's responsibility. + * - Presents a better interface in relation to THashTable's marker element trick. * * Internally this class is just a pointer-size pair, and the data on the heap * has the following structure: @@ -197,13 +197,13 @@ public: * `raw_size` stores the size of the allocated memory block. It is used to * support resizing without reallocation. * - * `marker` is a special marker element that is set by the THashTable that is + * `marker` is a special marker element that is set by the THashTable that is * then used in iterator implementation to know when the end is reached. * * Unused space at the end of the memory block may not be present. */ template <class T, class Alloc> -class _yhashtable_buckets: private _allocator_base<Alloc> { +class _yhashtable_buckets: private _allocator_base<Alloc> { using base_type = _allocator_base<Alloc>; static_assert(sizeof(T) == sizeof(size_t), "T is expected to be the same size as size_t."); @@ -221,14 +221,14 @@ public: using difference_type = ptrdiff_t; using TBucketDivisor = ::NPrivate::THashDivisor; - _yhashtable_buckets(const Alloc& other) - : base_type(other) + _yhashtable_buckets(const Alloc& other) + : base_type(other) , Data(nullptr) , Size() { } - ~_yhashtable_buckets() { + ~_yhashtable_buckets() { Y_ASSERT(!Data); } @@ -318,7 +318,7 @@ public: return *(Data + index); } - void swap(_yhashtable_buckets& other) { + void swap(_yhashtable_buckets& other) { base_type::swap(other); DoSwap(Data, other.Data); DoSwap(Size, other.Size); @@ -333,7 +333,7 @@ private: }; /** - * This class saves one word in THashTable for the most common use case of empty + * This class saves one word in THashTable for the most common use case of empty * functors. The exact implementation picks a specialization with storage allocated * for the functors if those are non-empty, and another specialization that creates * functors on the fly if they are empty. It is expected that empty functors have @@ -348,67 +348,67 @@ private: * of the functors are empty as this is a case that's just way too rare. */ template <class HashFcn, class ExtractKey, class EqualKey, class Alloc, bool IsEmpty = std::is_empty<HashFcn>::value&& std::is_empty<ExtractKey>::value&& std::is_empty<EqualKey>::value> -class _yhashtable_base: public _allocator_base<Alloc> { +class _yhashtable_base: public _allocator_base<Alloc> { using base_type = _allocator_base<Alloc>; public: - _yhashtable_base(const HashFcn& hash, const ExtractKey& extract, const EqualKey& equals, const Alloc& alloc) + _yhashtable_base(const HashFcn& hash, const ExtractKey& extract, const EqualKey& equals, const Alloc& alloc) : base_type(alloc) - , hash_(hash) - , extract_(extract) - , equals_(equals) + , hash_(hash) + , extract_(extract) + , equals_(equals) { } const EqualKey& _get_key_eq() const { - return equals_; + return equals_; } EqualKey& _get_key_eq() { - return equals_; + return equals_; } void _set_key_eq(const EqualKey& equals) { - this->equals_ = equals; + this->equals_ = equals; } const ExtractKey& _get_key_extract() const { - return extract_; + return extract_; } ExtractKey& _get_key_extract() { - return extract_; + return extract_; } void _set_key_extract(const ExtractKey& extract) { - this->extract_ = extract; + this->extract_ = extract; } const HashFcn& _get_hash_fun() const { - return hash_; + return hash_; } HashFcn& _get_hash_fun() { - return hash_; + return hash_; } void _set_hash_fun(const HashFcn& hash) { - this->hash_ = hash; + this->hash_ = hash; } - void swap(_yhashtable_base& other) { + void swap(_yhashtable_base& other) { base_type::swap(other); - DoSwap(equals_, other.equals_); - DoSwap(extract_, other.extract_); - DoSwap(hash_, other.hash_); + DoSwap(equals_, other.equals_); + DoSwap(extract_, other.extract_); + DoSwap(hash_, other.hash_); } private: - HashFcn hash_; - ExtractKey extract_; - EqualKey equals_; + HashFcn hash_; + ExtractKey extract_; + EqualKey equals_; }; template <class HashFcn, class ExtractKey, class EqualKey, class Alloc> -class _yhashtable_base<HashFcn, ExtractKey, EqualKey, Alloc, true>: public _allocator_base<Alloc> { +class _yhashtable_base<HashFcn, ExtractKey, EqualKey, Alloc, true>: public _allocator_base<Alloc> { using base_type = _allocator_base<Alloc>; public: - _yhashtable_base(const HashFcn&, const ExtractKey&, const EqualKey&, const Alloc& alloc) + _yhashtable_base(const HashFcn&, const ExtractKey&, const EqualKey&, const Alloc& alloc) : base_type(alloc) { } @@ -431,30 +431,30 @@ public: void _set_hash_fun(const HashFcn&) { } - void swap(_yhashtable_base& other) { + void swap(_yhashtable_base& other) { base_type::swap(other); } }; template <class Value, class Key, class HashFcn, class ExtractKey, class EqualKey, class Alloc> -struct _yhashtable_traits { - using node = __yhashtable_node<Value>; +struct _yhashtable_traits { + using node = __yhashtable_node<Value>; using node_allocator_type = TReboundAllocator<Alloc, node>; using nodep_allocator_type = TReboundAllocator<Alloc, node*>; - using base_type = _yhashtable_base<HashFcn, ExtractKey, EqualKey, node_allocator_type>; + using base_type = _yhashtable_base<HashFcn, ExtractKey, EqualKey, node_allocator_type>; }; -extern const void* const _yhashtable_empty_data[]; +extern const void* const _yhashtable_empty_data[]; template <class Value, class Key, class HashFcn, class ExtractKey, class EqualKey, class Alloc> -class THashTable: private _yhashtable_traits<Value, Key, HashFcn, ExtractKey, EqualKey, Alloc>::base_type { - using traits_type = _yhashtable_traits<Value, Key, HashFcn, ExtractKey, EqualKey, Alloc>; +class THashTable: private _yhashtable_traits<Value, Key, HashFcn, ExtractKey, EqualKey, Alloc>::base_type { + using traits_type = _yhashtable_traits<Value, Key, HashFcn, ExtractKey, EqualKey, Alloc>; using base_type = typename traits_type::base_type; using node = typename traits_type::node; using nodep_allocator_type = typename traits_type::nodep_allocator_type; - using buckets_type = _yhashtable_buckets<node*, nodep_allocator_type>; + using buckets_type = _yhashtable_buckets<node*, nodep_allocator_type>; using TBucketDivisor = ::NPrivate::THashDivisor; public: @@ -511,15 +511,15 @@ private: size_type num_elements; public: - using iterator = __yhashtable_iterator<Value>; - using const_iterator = __yhashtable_const_iterator<Value>; + using iterator = __yhashtable_iterator<Value>; + using const_iterator = __yhashtable_const_iterator<Value>; using insert_ctx = node**; - friend struct __yhashtable_iterator<Value>; - friend struct __yhashtable_const_iterator<Value>; + friend struct __yhashtable_iterator<Value>; + friend struct __yhashtable_const_iterator<Value>; public: - THashTable() + THashTable() : base_type(HashFcn(), ExtractKey(), EqualKey(), node_allocator_type()) , buckets(nodep_allocator_type()) , num_elements(0) @@ -527,7 +527,7 @@ public: initialize_buckets(buckets, 0); } - THashTable(size_type n, const HashFcn& hf, const EqualKey& eql, const ExtractKey& ext) + THashTable(size_type n, const HashFcn& hf, const EqualKey& eql, const ExtractKey& ext) : base_type(hf, ext, eql, node_allocator_type()) , buckets(nodep_allocator_type()) , num_elements(0) @@ -535,7 +535,7 @@ public: initialize_buckets(buckets, n); } - THashTable(size_type n, const HashFcn& hf, const EqualKey& eql) + THashTable(size_type n, const HashFcn& hf, const EqualKey& eql) : base_type(hf, ExtractKey(), eql, node_allocator_type()) , buckets(nodep_allocator_type()) , num_elements(0) @@ -544,7 +544,7 @@ public: } template <class TAllocParam> - THashTable(size_type n, const HashFcn& hf, const EqualKey& eql, TAllocParam* allocParam) + THashTable(size_type n, const HashFcn& hf, const EqualKey& eql, TAllocParam* allocParam) : base_type(hf, ExtractKey(), eql, allocParam) , buckets(allocParam) , num_elements(0) @@ -552,7 +552,7 @@ public: initialize_buckets(buckets, n); } - THashTable(const THashTable& ht) + THashTable(const THashTable& ht) : base_type(ht._get_hash_fun(), ht._get_key_extract(), ht._get_key_eq(), ht._get_alloc()) , buckets(ht.buckets.get_allocator()) , num_elements(0) @@ -565,7 +565,7 @@ public: } } - THashTable(THashTable&& ht) noexcept + THashTable(THashTable&& ht) noexcept : base_type(ht._get_hash_fun(), ht._get_key_extract(), ht._get_key_eq(), ht._get_alloc()) , buckets(ht.buckets.get_allocator()) , num_elements(0) @@ -574,7 +574,7 @@ public: this->swap(ht); } - THashTable& operator=(const THashTable& ht) { + THashTable& operator=(const THashTable& ht) { if (&ht != this) { basic_clear(); this->_set_hash_fun(ht._get_hash_fun()); @@ -603,14 +603,14 @@ public: return *this; } - THashTable& operator=(THashTable&& ht) noexcept { + THashTable& operator=(THashTable&& ht) noexcept { basic_clear(); swap(ht); return *this; } - ~THashTable() { + ~THashTable() { basic_clear(); deinitialize_buckets(buckets); } @@ -626,7 +626,7 @@ public: return size() == 0; } - void swap(THashTable& ht) { + void swap(THashTable& ht) { base_type::swap(ht); buckets.swap(ht.buckets); DoSwap(num_elements, ht.num_elements); @@ -857,7 +857,7 @@ public: * Clears the hashtable and tries to reasonably downsize it. Note that * downsizing is mainly for the following use case: * - * THashTable hash; + * THashTable hash; * for(...) { * if (someCond()) * hash.clear(); @@ -951,11 +951,11 @@ private: void erase_bucket(const size_type n, node* first, node* last); void erase_bucket(const size_type n, node* last); - void copy_from_dynamic(const THashTable& ht); + void copy_from_dynamic(const THashTable& ht); }; template <class V> -__yhashtable_iterator<V>& __yhashtable_iterator<V>::operator++() { +__yhashtable_iterator<V>& __yhashtable_iterator<V>::operator++() { Y_ASSERT(cur); cur = cur->next; if ((uintptr_t)cur & 1) { @@ -969,14 +969,14 @@ __yhashtable_iterator<V>& __yhashtable_iterator<V>::operator++() { } template <class V> -inline __yhashtable_iterator<V> __yhashtable_iterator<V>::operator++(int) { +inline __yhashtable_iterator<V> __yhashtable_iterator<V>::operator++(int) { iterator tmp = *this; ++*this; return tmp; } template <class V> -__yhashtable_const_iterator<V>& __yhashtable_const_iterator<V>::operator++() { +__yhashtable_const_iterator<V>& __yhashtable_const_iterator<V>::operator++() { Y_ASSERT(cur); cur = cur->next; if ((uintptr_t)cur & 1) { @@ -990,7 +990,7 @@ __yhashtable_const_iterator<V>& __yhashtable_const_iterator<V>::operator++() { } template <class V> -inline __yhashtable_const_iterator<V> __yhashtable_const_iterator<V>::operator++(int) { +inline __yhashtable_const_iterator<V> __yhashtable_const_iterator<V>::operator++(int) { const_iterator tmp = *this; ++*this; return tmp; @@ -998,7 +998,7 @@ inline __yhashtable_const_iterator<V> __yhashtable_const_iterator<V>::operator++ template <class V, class K, class HF, class Ex, class Eq, class A> template <typename... Args> -std::pair<typename THashTable<V, K, HF, Ex, Eq, A>::iterator, bool> THashTable<V, K, HF, Ex, Eq, A>::emplace_unique_noresize(Args&&... args) { +std::pair<typename THashTable<V, K, HF, Ex, Eq, A>::iterator, bool> THashTable<V, K, HF, Ex, Eq, A>::emplace_unique_noresize(Args&&... args) { auto deleter = [&](node* tmp) { delete_node(tmp); }; node* tmp = new_node(std::forward<Args>(args)...); std::unique_ptr<node, decltype(deleter)> guard(tmp, deleter); @@ -1020,7 +1020,7 @@ std::pair<typename THashTable<V, K, HF, Ex, Eq, A>::iterator, bool> THashTable<V template <class V, class K, class HF, class Ex, class Eq, class A> template <class OtherValue> -std::pair<typename THashTable<V, K, HF, Ex, Eq, A>::iterator, bool> THashTable<V, K, HF, Ex, Eq, A>::insert_unique_noresize(const OtherValue& obj) { +std::pair<typename THashTable<V, K, HF, Ex, Eq, A>::iterator, bool> THashTable<V, K, HF, Ex, Eq, A>::insert_unique_noresize(const OtherValue& obj) { const size_type n = bkt_num(obj); node* first = buckets[n]; @@ -1038,7 +1038,7 @@ std::pair<typename THashTable<V, K, HF, Ex, Eq, A>::iterator, bool> THashTable<V template <class V, class K, class HF, class Ex, class Eq, class A> template <typename... Args> -__yhashtable_iterator<V> THashTable<V, K, HF, Ex, Eq, A>::emplace_equal_noresize(Args&&... args) { +__yhashtable_iterator<V> THashTable<V, K, HF, Ex, Eq, A>::emplace_equal_noresize(Args&&... args) { auto deleter = [&](node* tmp) { delete_node(tmp); }; node* tmp = new_node(std::forward<Args>(args)...); std::unique_ptr<node, decltype(deleter)> guard(tmp, deleter); @@ -1064,7 +1064,7 @@ __yhashtable_iterator<V> THashTable<V, K, HF, Ex, Eq, A>::emplace_equal_noresize template <class V, class K, class HF, class Ex, class Eq, class A> template <class OtherValue> -typename THashTable<V, K, HF, Ex, Eq, A>::reference THashTable<V, K, HF, Ex, Eq, A>::find_or_insert(const OtherValue& v) { +typename THashTable<V, K, HF, Ex, Eq, A>::reference THashTable<V, K, HF, Ex, Eq, A>::find_or_insert(const OtherValue& v) { reserve(num_elements + 1); size_type n = bkt_num_key(get_key(v)); @@ -1084,7 +1084,7 @@ typename THashTable<V, K, HF, Ex, Eq, A>::reference THashTable<V, K, HF, Ex, Eq, template <class V, class K, class HF, class Ex, class Eq, class A> template <class OtherKey> -__yhashtable_iterator<V> THashTable<V, K, HF, Ex, Eq, A>::find_i(const OtherKey& key, insert_ctx& ins) { +__yhashtable_iterator<V> THashTable<V, K, HF, Ex, Eq, A>::find_i(const OtherKey& key, insert_ctx& ins) { size_type n = bkt_num_key(key); ins = &buckets[n]; node* first = buckets[n]; @@ -1098,7 +1098,7 @@ __yhashtable_iterator<V> THashTable<V, K, HF, Ex, Eq, A>::find_i(const OtherKey& template <class V, class K, class HF, class Ex, class Eq, class A> template <class OtherKey> -std::pair<__yhashtable_iterator<V>, __yhashtable_iterator<V>> THashTable<V, K, HF, Ex, Eq, A>::equal_range(const OtherKey& key) { +std::pair<__yhashtable_iterator<V>, __yhashtable_iterator<V>> THashTable<V, K, HF, Ex, Eq, A>::equal_range(const OtherKey& key) { using pii = std::pair<iterator, iterator>; const size_type n = bkt_num_key(key); node* first = buckets[n]; @@ -1121,7 +1121,7 @@ std::pair<__yhashtable_iterator<V>, __yhashtable_iterator<V>> THashTable<V, K, H template <class V, class K, class HF, class Ex, class Eq, class A> template <class OtherKey> -std::pair<__yhashtable_const_iterator<V>, __yhashtable_const_iterator<V>> THashTable<V, K, HF, Ex, Eq, A>::equal_range(const OtherKey& key) const { +std::pair<__yhashtable_const_iterator<V>, __yhashtable_const_iterator<V>> THashTable<V, K, HF, Ex, Eq, A>::equal_range(const OtherKey& key) const { using pii = std::pair<const_iterator, const_iterator>; const size_type n = bkt_num_key(key); const node* first = buckets[n]; @@ -1145,7 +1145,7 @@ std::pair<__yhashtable_const_iterator<V>, __yhashtable_const_iterator<V>> THashT template <class V, class K, class HF, class Ex, class Eq, class A> template <class OtherKey> -typename THashTable<V, K, HF, Ex, Eq, A>::size_type THashTable<V, K, HF, Ex, Eq, A>::erase(const OtherKey& key) { +typename THashTable<V, K, HF, Ex, Eq, A>::size_type THashTable<V, K, HF, Ex, Eq, A>::erase(const OtherKey& key) { const size_type n = bkt_num_key(key); node* first = buckets[n]; size_type erased = 0; @@ -1177,7 +1177,7 @@ typename THashTable<V, K, HF, Ex, Eq, A>::size_type THashTable<V, K, HF, Ex, Eq, template <class V, class K, class HF, class Ex, class Eq, class A> template <class OtherKey> -typename THashTable<V, K, HF, Ex, Eq, A>::size_type THashTable<V, K, HF, Ex, Eq, A>::erase_one(const OtherKey& key) { +typename THashTable<V, K, HF, Ex, Eq, A>::size_type THashTable<V, K, HF, Ex, Eq, A>::erase_one(const OtherKey& key) { const size_type n = bkt_num_key(key); node* first = buckets[n]; @@ -1206,7 +1206,7 @@ typename THashTable<V, K, HF, Ex, Eq, A>::size_type THashTable<V, K, HF, Ex, Eq, } template <class V, class K, class HF, class Ex, class Eq, class A> -void THashTable<V, K, HF, Ex, Eq, A>::erase(const iterator& it) { +void THashTable<V, K, HF, Ex, Eq, A>::erase(const iterator& it) { if (node* const p = it.cur) { const size_type n = bkt_num(p->val); node* cur = buckets[n]; @@ -1233,7 +1233,7 @@ void THashTable<V, K, HF, Ex, Eq, A>::erase(const iterator& it) { } template <class V, class K, class HF, class Ex, class Eq, class A> -void THashTable<V, K, HF, Ex, Eq, A>::erase(iterator first, iterator last) { +void THashTable<V, K, HF, Ex, Eq, A>::erase(iterator first, iterator last) { size_type f_bucket = first.cur ? bkt_num(first.cur->val) : buckets.size(); /*y*/ size_type l_bucket = last.cur ? bkt_num(last.cur->val) : buckets.size(); /*y*/ @@ -1252,22 +1252,22 @@ void THashTable<V, K, HF, Ex, Eq, A>::erase(iterator first, iterator last) { template <class V, class K, class HF, class Ex, class Eq, class A> inline void -THashTable<V, K, HF, Ex, Eq, A>::erase(const_iterator first, const_iterator last) { +THashTable<V, K, HF, Ex, Eq, A>::erase(const_iterator first, const_iterator last) { erase(iterator(const_cast<node*>(first.cur)), iterator(const_cast<node*>(last.cur))); } template <class V, class K, class HF, class Ex, class Eq, class A> -inline void THashTable<V, K, HF, Ex, Eq, A>::erase(const const_iterator& it) { +inline void THashTable<V, K, HF, Ex, Eq, A>::erase(const const_iterator& it) { erase(iterator(const_cast<node*>(it.cur))); } template <class V, class K, class HF, class Ex, class Eq, class A> -bool THashTable<V, K, HF, Ex, Eq, A>::reserve(size_type num_elements_hint) { +bool THashTable<V, K, HF, Ex, Eq, A>::reserve(size_type num_elements_hint) { const size_type old_n = buckets.size(); /*y*/ if (num_elements_hint + 1 > old_n) { - if (old_n != 1 && num_elements_hint <= old_n) // TODO: this if is for backwards compatibility down to order-in-buckets level. Can be safely removed. - return false; - + if (old_n != 1 && num_elements_hint <= old_n) // TODO: this if is for backwards compatibility down to order-in-buckets level. Can be safely removed. + return false; + const TBucketDivisor n = HashBucketCountExt(num_elements_hint + 1, buckets.BucketDivisorHint() + 1); if (n() > old_n) { buckets_type tmp(buckets.get_allocator()); @@ -1311,7 +1311,7 @@ bool THashTable<V, K, HF, Ex, Eq, A>::reserve(size_type num_elements_hint) { } template <class V, class K, class HF, class Ex, class Eq, class A> -void THashTable<V, K, HF, Ex, Eq, A>::erase_bucket(const size_type n, node* first, node* last) { +void THashTable<V, K, HF, Ex, Eq, A>::erase_bucket(const size_type n, node* first, node* last) { node* cur = buckets[n]; if (cur == first) erase_bucket(n, last); @@ -1329,7 +1329,7 @@ void THashTable<V, K, HF, Ex, Eq, A>::erase_bucket(const size_type n, node* firs } template <class V, class K, class HF, class Ex, class Eq, class A> -void THashTable<V, K, HF, Ex, Eq, A>::erase_bucket(const size_type n, node* last) { +void THashTable<V, K, HF, Ex, Eq, A>::erase_bucket(const size_type n, node* last) { node* cur = buckets[n]; while (cur != last) { node* next = cur->next; @@ -1341,7 +1341,7 @@ void THashTable<V, K, HF, Ex, Eq, A>::erase_bucket(const size_type n, node* last } template <class V, class K, class HF, class Ex, class Eq, class A> -void THashTable<V, K, HF, Ex, Eq, A>::basic_clear() { +void THashTable<V, K, HF, Ex, Eq, A>::basic_clear() { if (!num_elements) { return; } @@ -1363,7 +1363,7 @@ void THashTable<V, K, HF, Ex, Eq, A>::basic_clear() { } template <class V, class K, class HF, class Ex, class Eq, class A> -void THashTable<V, K, HF, Ex, Eq, A>::copy_from_dynamic(const THashTable& ht) { +void THashTable<V, K, HF, Ex, Eq, A>::copy_from_dynamic(const THashTable& ht) { Y_ASSERT(buckets.size() == ht.buckets.size() && !ht.empty()); #ifdef __STL_USE_EXCEPTIONS @@ -1392,29 +1392,29 @@ void THashTable<V, K, HF, Ex, Eq, A>::copy_from_dynamic(const THashTable& ht) { namespace NPrivate { template <class Key> - inline TString MapKeyToString(const Key&) { + inline TString MapKeyToString(const Key&) { return TypeName<Key>(); } - TString MapKeyToString(TStringBuf key); - TString MapKeyToString(unsigned short key); - TString MapKeyToString(short key); - TString MapKeyToString(unsigned int key); - TString MapKeyToString(int key); - TString MapKeyToString(unsigned long key); - TString MapKeyToString(long key); - TString MapKeyToString(unsigned long long key); - TString MapKeyToString(long long key); + TString MapKeyToString(TStringBuf key); + TString MapKeyToString(unsigned short key); + TString MapKeyToString(short key); + TString MapKeyToString(unsigned int key); + TString MapKeyToString(int key); + TString MapKeyToString(unsigned long key); + TString MapKeyToString(long key); + TString MapKeyToString(unsigned long long key); + TString MapKeyToString(long long key); - inline TString MapKeyToString(const TString& key) { + inline TString MapKeyToString(const TString& key) { return MapKeyToString(TStringBuf(key)); } - inline TString MapKeyToString(const char* key) { + inline TString MapKeyToString(const char* key) { return MapKeyToString(TStringBuf(key)); } - inline TString MapKeyToString(char* key) { + inline TString MapKeyToString(char* key) { return MapKeyToString(TStringBuf(key)); } @@ -1422,9 +1422,9 @@ namespace NPrivate { } template <class Key, class T, class HashFcn, class EqualKey, class Alloc> -class THashMap: public TMapOps<THashMap<Key, T, HashFcn, EqualKey, Alloc>> { +class THashMap: public TMapOps<THashMap<Key, T, HashFcn, EqualKey, Alloc>> { private: - using ht = THashTable<std::pair<const Key, T>, Key, HashFcn, TSelect1st, EqualKey, Alloc>; + using ht = THashTable<std::pair<const Key, T>, Key, HashFcn, TSelect1st, EqualKey, Alloc>; ht rep; public: @@ -1455,60 +1455,60 @@ public: } public: - THashMap() + THashMap() : rep(0, hasher(), key_equal()) { } template <class TAllocParam> - explicit THashMap(TAllocParam* allocParam, size_type n = 0) + explicit THashMap(TAllocParam* allocParam, size_type n = 0) : rep(n, hasher(), key_equal(), allocParam) { } - explicit THashMap(size_type n) + explicit THashMap(size_type n) : rep(n, hasher(), key_equal()) { } - THashMap(size_type n, const hasher& hf) + THashMap(size_type n, const hasher& hf) : rep(n, hf, key_equal()) { } - THashMap(size_type n, const hasher& hf, const key_equal& eql) + THashMap(size_type n, const hasher& hf, const key_equal& eql) : rep(n, hf, eql) { } template <class TAllocParam> - explicit THashMap(size_type n, TAllocParam* allocParam) + explicit THashMap(size_type n, TAllocParam* allocParam) : rep(n, hasher(), key_equal(), allocParam) { } template <class InputIterator> - THashMap(InputIterator f, InputIterator l) + THashMap(InputIterator f, InputIterator l) : rep(0, hasher(), key_equal()) { rep.insert_unique(f, l); } template <class InputIterator> - THashMap(InputIterator f, InputIterator l, size_type n) + THashMap(InputIterator f, InputIterator l, size_type n) : rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); } template <class InputIterator> - THashMap(InputIterator f, InputIterator l, size_type n, + THashMap(InputIterator f, InputIterator l, size_type n, const hasher& hf) : rep(n, hf, key_equal()) { rep.insert_unique(f, l); } template <class InputIterator> - THashMap(InputIterator f, InputIterator l, size_type n, + THashMap(InputIterator f, InputIterator l, size_type n, const hasher& hf, const key_equal& eql) : rep(n, hf, eql) { rep.insert_unique(f, l); } - THashMap(const std::initializer_list<std::pair<Key, T>>& list) + THashMap(const std::initializer_list<std::pair<Key, T>>& list) : rep(list.size(), hasher(), key_equal()) { for (const auto& v : list) { @@ -1516,8 +1516,8 @@ public: } } - // THashMap has implicit copy/move constructors and copy-/move-assignment operators - // because its implementation is backed by THashTable. + // THashMap has implicit copy/move constructors and copy-/move-assignment operators + // because its implementation is backed by THashTable. // See hash_ut.cpp public: @@ -1537,7 +1537,7 @@ public: explicit operator bool() const noexcept { return !empty(); } - void swap(THashMap& hs) { + void swap(THashMap& hs) { rep.swap(hs.rep); } @@ -1735,7 +1735,7 @@ public: }; template <class Key, class T, class HashFcn, class EqualKey, class Alloc> -inline bool operator==(const THashMap<Key, T, HashFcn, EqualKey, Alloc>& hm1, const THashMap<Key, T, HashFcn, EqualKey, Alloc>& hm2) { +inline bool operator==(const THashMap<Key, T, HashFcn, EqualKey, Alloc>& hm1, const THashMap<Key, T, HashFcn, EqualKey, Alloc>& hm2) { if (hm1.size() != hm2.size()) { return false; } @@ -1749,14 +1749,14 @@ inline bool operator==(const THashMap<Key, T, HashFcn, EqualKey, Alloc>& hm1, co } template <class Key, class T, class HashFcn, class EqualKey, class Alloc> -inline bool operator!=(const THashMap<Key, T, HashFcn, EqualKey, Alloc>& hm1, const THashMap<Key, T, HashFcn, EqualKey, Alloc>& hm2) { +inline bool operator!=(const THashMap<Key, T, HashFcn, EqualKey, Alloc>& hm1, const THashMap<Key, T, HashFcn, EqualKey, Alloc>& hm2) { return !(hm1 == hm2); } template <class Key, class T, class HashFcn, class EqualKey, class Alloc> -class THashMultiMap { +class THashMultiMap { private: - using ht = THashTable<std::pair<const Key, T>, Key, HashFcn, TSelect1st, EqualKey, Alloc>; + using ht = THashTable<std::pair<const Key, T>, Key, HashFcn, TSelect1st, EqualKey, Alloc>; ht rep; public: @@ -1786,54 +1786,54 @@ public: } public: - THashMultiMap() + THashMultiMap() : rep(0, hasher(), key_equal()) { } template <typename TAllocParam> - explicit THashMultiMap(TAllocParam* allocParam) + explicit THashMultiMap(TAllocParam* allocParam) : rep(0, hasher(), key_equal(), allocParam) { } - explicit THashMultiMap(size_type n) + explicit THashMultiMap(size_type n) : rep(n, hasher(), key_equal()) { } - THashMultiMap(size_type n, const hasher& hf) + THashMultiMap(size_type n, const hasher& hf) : rep(n, hf, key_equal()) { } - THashMultiMap(size_type n, const hasher& hf, const key_equal& eql) + THashMultiMap(size_type n, const hasher& hf, const key_equal& eql) : rep(n, hf, eql) { } template <class InputIterator> - THashMultiMap(InputIterator f, InputIterator l) + THashMultiMap(InputIterator f, InputIterator l) : rep(0, hasher(), key_equal()) { rep.insert_equal(f, l); } template <class InputIterator> - THashMultiMap(InputIterator f, InputIterator l, size_type n) + THashMultiMap(InputIterator f, InputIterator l, size_type n) : rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); } template <class InputIterator> - THashMultiMap(InputIterator f, InputIterator l, size_type n, const hasher& hf) + THashMultiMap(InputIterator f, InputIterator l, size_type n, const hasher& hf) : rep(n, hf, key_equal()) { rep.insert_equal(f, l); } template <class InputIterator> - THashMultiMap(InputIterator f, InputIterator l, size_type n, const hasher& hf, const key_equal& eql) + THashMultiMap(InputIterator f, InputIterator l, size_type n, const hasher& hf, const key_equal& eql) : rep(n, hf, eql) { rep.insert_equal(f, l); } - THashMultiMap(std::initializer_list<std::pair<Key, T>> list) + THashMultiMap(std::initializer_list<std::pair<Key, T>> list) : rep(list.size(), hasher(), key_equal()) { for (const auto& v : list) { @@ -1841,8 +1841,8 @@ public: } } - // THashMultiMap has implicit copy/move constructors and copy-/move-assignment operators - // because its implementation is backed by THashTable. + // THashMultiMap has implicit copy/move constructors and copy-/move-assignment operators + // because its implementation is backed by THashTable. // See hash_ut.cpp public: @@ -1862,7 +1862,7 @@ public: explicit operator bool() const noexcept { return !empty(); } - void swap(THashMultiMap& hs) { + void swap(THashMultiMap& hs) { rep.swap(hs.rep); } @@ -1995,14 +1995,14 @@ public: }; template <class Key, class T, class HF, class EqKey, class Alloc> -inline bool operator==(const THashMultiMap<Key, T, HF, EqKey, Alloc>& hm1, const THashMultiMap<Key, T, HF, EqKey, Alloc>& hm2) { +inline bool operator==(const THashMultiMap<Key, T, HF, EqKey, Alloc>& hm1, const THashMultiMap<Key, T, HF, EqKey, Alloc>& hm2) { // NOTE: copy-pasted from // contrib/libs/cxxsupp/libcxx/include/unordered_map - // and adapted to THashMultiMap + // and adapted to THashMultiMap if (hm1.size() != hm2.size()) { return false; } - using const_iterator = typename THashMultiMap<Key, T, HF, EqKey, Alloc>::const_iterator; + using const_iterator = typename THashMultiMap<Key, T, HF, EqKey, Alloc>::const_iterator; using TEqualRange = std::pair<const_iterator, const_iterator>; for (const_iterator it = hm1.begin(), end = hm1.end(); it != end;) { TEqualRange eq1 = hm1.equal_range(it->first); @@ -2018,7 +2018,7 @@ inline bool operator==(const THashMultiMap<Key, T, HF, EqKey, Alloc>& hm1, const } template <class Key, class T, class HF, class EqKey, class Alloc> -inline bool operator!=(const THashMultiMap<Key, T, HF, EqKey, Alloc>& hm1, const THashMultiMap<Key, T, HF, EqKey, Alloc>& hm2) { +inline bool operator!=(const THashMultiMap<Key, T, HF, EqKey, Alloc>& hm1, const THashMultiMap<Key, T, HF, EqKey, Alloc>& hm2) { return !(hm1 == hm2); } diff --git a/util/generic/hash.pxd b/util/generic/hash.pxd index 385c10d805..fd24d1ef27 100644 --- a/util/generic/hash.pxd +++ b/util/generic/hash.pxd @@ -1,7 +1,7 @@ from libcpp.pair cimport pair cdef extern from "util/generic/hash.h" nogil: - cdef cppclass THashMap[T, U]: + cdef cppclass THashMap[T, U]: cppclass iterator: pair[T, U]& operator*() iterator operator++() @@ -22,17 +22,17 @@ cdef extern from "util/generic/hash.h" nogil: cppclass const_reverse_iterator(reverse_iterator): pass - THashMap() except + - THashMap(THashMap&) except + + THashMap() except + + THashMap(THashMap&) except + U& operator[](T&) - THashMap& operator=(THashMap&) + THashMap& operator=(THashMap&) - bint operator==(THashMap&) - bint operator!=(THashMap&) - bint operator<(THashMap&) - bint operator>(THashMap&) - bint operator<=(THashMap&) - bint operator>=(THashMap&) + bint operator==(THashMap&) + bint operator!=(THashMap&) + bint operator<(THashMap&) + bint operator>(THashMap&) + bint operator<=(THashMap&) + bint operator>=(THashMap&) U& at(T&) except + iterator begin() @@ -53,7 +53,7 @@ cdef extern from "util/generic/hash.h" nogil: iterator insert(iterator, pair[T, U]) # XXX pair[T,U]& size_t max_size() size_t size() - void swap(THashMap&) + void swap(THashMap&) iterator lower_bound(T&) const_iterator const_lower_bound "lower_bound"(T&) reverse_iterator rbegin() diff --git a/util/generic/hash_set.h b/util/generic/hash_set.h index e8088cf23b..7890b7ab07 100644 --- a/util/generic/hash_set.h +++ b/util/generic/hash_set.h @@ -9,9 +9,9 @@ #undef value_type template <class Value, class HashFcn, class EqualKey, class Alloc> -class THashSet { +class THashSet { private: - using ht = THashTable<Value, Value, HashFcn, ::TIdentity, EqualKey, Alloc>; + using ht = THashTable<Value, Value, HashFcn, ::TIdentity, EqualKey, Alloc>; ht rep; using mutable_iterator = typename ht::iterator; @@ -43,76 +43,76 @@ public: } public: - THashSet() { + THashSet() { } template <class TT> - explicit THashSet(TT* allocParam, size_type n = 0) + explicit THashSet(TT* allocParam, size_type n = 0) : rep(n, hasher(), key_equal(), allocParam) { } - explicit THashSet(size_type n) + explicit THashSet(size_type n) : rep(n, hasher(), key_equal()) { } - THashSet(size_type n, const hasher& hf) + THashSet(size_type n, const hasher& hf) : rep(n, hf, key_equal()) { } - THashSet(size_type n, const hasher& hf, const key_equal& eql) + THashSet(size_type n, const hasher& hf, const key_equal& eql) : rep(n, hf, eql) { } - THashSet(std::initializer_list<value_type> list) + THashSet(std::initializer_list<value_type> list) : rep(list.size(), hasher(), key_equal()) { rep.insert_unique(list.begin(), list.end()); } - THashSet(std::initializer_list<value_type> list, size_type n) + THashSet(std::initializer_list<value_type> list, size_type n) : rep(n, hasher(), key_equal()) { rep.insert_unique(list.begin(), list.end()); } - THashSet(std::initializer_list<value_type> list, size_type n, const hasher& hf) + THashSet(std::initializer_list<value_type> list, size_type n, const hasher& hf) : rep(n, hf, key_equal()) { rep.insert_unique(list.begin(), list.end()); } - THashSet(std::initializer_list<value_type> list, size_type n, const hasher& hf, const key_equal& eql) + THashSet(std::initializer_list<value_type> list, size_type n, const hasher& hf, const key_equal& eql) : rep(n, hf, eql) { rep.insert_unique(list.begin(), list.end()); } template <class InputIterator> - THashSet(InputIterator f, InputIterator l) + THashSet(InputIterator f, InputIterator l) : rep(0, hasher(), key_equal()) { rep.insert_unique(f, l); } template <class InputIterator> - THashSet(InputIterator f, InputIterator l, size_type n) + THashSet(InputIterator f, InputIterator l, size_type n) : rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); } template <class InputIterator> - THashSet(InputIterator f, InputIterator l, size_type n, + THashSet(InputIterator f, InputIterator l, size_type n, const hasher& hf) : rep(n, hf, key_equal()) { rep.insert_unique(f, l); } template <class InputIterator> - THashSet(InputIterator f, InputIterator l, size_type n, + THashSet(InputIterator f, InputIterator l, size_type n, const hasher& hf, const key_equal& eql) : rep(n, hf, eql) { rep.insert_unique(f, l); } - // THashSet has implicit copy/move constructors and copy-/move-assignment operators - // because its implementation is backed by THashTable. + // THashSet has implicit copy/move constructors and copy-/move-assignment operators + // because its implementation is backed by THashTable. // See hash_ut.cpp public: @@ -129,7 +129,7 @@ public: explicit operator bool() const noexcept { return !empty(); } - void swap(THashSet& hs) { + void swap(THashSet& hs) { rep.swap(hs.rep); } @@ -261,7 +261,7 @@ public: }; template <class Value, class HashFcn, class EqualKey, class Alloc> -inline bool operator==(const THashSet<Value, HashFcn, EqualKey, Alloc>& hs1, const THashSet<Value, HashFcn, EqualKey, Alloc>& hs2) { +inline bool operator==(const THashSet<Value, HashFcn, EqualKey, Alloc>& hs1, const THashSet<Value, HashFcn, EqualKey, Alloc>& hs2) { if (hs1.size() != hs2.size()) { return false; } @@ -274,14 +274,14 @@ inline bool operator==(const THashSet<Value, HashFcn, EqualKey, Alloc>& hs1, con } template <class Value, class HashFcn, class EqualKey, class Alloc> -inline bool operator!=(const THashSet<Value, HashFcn, EqualKey, Alloc>& hs1, const THashSet<Value, HashFcn, EqualKey, Alloc>& hs2) { +inline bool operator!=(const THashSet<Value, HashFcn, EqualKey, Alloc>& hs1, const THashSet<Value, HashFcn, EqualKey, Alloc>& hs2) { return !(hs1 == hs2); } template <class Value, class HashFcn, class EqualKey, class Alloc> -class THashMultiSet { +class THashMultiSet { private: - using ht = THashTable<Value, Value, HashFcn, ::TIdentity, EqualKey, Alloc>; + using ht = THashTable<Value, Value, HashFcn, ::TIdentity, EqualKey, Alloc>; ht rep; public: @@ -310,58 +310,58 @@ public: } public: - THashMultiSet() + THashMultiSet() : rep(0, hasher(), key_equal()) { } - explicit THashMultiSet(size_type n) + explicit THashMultiSet(size_type n) : rep(n, hasher(), key_equal()) { } - THashMultiSet(size_type n, const hasher& hf) + THashMultiSet(size_type n, const hasher& hf) : rep(n, hf, key_equal()) { } - THashMultiSet(size_type n, const hasher& hf, const key_equal& eql) + THashMultiSet(size_type n, const hasher& hf, const key_equal& eql) : rep(n, hf, eql) { } template <class InputIterator> - THashMultiSet(InputIterator f, InputIterator l) + THashMultiSet(InputIterator f, InputIterator l) : rep(0, hasher(), key_equal()) { rep.insert_equal(f, l); } template <class InputIterator> - THashMultiSet(InputIterator f, InputIterator l, size_type n) + THashMultiSet(InputIterator f, InputIterator l, size_type n) : rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); } template <class InputIterator> - THashMultiSet(InputIterator f, InputIterator l, size_type n, + THashMultiSet(InputIterator f, InputIterator l, size_type n, const hasher& hf) : rep(n, hf, key_equal()) { rep.insert_equal(f, l); } template <class InputIterator> - THashMultiSet(InputIterator f, InputIterator l, size_type n, + THashMultiSet(InputIterator f, InputIterator l, size_type n, const hasher& hf, const key_equal& eql) : rep(n, hf, eql) { rep.insert_equal(f, l); } - THashMultiSet(std::initializer_list<value_type> list) + THashMultiSet(std::initializer_list<value_type> list) : rep(list.size(), hasher(), key_equal()) { rep.insert_equal(list.begin(), list.end()); } - // THashMultiSet has implicit copy/move constructors and copy-/move-assignment operators - // because its implementation is backed by THashTable. + // THashMultiSet has implicit copy/move constructors and copy-/move-assignment operators + // because its implementation is backed by THashTable. // See hash_ut.cpp public: @@ -378,7 +378,7 @@ public: explicit operator bool() const noexcept { return !empty(); } - void swap(THashMultiSet& hs) { + void swap(THashMultiSet& hs) { rep.swap(hs.rep); } @@ -464,7 +464,7 @@ public: }; template <class Val, class HashFcn, class EqualKey, class Alloc> -inline bool operator==(const THashMultiSet<Val, HashFcn, EqualKey, Alloc>& hs1, const THashMultiSet<Val, HashFcn, EqualKey, Alloc>& hs2) { +inline bool operator==(const THashMultiSet<Val, HashFcn, EqualKey, Alloc>& hs1, const THashMultiSet<Val, HashFcn, EqualKey, Alloc>& hs2) { if (hs1.size() != hs2.size()) { return false; } @@ -483,6 +483,6 @@ inline bool operator==(const THashMultiSet<Val, HashFcn, EqualKey, Alloc>& hs1, } template <class Val, class HashFcn, class EqualKey, class Alloc> -inline bool operator!=(const THashMultiSet<Val, HashFcn, EqualKey, Alloc>& hs1, const THashMultiSet<Val, HashFcn, EqualKey, Alloc>& hs2) { +inline bool operator!=(const THashMultiSet<Val, HashFcn, EqualKey, Alloc>& hs1, const THashMultiSet<Val, HashFcn, EqualKey, Alloc>& hs2) { return !(hs1 == hs2); } diff --git a/util/generic/hash_ut.cpp b/util/generic/hash_ut.cpp index 0551d58770..12de252a26 100644 --- a/util/generic/hash_ut.cpp +++ b/util/generic/hash_ut.cpp @@ -61,7 +61,7 @@ class THashTest: public TTestBase { UNIT_TEST(TestTupleHash); UNIT_TEST_SUITE_END(); - using hmset = THashMultiSet<char, hash<char>, TEqualTo<char>>; + using hmset = THashMultiSet<char, hash<char>, TEqualTo<char>>; protected: void TestHMapConstructorsAndAssignments(); @@ -115,7 +115,7 @@ protected: UNIT_TEST_SUITE_REGISTRATION(THashTest); void THashTest::TestHMapConstructorsAndAssignments() { - using container = THashMap<TString, int>; + using container = THashMap<TString, int>; container c1; c1["one"] = 1; @@ -166,7 +166,7 @@ void THashTest::TestHMapConstructorsAndAssignments() { } void THashTest::TestHMap1() { - using maptype = THashMap<char, TString, THash<char>, TEqualTo<char>>; + using maptype = THashMap<char, TString, THash<char>, TEqualTo<char>>; maptype m; // Store mappings between roman numerals and decimals. m['l'] = "50"; @@ -182,11 +182,11 @@ void THashTest::TestHMap1() { UNIT_ASSERT(m.contains('z')); UNIT_ASSERT(m.count('z') == 1); - auto p = m.insert(std::pair<const char, TString>('c', TString("100"))); + auto p = m.insert(std::pair<const char, TString>('c', TString("100"))); UNIT_ASSERT(p.second); - p = m.insert(std::pair<const char, TString>('c', TString("100"))); + p = m.insert(std::pair<const char, TString>('c', TString("100"))); UNIT_ASSERT(!p.second); //Some iterators compare check, really compile time checks @@ -203,7 +203,7 @@ void THashTest::TestHMap1() { } void THashTest::TestHMapEqualityOperator() { - using container = THashMap<TString, int>; + using container = THashMap<TString, int>; container base; base["one"] = 1; @@ -226,7 +226,7 @@ void THashTest::TestHMapEqualityOperator() { } void THashTest::TestHMMapEqualityOperator() { - using container = THashMultiMap<TString, int>; + using container = THashMultiMap<TString, int>; using value = container::value_type; container base; @@ -261,7 +261,7 @@ void THashTest::TestHMMapEqualityOperator() { } void THashTest::TestHMMapConstructorsAndAssignments() { - using container = THashMultiMap<TString, int>; + using container = THashMultiMap<TString, int>; container c1; c1.insert(container::value_type("one", 1)); @@ -291,7 +291,7 @@ void THashTest::TestHMMapConstructorsAndAssignments() { } void THashTest::TestHMMap1() { - using mmap = THashMultiMap<char, int, THash<char>, TEqualTo<char>>; + using mmap = THashMultiMap<char, int, THash<char>, TEqualTo<char>>; mmap m; UNIT_ASSERT(m.count('X') == 0); @@ -329,7 +329,7 @@ void THashTest::TestHMMap1() { UNIT_ASSERT(cite == (mmap::const_iterator)ite); UNIT_ASSERT(!(cite != (mmap::const_iterator)ite)); - using HMapType = THashMultiMap<size_t, size_t>; + using HMapType = THashMultiMap<size_t, size_t>; HMapType hmap; //We fill the map to implicitely start a rehash. @@ -356,7 +356,7 @@ void THashTest::TestHMMap1() { } void THashTest::TestHMMapHas() { - using mmap = THashMultiMap<char, int, THash<char>, TEqualTo<char>>; + using mmap = THashMultiMap<char, int, THash<char>, TEqualTo<char>>; mmap m; m.insert(std::pair<const char, int>('X', 10)); m.insert(std::pair<const char, int>('X', 20)); @@ -367,7 +367,7 @@ void THashTest::TestHMMapHas() { } void THashTest::TestHSetConstructorsAndAssignments() { - using container = THashSet<int>; + using container = THashSet<int>; container c1; c1.insert(100); @@ -408,7 +408,7 @@ void THashTest::TestHSetConstructorsAndAssignments() { } void THashTest::TestHSetSize() { - using container = THashSet<int>; + using container = THashSet<int>; container c; c.insert(100); @@ -422,7 +422,7 @@ void THashTest::TestHSetSize() { } void THashTest::TestHSet2() { - THashSet<int, THash<int>, TEqualTo<int>> s; + THashSet<int, THash<int>, TEqualTo<int>> s; auto p = s.insert(42); UNIT_ASSERT(p.second); UNIT_ASSERT(*(p.first) == 42); @@ -432,7 +432,7 @@ void THashTest::TestHSet2() { } void THashTest::TestHSetEqualityOperator() { - using container = THashSet<int>; + using container = THashSet<int>; container base; base.insert(1); @@ -458,7 +458,7 @@ void THashTest::TestHSetEqualityOperator() { } void THashTest::TestHMSetConstructorsAndAssignments() { - using container = THashMultiSet<int>; + using container = THashMultiSet<int>; container c1; c1.insert(100); @@ -493,7 +493,7 @@ void THashTest::TestHMSetConstructorsAndAssignments() { } void THashTest::TestHMSetSize() { - using container = THashMultiSet<int>; + using container = THashMultiSet<int>; container c; c.insert(100); @@ -523,7 +523,7 @@ void THashTest::TestHMSet1() { } void THashTest::TestHMSetEqualityOperator() { - using container = THashMultiSet<int>; + using container = THashMultiSet<int>; container base; base.insert(1); @@ -605,7 +605,7 @@ void THashTest::TestHMSetEmplace() { } void THashTest::TestInsertErase() { - using hmap = THashMap<TString, size_t, THash<TString>, TEqualTo<TString>>; + using hmap = THashMap<TString, size_t, THash<TString>, TEqualTo<TString>>; using val_type = hmap::value_type; { @@ -635,10 +635,10 @@ void THashTest::TestInsertErase() { namespace { struct TItem: public TSimpleRefCount<TItem> { - const TString Key; - const TString Value; + const TString Key; + const TString Value; - TItem(const TString& key, const TString& value) + TItem(const TString& key, const TString& value) : Key(key) , Value(value) { @@ -648,26 +648,26 @@ namespace { using TItemPtr = TIntrusivePtr<TItem>; struct TSelectKey { - const TString& operator()(const TItemPtr& item) const { + const TString& operator()(const TItemPtr& item) const { return item->Key; } }; - using TItemMapBase = THashTable< + using TItemMapBase = THashTable< TItemPtr, - TString, - THash<TString>, + TString, + THash<TString>, TSelectKey, - TEqualTo<TString>, + TEqualTo<TString>, std::allocator<TItemPtr>>; struct TItemMap: public TItemMapBase { TItemMap() - : TItemMapBase(1, THash<TString>(), TEqualTo<TString>()) + : TItemMapBase(1, THash<TString>(), TEqualTo<TString>()) { } - TItem& Add(const TString& key, const TString& value) { + TItem& Add(const TString& key, const TString& value) { insert_ctx ins; iterator it = find_i(key, ins); if (it == end()) { @@ -701,13 +701,13 @@ static void EmptyAndInsertTest(typename T::value_type v) { } void THashTest::TestEmpty() { - EmptyAndInsertTest<THashSet<int>>(1); - EmptyAndInsertTest<THashMap<int, int>>(std::pair<int, int>(1, 2)); - EmptyAndInsertTest<THashMultiMap<int, int>>(std::pair<int, int>(1, 2)); + EmptyAndInsertTest<THashSet<int>>(1); + EmptyAndInsertTest<THashMap<int, int>>(std::pair<int, int>(1, 2)); + EmptyAndInsertTest<THashMultiMap<int, int>>(std::pair<int, int>(1, 2)); } void THashTest::TestDefaultConstructor() { - THashSet<int> set; + THashSet<int> set; UNIT_ASSERT(set.begin() == set.end()); @@ -719,18 +719,18 @@ void THashTest::TestDefaultConstructor() { void THashTest::TestSizeOf() { /* This test checks that we don't waste memory when all functors passed to - * THashTable are empty. It does rely on knowledge of THashTable internals, + * THashTable are empty. It does rely on knowledge of THashTable internals, * so if those change, the test will have to be adjusted accordingly. */ size_t expectedSize = sizeof(uintptr_t) + 3 * sizeof(size_t); - UNIT_ASSERT_VALUES_EQUAL(sizeof(THashMap<int, int>), expectedSize); - UNIT_ASSERT_VALUES_EQUAL(sizeof(THashMap<std::pair<int, int>, std::pair<int, int>>), expectedSize); + UNIT_ASSERT_VALUES_EQUAL(sizeof(THashMap<int, int>), expectedSize); + UNIT_ASSERT_VALUES_EQUAL(sizeof(THashMap<std::pair<int, int>, std::pair<int, int>>), expectedSize); } void THashTest::TestInvariants() { std::set<int> reference_set; - THashSet<int> set; + THashSet<int> set; for (int i = 0; i < 1000; i++) { set.insert(i); @@ -775,7 +775,7 @@ struct TAllocatorCounters { size_t Allocations; size_t Deallocations; - TSet<std::pair<void*, size_t>> Chunks; + TSet<std::pair<void*, size_t>> Chunks; }; template <class T> @@ -834,7 +834,7 @@ private: void THashTest::TestAllocation() { TAllocatorCounters counters; - using int_set = THashSet<int, THash<int>, TEqualTo<int>, TCountingAllocator<int>>; + using int_set = THashSet<int, THash<int>, TEqualTo<int>, TCountingAllocator<int>>; { int_set set0(&counters); @@ -881,14 +881,14 @@ public: }; void THashTest::TestInsertCopy() { - THashMap<int, int> hash; + THashMap<int, int> hash; /* Insertion should not make copies of the provided key. */ hash[TNonCopyableInt<0>(0)] = 0; } void THashTest::TestEmplace() { - using hash_t = THashMap<int, TNonCopyableInt<0>>; + using hash_t = THashMap<int, TNonCopyableInt<0>>; hash_t hash; hash.emplace(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); auto it = hash.find(1); @@ -896,7 +896,7 @@ void THashTest::TestEmplace() { } void THashTest::TestEmplaceNoresize() { - using hash_t = THashMap<int, TNonCopyableInt<0>>; + using hash_t = THashMap<int, TNonCopyableInt<0>>; hash_t hash; hash.reserve(1); hash.emplace_noresize(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); @@ -905,7 +905,7 @@ void THashTest::TestEmplaceNoresize() { } void THashTest::TestEmplaceDirect() { - using hash_t = THashMap<int, TNonCopyableInt<0>>; + using hash_t = THashMap<int, TNonCopyableInt<0>>; hash_t hash; hash_t::insert_ctx ins; hash.find(1, ins); @@ -981,7 +981,7 @@ void THashTest::TestTryEmplaceCopyKey() { } void THashTest::TestHMMapEmplace() { - using hash_t = THashMultiMap<int, TNonCopyableInt<0>>; + using hash_t = THashMultiMap<int, TNonCopyableInt<0>>; hash_t hash; hash.emplace(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); auto it = hash.find(1); @@ -989,7 +989,7 @@ void THashTest::TestHMMapEmplace() { } void THashTest::TestHMMapEmplaceNoresize() { - using hash_t = THashMultiMap<int, TNonCopyableInt<0>>; + using hash_t = THashMultiMap<int, TNonCopyableInt<0>>; hash_t hash; hash.reserve(1); hash.emplace_noresize(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); @@ -998,7 +998,7 @@ void THashTest::TestHMMapEmplaceNoresize() { } void THashTest::TestHMMapEmplaceDirect() { - using hash_t = THashMultiMap<int, TNonCopyableInt<0>>; + using hash_t = THashMultiMap<int, TNonCopyableInt<0>>; hash_t hash; hash_t::insert_ctx ins; hash.find(1, ins); @@ -1008,7 +1008,7 @@ void THashTest::TestHMMapEmplaceDirect() { } void THashTest::TestHSetEmplace() { - using hash_t = THashSet<TNonCopyableInt<0>, THash<int>, TEqualTo<int>>; + using hash_t = THashSet<TNonCopyableInt<0>, THash<int>, TEqualTo<int>>; hash_t hash; UNIT_ASSERT(!hash.contains(0)); hash.emplace(0); @@ -1017,7 +1017,7 @@ void THashTest::TestHSetEmplace() { } void THashTest::TestHSetEmplaceNoresize() { - using hash_t = THashSet<TNonCopyableInt<0>, THash<int>, TEqualTo<int>>; + using hash_t = THashSet<TNonCopyableInt<0>, THash<int>, TEqualTo<int>>; hash_t hash; hash.reserve(1); UNIT_ASSERT(!hash.contains(0)); @@ -1027,7 +1027,7 @@ void THashTest::TestHSetEmplaceNoresize() { } void THashTest::TestHSetEmplaceDirect() { - using hash_t = THashSet<TNonCopyableInt<0>, THash<int>, TEqualTo<int>>; + using hash_t = THashSet<TNonCopyableInt<0>, THash<int>, TEqualTo<int>>; hash_t hash; UNIT_ASSERT(!hash.contains(0)); hash_t::insert_ctx ins; @@ -1049,7 +1049,7 @@ void THashTest::TestNonCopyable() { } }; - THashMap<int, TValue> hash; + THashMap<int, TValue> hash; hash.emplace(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(5)); auto&& value = hash[1]; UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(value), 5); @@ -1058,7 +1058,7 @@ void THashTest::TestNonCopyable() { } void THashTest::TestValueInitialization() { - THashMap<int, int> hash; + THashMap<int, int> hash; int& value = hash[0]; @@ -1070,21 +1070,21 @@ void THashTest::TestAssignmentClear() { /* This one tests that assigning an empty hash resets the buckets array. * See operator= for details. */ - THashMap<int, int> hash; + THashMap<int, int> hash; size_t emptyBucketCount = hash.bucket_count(); for (int i = 0; i < 100; i++) { hash[i] = i; } - hash = THashMap<int, int>(); + hash = THashMap<int, int>(); UNIT_ASSERT_VALUES_EQUAL(hash.bucket_count(), emptyBucketCount); } void THashTest::TestReleaseNodes() { TAllocatorCounters counters; - using TIntSet = THashSet<int, THash<int>, TEqualTo<int>, TCountingAllocator<int>>; + using TIntSet = THashSet<int, THash<int>, TEqualTo<int>, TCountingAllocator<int>>; TIntSet set(&counters); for (int i = 0; i < 3; i++) { @@ -1127,10 +1127,10 @@ void THashTest::TestAt() { } \ } - TEST_AT_THROWN_EXCEPTION(TString, TString, TString, "111", "111"); - TEST_AT_THROWN_EXCEPTION(TString, TString, const TString, "111", "111"); - TEST_AT_THROWN_EXCEPTION(TString, TString, TStringBuf, "111", "111"); - TEST_AT_THROWN_EXCEPTION(TString, TString, const TStringBuf, "111", "111"); + TEST_AT_THROWN_EXCEPTION(TString, TString, TString, "111", "111"); + TEST_AT_THROWN_EXCEPTION(TString, TString, const TString, "111", "111"); + TEST_AT_THROWN_EXCEPTION(TString, TString, TStringBuf, "111", "111"); + TEST_AT_THROWN_EXCEPTION(TString, TString, const TStringBuf, "111", "111"); TEST_AT_THROWN_EXCEPTION(TStringBuf, TStringBuf, const char*, "111", "111"); TEST_AT_THROWN_EXCEPTION(int, int, short, 11, "11"); TEST_AT_THROWN_EXCEPTION(int, int, int, -1, "-1"); @@ -1142,36 +1142,36 @@ void THashTest::TestAt() { TEST_AT_THROWN_EXCEPTION(int, int, unsigned long long, 1000000000000ll, "1000000000000"); char key[] = {11, 12, 0, 1, 2, 11, 0}; - TEST_AT_THROWN_EXCEPTION(TString, TString, char*, key, "\\x0B\\x0C"); + TEST_AT_THROWN_EXCEPTION(TString, TString, char*, key, "\\x0B\\x0C"); TEST_AT_THROWN_EXCEPTION(TString, TString, TStringBuf, TStringBuf(key, sizeof(key) - 1), "\\x0B\\x0C\\0\\1\\2\\x0B"); #undef TEST_AT_THROWN_EXCEPTION } void THashTest::TestHMapInitializerList() { - THashMap<TString, TString> h1 = {{"foo", "bar"}, {"bar", "baz"}, {"baz", "qux"}}; - THashMap<TString, TString> h2; - h2.insert(std::pair<TString, TString>("foo", "bar")); - h2.insert(std::pair<TString, TString>("bar", "baz")); - h2.insert(std::pair<TString, TString>("baz", "qux")); + THashMap<TString, TString> h1 = {{"foo", "bar"}, {"bar", "baz"}, {"baz", "qux"}}; + THashMap<TString, TString> h2; + h2.insert(std::pair<TString, TString>("foo", "bar")); + h2.insert(std::pair<TString, TString>("bar", "baz")); + h2.insert(std::pair<TString, TString>("baz", "qux")); UNIT_ASSERT_EQUAL(h1, h2); } void THashTest::TestHMMapInitializerList() { - THashMultiMap<TString, TString> h1 = { + THashMultiMap<TString, TString> h1 = { {"foo", "bar"}, {"foo", "baz"}, {"baz", "qux"}}; - THashMultiMap<TString, TString> h2; - h2.insert(std::pair<TString, TString>("foo", "bar")); - h2.insert(std::pair<TString, TString>("foo", "baz")); - h2.insert(std::pair<TString, TString>("baz", "qux")); + THashMultiMap<TString, TString> h2; + h2.insert(std::pair<TString, TString>("foo", "bar")); + h2.insert(std::pair<TString, TString>("foo", "baz")); + h2.insert(std::pair<TString, TString>("baz", "qux")); UNIT_ASSERT_EQUAL(h1, h2); } void THashTest::TestHSetInitializerList() { - THashSet<TString> h1 = {"foo", "bar", "baz"}; - THashSet<TString> h2; + THashSet<TString> h1 = {"foo", "bar", "baz"}; + THashSet<TString> h2; h2.insert("foo"); h2.insert("bar"); h2.insert("baz"); @@ -1179,8 +1179,8 @@ void THashTest::TestHSetInitializerList() { } void THashTest::TestHMSetInitializerList() { - THashMultiSet<TString> h1 = {"foo", "foo", "bar", "baz"}; - THashMultiSet<TString> h2; + THashMultiSet<TString> h1 = {"foo", "foo", "bar", "baz"}; + THashMultiSet<TString> h2; h2.insert("foo"); h2.insert("foo"); h2.insert("bar"); @@ -1213,20 +1213,20 @@ void Out<TFoo>(IOutputStream& o, const TFoo& v) { void THashTest::TestHSetInsertInitializerList() { { - const THashSet<int> x = {1}; - THashSet<int> y; + const THashSet<int> x = {1}; + THashSet<int> y; y.insert({1}); UNIT_ASSERT_VALUES_EQUAL(x, y); } { - const THashSet<int> x = {1, 2}; - THashSet<int> y; + const THashSet<int> x = {1, 2}; + THashSet<int> y; y.insert({1, 2}); UNIT_ASSERT_VALUES_EQUAL(x, y); } { - const THashSet<int> x = {1, 2, 3, 4, 5}; - THashSet<int> y; + const THashSet<int> x = {1, 2, 3, 4, 5}; + THashSet<int> y; y.insert({ 1, 2, @@ -1237,14 +1237,14 @@ void THashTest::TestHSetInsertInitializerList() { UNIT_ASSERT_VALUES_EQUAL(x, y); } { - const THashSet<TFoo> x = {{1, 2}}; - THashSet<TFoo> y; + const THashSet<TFoo> x = {{1, 2}}; + THashSet<TFoo> y; y.insert({{1, 2}}); UNIT_ASSERT_VALUES_EQUAL(x, y); } { - const THashSet<TFoo> x = {{1, 2}, {3, 4}}; - THashSet<TFoo> y; + const THashSet<TFoo> x = {{1, 2}, {3, 4}}; + THashSet<TFoo> y; y.insert({{1, 2}, {3, 4}}); UNIT_ASSERT_VALUES_EQUAL(x, y); } diff --git a/util/generic/hash_ut.pyx b/util/generic/hash_ut.pyx index ecf6dac2e6..ba630cecfd 100644 --- a/util/generic/hash_ut.pyx +++ b/util/generic/hash_ut.pyx @@ -1,6 +1,6 @@ # cython: c_string_type=str, c_string_encoding=utf8 -from util.generic.hash cimport THashMap +from util.generic.hash cimport THashMap from util.generic.string cimport TString import pytest @@ -10,17 +10,17 @@ from libcpp.pair cimport pair from cython.operator cimport dereference as deref -def _check_convert(THashMap[TString, int] x): +def _check_convert(THashMap[TString, int] x): return x class TestHash(unittest.TestCase): def test_constructors_and_assignments(self): - cdef THashMap[TString, int] c1 + cdef THashMap[TString, int] c1 c1["one"] = 1 c1["two"] = 2 - cdef THashMap[TString, int] c2 = THashMap[TString, int](c1) + cdef THashMap[TString, int] c2 = THashMap[TString, int](c1) self.assertEqual(2, c1.size()) self.assertEqual(2, c2.size()) self.assertEqual(1, c1.at("one")) @@ -34,14 +34,14 @@ class TestHash(unittest.TestCase): self.assertEqual(3, c1.at("three")) def test_equality_operator(self): - cdef THashMap[TString, int] base + cdef THashMap[TString, int] base base["one"] = 1 base["two"] = 2 - cdef THashMap[TString, int] c1 = THashMap[TString, int](base) + cdef THashMap[TString, int] c1 = THashMap[TString, int](base) self.assertTrue(c1==base) - cdef THashMap[TString, int] c2 + cdef THashMap[TString, int] c2 c2["one"] = 1 c2["two"] = 2 self.assertTrue(c2 == base) @@ -49,12 +49,12 @@ class TestHash(unittest.TestCase): c2["three"] = 3 self.assertTrue(c2 != base) - cdef THashMap[TString, int] c3 = THashMap[TString, int](base) + cdef THashMap[TString, int] c3 = THashMap[TString, int](base) c3["one"] = 0 self.assertTrue(c3 != base) def test_insert_erase(self): - cdef THashMap[TString, int] tmp + cdef THashMap[TString, int] tmp self.assertTrue(tmp.insert(pair[TString, int]("one", 0)).second) self.assertFalse(tmp.insert(pair[TString, int]("one", 1)).second) self.assertTrue(tmp.insert(pair[TString, int]("two", 2)).second) @@ -66,12 +66,12 @@ class TestHash(unittest.TestCase): self.assertTrue(tmp.empty()) def test_iterators_and_find(self): - cdef THashMap[TString, int] tmp + cdef THashMap[TString, int] tmp self.assertTrue(tmp.begin() == tmp.end()) self.assertTrue(tmp.find("1") == tmp.end()) tmp["1"] = 1 self.assertTrue(tmp.begin() != tmp.end()) - cdef THashMap[TString, int].iterator it = tmp.find("1") + cdef THashMap[TString, int].iterator it = tmp.find("1") self.assertTrue(it != tmp.end()) self.assertEqual(deref(it).second, 1) diff --git a/util/generic/intrlist.h b/util/generic/intrlist.h index b5d3f2051b..f90561e24c 100644 --- a/util/generic/intrlist.h +++ b/util/generic/intrlist.h @@ -16,13 +16,13 @@ private: using TListItem = TIntrusiveListItem<T, Tag>; public: - inline TIntrusiveListItem() noexcept + inline TIntrusiveListItem() noexcept : Next_(this) , Prev_(Next_) { } - inline ~TIntrusiveListItem() { + inline ~TIntrusiveListItem() { Unlink(); } @@ -31,7 +31,7 @@ public: return (Prev_ == this) && (Next_ == this); } - inline void Unlink() noexcept { + inline void Unlink() noexcept { if (Empty()) { return; } @@ -42,12 +42,12 @@ public: SetEnd(); } - inline void LinkBefore(TListItem* before) noexcept { + inline void LinkBefore(TListItem* before) noexcept { Unlink(); LinkBeforeNoUnlink(before); } - inline void LinkBeforeNoUnlink(TListItem* before) noexcept { + inline void LinkBeforeNoUnlink(TListItem* before) noexcept { TListItem* const after = before->Prev(); after->SetNext(this); @@ -56,56 +56,56 @@ public: before->SetPrev(this); } - inline void LinkBefore(TListItem& before) noexcept { + inline void LinkBefore(TListItem& before) noexcept { LinkBefore(&before); } - inline void LinkAfter(TListItem* after) noexcept { + inline void LinkAfter(TListItem* after) noexcept { Unlink(); LinkBeforeNoUnlink(after->Next()); } - inline void LinkAfter(TListItem& after) noexcept { + inline void LinkAfter(TListItem& after) noexcept { LinkAfter(&after); } public: - inline TListItem* Prev() noexcept { + inline TListItem* Prev() noexcept { return Prev_; } - inline const TListItem* Prev() const noexcept { + inline const TListItem* Prev() const noexcept { return Prev_; } - inline TListItem* Next() noexcept { + inline TListItem* Next() noexcept { return Next_; } - inline const TListItem* Next() const noexcept { + inline const TListItem* Next() const noexcept { return Next_; } public: - inline void SetEnd() noexcept { + inline void SetEnd() noexcept { Prev_ = this; Next_ = Prev_; } - inline void SetNext(TListItem* item) noexcept { + inline void SetNext(TListItem* item) noexcept { Next_ = item; } - inline void SetPrev(TListItem* item) noexcept { + inline void SetPrev(TListItem* item) noexcept { Prev_ = item; } public: - inline T* Node() noexcept { + inline T* Node() noexcept { return static_cast<T*>(this); } - inline const T* Node() const noexcept { + inline const T* Node() const noexcept { return static_cast<const T*>(this); } @@ -137,51 +137,51 @@ private: using reference = TReference; using pointer = TPointer; - inline TIteratorBase() noexcept + inline TIteratorBase() noexcept : Item_(nullptr) { } template <class TListItem_, class TNode_> - inline TIteratorBase(const TIteratorBase<TListItem_, TNode_>& right) noexcept + inline TIteratorBase(const TIteratorBase<TListItem_, TNode_>& right) noexcept : Item_(right.Item()) { } - inline TIteratorBase(TItem* item) noexcept + inline TIteratorBase(TItem* item) noexcept : Item_(item) { } - inline TItem* Item() const noexcept { + inline TItem* Item() const noexcept { return Item_; } - inline void Next() noexcept { + inline void Next() noexcept { Item_ = Item_->Next(); } - inline void Prev() noexcept { + inline void Prev() noexcept { Item_ = Item_->Prev(); } template <class TListItem_, class TNode_> - inline bool operator==(const TIteratorBase<TListItem_, TNode_>& right) const noexcept { + inline bool operator==(const TIteratorBase<TListItem_, TNode_>& right) const noexcept { return Item() == right.Item(); } template <class TListItem_, class TNode_> - inline bool operator!=(const TIteratorBase<TListItem_, TNode_>& right) const noexcept { + inline bool operator!=(const TIteratorBase<TListItem_, TNode_>& right) const noexcept { return Item() != right.Item(); } - inline TIteratorBase& operator++() noexcept { + inline TIteratorBase& operator++() noexcept { Next(); return *this; } - inline TIteratorBase operator++(int) noexcept { + inline TIteratorBase operator++(int) noexcept { TIteratorBase ret(*this); Next(); @@ -189,13 +189,13 @@ private: return ret; } - inline TIteratorBase& operator--() noexcept { + inline TIteratorBase& operator--() noexcept { Prev(); return *this; } - inline TIteratorBase operator--(int) noexcept { + inline TIteratorBase operator--(int) noexcept { TIteratorBase ret(*this); Prev(); @@ -203,11 +203,11 @@ private: return ret; } - inline TReference operator*() const noexcept { + inline TReference operator*() const noexcept { return *Item_->Node(); } - inline TPointer operator->() const noexcept { + inline TPointer operator->() const noexcept { return Item_->Node(); } @@ -232,51 +232,51 @@ private: inline TReverseIteratorBase() noexcept = default; template <class TIterator_> - inline TReverseIteratorBase(const TReverseIteratorBase<TIterator_>& right) noexcept + inline TReverseIteratorBase(const TReverseIteratorBase<TIterator_>& right) noexcept : Current_(right.Base()) { } - inline explicit TReverseIteratorBase(TIterator item) noexcept + inline explicit TReverseIteratorBase(TIterator item) noexcept : Current_(item) { } - inline TIterator Base() const noexcept { + inline TIterator Base() const noexcept { return Current_; } - inline TItem* Item() const noexcept { + inline TItem* Item() const noexcept { TIterator ret = Current_; return (--ret).Item(); } - inline void Next() noexcept { + inline void Next() noexcept { Current_.Prev(); } - inline void Prev() noexcept { + inline void Prev() noexcept { Current_.Next(); } template <class TIterator_> - inline bool operator==(const TReverseIteratorBase<TIterator_>& right) const noexcept { + inline bool operator==(const TReverseIteratorBase<TIterator_>& right) const noexcept { return Base() == right.Base(); } template <class TIterator_> - inline bool operator!=(const TReverseIteratorBase<TIterator_>& right) const noexcept { + inline bool operator!=(const TReverseIteratorBase<TIterator_>& right) const noexcept { return Base() != right.Base(); } - inline TReverseIteratorBase& operator++() noexcept { + inline TReverseIteratorBase& operator++() noexcept { Next(); return *this; } - inline TReverseIteratorBase operator++(int) noexcept { + inline TReverseIteratorBase operator++(int) noexcept { TReverseIteratorBase ret(*this); Next(); @@ -284,13 +284,13 @@ private: return ret; } - inline TReverseIteratorBase& operator--() noexcept { + inline TReverseIteratorBase& operator--() noexcept { Prev(); return *this; } - inline TReverseIteratorBase operator--(int) noexcept { + inline TReverseIteratorBase operator--(int) noexcept { TReverseIteratorBase ret(*this); Prev(); @@ -298,13 +298,13 @@ private: return ret; } - inline TReference operator*() const noexcept { + inline TReference operator*() const noexcept { TIterator ret = Current_; return *--ret; } - inline TPointer operator->() const noexcept { + inline TPointer operator->() const noexcept { TIterator ret = Current_; return &*--ret; @@ -328,7 +328,7 @@ public: using const_reverse_iterator = TConstReverseIterator; public: - inline void Swap(TIntrusiveList& right) noexcept { + inline void Swap(TIntrusiveList& right) noexcept { TIntrusiveList temp; temp.Append(right); @@ -344,7 +344,7 @@ public: inline ~TIntrusiveList() = default; - inline TIntrusiveList(TIntrusiveList&& right) noexcept { + inline TIntrusiveList(TIntrusiveList&& right) noexcept { this->Swap(right); } @@ -353,7 +353,7 @@ public: return *this; } - inline explicit operator bool() const noexcept { + inline explicit operator bool() const noexcept { return !Empty(); } @@ -361,7 +361,7 @@ public: return End_.Empty(); } - inline size_t Size() const noexcept { + inline size_t Size() const noexcept { return std::distance(Begin(), End()); } @@ -369,126 +369,126 @@ public: item->Unlink(); } - inline void Clear() noexcept { + inline void Clear() noexcept { End_.Unlink(); } public: - inline TIterator Begin() noexcept { + inline TIterator Begin() noexcept { return ++End(); } - inline TIterator End() noexcept { + inline TIterator End() noexcept { return TIterator(&End_); } - inline TConstIterator Begin() const noexcept { + inline TConstIterator Begin() const noexcept { return ++End(); } - inline TConstIterator End() const noexcept { + inline TConstIterator End() const noexcept { return TConstIterator(&End_); } - inline TReverseIterator RBegin() noexcept { + inline TReverseIterator RBegin() noexcept { return TReverseIterator(End()); } - inline TReverseIterator REnd() noexcept { + inline TReverseIterator REnd() noexcept { return TReverseIterator(Begin()); } - inline TConstReverseIterator RBegin() const noexcept { + inline TConstReverseIterator RBegin() const noexcept { return TConstReverseIterator(End()); } - inline TConstReverseIterator REnd() const noexcept { + inline TConstReverseIterator REnd() const noexcept { return TConstReverseIterator(Begin()); } - inline TConstIterator CBegin() const noexcept { + inline TConstIterator CBegin() const noexcept { return Begin(); } - inline TConstIterator CEnd() const noexcept { + inline TConstIterator CEnd() const noexcept { return End(); } - inline TConstReverseIterator CRBegin() const noexcept { + inline TConstReverseIterator CRBegin() const noexcept { return RBegin(); } - inline TConstReverseIterator CREnd() const noexcept { + inline TConstReverseIterator CREnd() const noexcept { return REnd(); } public: - inline iterator begin() noexcept { + inline iterator begin() noexcept { return Begin(); } - inline iterator end() noexcept { + inline iterator end() noexcept { return End(); } - inline const_iterator begin() const noexcept { + inline const_iterator begin() const noexcept { return Begin(); } - inline const_iterator end() const noexcept { + inline const_iterator end() const noexcept { return End(); } - inline reverse_iterator rbegin() noexcept { + inline reverse_iterator rbegin() noexcept { return RBegin(); } - inline reverse_iterator rend() noexcept { + inline reverse_iterator rend() noexcept { return REnd(); } - inline const_iterator cbegin() const noexcept { + inline const_iterator cbegin() const noexcept { return CBegin(); } - inline const_iterator cend() const noexcept { + inline const_iterator cend() const noexcept { return CEnd(); } - inline const_reverse_iterator crbegin() const noexcept { + inline const_reverse_iterator crbegin() const noexcept { return CRBegin(); } - inline const_reverse_iterator crend() const noexcept { + inline const_reverse_iterator crend() const noexcept { return CREnd(); } public: - inline T* Back() noexcept { + inline T* Back() noexcept { return End_.Prev()->Node(); } - inline T* Front() noexcept { + inline T* Front() noexcept { return End_.Next()->Node(); } - inline const T* Back() const noexcept { + inline const T* Back() const noexcept { return End_.Prev()->Node(); } - inline const T* Front() const noexcept { + inline const T* Front() const noexcept { return End_.Next()->Node(); } - inline void PushBack(TListItem* item) noexcept { + inline void PushBack(TListItem* item) noexcept { item->LinkBefore(End_); } - inline void PushFront(TListItem* item) noexcept { + inline void PushFront(TListItem* item) noexcept { item->LinkAfter(End_); } - inline T* PopBack() noexcept { + inline T* PopBack() noexcept { TListItem* const ret = End_.Prev(); ret->Unlink(); @@ -496,7 +496,7 @@ public: return ret->Node(); } - inline T* PopFront() noexcept { + inline T* PopFront() noexcept { TListItem* const ret = End_.Next(); ret->Unlink(); @@ -504,11 +504,11 @@ public: return ret->Node(); } - inline void Append(TIntrusiveList& list) noexcept { + inline void Append(TIntrusiveList& list) noexcept { Cut(list.Begin(), list.End(), End()); } - inline static void Cut(TIterator begin, TIterator end, TIterator pasteBefore) noexcept { + inline static void Cut(TIterator begin, TIterator end, TIterator pasteBefore) noexcept { if (begin == end) { return; } @@ -602,12 +602,12 @@ public: public: inline TIntrusiveListWithAutoDelete() noexcept = default; - inline TIntrusiveListWithAutoDelete(TIntrusiveListWithAutoDelete&& right) noexcept + inline TIntrusiveListWithAutoDelete(TIntrusiveListWithAutoDelete&& right) noexcept : TIntrusiveList<T, Tag>(std::move(right)) { } - inline ~TIntrusiveListWithAutoDelete() { + inline ~TIntrusiveListWithAutoDelete() { this->Clear(); } @@ -617,18 +617,18 @@ public: } public: - inline void Clear() noexcept { + inline void Clear() noexcept { this->ForEach([](auto* item) { D::Destroy(item); }); } - inline static void Cut(TIterator begin, TIterator end) noexcept { + inline static void Cut(TIterator begin, TIterator end) noexcept { TIntrusiveListWithAutoDelete<T, D, Tag> temp; Cut(begin, end, temp.End()); } - inline static void Cut(TIterator begin, TIterator end, TIterator pasteBefore) noexcept { + inline static void Cut(TIterator begin, TIterator end, TIterator pasteBefore) noexcept { TIntrusiveList<T, Tag>::Cut(begin, end, pasteBefore); } }; @@ -642,35 +642,35 @@ private: using TListItem = TIntrusiveSListItem<T, Tag>; public: - inline TIntrusiveSListItem() noexcept + inline TIntrusiveSListItem() noexcept : Next_(nullptr) { } inline ~TIntrusiveSListItem() = default; - inline bool IsEnd() const noexcept { + inline bool IsEnd() const noexcept { return Next_ == nullptr; } - inline TListItem* Next() noexcept { + inline TListItem* Next() noexcept { return Next_; } - inline const TListItem* Next() const noexcept { + inline const TListItem* Next() const noexcept { return Next_; } - inline void SetNext(TListItem* item) noexcept { + inline void SetNext(TListItem* item) noexcept { Next_ = item; } public: - inline T* Node() noexcept { + inline T* Node() noexcept { return static_cast<T*>(this); } - inline const T* Node() const noexcept { + inline const T* Node() const noexcept { return static_cast<const T*>(this); } @@ -697,30 +697,30 @@ public: using reference = TReference; using iterator_category = std::forward_iterator_tag; - inline TIteratorBase(TListItem* item) noexcept + inline TIteratorBase(TListItem* item) noexcept : Item_(item) { } - inline void Next() noexcept { + inline void Next() noexcept { Item_ = Item_->Next(); } - inline bool operator==(const TIteratorBase& right) const noexcept { + inline bool operator==(const TIteratorBase& right) const noexcept { return Item_ == right.Item_; } - inline bool operator!=(const TIteratorBase& right) const noexcept { + inline bool operator!=(const TIteratorBase& right) const noexcept { return Item_ != right.Item_; } - inline TIteratorBase& operator++() noexcept { + inline TIteratorBase& operator++() noexcept { Next(); return *this; } - inline TIteratorBase operator++(int) noexcept { + inline TIteratorBase operator++(int) noexcept { TIteratorBase ret(*this); Next(); @@ -728,11 +728,11 @@ public: return ret; } - inline TNode& operator*() noexcept { + inline TNode& operator*() noexcept { return *Item_->Node(); } - inline TNode* operator->() noexcept { + inline TNode* operator->() noexcept { return Item_->Node(); } @@ -748,16 +748,16 @@ public: using const_iterator = TConstIterator; public: - inline TIntrusiveSList() noexcept + inline TIntrusiveSList() noexcept : Begin_(nullptr) { } - inline void Swap(TIntrusiveSList& right) noexcept { + inline void Swap(TIntrusiveSList& right) noexcept { DoSwap(Begin_, right.Begin_); } - inline explicit operator bool() const noexcept { + inline explicit operator bool() const noexcept { return !Empty(); } @@ -765,79 +765,79 @@ public: return Begin_ == nullptr; } - inline size_t Size() const noexcept { + inline size_t Size() const noexcept { return std::distance(Begin(), End()); } - inline void Clear() noexcept { + inline void Clear() noexcept { Begin_ = nullptr; } - inline TIterator Begin() noexcept { + inline TIterator Begin() noexcept { return TIterator(Begin_); } - inline TIterator End() noexcept { + inline TIterator End() noexcept { return TIterator(nullptr); } - inline TConstIterator Begin() const noexcept { + inline TConstIterator Begin() const noexcept { return TConstIterator(Begin_); } - inline TConstIterator End() const noexcept { + inline TConstIterator End() const noexcept { return TConstIterator(nullptr); } - inline TConstIterator CBegin() const noexcept { + inline TConstIterator CBegin() const noexcept { return Begin(); } - inline TConstIterator CEnd() const noexcept { + inline TConstIterator CEnd() const noexcept { return End(); } //compat methods - inline iterator begin() noexcept { + inline iterator begin() noexcept { return Begin(); } - inline iterator end() noexcept { + inline iterator end() noexcept { return End(); } - inline const_iterator begin() const noexcept { + inline const_iterator begin() const noexcept { return Begin(); } - inline const_iterator end() const noexcept { + inline const_iterator end() const noexcept { return End(); } - inline const_iterator cbegin() const noexcept { + inline const_iterator cbegin() const noexcept { return CBegin(); } - inline const_iterator cend() const noexcept { + inline const_iterator cend() const noexcept { return CEnd(); } - inline T* Front() noexcept { + inline T* Front() noexcept { Y_ASSERT(Begin_); return Begin_->Node(); } - inline const T* Front() const noexcept { + inline const T* Front() const noexcept { Y_ASSERT(Begin_); return Begin_->Node(); } - inline void PushFront(TListItem* item) noexcept { + inline void PushFront(TListItem* item) noexcept { item->SetNext(Begin_); Begin_ = item; } - inline T* PopFront() noexcept { + inline T* PopFront() noexcept { Y_ASSERT(Begin_); TListItem* const ret = Begin_; @@ -846,7 +846,7 @@ public: return ret->Node(); } - inline void Reverse() noexcept { + inline void Reverse() noexcept { TIntrusiveSList temp; while (!Empty()) { diff --git a/util/generic/intrlist_ut.cpp b/util/generic/intrlist_ut.cpp index eff7cdf2ee..7d6322d693 100644 --- a/util/generic/intrlist_ut.cpp +++ b/util/generic/intrlist_ut.cpp @@ -45,7 +45,7 @@ UNIT_TEST_SUITE_REGISTRATION(TListTest); class TInt: public TIntrusiveListItem<TInt> { public: - inline TInt(int value) noexcept + inline TInt(int value) noexcept : Value_(value) { } @@ -62,11 +62,11 @@ public: return *this; } - inline operator int&() noexcept { + inline operator int&() noexcept { return Value_; } - inline operator const int&() const noexcept { + inline operator const int&() const noexcept { return Value_; } @@ -88,7 +88,7 @@ public: //operator=(const TMyList& rhs) = default; TMyList& operator=(TMyList&& rhs) noexcept = default; - inline ~TMyList() { + inline ~TMyList() { while (!Empty()) { delete PopBack(); } @@ -96,7 +96,7 @@ public: }; struct TIntGreater: private TGreater<int> { - inline bool operator()(const TInt& l, const TInt& r) const noexcept { + inline bool operator()(const TInt& l, const TInt& r) const noexcept { return TGreater<int>::operator()(l, r); } }; @@ -154,7 +154,7 @@ public: { } - inline void operator()(const TInt* v) noexcept { + inline void operator()(const TInt* v) noexcept { Sum_ += *v; } @@ -169,7 +169,7 @@ public: { } - inline void operator()(TInt* v) noexcept { + inline void operator()(TInt* v) noexcept { if (*v % 2) { Sum_ += *v; } else { @@ -393,10 +393,10 @@ struct TSelfCountingIntDelete { }; void TListTest::TestListWithAutoDelete() { - using TListType = TIntrusiveListWithAutoDelete<TSelfCountingInt, TSelfCountingIntDelete>; + using TListType = TIntrusiveListWithAutoDelete<TSelfCountingInt, TSelfCountingIntDelete>; int counter{0}; { - TListType lst; + TListType lst; UNIT_ASSERT(lst.Empty()); lst.PushFront(new TSelfCountingInt(counter, 2)); UNIT_ASSERT_EQUAL(lst.Size(), 1); @@ -411,17 +411,17 @@ void TListTest::TestListWithAutoDelete() { } void TListTest::TestListWithAutoDeleteMoveCtor() { - using TListType = TIntrusiveListWithAutoDelete<TSelfCountingInt, TSelfCountingIntDelete>; + using TListType = TIntrusiveListWithAutoDelete<TSelfCountingInt, TSelfCountingIntDelete>; int counter{0}; { - TListType lst; + TListType lst; lst.PushFront(new TSelfCountingInt(counter, 2)); lst.PushFront(new TSelfCountingInt(counter, 1)); UNIT_ASSERT_EQUAL(lst.Size(), 2); UNIT_ASSERT_EQUAL(counter, 2); CheckList(lst); - TListType nextList(std::move(lst)); + TListType nextList(std::move(lst)); UNIT_ASSERT_EQUAL(nextList.Size(), 2); CheckList(nextList); UNIT_ASSERT_EQUAL(counter, 2); @@ -431,17 +431,17 @@ void TListTest::TestListWithAutoDeleteMoveCtor() { } void TListTest::TestListWithAutoDeleteMoveOpEq() { - using TListType = TIntrusiveListWithAutoDelete<TSelfCountingInt, TSelfCountingIntDelete>; + using TListType = TIntrusiveListWithAutoDelete<TSelfCountingInt, TSelfCountingIntDelete>; int counter{0}; { - TListType lst; + TListType lst; lst.PushFront(new TSelfCountingInt(counter, 2)); lst.PushFront(new TSelfCountingInt(counter, 1)); UNIT_ASSERT_EQUAL(lst.Size(), 2); UNIT_ASSERT_EQUAL(counter, 2); CheckList(lst); - TListType nextList; + TListType nextList; UNIT_ASSERT(nextList.Empty()); nextList = std::move(lst); UNIT_ASSERT_EQUAL(nextList.Size(), 2); @@ -453,10 +453,10 @@ void TListTest::TestListWithAutoDeleteMoveOpEq() { } void TListTest::TestListWithAutoDeleteClear() { - using TListType = TIntrusiveListWithAutoDelete<TSelfCountingInt, TSelfCountingIntDelete>; + using TListType = TIntrusiveListWithAutoDelete<TSelfCountingInt, TSelfCountingIntDelete>; int counter{0}; { - TListType lst; + TListType lst; UNIT_ASSERT(lst.Empty()); lst.PushFront(new TSelfCountingInt(counter, 2)); UNIT_ASSERT_EQUAL(lst.Size(), 1); diff --git a/util/generic/is_in_ut.cpp b/util/generic/is_in_ut.cpp index c668bce807..b98b37aa70 100644 --- a/util/generic/is_in_ut.cpp +++ b/util/generic/is_in_ut.cpp @@ -7,7 +7,7 @@ #include "map.h" #include "set.h" #include "strbuf.h" -#include "string.h" +#include "string.h" Y_UNIT_TEST_SUITE(TIsIn) { template <class TCont, class T> @@ -41,18 +41,18 @@ Y_UNIT_TEST_SUITE(TIsIn) { } Y_UNIT_TEST(IsInTest) { - TestIsInWithCont<TMap<TString, TString>>(std::make_pair("found", "1")); - TestIsInWithCont<TMultiMap<TString, TString>>(std::make_pair("found", "1")); - TestIsInWithCont<THashMap<TString, TString>>(std::make_pair("found", "1")); - TestIsInWithCont<THashMultiMap<TString, TString>>(std::make_pair("found", "1")); + TestIsInWithCont<TMap<TString, TString>>(std::make_pair("found", "1")); + TestIsInWithCont<TMultiMap<TString, TString>>(std::make_pair("found", "1")); + TestIsInWithCont<THashMap<TString, TString>>(std::make_pair("found", "1")); + TestIsInWithCont<THashMultiMap<TString, TString>>(std::make_pair("found", "1")); - TestIsInWithCont<TSet<TString>>("found"); - TestIsInWithCont<TMultiSet<TString>>("found"); - TestIsInWithCont<THashSet<TString>>("found"); - TestIsInWithCont<THashMultiSet<TString>>("found"); + TestIsInWithCont<TSet<TString>>("found"); + TestIsInWithCont<TMultiSet<TString>>("found"); + TestIsInWithCont<THashSet<TString>>("found"); + TestIsInWithCont<THashMultiSet<TString>>("found"); // vector also compiles and works - TVector<TString> v; + TVector<TString> v; v.push_back("found"); UNIT_ASSERT(IsIn(v, "found")); UNIT_ASSERT(!IsIn(v, "not found")); @@ -61,8 +61,8 @@ Y_UNIT_TEST_SUITE(TIsIn) { UNIT_ASSERT(IsIn(v.begin(), v.end(), "found")); UNIT_ASSERT(!IsIn(v.begin(), v.end(), "not found")); - // Works with TString (it has find, but find is not used) - TString s = "found"; + // Works with TString (it has find, but find is not used) + TString s = "found"; UNIT_ASSERT(IsIn(s, 'f')); UNIT_ASSERT(!IsIn(s, 'z')); @@ -87,7 +87,7 @@ Y_UNIT_TEST_SUITE(TIsIn) { UNIT_ASSERT(IsIn({abc, def}, def)); // direct pointer comparison UNIT_ASSERT(!IsIn({TStringBuf("abc"), TStringBuf("def")}, TStringBuf("ghi"))); UNIT_ASSERT(!IsIn({"abc", "def"}, TStringBuf("ghi"))); - UNIT_ASSERT(!IsIn({"abc", "def"}, TString("ghi"))); + UNIT_ASSERT(!IsIn({"abc", "def"}, TString("ghi"))); const TStringBuf str = "abc////"; @@ -98,11 +98,11 @@ Y_UNIT_TEST_SUITE(TIsIn) { UNIT_ASSERT(IsIn({1, 2, 3}, 1)); UNIT_ASSERT(!IsIn({1, 2, 3}, 4)); - const TString b = "b"; + const TString b = "b"; UNIT_ASSERT(!IsIn({"a", "b", "c"}, b.data())); // compares pointers by value. Whether it's good or not. UNIT_ASSERT(IsIn(TVector<TStringBuf>({"a", "b", "c"}), b.data())); - UNIT_ASSERT(IsIn(TVector<TStringBuf>({"a", "b", "c"}), "b")); + UNIT_ASSERT(IsIn(TVector<TStringBuf>({"a", "b", "c"}), "b")); } Y_UNIT_TEST(IsInArrayTest) { diff --git a/util/generic/iterator_range_ut.cpp b/util/generic/iterator_range_ut.cpp index a7e3670ae1..abd59a94cd 100644 --- a/util/generic/iterator_range_ut.cpp +++ b/util/generic/iterator_range_ut.cpp @@ -69,7 +69,7 @@ Y_UNIT_TEST_SUITE(IteratorRange) { } Y_UNIT_TEST(OperatorsAndReferences) { - TVector<size_t> values{1, 2, 3, 4, 5}; + TVector<size_t> values{1, 2, 3, 4, 5}; auto range = MakeIteratorRange(values.begin(), values.end()); UNIT_ASSERT_VALUES_EQUAL(range[2], 3); UNIT_ASSERT_VALUES_EQUAL(range[range[2]], 4); @@ -78,7 +78,7 @@ Y_UNIT_TEST_SUITE(IteratorRange) { range[0] = 100501; UNIT_ASSERT_VALUES_EQUAL(range[0], 100501); - TVector<bool> valuesBool{false, true, false, false, false, false, true}; + TVector<bool> valuesBool{false, true, false, false, false, false, true}; auto rangeBVector = MakeIteratorRange(valuesBool.begin(), valuesBool.end()); UNIT_ASSERT_VALUES_EQUAL(rangeBVector[1], true); rangeBVector[0] = true; diff --git a/util/generic/iterator_ut.cpp b/util/generic/iterator_ut.cpp index 00be19e10e..a24e7502ef 100644 --- a/util/generic/iterator_ut.cpp +++ b/util/generic/iterator_ut.cpp @@ -4,7 +4,7 @@ Y_UNIT_TEST_SUITE(TIterator) { Y_UNIT_TEST(ToForwardIteratorTest) { - TVector<int> x = {1, 2}; + TVector<int> x = {1, 2}; UNIT_ASSERT_VALUES_EQUAL(*std::prev(x.end()), *ToForwardIterator(x.rbegin())); UNIT_ASSERT_VALUES_EQUAL(*ToForwardIterator(std::prev(x.rend())), *x.begin()); } diff --git a/util/generic/lazy_value_ut.cpp b/util/generic/lazy_value_ut.cpp index f6135880c3..9669204b6b 100644 --- a/util/generic/lazy_value_ut.cpp +++ b/util/generic/lazy_value_ut.cpp @@ -98,7 +98,7 @@ Y_UNIT_TEST_SUITE(TLazyValueTestSuite) { { } - const TString& GetData() const { + const TString& GetData() const { return *Data_; } diff --git a/util/generic/list.h b/util/generic/list.h index 7b0b8ffc72..40b99bc474 100644 --- a/util/generic/list.h +++ b/util/generic/list.h @@ -10,7 +10,7 @@ #include <utility> template <class T, class A> -class TList: public std::list<T, TReboundAllocator<A, T>> { +class TList: public std::list<T, TReboundAllocator<A, T>> { using TBase = std::list<T, TReboundAllocator<A, T>>; public: diff --git a/util/generic/list_ut.cpp b/util/generic/list_ut.cpp index 9e60ecf01b..79c806f827 100644 --- a/util/generic/list_ut.cpp +++ b/util/generic/list_ut.cpp @@ -4,8 +4,8 @@ Y_UNIT_TEST_SUITE(TYListSuite) { Y_UNIT_TEST(TestInitializerList) { - TList<int> l = {3, 42, 6}; - TList<int> expected; + TList<int> l = {3, 42, 6}; + TList<int> expected; expected.push_back(3); expected.push_back(42); expected.push_back(6); diff --git a/util/generic/map.h b/util/generic/map.h index b5001b56c0..399a521683 100644 --- a/util/generic/map.h +++ b/util/generic/map.h @@ -12,7 +12,7 @@ #include <memory> template <class K, class V, class Less, class A> -class TMap: public std::map<K, V, Less, TReboundAllocator<A, std::pair<const K, V>>>, public TMapOps<TMap<K, V, Less, A>> { +class TMap: public std::map<K, V, Less, TReboundAllocator<A, std::pair<const K, V>>>, public TMapOps<TMap<K, V, Less, A>> { using TBase = std::map<K, V, Less, TReboundAllocator<A, std::pair<const K, V>>>; public: @@ -28,7 +28,7 @@ public: }; template <class K, class V, class Less, class A> -class TMultiMap: public std::multimap<K, V, Less, TReboundAllocator<A, std::pair<const K, V>>> { +class TMultiMap: public std::multimap<K, V, Less, TReboundAllocator<A, std::pair<const K, V>>> { using TBase = std::multimap<K, V, Less, TReboundAllocator<A, std::pair<const K, V>>>; public: diff --git a/util/generic/map_ut.cpp b/util/generic/map_ut.cpp index 79e832b024..0987ecf705 100644 --- a/util/generic/map_ut.cpp +++ b/util/generic/map_ut.cpp @@ -13,31 +13,31 @@ Y_UNIT_TEST_SUITE(TYMapTest) { Y_UNIT_TEST(TestMap1) { { - TMap<char, int, TLess<char>> m; + TMap<char, int, TLess<char>> m; DoTestMap1(m); } { TMemoryPool p(100); - TMap<char, int, TLess<char>, TPoolAllocator> m(&p); + TMap<char, int, TLess<char>, TPoolAllocator> m(&p); DoTestMap1(m); } } Y_UNIT_TEST(TestMMap1) { { - TMultiMap<char, int, TLess<char>> mm; + TMultiMap<char, int, TLess<char>> mm; DoTestMMap1(mm); } { TMemoryPool p(100); - TMultiMap<char, int, TLess<char>, TPoolAllocator> mm(&p); + TMultiMap<char, int, TLess<char>, TPoolAllocator> mm(&p); DoTestMMap1(mm); } } template <typename TAlloc> void DoTestMap1(TMap<char, int, TLess<char>, TAlloc>& m) { - using maptype = TMap<char, int, TLess<char>, TAlloc>; + using maptype = TMap<char, int, TLess<char>, TAlloc>; // Store mappings between roman numerals and decimals. m['l'] = 50; m['x'] = 20; // Deliberate mistake. @@ -68,7 +68,7 @@ Y_UNIT_TEST_SUITE(TYMapTest) { template <typename TAlloc> void DoTestMMap1(TMultiMap<char, int, TLess<char>, TAlloc>& m) { - using mmap = TMultiMap<char, int, TLess<char>, TAlloc>; + using mmap = TMultiMap<char, int, TLess<char>, TAlloc>; UNIT_ASSERT(m.count('X') == 0); @@ -103,7 +103,7 @@ Y_UNIT_TEST_SUITE(TYMapTest) { pair_type p5(3, 'x'); pair_type p6(6, 'f'); - using mmap = TMultiMap<int, char, TLess<int>>; + using mmap = TMultiMap<int, char, TLess<int>>; pair_type array[] = { p1, @@ -125,7 +125,7 @@ Y_UNIT_TEST_SUITE(TYMapTest) { } Y_UNIT_TEST(TestIterators) { - using int_map = TMap<int, char, TLess<int>>; + using int_map = TMap<int, char, TLess<int>>; int_map imap; { @@ -138,7 +138,7 @@ Y_UNIT_TEST_SUITE(TYMapTest) { UNIT_ASSERT(!(cite != ite)); } - using mmap = TMultiMap<int, char, TLess<int>>; + using mmap = TMultiMap<int, char, TLess<int>>; using pair_type = mmap::value_type; pair_type p1(3, 'c'); @@ -188,7 +188,7 @@ Y_UNIT_TEST_SUITE(TYMapTest) { } Y_UNIT_TEST(TestEqualRange) { - using maptype = TMap<char, int, TLess<char>>; + using maptype = TMap<char, int, TLess<char>>; { maptype m; @@ -276,7 +276,7 @@ Y_UNIT_TEST_SUITE(TYMapTest) { Y_UNIT_TEST(TestTemplateMethods) { { - using Container = TMap<TKey, int, TKeyCmp>; + using Container = TMap<TKey, int, TKeyCmp>; using value = Container::value_type; Container cont; @@ -304,7 +304,7 @@ Y_UNIT_TEST_SUITE(TYMapTest) { } { - using Container = TMap<TKey*, int, TKeyCmpPtr>; + using Container = TMap<TKey*, int, TKeyCmpPtr>; using value = Container::value_type; Container cont; @@ -333,7 +333,7 @@ Y_UNIT_TEST_SUITE(TYMapTest) { } { - using Container = TMultiMap<TKey, int, TKeyCmp>; + using Container = TMultiMap<TKey, int, TKeyCmp>; using value = Container::value_type; Container cont; @@ -361,7 +361,7 @@ Y_UNIT_TEST_SUITE(TYMapTest) { } { - using Container = TMultiMap<TKey const volatile*, int, TKeyCmpPtr>; + using Container = TMultiMap<TKey const volatile*, int, TKeyCmpPtr>; using value = Container::value_type; Container cont; @@ -399,8 +399,8 @@ Y_UNIT_TEST_SUITE(TYMapTest) { } Y_UNIT_TEST(TestEmpty) { - EmptyAndInsertTest<TMap<char, int, TLess<char>>>(std::pair<char, int>('a', 1)); - EmptyAndInsertTest<TMultiMap<char, int, TLess<char>>>(std::pair<char, int>('a', 1)); + EmptyAndInsertTest<TMap<char, int, TLess<char>>>(std::pair<char, int>('a', 1)); + EmptyAndInsertTest<TMultiMap<char, int, TLess<char>>>(std::pair<char, int>('a', 1)); } struct TParametrizedKeyCmp { @@ -421,7 +421,7 @@ Y_UNIT_TEST_SUITE(TYMapTest) { }; Y_UNIT_TEST(TestMoveComparator) { - using Container = TMultiMap<TKey, int, TParametrizedKeyCmp>; + using Container = TMultiMap<TKey, int, TParametrizedKeyCmp>; TParametrizedKeyCmp direct(false); TParametrizedKeyCmp inverse(true); @@ -434,7 +434,7 @@ Y_UNIT_TEST_SUITE(TYMapTest) { c.insert(std::make_pair(TKey(2), 102)); c.insert(std::make_pair(TKey(3), 103)); - TVector<int> values; + TVector<int> values; for (auto& i : c) { values.push_back(i.second); } @@ -447,7 +447,7 @@ Y_UNIT_TEST_SUITE(TYMapTest) { } Y_UNIT_TEST(TestMapInitializerList) { - TMap<TString, int> m = { + TMap<TString, int> m = { {"one", 1}, {"two", 2}, {"three", 3}, @@ -462,14 +462,14 @@ Y_UNIT_TEST_SUITE(TYMapTest) { } Y_UNIT_TEST(TestMMapInitializerList) { - TMultiMap<TString, int> mm = { + TMultiMap<TString, int> mm = { {"one", 1}, {"two", 2}, {"two", -2}, {"three", 3}, }; UNIT_ASSERT(mm.contains("two")); - TMultiMap<TString, int> expected; + TMultiMap<TString, int> expected; expected.emplace("one", 1); expected.emplace("two", 2); expected.emplace("two", -2); @@ -478,7 +478,7 @@ Y_UNIT_TEST_SUITE(TYMapTest) { } Y_UNIT_TEST(TestMovePoolAlloc) { - using TMapInPool = TMap<int, int, TLess<int>, TPoolAllocator>; + using TMapInPool = TMap<int, int, TLess<int>, TPoolAllocator>; TMemoryPool pool(1); diff --git a/util/generic/mapfindptr.h b/util/generic/mapfindptr.h index bc10cac60f..540b4df20a 100644 --- a/util/generic/mapfindptr.h +++ b/util/generic/mapfindptr.h @@ -24,7 +24,7 @@ inline auto MapFindPtr(const Map& map, const K& key) { return (i == map.end() ? nullptr : &i->second); } -/** helper for THashMap/TMap */ +/** helper for THashMap/TMap */ template <class Derived> struct TMapOps { template <class K> diff --git a/util/generic/mapfindptr_ut.cpp b/util/generic/mapfindptr_ut.cpp index 613da7a96b..83e3c220bc 100644 --- a/util/generic/mapfindptr_ut.cpp +++ b/util/generic/mapfindptr_ut.cpp @@ -1,4 +1,4 @@ -#include "string.h" +#include "string.h" #include "hash.h" #include <library/cpp/testing/unittest/registar.h> @@ -19,7 +19,7 @@ Y_UNIT_TEST_SUITE(TMapFindPtrTest) { UNIT_ASSERT_EQUAL(a.FindPtr(0), nullptr); //test mutation - if (TString* p = a.FindPtr(42)) { + if (TString* p = a.FindPtr(42)) { *p = "dog"; } UNIT_ASSERT(a.FindPtr(42)); @@ -35,9 +35,9 @@ Y_UNIT_TEST_SUITE(TMapFindPtrTest) { } Y_UNIT_TEST(TestTemplateFind) { - THashMap<TString, int> m; + THashMap<TString, int> m; - m[TString("x")] = 2; + m[TString("x")] = 2; UNIT_ASSERT(m.FindPtr(TStringBuf("x"))); UNIT_ASSERT_EQUAL(*m.FindPtr(TStringBuf("x")), 2); @@ -57,8 +57,8 @@ Y_UNIT_TEST_SUITE(TMapFindPtrTest) { a[1] = "lol"; - const TString str123 = "123"; - TString str1234 = "1234"; + const TString str123 = "123"; + TString str1234 = "1234"; UNIT_ASSERT_VALUES_EQUAL(a.ValueRef(1, str123), "lol"); UNIT_ASSERT_VALUES_EQUAL(a.ValueRef(2, str123), "123"); diff --git a/util/generic/maybe.h b/util/generic/maybe.h index 34d21aebcd..f5226fee46 100644 --- a/util/generic/maybe.h +++ b/util/generic/maybe.h @@ -19,21 +19,21 @@ namespace NMaybe { }; } -struct TNothing { +struct TNothing { explicit constexpr TNothing(int) noexcept { } -}; - -constexpr TNothing NothingObject{0}; - -constexpr TNothing Nothing() noexcept { - return NothingObject; -} - -constexpr bool operator==(TNothing, TNothing) noexcept { - return true; -} - +}; + +constexpr TNothing NothingObject{0}; + +constexpr TNothing Nothing() noexcept { + return NothingObject; +} + +constexpr bool operator==(TNothing, TNothing) noexcept { + return true; +} + template <class T, class Policy /*= ::NMaybe::TPolicyUndefinedExcept*/> class TMaybe: private TMaybeBase<T> { public: @@ -48,7 +48,7 @@ private: "Instantiation of TMaybe with reference type is ill-formed"); static_assert(std::is_destructible<T>::value, "Instantiation of TMaybe with non-destructible type is ill-formed"); - + template <class U> struct TConstructibleFromMaybeSomehow { public: @@ -152,13 +152,13 @@ private: }; using TBase = TMaybeBase<T>; - + public: using value_type = T; using TValueType = value_type; - + TMaybe() noexcept = default; - + constexpr TMaybe(const TMaybe&) = default; constexpr TMaybe(TMaybe&&) = default; @@ -168,15 +168,15 @@ public: { } - template <class U, class... TArgs> - constexpr explicit TMaybe(TInPlace, std::initializer_list<U> il, TArgs&&... args) + template <class U, class... TArgs> + constexpr explicit TMaybe(TInPlace, std::initializer_list<U> il, TArgs&&... args) : TBase(TInPlace{}, il, std::forward<TArgs>(args)...) { } - + constexpr TMaybe(TNothing) noexcept { } - + template <class U, class = std::enable_if_t<TImplicitCopyCtor<U>::value>> TMaybe(const TMaybe<U, Policy>& right) { if (right.Defined()) { @@ -227,10 +227,10 @@ public: constexpr TMaybe& operator=(TMaybe&&) = default; TMaybe& operator=(TNothing) noexcept { - Clear(); - return *this; - } - + Clear(); + return *this; + } + template <class U = T> std::enable_if_t<TAssignableFromAny<U>::value, TMaybe&> operator=(U&& right) { if (Defined()) { @@ -287,7 +287,7 @@ public: void Clear() noexcept { if (Defined()) { this->Defined_ = false; - Data()->~T(); + Data()->~T(); } } @@ -382,7 +382,7 @@ public: return Defined() ? TMaybe<U, Policy>(*Data()) : TMaybe<U, Policy>(); } - constexpr explicit operator bool() const noexcept { + constexpr explicit operator bool() const noexcept { return Defined(); } @@ -413,25 +413,25 @@ public: } void Swap(TMaybe& other) { - if (this->Defined_ == other.Defined_) { - if (this->Defined_) { - ::DoSwap(this->Data_, other.Data_); - } - } else { - if (this->Defined_) { - other.Init(std::move(this->Data_)); - this->Clear(); - } else { - this->Init(std::move(other.Data_)); - other.Clear(); - } - } - } - + if (this->Defined_ == other.Defined_) { + if (this->Defined_) { + ::DoSwap(this->Data_, other.Data_); + } + } else { + if (this->Defined_) { + other.Init(std::move(this->Data_)); + this->Clear(); + } else { + this->Init(std::move(other.Data_)); + other.Clear(); + } + } + } + void swap(TMaybe& other) { - Swap(other); - } - + Swap(other); + } + private: constexpr const T* Data() const noexcept { return std::addressof(this->Data_); @@ -454,28 +454,28 @@ using TMaybeFail = TMaybe<T, NMaybe::TPolicyUndefinedFail>; template <class T, class TPolicy = ::NMaybe::TPolicyUndefinedExcept> constexpr TMaybe<std::decay_t<T>, TPolicy> MakeMaybe(T&& value) { return TMaybe<std::decay_t<T>, TPolicy>(std::forward<T>(value)); -} - -template <class T, class... TArgs> -constexpr TMaybe<T> MakeMaybe(TArgs&&... args) { - return TMaybe<T>(typename TMaybe<T>::TInPlace{}, std::forward<TArgs>(args)...); -} - -template <class T, class U, class... TArgs> -constexpr TMaybe<T> MakeMaybe(std::initializer_list<U> il, TArgs&&... args) { - return TMaybe<T>(typename TMaybe<T>::TInPlace{}, il, std::forward<TArgs>(args)...); -} - +} + +template <class T, class... TArgs> +constexpr TMaybe<T> MakeMaybe(TArgs&&... args) { + return TMaybe<T>(typename TMaybe<T>::TInPlace{}, std::forward<TArgs>(args)...); +} + +template <class T, class U, class... TArgs> +constexpr TMaybe<T> MakeMaybe(std::initializer_list<U> il, TArgs&&... args) { + return TMaybe<T>(typename TMaybe<T>::TInPlace{}, il, std::forward<TArgs>(args)...); +} + template <class T, class TPolicy> void Swap(TMaybe<T, TPolicy>& lhs, TMaybe<T, TPolicy>& rhs) { - lhs.Swap(rhs); -} - + lhs.Swap(rhs); +} + template <class T, class TPolicy> void swap(TMaybe<T, TPolicy>& lhs, TMaybe<T, TPolicy>& rhs) { - lhs.Swap(rhs); -} - + lhs.Swap(rhs); +} + template <typename T, class TPolicy> struct THash<TMaybe<T, TPolicy>> { constexpr size_t operator()(const TMaybe<T, TPolicy>& data) const { @@ -483,7 +483,7 @@ struct THash<TMaybe<T, TPolicy>> { } }; -// Comparisons between TMaybe +// Comparisons between TMaybe template <class T, class TPolicy> constexpr bool operator==(const ::TMaybe<T, TPolicy>& left, const ::TMaybe<T, TPolicy>& right) { return (static_cast<bool>(left) != static_cast<bool>(right)) @@ -496,218 +496,218 @@ constexpr bool operator==(const ::TMaybe<T, TPolicy>& left, const ::TMaybe<T, TP template <class T, class TPolicy> constexpr bool operator!=(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) { - return !(left == right); + return !(left == right); } - + template <class T, class TPolicy> constexpr bool operator<(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) { - return (!static_cast<bool>(right)) + return (!static_cast<bool>(right)) ? false : ( !static_cast<bool>(left) ? true : (*left < *right)); -} - +} + template <class T, class TPolicy> constexpr bool operator>(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) { - return right < left; -} - + return right < left; +} + template <class T, class TPolicy> constexpr bool operator<=(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) { - return !(right < left); -} - + return !(right < left); +} + template <class T, class TPolicy> constexpr bool operator>=(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) { - return !(left < right); -} - -// Comparisons with TNothing + return !(left < right); +} + +// Comparisons with TNothing template <class T, class TPolicy> constexpr bool operator==(const TMaybe<T, TPolicy>& left, TNothing) noexcept { - return !static_cast<bool>(left); -} - + return !static_cast<bool>(left); +} + template <class T, class TPolicy> constexpr bool operator==(TNothing, const TMaybe<T, TPolicy>& right) noexcept { - return !static_cast<bool>(right); -} - + return !static_cast<bool>(right); +} + template <class T, class TPolicy> constexpr bool operator!=(const TMaybe<T, TPolicy>& left, TNothing) noexcept { - return static_cast<bool>(left); -} - + return static_cast<bool>(left); +} + template <class T, class TPolicy> constexpr bool operator!=(TNothing, const TMaybe<T, TPolicy>& right) noexcept { - return static_cast<bool>(right); -} - + return static_cast<bool>(right); +} + template <class T, class TPolicy> constexpr bool operator<(const TMaybe<T, TPolicy>&, TNothing) noexcept { - return false; -} - + return false; +} + template <class T, class TPolicy> constexpr bool operator<(TNothing, const TMaybe<T, TPolicy>& right) noexcept { - return static_cast<bool>(right); -} - + return static_cast<bool>(right); +} + template <class T, class TPolicy> constexpr bool operator<=(const TMaybe<T, TPolicy>& left, TNothing) noexcept { - return !static_cast<bool>(left); -} - + return !static_cast<bool>(left); +} + template <class T, class TPolicy> constexpr bool operator<=(TNothing, const TMaybe<T, TPolicy>&) noexcept { - return true; -} - + return true; +} + template <class T, class TPolicy> constexpr bool operator>(const TMaybe<T, TPolicy>& left, TNothing) noexcept { - return static_cast<bool>(left); -} - + return static_cast<bool>(left); +} + template <class T, class TPolicy> constexpr bool operator>(TNothing, const TMaybe<T, TPolicy>&) noexcept { - return false; -} - + return false; +} + template <class T, class TPolicy> constexpr bool operator>=(const TMaybe<T, TPolicy>&, TNothing) noexcept { - return true; -} - + return true; +} + template <class T, class TPolicy> constexpr bool operator>=(TNothing, const TMaybe<T, TPolicy>& right) noexcept { - return !static_cast<bool>(right); -} - -// Comparisons with T - + return !static_cast<bool>(right); +} + +// Comparisons with T + template <class T, class TPolicy> constexpr bool operator==(const TMaybe<T, TPolicy>& maybe, const T& value) { - return static_cast<bool>(maybe) ? *maybe == value : false; -} - + return static_cast<bool>(maybe) ? *maybe == value : false; +} + template <class T, class TPolicy> constexpr bool operator==(const T& value, const TMaybe<T, TPolicy>& maybe) { - return static_cast<bool>(maybe) ? *maybe == value : false; -} - + return static_cast<bool>(maybe) ? *maybe == value : false; +} + template <class T, class TPolicy> constexpr bool operator!=(const TMaybe<T, TPolicy>& maybe, const T& value) { - return static_cast<bool>(maybe) ? !(*maybe == value) : true; -} - + return static_cast<bool>(maybe) ? !(*maybe == value) : true; +} + template <class T, class TPolicy> constexpr bool operator!=(const T& value, const TMaybe<T, TPolicy>& maybe) { - return static_cast<bool>(maybe) ? !(*maybe == value) : true; -} - + return static_cast<bool>(maybe) ? !(*maybe == value) : true; +} + template <class T, class TPolicy> constexpr bool operator<(const TMaybe<T, TPolicy>& maybe, const T& value) { - return static_cast<bool>(maybe) ? std::less<T>{}(*maybe, value) : true; -} - + return static_cast<bool>(maybe) ? std::less<T>{}(*maybe, value) : true; +} + template <class T, class TPolicy> constexpr bool operator<(const T& value, const TMaybe<T, TPolicy>& maybe) { - return static_cast<bool>(maybe) ? std::less<T>{}(value, *maybe) : false; -} - + return static_cast<bool>(maybe) ? std::less<T>{}(value, *maybe) : false; +} + template <class T, class TPolicy> constexpr bool operator<=(const TMaybe<T, TPolicy>& maybe, const T& value) { - return !(maybe > value); -} - + return !(maybe > value); +} + template <class T, class TPolicy> constexpr bool operator<=(const T& value, const TMaybe<T, TPolicy>& maybe) { - return !(value > maybe); -} - + return !(value > maybe); +} + template <class T, class TPolicy> constexpr bool operator>(const TMaybe<T, TPolicy>& maybe, const T& value) { - return static_cast<bool>(maybe) ? value < maybe : false; -} - + return static_cast<bool>(maybe) ? value < maybe : false; +} + template <class T, class TPolicy> constexpr bool operator>(const T& value, const TMaybe<T, TPolicy>& maybe) { - return static_cast<bool>(maybe) ? maybe < value : true; -} - + return static_cast<bool>(maybe) ? maybe < value : true; +} + template <class T, class TPolicy> constexpr bool operator>=(const TMaybe<T, TPolicy>& maybe, const T& value) { - return !(maybe < value); -} - + return !(maybe < value); +} + template <class T, class TPolicy> constexpr bool operator>=(const T& value, const TMaybe<T, TPolicy>& maybe) { - return !(value < maybe); -} - -// Comparison with values convertible to T - + return !(value < maybe); +} + +// Comparison with values convertible to T + template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> constexpr bool operator==(const ::TMaybe<T, TPolicy>& maybe, const U& value) { - return static_cast<bool>(maybe) ? *maybe == value : false; -} - + return static_cast<bool>(maybe) ? *maybe == value : false; +} + template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> constexpr bool operator==(const U& value, const ::TMaybe<T, TPolicy>& maybe) { - return static_cast<bool>(maybe) ? *maybe == value : false; -} - + return static_cast<bool>(maybe) ? *maybe == value : false; +} + template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> constexpr bool operator!=(const TMaybe<T, TPolicy>& maybe, const U& value) { - return static_cast<bool>(maybe) ? !(*maybe == value) : true; -} - + return static_cast<bool>(maybe) ? !(*maybe == value) : true; +} + template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> constexpr bool operator!=(const U& value, const TMaybe<T, TPolicy>& maybe) { - return static_cast<bool>(maybe) ? !(*maybe == value) : true; -} - + return static_cast<bool>(maybe) ? !(*maybe == value) : true; +} + template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> constexpr bool operator<(const TMaybe<T, TPolicy>& maybe, const U& value) { - return static_cast<bool>(maybe) ? std::less<T>{}(*maybe, value) : true; -} - + return static_cast<bool>(maybe) ? std::less<T>{}(*maybe, value) : true; +} + template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> constexpr bool operator<(const U& value, const TMaybe<T, TPolicy>& maybe) { - return static_cast<bool>(maybe) ? std::less<T>{}(value, *maybe) : false; -} - + return static_cast<bool>(maybe) ? std::less<T>{}(value, *maybe) : false; +} + template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> constexpr bool operator<=(const TMaybe<T, TPolicy>& maybe, const U& value) { - return !(maybe > value); -} - + return !(maybe > value); +} + template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> constexpr bool operator<=(const U& value, const TMaybe<T, TPolicy>& maybe) { - return !(value > maybe); -} - + return !(value > maybe); +} + template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> constexpr bool operator>(const TMaybe<T, TPolicy>& maybe, const U& value) { - return static_cast<bool>(maybe) ? value < maybe : false; -} - + return static_cast<bool>(maybe) ? value < maybe : false; +} + template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> constexpr bool operator>(const U& value, const TMaybe<T, TPolicy>& maybe) { - return static_cast<bool>(maybe) ? maybe < value : true; -} - + return static_cast<bool>(maybe) ? maybe < value : true; +} + template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> constexpr bool operator>=(const TMaybe<T, TPolicy>& maybe, const U& value) { - return !(maybe < value); -} - + return !(maybe < value); +} + template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0> constexpr bool operator>=(const U& value, const TMaybe<T, TPolicy>& maybe) { - return !(value < maybe); -} + return !(value < maybe); +} class IOutputStream; diff --git a/util/generic/maybe_ut.cpp b/util/generic/maybe_ut.cpp index 2c1a425c5e..85c328309b 100644 --- a/util/generic/maybe_ut.cpp +++ b/util/generic/maybe_ut.cpp @@ -1,5 +1,5 @@ -#include <util/generic/string.h> -#include <util/generic/vector.h> +#include <util/generic/string.h> +#include <util/generic/vector.h> #include <util/stream/str.h> #include <library/cpp/testing/unittest/registar.h> @@ -10,12 +10,12 @@ private: int* Ptr_; public: - TIncrementOnDestroy(int* ptr) noexcept + TIncrementOnDestroy(int* ptr) noexcept : Ptr_(ptr) { } - ~TIncrementOnDestroy() { + ~TIncrementOnDestroy() { ++*Ptr_; } }; @@ -42,13 +42,13 @@ Y_UNIT_TEST_SUITE(TMaybeTest) { Y_UNIT_TEST(TestWarning) { TMaybe<size_t> x; TStringStream ss; - TString line; + TString line; while (ss.ReadLine(line)) { x = line.size(); } - if (x == 5u) { + if (x == 5u) { ss << "5\n"; } } @@ -221,575 +221,575 @@ Y_UNIT_TEST_SUITE(TMaybeTest) { UNIT_ASSERT(longMaybe.Defined()); UNIT_ASSERT_VALUES_EQUAL(34, longMaybe.GetRef()); } - + Y_UNIT_TEST(TestGetOr) { - UNIT_ASSERT_VALUES_EQUAL(TMaybe<TString>().GetOrElse("xxx"), TString("xxx")); - UNIT_ASSERT_VALUES_EQUAL(TMaybe<TString>("yyy").GetOrElse("xxx"), TString("yyy")); + UNIT_ASSERT_VALUES_EQUAL(TMaybe<TString>().GetOrElse("xxx"), TString("xxx")); + UNIT_ASSERT_VALUES_EQUAL(TMaybe<TString>("yyy").GetOrElse("xxx"), TString("yyy")); { - TString xxx = "xxx"; - UNIT_ASSERT_VALUES_EQUAL(TMaybe<TString>().GetOrElse(xxx).append('x'), TString("xxxx")); + TString xxx = "xxx"; + UNIT_ASSERT_VALUES_EQUAL(TMaybe<TString>().GetOrElse(xxx).append('x'), TString("xxxx")); UNIT_ASSERT_VALUES_EQUAL(xxx, "xxxx"); } { - TString xxx = "xxx"; - UNIT_ASSERT_VALUES_EQUAL(TMaybe<TString>("yyy").GetOrElse(xxx).append('x'), TString("yyyx")); + TString xxx = "xxx"; + UNIT_ASSERT_VALUES_EQUAL(TMaybe<TString>("yyy").GetOrElse(xxx).append('x'), TString("yyyx")); UNIT_ASSERT_VALUES_EQUAL(xxx, "xxx"); } } /* - == - != - < - <= - > - >= -*/ - + == + != + < + <= + > + >= +*/ + Y_UNIT_TEST(TestCompareEqualEmpty) { - TMaybe<int> m1; - TMaybe<int> m2; - - UNIT_ASSERT(m1 == m2); - UNIT_ASSERT(!(m1 != m2)); - UNIT_ASSERT(!(m1 < m2)); - UNIT_ASSERT(m1 <= m2); - UNIT_ASSERT(!(m1 > m2)); - UNIT_ASSERT(m1 >= m2); - } - + TMaybe<int> m1; + TMaybe<int> m2; + + UNIT_ASSERT(m1 == m2); + UNIT_ASSERT(!(m1 != m2)); + UNIT_ASSERT(!(m1 < m2)); + UNIT_ASSERT(m1 <= m2); + UNIT_ASSERT(!(m1 > m2)); + UNIT_ASSERT(m1 >= m2); + } + Y_UNIT_TEST(TestCompareEqualNonEmpty) { TMaybe<int> m1{1}; TMaybe<int> m2{1}; - - UNIT_ASSERT(m1 == m2); - UNIT_ASSERT(!(m1 != m2)); - UNIT_ASSERT(!(m1 < m2)); - UNIT_ASSERT(m1 <= m2); - UNIT_ASSERT(!(m1 > m2)); - UNIT_ASSERT(m1 >= m2); - } - + + UNIT_ASSERT(m1 == m2); + UNIT_ASSERT(!(m1 != m2)); + UNIT_ASSERT(!(m1 < m2)); + UNIT_ASSERT(m1 <= m2); + UNIT_ASSERT(!(m1 > m2)); + UNIT_ASSERT(m1 >= m2); + } + Y_UNIT_TEST(TestCompareOneLessThanOther) { TMaybe<int> m1{1}; TMaybe<int> m2{2}; - - UNIT_ASSERT(!(m1 == m2)); - UNIT_ASSERT(m1 != m2); - UNIT_ASSERT(m1 < m2); - UNIT_ASSERT(m1 <= m2); - UNIT_ASSERT(!(m1 > m2)); - UNIT_ASSERT(!(m1 >= m2)); - } - + + UNIT_ASSERT(!(m1 == m2)); + UNIT_ASSERT(m1 != m2); + UNIT_ASSERT(m1 < m2); + UNIT_ASSERT(m1 <= m2); + UNIT_ASSERT(!(m1 > m2)); + UNIT_ASSERT(!(m1 >= m2)); + } + Y_UNIT_TEST(TestCompareTMaybeAndT_Equal) { TMaybe<int> m{1}; int v{1}; - - UNIT_ASSERT(m == v); - UNIT_ASSERT(!(m != v)); - UNIT_ASSERT(!(m < v)); - UNIT_ASSERT(m <= v); - UNIT_ASSERT(!(m > v)); - UNIT_ASSERT(m >= v); - - UNIT_ASSERT(v == m); - UNIT_ASSERT(!(v != m)); - UNIT_ASSERT(!(v < m)); - UNIT_ASSERT(v <= m); - UNIT_ASSERT(!(v > m)); - UNIT_ASSERT(v >= m); - } - + + UNIT_ASSERT(m == v); + UNIT_ASSERT(!(m != v)); + UNIT_ASSERT(!(m < v)); + UNIT_ASSERT(m <= v); + UNIT_ASSERT(!(m > v)); + UNIT_ASSERT(m >= v); + + UNIT_ASSERT(v == m); + UNIT_ASSERT(!(v != m)); + UNIT_ASSERT(!(v < m)); + UNIT_ASSERT(v <= m); + UNIT_ASSERT(!(v > m)); + UNIT_ASSERT(v >= m); + } + Y_UNIT_TEST(TestCompareTMaybeAndT_TMaybeLessThanT) { TMaybe<int> m{1}; int v{2}; - - UNIT_ASSERT(!(m == v)); - UNIT_ASSERT(m != v); - UNIT_ASSERT(m < v); - UNIT_ASSERT(m <= v); - UNIT_ASSERT(!(m > v)); - UNIT_ASSERT(!(m >= v)); - - UNIT_ASSERT(!(v == m)); - UNIT_ASSERT(v != m); - UNIT_ASSERT(!(v < m)); - UNIT_ASSERT(!(v <= m)); - UNIT_ASSERT(v > m); - UNIT_ASSERT(v >= m); - } - + + UNIT_ASSERT(!(m == v)); + UNIT_ASSERT(m != v); + UNIT_ASSERT(m < v); + UNIT_ASSERT(m <= v); + UNIT_ASSERT(!(m > v)); + UNIT_ASSERT(!(m >= v)); + + UNIT_ASSERT(!(v == m)); + UNIT_ASSERT(v != m); + UNIT_ASSERT(!(v < m)); + UNIT_ASSERT(!(v <= m)); + UNIT_ASSERT(v > m); + UNIT_ASSERT(v >= m); + } + Y_UNIT_TEST(TestCompareTMaybeAndT_TMaybeGreaterThanT) { TMaybe<int> m{2}; int v{1}; - - UNIT_ASSERT(!(m == v)); - UNIT_ASSERT(m != v); - UNIT_ASSERT(!(m < v)); - UNIT_ASSERT(!(m <= v)); - UNIT_ASSERT(m > v); - UNIT_ASSERT(m >= v); - - UNIT_ASSERT(!(v == m)); - UNIT_ASSERT(v != m); - UNIT_ASSERT(v < m); - UNIT_ASSERT(v <= m); - UNIT_ASSERT(!(v > m)); - UNIT_ASSERT(!(v >= m)); - } - + + UNIT_ASSERT(!(m == v)); + UNIT_ASSERT(m != v); + UNIT_ASSERT(!(m < v)); + UNIT_ASSERT(!(m <= v)); + UNIT_ASSERT(m > v); + UNIT_ASSERT(m >= v); + + UNIT_ASSERT(!(v == m)); + UNIT_ASSERT(v != m); + UNIT_ASSERT(v < m); + UNIT_ASSERT(v <= m); + UNIT_ASSERT(!(v > m)); + UNIT_ASSERT(!(v >= m)); + } + Y_UNIT_TEST(TestCompareEmptyTMaybeAndT) { - TMaybe<int> m; + TMaybe<int> m; int v{1}; - - UNIT_ASSERT(!(m == v)); - UNIT_ASSERT(m != v); - UNIT_ASSERT(m < v); - UNIT_ASSERT(m <= v); - UNIT_ASSERT(!(m > v)); - UNIT_ASSERT(!(m >= v)); - - UNIT_ASSERT(!(v == m)); - UNIT_ASSERT(v != m); - UNIT_ASSERT(!(v < m)); - UNIT_ASSERT(!(v <= m)); - UNIT_ASSERT(v > m); - UNIT_ASSERT(v >= m); - } - + + UNIT_ASSERT(!(m == v)); + UNIT_ASSERT(m != v); + UNIT_ASSERT(m < v); + UNIT_ASSERT(m <= v); + UNIT_ASSERT(!(m > v)); + UNIT_ASSERT(!(m >= v)); + + UNIT_ASSERT(!(v == m)); + UNIT_ASSERT(v != m); + UNIT_ASSERT(!(v < m)); + UNIT_ASSERT(!(v <= m)); + UNIT_ASSERT(v > m); + UNIT_ASSERT(v >= m); + } + Y_UNIT_TEST(TestCompareEmptyTMaybeAndNothing) { - TMaybe<int> m; - auto n = Nothing(); - - UNIT_ASSERT(m == n); - UNIT_ASSERT(!(m != n)); - UNIT_ASSERT(!(m < n)); - UNIT_ASSERT(m <= n); - UNIT_ASSERT(!(m > n)); - UNIT_ASSERT(m >= n); - - UNIT_ASSERT(n == m); - UNIT_ASSERT(!(n != m)); - UNIT_ASSERT(!(n < m)); - UNIT_ASSERT(n <= m); - UNIT_ASSERT(!(n > m)); - UNIT_ASSERT(n >= m); - } - + TMaybe<int> m; + auto n = Nothing(); + + UNIT_ASSERT(m == n); + UNIT_ASSERT(!(m != n)); + UNIT_ASSERT(!(m < n)); + UNIT_ASSERT(m <= n); + UNIT_ASSERT(!(m > n)); + UNIT_ASSERT(m >= n); + + UNIT_ASSERT(n == m); + UNIT_ASSERT(!(n != m)); + UNIT_ASSERT(!(n < m)); + UNIT_ASSERT(n <= m); + UNIT_ASSERT(!(n > m)); + UNIT_ASSERT(n >= m); + } + Y_UNIT_TEST(TestCompareNonEmptyTMaybeAndNothing) { TMaybe<int> m{1}; - auto n = Nothing(); - - UNIT_ASSERT(!(m == n)); - UNIT_ASSERT(m != n); - UNIT_ASSERT(!(m < n)); - UNIT_ASSERT(!(m <= n)); - UNIT_ASSERT(m > n); - UNIT_ASSERT(m >= n); - - UNIT_ASSERT(!(n == m)); - UNIT_ASSERT(n != m); - UNIT_ASSERT(n < m); - UNIT_ASSERT(n <= m); - UNIT_ASSERT(!(n > m)); - UNIT_ASSERT(!(n >= m)); - } - + auto n = Nothing(); + + UNIT_ASSERT(!(m == n)); + UNIT_ASSERT(m != n); + UNIT_ASSERT(!(m < n)); + UNIT_ASSERT(!(m <= n)); + UNIT_ASSERT(m > n); + UNIT_ASSERT(m >= n); + + UNIT_ASSERT(!(n == m)); + UNIT_ASSERT(n != m); + UNIT_ASSERT(n < m); + UNIT_ASSERT(n <= m); + UNIT_ASSERT(!(n > m)); + UNIT_ASSERT(!(n >= m)); + } + Y_UNIT_TEST(TestCompareTMaybeAndConvertibleT_Equal) { TMaybe<size_t> m{1}; unsigned int v{1}; - - UNIT_ASSERT(m == v); - UNIT_ASSERT(!(m != v)); - UNIT_ASSERT(!(m < v)); - UNIT_ASSERT(m <= v); - UNIT_ASSERT(!(m > v)); - UNIT_ASSERT(m >= v); - - UNIT_ASSERT(v == m); - UNIT_ASSERT(!(v != m)); - UNIT_ASSERT(!(v < m)); - UNIT_ASSERT(v <= m); - UNIT_ASSERT(!(v > m)); - UNIT_ASSERT(v >= m); - } - + + UNIT_ASSERT(m == v); + UNIT_ASSERT(!(m != v)); + UNIT_ASSERT(!(m < v)); + UNIT_ASSERT(m <= v); + UNIT_ASSERT(!(m > v)); + UNIT_ASSERT(m >= v); + + UNIT_ASSERT(v == m); + UNIT_ASSERT(!(v != m)); + UNIT_ASSERT(!(v < m)); + UNIT_ASSERT(v <= m); + UNIT_ASSERT(!(v > m)); + UNIT_ASSERT(v >= m); + } + Y_UNIT_TEST(TestCompareTMaybeAndConvertibleT_TMaybeLessThanT) { TMaybe<size_t> m{1}; unsigned int v{2}; - - UNIT_ASSERT(!(m == v)); - UNIT_ASSERT(m != v); - UNIT_ASSERT(m < v); - UNIT_ASSERT(m <= v); - UNIT_ASSERT(!(m > v)); - UNIT_ASSERT(!(m >= v)); - - UNIT_ASSERT(!(v == m)); - UNIT_ASSERT(v != m); - UNIT_ASSERT(!(v < m)); - UNIT_ASSERT(!(v <= m)); - UNIT_ASSERT(v > m); - UNIT_ASSERT(v >= m); - } - + + UNIT_ASSERT(!(m == v)); + UNIT_ASSERT(m != v); + UNIT_ASSERT(m < v); + UNIT_ASSERT(m <= v); + UNIT_ASSERT(!(m > v)); + UNIT_ASSERT(!(m >= v)); + + UNIT_ASSERT(!(v == m)); + UNIT_ASSERT(v != m); + UNIT_ASSERT(!(v < m)); + UNIT_ASSERT(!(v <= m)); + UNIT_ASSERT(v > m); + UNIT_ASSERT(v >= m); + } + Y_UNIT_TEST(TestCompareTMaybeAndConvertibleT_TMaybeGreaterThanT) { TMaybe<size_t> m{2}; unsigned int v{1}; - - UNIT_ASSERT(!(m == v)); - UNIT_ASSERT(m != v); - UNIT_ASSERT(!(m < v)); - UNIT_ASSERT(!(m <= v)); - UNIT_ASSERT(m > v); - UNIT_ASSERT(m >= v); - - UNIT_ASSERT(!(v == m)); - UNIT_ASSERT(v != m); - UNIT_ASSERT(v < m); - UNIT_ASSERT(v <= m); - UNIT_ASSERT(!(v > m)); - UNIT_ASSERT(!(v >= m)); - } - + + UNIT_ASSERT(!(m == v)); + UNIT_ASSERT(m != v); + UNIT_ASSERT(!(m < v)); + UNIT_ASSERT(!(m <= v)); + UNIT_ASSERT(m > v); + UNIT_ASSERT(m >= v); + + UNIT_ASSERT(!(v == m)); + UNIT_ASSERT(v != m); + UNIT_ASSERT(v < m); + UNIT_ASSERT(v <= m); + UNIT_ASSERT(!(v > m)); + UNIT_ASSERT(!(v >= m)); + } + Y_UNIT_TEST(TestCompareEmptyTMaybeAndConvertibleT) { - TMaybe<size_t> m; + TMaybe<size_t> m; unsigned int v{1}; - - UNIT_ASSERT(!(m == v)); - UNIT_ASSERT(m != v); - UNIT_ASSERT(m < v); - UNIT_ASSERT(m <= v); - UNIT_ASSERT(!(m > v)); - UNIT_ASSERT(!(m >= v)); - - UNIT_ASSERT(!(v == m)); - UNIT_ASSERT(v != m); - UNIT_ASSERT(!(v < m)); - UNIT_ASSERT(!(v <= m)); - UNIT_ASSERT(v > m); - UNIT_ASSERT(v >= m); - } - + + UNIT_ASSERT(!(m == v)); + UNIT_ASSERT(m != v); + UNIT_ASSERT(m < v); + UNIT_ASSERT(m <= v); + UNIT_ASSERT(!(m > v)); + UNIT_ASSERT(!(m >= v)); + + UNIT_ASSERT(!(v == m)); + UNIT_ASSERT(v != m); + UNIT_ASSERT(!(v < m)); + UNIT_ASSERT(!(v <= m)); + UNIT_ASSERT(v > m); + UNIT_ASSERT(v >= m); + } + Y_UNIT_TEST(TestMakeMaybe) { - { - auto m1 = MakeMaybe<int>(1); - UNIT_ASSERT(*m1 == 1); - } - - { - struct TMockClass { - TMockClass(int i) - : I_(i) - { - } - - TMockClass(const TMockClass& other) - : I_(other.I_) - { - IsCopyConstructorCalled_ = true; - } - - TMockClass& operator=(const TMockClass& other) { - if (this != &other) { - I_ = other.I_; - IsCopyAssignmentOperatorCalled_ = true; - } - - return *this; - } - - TMockClass(TMockClass&& other) - : I_(other.I_) - { - IsMoveConstructorCalled_ = true; - } - - TMockClass& operator=(TMockClass&& other) { - if (this != &other) { - I_ = other.I_; - IsMoveAssignmentOperatorCalled_ = true; - } - - return *this; - } - - int I_; + { + auto m1 = MakeMaybe<int>(1); + UNIT_ASSERT(*m1 == 1); + } + + { + struct TMockClass { + TMockClass(int i) + : I_(i) + { + } + + TMockClass(const TMockClass& other) + : I_(other.I_) + { + IsCopyConstructorCalled_ = true; + } + + TMockClass& operator=(const TMockClass& other) { + if (this != &other) { + I_ = other.I_; + IsCopyAssignmentOperatorCalled_ = true; + } + + return *this; + } + + TMockClass(TMockClass&& other) + : I_(other.I_) + { + IsMoveConstructorCalled_ = true; + } + + TMockClass& operator=(TMockClass&& other) { + if (this != &other) { + I_ = other.I_; + IsMoveAssignmentOperatorCalled_ = true; + } + + return *this; + } + + int I_; bool IsCopyConstructorCalled_{false}; bool IsMoveConstructorCalled_{false}; bool IsCopyAssignmentOperatorCalled_{false}; bool IsMoveAssignmentOperatorCalled_{false}; - }; - - auto m2 = MakeMaybe<TMockClass>(1); - UNIT_ASSERT(m2->I_ == 1); - UNIT_ASSERT(!m2->IsCopyConstructorCalled_); - UNIT_ASSERT(!m2->IsMoveConstructorCalled_); - UNIT_ASSERT(!m2->IsCopyAssignmentOperatorCalled_); - UNIT_ASSERT(!m2->IsMoveAssignmentOperatorCalled_); - } - - { - auto m3 = MakeMaybe<TVector<int>>({1, 2, 3, 4, 5}); - UNIT_ASSERT(m3->size() == 5); - UNIT_ASSERT(m3->at(0) == 1); - UNIT_ASSERT(m3->at(1) == 2); - UNIT_ASSERT(m3->at(2) == 3); - UNIT_ASSERT(m3->at(3) == 4); - UNIT_ASSERT(m3->at(4) == 5); - } - - { - struct TMockStruct4 { - TMockStruct4(int a, int b, int c) - : A_(a) - , B_(b) - , C_(c) - { - } - - int A_; - int B_; - int C_; - }; - - auto m4 = MakeMaybe<TMockStruct4>(1, 2, 3); - UNIT_ASSERT(m4->A_ == 1); - UNIT_ASSERT(m4->B_ == 2); - UNIT_ASSERT(m4->C_ == 3); - } - - { - struct TMockStruct5 { - TMockStruct5(const TVector<int>& vec, bool someFlag) - : Vec_(vec) - , SomeFlag_(someFlag) - { - } - - TVector<int> Vec_; - bool SomeFlag_; - }; - + }; + + auto m2 = MakeMaybe<TMockClass>(1); + UNIT_ASSERT(m2->I_ == 1); + UNIT_ASSERT(!m2->IsCopyConstructorCalled_); + UNIT_ASSERT(!m2->IsMoveConstructorCalled_); + UNIT_ASSERT(!m2->IsCopyAssignmentOperatorCalled_); + UNIT_ASSERT(!m2->IsMoveAssignmentOperatorCalled_); + } + + { + auto m3 = MakeMaybe<TVector<int>>({1, 2, 3, 4, 5}); + UNIT_ASSERT(m3->size() == 5); + UNIT_ASSERT(m3->at(0) == 1); + UNIT_ASSERT(m3->at(1) == 2); + UNIT_ASSERT(m3->at(2) == 3); + UNIT_ASSERT(m3->at(3) == 4); + UNIT_ASSERT(m3->at(4) == 5); + } + + { + struct TMockStruct4 { + TMockStruct4(int a, int b, int c) + : A_(a) + , B_(b) + , C_(c) + { + } + + int A_; + int B_; + int C_; + }; + + auto m4 = MakeMaybe<TMockStruct4>(1, 2, 3); + UNIT_ASSERT(m4->A_ == 1); + UNIT_ASSERT(m4->B_ == 2); + UNIT_ASSERT(m4->C_ == 3); + } + + { + struct TMockStruct5 { + TMockStruct5(const TVector<int>& vec, bool someFlag) + : Vec_(vec) + , SomeFlag_(someFlag) + { + } + + TVector<int> Vec_; + bool SomeFlag_; + }; + auto m5 = MakeMaybe<TMockStruct5>({1, 2, 3}, true); - UNIT_ASSERT(m5->Vec_.size() == 3); - UNIT_ASSERT(m5->Vec_[0] == 1); - UNIT_ASSERT(m5->Vec_[1] == 2); - UNIT_ASSERT(m5->Vec_[2] == 3); - UNIT_ASSERT(m5->SomeFlag_); - } - } - + UNIT_ASSERT(m5->Vec_.size() == 3); + UNIT_ASSERT(m5->Vec_[0] == 1); + UNIT_ASSERT(m5->Vec_[1] == 2); + UNIT_ASSERT(m5->Vec_[2] == 3); + UNIT_ASSERT(m5->SomeFlag_); + } + } + Y_UNIT_TEST(TestSwappingUsingMemberSwap) { - { - TMaybe<int> m1 = 1; - TMaybe<int> m2 = 2; - - UNIT_ASSERT(*m1 == 1); - UNIT_ASSERT(*m2 == 2); - - m1.Swap(m2); - - UNIT_ASSERT(*m1 == 2); - UNIT_ASSERT(*m2 == 1); - } - - { - TMaybe<int> m1 = 1; - TMaybe<int> m2 = Nothing(); - - UNIT_ASSERT(*m1 == 1); - UNIT_ASSERT(m2 == Nothing()); - - m1.Swap(m2); - - UNIT_ASSERT(m1 == Nothing()); - UNIT_ASSERT(*m2 == 1); - } - - { - TMaybe<int> m1 = Nothing(); - TMaybe<int> m2 = 1; - - UNIT_ASSERT(m1 == Nothing()); - UNIT_ASSERT(*m2 == 1); - - m1.Swap(m2); - - UNIT_ASSERT(*m1 == 1); - UNIT_ASSERT(m2 == Nothing()); - } - } - + { + TMaybe<int> m1 = 1; + TMaybe<int> m2 = 2; + + UNIT_ASSERT(*m1 == 1); + UNIT_ASSERT(*m2 == 2); + + m1.Swap(m2); + + UNIT_ASSERT(*m1 == 2); + UNIT_ASSERT(*m2 == 1); + } + + { + TMaybe<int> m1 = 1; + TMaybe<int> m2 = Nothing(); + + UNIT_ASSERT(*m1 == 1); + UNIT_ASSERT(m2 == Nothing()); + + m1.Swap(m2); + + UNIT_ASSERT(m1 == Nothing()); + UNIT_ASSERT(*m2 == 1); + } + + { + TMaybe<int> m1 = Nothing(); + TMaybe<int> m2 = 1; + + UNIT_ASSERT(m1 == Nothing()); + UNIT_ASSERT(*m2 == 1); + + m1.Swap(m2); + + UNIT_ASSERT(*m1 == 1); + UNIT_ASSERT(m2 == Nothing()); + } + } + Y_UNIT_TEST(TestSwappingUsingMemberLittleSwap) { - { - TMaybe<int> m1 = 1; - TMaybe<int> m2 = 2; - - UNIT_ASSERT(*m1 == 1); - UNIT_ASSERT(*m2 == 2); - - m1.swap(m2); - - UNIT_ASSERT(*m1 == 2); - UNIT_ASSERT(*m2 == 1); - } - - { - TMaybe<int> m1 = 1; - TMaybe<int> m2 = Nothing(); - - UNIT_ASSERT(*m1 == 1); - UNIT_ASSERT(m2 == Nothing()); - - m1.swap(m2); - - UNIT_ASSERT(m1 == Nothing()); - UNIT_ASSERT(*m2 == 1); - } - - { - TMaybe<int> m1 = Nothing(); - TMaybe<int> m2 = 1; - - UNIT_ASSERT(m1 == Nothing()); - UNIT_ASSERT(*m2 == 1); - - m1.swap(m2); - - UNIT_ASSERT(*m1 == 1); - UNIT_ASSERT(m2 == Nothing()); - } - } - + { + TMaybe<int> m1 = 1; + TMaybe<int> m2 = 2; + + UNIT_ASSERT(*m1 == 1); + UNIT_ASSERT(*m2 == 2); + + m1.swap(m2); + + UNIT_ASSERT(*m1 == 2); + UNIT_ASSERT(*m2 == 1); + } + + { + TMaybe<int> m1 = 1; + TMaybe<int> m2 = Nothing(); + + UNIT_ASSERT(*m1 == 1); + UNIT_ASSERT(m2 == Nothing()); + + m1.swap(m2); + + UNIT_ASSERT(m1 == Nothing()); + UNIT_ASSERT(*m2 == 1); + } + + { + TMaybe<int> m1 = Nothing(); + TMaybe<int> m2 = 1; + + UNIT_ASSERT(m1 == Nothing()); + UNIT_ASSERT(*m2 == 1); + + m1.swap(m2); + + UNIT_ASSERT(*m1 == 1); + UNIT_ASSERT(m2 == Nothing()); + } + } + Y_UNIT_TEST(TestSwappingUsingGlobalSwap) { - { - TMaybe<int> m1 = 1; - TMaybe<int> m2 = 2; - - UNIT_ASSERT(*m1 == 1); - UNIT_ASSERT(*m2 == 2); - - ::Swap(m1, m2); - - UNIT_ASSERT(*m1 == 2); - UNIT_ASSERT(*m2 == 1); - } - - { - TMaybe<int> m1 = 1; - TMaybe<int> m2 = Nothing(); - - UNIT_ASSERT(*m1 == 1); - UNIT_ASSERT(m2 == Nothing()); - - ::Swap(m1, m2); - - UNIT_ASSERT(m1 == Nothing()); - UNIT_ASSERT(*m2 == 1); - } - - { - TMaybe<int> m1 = Nothing(); - TMaybe<int> m2 = 1; - - UNIT_ASSERT(m1 == Nothing()); - UNIT_ASSERT(*m2 == 1); - - ::Swap(m1, m2); - - UNIT_ASSERT(*m1 == 1); - UNIT_ASSERT(m2 == Nothing()); - } - } - + { + TMaybe<int> m1 = 1; + TMaybe<int> m2 = 2; + + UNIT_ASSERT(*m1 == 1); + UNIT_ASSERT(*m2 == 2); + + ::Swap(m1, m2); + + UNIT_ASSERT(*m1 == 2); + UNIT_ASSERT(*m2 == 1); + } + + { + TMaybe<int> m1 = 1; + TMaybe<int> m2 = Nothing(); + + UNIT_ASSERT(*m1 == 1); + UNIT_ASSERT(m2 == Nothing()); + + ::Swap(m1, m2); + + UNIT_ASSERT(m1 == Nothing()); + UNIT_ASSERT(*m2 == 1); + } + + { + TMaybe<int> m1 = Nothing(); + TMaybe<int> m2 = 1; + + UNIT_ASSERT(m1 == Nothing()); + UNIT_ASSERT(*m2 == 1); + + ::Swap(m1, m2); + + UNIT_ASSERT(*m1 == 1); + UNIT_ASSERT(m2 == Nothing()); + } + } + Y_UNIT_TEST(TestSwappingUsingGlobalDoSwap) { - { - TMaybe<int> m1 = 1; - TMaybe<int> m2 = 2; - - UNIT_ASSERT(*m1 == 1); - UNIT_ASSERT(*m2 == 2); - - ::DoSwap(m1, m2); - - UNIT_ASSERT(*m1 == 2); - UNIT_ASSERT(*m2 == 1); - } - - { - TMaybe<int> m1 = 1; - TMaybe<int> m2 = Nothing(); - - UNIT_ASSERT(*m1 == 1); - UNIT_ASSERT(m2 == Nothing()); - - ::DoSwap(m1, m2); - - UNIT_ASSERT(m1 == Nothing()); - UNIT_ASSERT(*m2 == 1); - } - - { - TMaybe<int> m1 = Nothing(); - TMaybe<int> m2 = 1; - - UNIT_ASSERT(m1 == Nothing()); - UNIT_ASSERT(*m2 == 1); - - ::DoSwap(m1, m2); - - UNIT_ASSERT(*m1 == 1); - UNIT_ASSERT(m2 == Nothing()); - } - } - + { + TMaybe<int> m1 = 1; + TMaybe<int> m2 = 2; + + UNIT_ASSERT(*m1 == 1); + UNIT_ASSERT(*m2 == 2); + + ::DoSwap(m1, m2); + + UNIT_ASSERT(*m1 == 2); + UNIT_ASSERT(*m2 == 1); + } + + { + TMaybe<int> m1 = 1; + TMaybe<int> m2 = Nothing(); + + UNIT_ASSERT(*m1 == 1); + UNIT_ASSERT(m2 == Nothing()); + + ::DoSwap(m1, m2); + + UNIT_ASSERT(m1 == Nothing()); + UNIT_ASSERT(*m2 == 1); + } + + { + TMaybe<int> m1 = Nothing(); + TMaybe<int> m2 = 1; + + UNIT_ASSERT(m1 == Nothing()); + UNIT_ASSERT(*m2 == 1); + + ::DoSwap(m1, m2); + + UNIT_ASSERT(*m1 == 1); + UNIT_ASSERT(m2 == Nothing()); + } + } + Y_UNIT_TEST(TestSwappingUsingStdSwap) { - { - TMaybe<int> m1 = 1; - TMaybe<int> m2 = 2; - - UNIT_ASSERT(*m1 == 1); - UNIT_ASSERT(*m2 == 2); - - ::std::swap(m1, m2); - - UNIT_ASSERT(*m1 == 2); - UNIT_ASSERT(*m2 == 1); - } - - { - TMaybe<int> m1 = 1; - TMaybe<int> m2 = Nothing(); - - UNIT_ASSERT(*m1 == 1); - UNIT_ASSERT(m2 == Nothing()); - - ::std::swap(m1, m2); - - UNIT_ASSERT(m1 == Nothing()); - UNIT_ASSERT(*m2 == 1); - } - - { - TMaybe<int> m1 = Nothing(); - TMaybe<int> m2 = 1; - - UNIT_ASSERT(m1 == Nothing()); - UNIT_ASSERT(*m2 == 1); - - ::std::swap(m1, m2); - - UNIT_ASSERT(*m1 == 1); - UNIT_ASSERT(m2 == Nothing()); - } - } + { + TMaybe<int> m1 = 1; + TMaybe<int> m2 = 2; + + UNIT_ASSERT(*m1 == 1); + UNIT_ASSERT(*m2 == 2); + + ::std::swap(m1, m2); + + UNIT_ASSERT(*m1 == 2); + UNIT_ASSERT(*m2 == 1); + } + + { + TMaybe<int> m1 = 1; + TMaybe<int> m2 = Nothing(); + + UNIT_ASSERT(*m1 == 1); + UNIT_ASSERT(m2 == Nothing()); + + ::std::swap(m1, m2); + + UNIT_ASSERT(m1 == Nothing()); + UNIT_ASSERT(*m2 == 1); + } + + { + TMaybe<int> m1 = Nothing(); + TMaybe<int> m2 = 1; + + UNIT_ASSERT(m1 == Nothing()); + UNIT_ASSERT(*m2 == 1); + + ::std::swap(m1, m2); + + UNIT_ASSERT(*m1 == 1); + UNIT_ASSERT(m2 == Nothing()); + } + } Y_UNIT_TEST(TestOutputStreamEmptyMaybe) { - TString s; + TString s; TStringOutput output(s); output << TMaybe<int>(); UNIT_ASSERT_EQUAL("(empty maybe)", s); @@ -803,7 +803,7 @@ Y_UNIT_TEST_SUITE(TMaybeTest) { } Y_UNIT_TEST(TestOutputStreamDefinedMaybe) { - TString s; + TString s; TStringOutput output(s); output << TMaybe<int>(42); UNIT_ASSERT_EQUAL("42", s); diff --git a/util/generic/mem_copy.h b/util/generic/mem_copy.h index b68c852953..6f38fdc1ab 100644 --- a/util/generic/mem_copy.h +++ b/util/generic/mem_copy.h @@ -13,7 +13,7 @@ template <class T> using TIfNotPOD = std::enable_if_t<!TTypeTraits<T>::IsPod, T*>; template <class T> -static inline TIfPOD<T> MemCopy(T* to, const T* from, size_t n) noexcept { +static inline TIfPOD<T> MemCopy(T* to, const T* from, size_t n) noexcept { if (n) { memcpy(to, from, n * sizeof(T)); } @@ -31,7 +31,7 @@ static inline TIfNotPOD<T> MemCopy(T* to, const T* from, size_t n) { } template <class T> -static inline TIfPOD<T> MemMove(T* to, const T* from, size_t n) noexcept { +static inline TIfPOD<T> MemMove(T* to, const T* from, size_t n) noexcept { if (n) { memmove(to, from, n * sizeof(T)); } diff --git a/util/generic/noncopyable.h b/util/generic/noncopyable.h index c007934133..dca012a738 100644 --- a/util/generic/noncopyable.h +++ b/util/generic/noncopyable.h @@ -15,11 +15,11 @@ namespace NNonCopyable { // protection from unintended ADL struct TNonCopyable { - TNonCopyable(const TNonCopyable&) = delete; - TNonCopyable& operator=(const TNonCopyable&) = delete; + TNonCopyable(const TNonCopyable&) = delete; + TNonCopyable& operator=(const TNonCopyable&) = delete; - TNonCopyable() = default; - ~TNonCopyable() = default; + TNonCopyable() = default; + ~TNonCopyable() = default; }; struct TMoveOnly { diff --git a/util/generic/object_counter.h b/util/generic/object_counter.h index 5257afa2e6..c69e94c226 100644 --- a/util/generic/object_counter.h +++ b/util/generic/object_counter.h @@ -19,7 +19,7 @@ template <class T> class TObjectCounter { public: - inline TObjectCounter() noexcept { + inline TObjectCounter() noexcept { AtomicIncrement(Count_); } @@ -27,11 +27,11 @@ public: AtomicIncrement(Count_); } - inline ~TObjectCounter() { + inline ~TObjectCounter() { AtomicDecrement(Count_); } - static inline long ObjectCount() noexcept { + static inline long ObjectCount() noexcept { return AtomicGet(Count_); } diff --git a/util/generic/objects_counter_ut.cpp b/util/generic/objects_counter_ut.cpp index 4d5da37a56..6f4ae128fd 100644 --- a/util/generic/objects_counter_ut.cpp +++ b/util/generic/objects_counter_ut.cpp @@ -8,7 +8,7 @@ Y_UNIT_TEST_SUITE(ObjectsCounter) { Y_UNIT_TEST(Test1) { TObject obj; - TVector<TObject> objects; + TVector<TObject> objects; for (ui32 i = 0; i < 100; ++i) { objects.push_back(obj); } diff --git a/util/generic/ptr.cpp b/util/generic/ptr.cpp index b29baebc17..b28755821f 100644 --- a/util/generic/ptr.cpp +++ b/util/generic/ptr.cpp @@ -6,11 +6,11 @@ #include <new> #include <cstdlib> -void TFree::DoDestroy(void* t) noexcept { +void TFree::DoDestroy(void* t) noexcept { free(t); } -void TDelete::Destroy(void* t) noexcept { +void TDelete::Destroy(void* t) noexcept { ::operator delete(t); } diff --git a/util/generic/ptr.h b/util/generic/ptr.h index 19db0e3ec5..61bd1f89b5 100644 --- a/util/generic/ptr.h +++ b/util/generic/ptr.h @@ -44,33 +44,33 @@ inline void CheckedArrayDelete(T* t) { class TNoAction { public: template <class T> - static inline void Destroy(T*) noexcept { + static inline void Destroy(T*) noexcept { } }; class TDelete { public: template <class T> - static inline void Destroy(T* t) noexcept { + static inline void Destroy(T* t) noexcept { CheckedDelete(t); } /* - * special handling for nullptr - call nothing - */ - static inline void Destroy(std::nullptr_t) noexcept { - } - - /* + * special handling for nullptr - call nothing + */ + static inline void Destroy(std::nullptr_t) noexcept { + } + + /* * special handling for void* - call ::operator delete() */ - static void Destroy(void* t) noexcept; + static void Destroy(void* t) noexcept; }; class TDeleteArray { public: template <class T> - static inline void Destroy(T* t) noexcept { + static inline void Destroy(T* t) noexcept { CheckedArrayDelete(t); } }; @@ -78,7 +78,7 @@ public: class TDestructor { public: template <class T> - static inline void Destroy(T* t) noexcept { + static inline void Destroy(T* t) noexcept { (void)t; t->~T(); } @@ -87,7 +87,7 @@ public: class TFree { public: template <class T> - static inline void Destroy(T* t) noexcept { + static inline void Destroy(T* t) noexcept { DoDestroy((void*)t); } @@ -95,7 +95,7 @@ private: /* * we do not want dependancy on cstdlib here... */ - static void DoDestroy(void* t) noexcept; + static void DoDestroy(void* t) noexcept; }; template <class Base, class T> @@ -103,7 +103,7 @@ class TPointerCommon { public: using TValueType = T; - inline T* operator->() const noexcept { + inline T* operator->() const noexcept { T* ptr = AsT(); Y_ASSERT(ptr); return ptr; @@ -111,26 +111,26 @@ public: #ifndef __cpp_impl_three_way_comparison template <class C> - inline bool operator==(const C& p) const noexcept { + inline bool operator==(const C& p) const noexcept { return (p == AsT()); } template <class C> - inline bool operator!=(const C& p) const noexcept { + inline bool operator!=(const C& p) const noexcept { return (p != AsT()); } #endif - inline explicit operator bool() const noexcept { + inline explicit operator bool() const noexcept { return nullptr != AsT(); } protected: - inline T* AsT() const noexcept { + inline T* AsT() const noexcept { return (static_cast<const Base*>(this))->Get(); } - static inline T* DoRelease(T*& t) noexcept { + static inline T* DoRelease(T*& t) noexcept { T* ret = t; t = nullptr; return ret; @@ -140,13 +140,13 @@ protected: template <class Base, class T> class TPointerBase: public TPointerCommon<Base, T> { public: - inline T& operator*() const noexcept { + inline T& operator*() const noexcept { Y_ASSERT(this->AsT()); return *(this->AsT()); } - inline T& operator[](size_t n) const noexcept { + inline T& operator[](size_t n) const noexcept { Y_ASSERT(this->AsT()); return (this->AsT())[n]; @@ -163,21 +163,21 @@ class TPointerBase<Base, void>: public TPointerCommon<Base, void> { template <class T, class D> class TAutoPtr: public TPointerBase<TAutoPtr<T, D>, T> { public: - inline TAutoPtr(T* t = nullptr) noexcept + inline TAutoPtr(T* t = nullptr) noexcept : T_(t) { } - inline TAutoPtr(const TAutoPtr& t) noexcept + inline TAutoPtr(const TAutoPtr& t) noexcept : T_(t.Release()) { } - inline ~TAutoPtr() { + inline ~TAutoPtr() { DoDestroy(); } - inline TAutoPtr& operator=(const TAutoPtr& t) noexcept { + inline TAutoPtr& operator=(const TAutoPtr& t) noexcept { if (this != &t) { Reset(t.Release()); } @@ -189,26 +189,26 @@ public: return this->DoRelease(T_); } - inline void Reset(T* t) noexcept { + inline void Reset(T* t) noexcept { if (T_ != t) { DoDestroy(); T_ = t; } } - inline void Reset() noexcept { + inline void Reset() noexcept { Destroy(); } - inline void Destroy() noexcept { + inline void Destroy() noexcept { Reset(nullptr); } - inline void Swap(TAutoPtr& r) noexcept { + inline void Swap(TAutoPtr& r) noexcept { DoSwap(T_, r.T_); } - inline T* Get() const noexcept { + inline T* Get() const noexcept { return T_; } @@ -219,7 +219,7 @@ public: } #endif private: - inline void DoDestroy() noexcept { + inline void DoDestroy() noexcept { if (T_) { D::Destroy(T_); } @@ -232,22 +232,22 @@ private: template <class T, class D> class THolder: public TPointerBase<THolder<T, D>, T> { public: - constexpr THolder() noexcept - : T_(nullptr) - { - } - - constexpr THolder(std::nullptr_t) noexcept - : T_(nullptr) - { - } - + constexpr THolder() noexcept + : T_(nullptr) + { + } + + constexpr THolder(std::nullptr_t) noexcept + : T_(nullptr) + { + } + explicit THolder(T* t) noexcept : T_(t) { } - inline THolder(TAutoPtr<T, D> t) noexcept + inline THolder(TAutoPtr<T, D> t) noexcept : T_(t.Release()) { } @@ -272,11 +272,11 @@ public: THolder(const THolder&) = delete; THolder& operator=(const THolder&) = delete; - inline ~THolder() { + inline ~THolder() { DoDestroy(); } - inline void Destroy() noexcept { + inline void Destroy() noexcept { Reset(nullptr); } @@ -284,22 +284,22 @@ public: return this->DoRelease(T_); } - inline void Reset(T* t) noexcept { + inline void Reset(T* t) noexcept { if (T_ != t) { DoDestroy(); T_ = t; } } - inline void Reset(TAutoPtr<T, D> t) noexcept { + inline void Reset(TAutoPtr<T, D> t) noexcept { Reset(t.Release()); } - inline void Reset() noexcept { + inline void Reset() noexcept { Destroy(); } - inline void Swap(THolder& r) noexcept { + inline void Swap(THolder& r) noexcept { DoSwap(T_, r.T_); } @@ -307,15 +307,15 @@ public: return T_; } - inline operator TAutoPtr<T, D>() noexcept { + inline operator TAutoPtr<T, D>() noexcept { return Release(); } - THolder& operator=(std::nullptr_t) noexcept { - this->Reset(nullptr); - return *this; - } - + THolder& operator=(std::nullptr_t) noexcept { + this->Reset(nullptr); + return *this; + } + THolder& operator=(THolder&& that) noexcept { this->Reset(that.Release()); return *this; @@ -334,7 +334,7 @@ public: } #endif private: - inline void DoDestroy() noexcept { + inline void DoDestroy() noexcept { if (T_) { D::Destroy(T_); } @@ -358,26 +358,26 @@ template <typename T, typename... Args> template <class T, class C, class D> class TRefCounted { public: - inline TRefCounted(long initval = 0) noexcept + inline TRefCounted(long initval = 0) noexcept : Counter_(initval) { } inline ~TRefCounted() = default; - inline void Ref(TAtomicBase d) noexcept { + inline void Ref(TAtomicBase d) noexcept { auto resultCount = Counter_.Add(d); Y_ASSERT(resultCount >= d); (void)resultCount; } - inline void Ref() noexcept { + inline void Ref() noexcept { auto resultCount = Counter_.Inc(); Y_ASSERT(resultCount != 0); (void)resultCount; } - inline void UnRef(TAtomicBase d) noexcept { + inline void UnRef(TAtomicBase d) noexcept { auto resultCount = Counter_.Sub(d); Y_ASSERT(resultCount >= 0); if (resultCount == 0) { @@ -385,7 +385,7 @@ public: } } - inline void UnRef() noexcept { + inline void UnRef() noexcept { UnRef(1); } @@ -393,7 +393,7 @@ public: return Counter_.Val(); } - inline void DecRef() noexcept { + inline void DecRef() noexcept { auto resultCount = Counter_.Dec(); Y_ASSERT(resultCount >= 0); (void)resultCount; @@ -448,25 +448,25 @@ using TSimpleRefCount = TRefCounted<T, TSimpleCounter, D>; template <class T> class TDefaultIntrusivePtrOps { public: - static inline void Ref(T* t) noexcept { + static inline void Ref(T* t) noexcept { Y_ASSERT(t); t->Ref(); } - static inline void UnRef(T* t) noexcept { + static inline void UnRef(T* t) noexcept { Y_ASSERT(t); t->UnRef(); } - static inline void DecRef(T* t) noexcept { + static inline void DecRef(T* t) noexcept { Y_ASSERT(t); t->DecRef(); } - static inline long RefCount(const T* t) noexcept { + static inline long RefCount(const T* t) noexcept { Y_ASSERT(t); return t->RefCount(); @@ -485,7 +485,7 @@ public: struct TNoIncrement { }; - inline TIntrusivePtr(T* t = nullptr) noexcept + inline TIntrusivePtr(T* t = nullptr) noexcept : T_(t) { Ops(); @@ -498,11 +498,11 @@ public: Ops(); } - inline ~TIntrusivePtr() { + inline ~TIntrusivePtr() { UnRef(); } - inline TIntrusivePtr(const TIntrusivePtr& p) noexcept + inline TIntrusivePtr(const TIntrusivePtr& p) noexcept : T_(p.T_) { Ref(); @@ -537,7 +537,7 @@ public: Swap(p); } - inline TIntrusivePtr& operator=(TIntrusivePtr p) noexcept { + inline TIntrusivePtr& operator=(TIntrusivePtr p) noexcept { p.Swap(*this); return *this; @@ -550,19 +550,19 @@ public: Swap(t); } - inline void Reset() noexcept { + inline void Reset() noexcept { Drop(); } - inline T* Get() const noexcept { + inline T* Get() const noexcept { return T_; } - inline void Swap(TIntrusivePtr& r) noexcept { + inline void Swap(TIntrusivePtr& r) noexcept { DoSwap(T_, r.T_); } - inline void Drop() noexcept { + inline void Drop() noexcept { TIntrusivePtr(nullptr).Swap(*this); } @@ -575,7 +575,7 @@ public: return res; } - inline long RefCount() const noexcept { + inline long RefCount() const noexcept { return T_ ? Ops::RefCount(T_) : 0; } @@ -586,13 +586,13 @@ public: } #endif private: - inline void Ref() noexcept { + inline void Ref() noexcept { if (T_) { Ops::Ref(T_); } } - inline void UnRef() noexcept { + inline void UnRef() noexcept { if (T_) { Ops::UnRef(T_); } @@ -614,18 +614,18 @@ struct THash<TIntrusivePtr<T, Ops>>: THash<const T*> { template <class T, class Ops> class TIntrusiveConstPtr: public TPointerBase<TIntrusiveConstPtr<T, Ops>, const T> { public: - inline TIntrusiveConstPtr(T* t = nullptr) noexcept // we need a non-const pointer to Ref(), UnRef() and eventually delete it. + inline TIntrusiveConstPtr(T* t = nullptr) noexcept // we need a non-const pointer to Ref(), UnRef() and eventually delete it. : T_(t) { Ops(); Ref(); } - inline ~TIntrusiveConstPtr() { + inline ~TIntrusiveConstPtr() { UnRef(); } - inline TIntrusiveConstPtr(const TIntrusiveConstPtr& p) noexcept + inline TIntrusiveConstPtr(const TIntrusiveConstPtr& p) noexcept : T_(p.T_) { Ref(); @@ -657,7 +657,7 @@ public: p.T_ = nullptr; } - inline TIntrusiveConstPtr& operator=(TIntrusiveConstPtr p) noexcept { + inline TIntrusiveConstPtr& operator=(TIntrusiveConstPtr p) noexcept { p.Swap(*this); return *this; @@ -670,19 +670,19 @@ public: Swap(t); } - inline void Reset() noexcept { + inline void Reset() noexcept { Drop(); } - inline const T* Get() const noexcept { + inline const T* Get() const noexcept { return T_; } - inline void Swap(TIntrusiveConstPtr& r) noexcept { + inline void Swap(TIntrusiveConstPtr& r) noexcept { DoSwap(T_, r.T_); } - inline void Drop() noexcept { + inline void Drop() noexcept { TIntrusiveConstPtr(nullptr).Swap(*this); } @@ -697,13 +697,13 @@ public: } #endif private: - inline void Ref() noexcept { + inline void Ref() noexcept { if (T_ != nullptr) { Ops::Ref(T_); } } - inline void UnRef() noexcept { + inline void UnRef() noexcept { if (T_ != nullptr) { Ops::UnRef(T_); } @@ -732,31 +732,31 @@ class TSimpleIntrusiveOps { #endif ; - static void DoRef(T* t) noexcept { + static void DoRef(T* t) noexcept { Ops::Ref(t); } - static void DoUnRef(T* t) noexcept { + static void DoUnRef(T* t) noexcept { Ops::UnRef(t); } public: - inline TSimpleIntrusiveOps() noexcept { + inline TSimpleIntrusiveOps() noexcept { InitStaticOps(); } inline ~TSimpleIntrusiveOps() = default; - static inline void Ref(T* t) noexcept { + static inline void Ref(T* t) noexcept { Ref_(t); } - static inline void UnRef(T* t) noexcept { + static inline void UnRef(T* t) noexcept { UnRef_(t); } private: - static inline void InitStaticOps() noexcept { + static inline void InitStaticOps() noexcept { struct TInit { inline TInit() noexcept { Ref_ = DoRef; @@ -794,7 +794,7 @@ class TSharedPtr: public TPointerBase<TSharedPtr<T, C, D>, T> { friend class TSharedPtr; public: - inline TSharedPtr() noexcept + inline TSharedPtr() noexcept : T_(nullptr) , C_(nullptr) { @@ -810,7 +810,7 @@ public: Init(t); } - inline TSharedPtr(T* t, C* c) noexcept + inline TSharedPtr(T* t, C* c) noexcept : T_(t) , C_(c) { @@ -825,7 +825,7 @@ public: UnRef(); } - inline TSharedPtr(const TSharedPtr& t) noexcept + inline TSharedPtr(const TSharedPtr& t) noexcept : T_(t.T_) , C_(t.C_) { @@ -840,7 +840,7 @@ public: } template <class TT, class = TGuardConversion<T, TT>> - inline TSharedPtr(const TSharedPtr<TT, C, D>& t) noexcept + inline TSharedPtr(const TSharedPtr<TT, C, D>& t) noexcept : T_(t.T_) , C_(t.C_) { @@ -856,7 +856,7 @@ public: t.C_ = nullptr; } - inline TSharedPtr& operator=(TSharedPtr t) noexcept { + inline TSharedPtr& operator=(TSharedPtr t) noexcept { t.Swap(*this); return *this; @@ -869,28 +869,28 @@ public: Swap(t); } - inline void Reset() noexcept { + inline void Reset() noexcept { Drop(); } - inline void Drop() noexcept { + inline void Drop() noexcept { TSharedPtr().Swap(*this); } - inline T* Get() const noexcept { + inline T* Get() const noexcept { return T_; } - inline C* ReferenceCounter() const noexcept { + inline C* ReferenceCounter() const noexcept { return C_; } - inline void Swap(TSharedPtr& r) noexcept { + inline void Swap(TSharedPtr& r) noexcept { DoSwap(T_, r.T_); DoSwap(C_, r.C_); } - inline long RefCount() const noexcept { + inline long RefCount() const noexcept { return C_ ? C_->Val() : 0; } @@ -907,19 +907,19 @@ private: T_ = t.Release(); } - inline void Ref() noexcept { + inline void Ref() noexcept { if (C_) { C_->Inc(); } } - inline void UnRef() noexcept { + inline void UnRef() noexcept { if (C_ && !C_->Dec()) { DoDestroy(); } } - inline void DoDestroy() noexcept { + inline void DoDestroy() noexcept { if (T_) { D::Destroy(T_); } @@ -985,7 +985,7 @@ public: template <class T, class C, class D> class TCopyPtr: public TPointerBase<TCopyPtr<T, C, D>, T> { public: - inline TCopyPtr(T* t = nullptr) noexcept + inline TCopyPtr(T* t = nullptr) noexcept : T_(t) { } @@ -1001,7 +1001,7 @@ public: Swap(t); } - inline ~TCopyPtr() { + inline ~TCopyPtr() { DoDestroy(); } @@ -1015,26 +1015,26 @@ public: return DoRelease(T_); } - inline void Reset(T* t) noexcept { + inline void Reset(T* t) noexcept { if (T_ != t) { DoDestroy(); T_ = t; } } - inline void Reset() noexcept { + inline void Reset() noexcept { Destroy(); } - inline void Destroy() noexcept { + inline void Destroy() noexcept { Reset(nullptr); } - inline void Swap(TCopyPtr& r) noexcept { + inline void Swap(TCopyPtr& r) noexcept { DoSwap(T_, r.T_); } - inline T* Get() const noexcept { + inline T* Get() const noexcept { return T_; } @@ -1045,7 +1045,7 @@ public: } #endif private: - inline void DoDestroy() noexcept { + inline void DoDestroy() noexcept { if (T_) D::Destroy(T_); } @@ -1072,11 +1072,11 @@ public: { } - inline const T* Get() const noexcept { + inline const T* Get() const noexcept { return Const(); } - inline const T* Const() const noexcept { + inline const T* Const() const noexcept { return T_.Get(); } @@ -1086,11 +1086,11 @@ public: return T_.Get(); } - inline bool Shared() const noexcept { + inline bool Shared() const noexcept { return T_.RefCount() > 1; } - inline void Swap(TCowPtr& r) noexcept { + inline void Swap(TCowPtr& r) noexcept { T_.Swap(r.T_); } diff --git a/util/generic/ptr_ut.cpp b/util/generic/ptr_ut.cpp index c2dcff23f6..8dab40aa5e 100644 --- a/util/generic/ptr_ut.cpp +++ b/util/generic/ptr_ut.cpp @@ -268,10 +268,10 @@ void TPointerTest::TestAutoToHolder() { UNIT_ASSERT_VALUES_EQUAL(cnt, 0); { - class B1: public A { + class B1: public A { }; - TAutoPtr<B1> x(new B1()); + TAutoPtr<B1> x(new B1()); THolder<A> y = x; } @@ -340,9 +340,9 @@ void TPointerTest::TestIntrPtr() { TIntrusivePtr<TOp> p, p2; TOp3 op3; { - TVector<TIntrusivePtr<TOp>> f1; + TVector<TIntrusivePtr<TOp>> f1; { - TVector<TIntrusivePtr<TOp>> f2; + TVector<TIntrusivePtr<TOp>> f2; f2.push_back(new TOp); p = new TOp; f2.push_back(p); @@ -560,7 +560,7 @@ namespace { } void TPointerTest::TestOperatorBool() { - using TVec = TVector<ui32>; + using TVec = TVector<ui32>; // to be sure TImplicitlyCastable works as expected UNIT_ASSERT((TImplicitlyCastable<int, bool>::Result)); diff --git a/util/generic/queue.h b/util/generic/queue.h index f5959f68f2..9f1cd02f17 100644 --- a/util/generic/queue.h +++ b/util/generic/queue.h @@ -10,7 +10,7 @@ #include <queue> template <class T, class S> -class TQueue: public std::queue<T, S> { +class TQueue: public std::queue<T, S> { using TBase = std::queue<T, S>; public: @@ -34,7 +34,7 @@ public: }; template <class T, class S, class C> -class TPriorityQueue: public std::priority_queue<T, S, C> { +class TPriorityQueue: public std::priority_queue<T, S, C> { using TBase = std::priority_queue<T, S, C>; public: diff --git a/util/generic/queue_ut.cpp b/util/generic/queue_ut.cpp index a33399e104..afaea028ad 100644 --- a/util/generic/queue_ut.cpp +++ b/util/generic/queue_ut.cpp @@ -9,7 +9,7 @@ Y_UNIT_TEST_SUITE(TYQueueTest) { Y_UNIT_TEST(ConstructorsAndAssignments) { { - using container = TQueue<int>; + using container = TQueue<int>; container c1; UNIT_ASSERT(!c1); @@ -41,7 +41,7 @@ Y_UNIT_TEST_SUITE(TYQueueTest) { } { - using container = TPriorityQueue<int>; + using container = TPriorityQueue<int>; container c1; UNIT_ASSERT(!c1); @@ -74,7 +74,7 @@ Y_UNIT_TEST_SUITE(TYQueueTest) { } Y_UNIT_TEST(pqueue1) { - TPriorityQueue<int, TDeque<int>, TLess<int>> q; + TPriorityQueue<int, TDeque<int>, TLess<int>> q; q.push(42); q.push(101); @@ -92,7 +92,7 @@ Y_UNIT_TEST_SUITE(TYQueueTest) { } Y_UNIT_TEST(pqueue2) { - using TPQueue = TPriorityQueue<int, TDeque<int>, TLess<int>>; + using TPQueue = TPriorityQueue<int, TDeque<int>, TLess<int>>; TPQueue q; { @@ -118,7 +118,7 @@ Y_UNIT_TEST_SUITE(TYQueueTest) { } Y_UNIT_TEST(pqueue3) { - TPriorityQueue<int, TDeque<int>, TLess<int>> q; + TPriorityQueue<int, TDeque<int>, TLess<int>> q; q.push(42); q.push(101); @@ -129,12 +129,12 @@ Y_UNIT_TEST_SUITE(TYQueueTest) { } Y_UNIT_TEST(pqueue4) { - TDeque<int> c; + TDeque<int> c; c.push_back(42); c.push_back(101); c.push_back(69); - TPriorityQueue<int, TDeque<int>, TLess<int>> q(TLess<int>(), std::move(c)); + TPriorityQueue<int, TDeque<int>, TLess<int>> q(TLess<int>(), std::move(c)); UNIT_ASSERT(c.empty()); @@ -153,7 +153,7 @@ Y_UNIT_TEST_SUITE(TYQueueTest) { } Y_UNIT_TEST(queue1) { - TQueue<int, TList<int>> q; + TQueue<int, TList<int>> q; q.push(42); q.push(101); @@ -171,11 +171,11 @@ Y_UNIT_TEST_SUITE(TYQueueTest) { } Y_UNIT_TEST(queue2) { - using TQueueType = TQueue<int>; - TQueueType q; + using TQueueType = TQueue<int>; + TQueueType q; { - TQueueType qq; + TQueueType qq; qq.push(42); qq.push(101); @@ -197,8 +197,8 @@ Y_UNIT_TEST_SUITE(TYQueueTest) { } Y_UNIT_TEST(queue3) { - using TQueueType = TQueue<int>; - TQueueType q; + using TQueueType = TQueue<int>; + TQueueType q; q.push(42); q.push(101); diff --git a/util/generic/refcount.h b/util/generic/refcount.h index 966e853b77..c21be4f579 100644 --- a/util/generic/refcount.h +++ b/util/generic/refcount.h @@ -10,12 +10,12 @@ class TSimpleCounterTemplate: public TCounterCheckPolicy { using TCounterCheckPolicy::Check; public: - inline TSimpleCounterTemplate(long initial = 0) noexcept + inline TSimpleCounterTemplate(long initial = 0) noexcept : Counter_(initial) { } - inline ~TSimpleCounterTemplate() { + inline ~TSimpleCounterTemplate() { Check(); } @@ -37,7 +37,7 @@ public: return Sub(1); } - inline bool TryWeakInc() noexcept { + inline bool TryWeakInc() noexcept { if (!Counter_) { return false; } @@ -91,18 +91,18 @@ using TExplicitSimpleCounter = TSimpleCounterTemplate<TNoCheckPolicy>; template <class TCounterCheckPolicy> struct TCommonLockOps<TSimpleCounterTemplate<TCounterCheckPolicy>> { - static inline void Acquire(TSimpleCounterTemplate<TCounterCheckPolicy>* t) noexcept { + static inline void Acquire(TSimpleCounterTemplate<TCounterCheckPolicy>* t) noexcept { t->Inc(); } - static inline void Release(TSimpleCounterTemplate<TCounterCheckPolicy>* t) noexcept { + static inline void Release(TSimpleCounterTemplate<TCounterCheckPolicy>* t) noexcept { t->Dec(); } }; class TAtomicCounter { public: - inline TAtomicCounter(long initial = 0) noexcept + inline TAtomicCounter(long initial = 0) noexcept : Counter_(initial) { } @@ -117,19 +117,19 @@ public: return Add(1); } - inline TAtomicBase Sub(TAtomicBase d) noexcept { + inline TAtomicBase Sub(TAtomicBase d) noexcept { return AtomicSub(Counter_, d); } - inline TAtomicBase Dec() noexcept { + inline TAtomicBase Dec() noexcept { return Sub(1); } - inline TAtomicBase Val() const noexcept { + inline TAtomicBase Val() const noexcept { return AtomicGet(Counter_); } - inline bool TryWeakInc() noexcept { + inline bool TryWeakInc() noexcept { while (true) { intptr_t curValue = Counter_; @@ -152,11 +152,11 @@ private: template <> struct TCommonLockOps<TAtomicCounter> { - static inline void Acquire(TAtomicCounter* t) noexcept { + static inline void Acquire(TAtomicCounter* t) noexcept { t->Inc(); } - static inline void Release(TAtomicCounter* t) noexcept { + static inline void Release(TAtomicCounter* t) noexcept { t->Dec(); } }; diff --git a/util/generic/serialized_enum.h b/util/generic/serialized_enum.h index 79df2bac22..50eda8a4bf 100644 --- a/util/generic/serialized_enum.h +++ b/util/generic/serialized_enum.h @@ -1,34 +1,34 @@ -#pragma once - +#pragma once + #include <util/generic/fwd.h> #include <util/generic/vector.h> #include <util/generic/map.h> -#include <cstddef> +#include <cstddef> #include <type_traits> - -/* - + +/* + A file with declarations of enumeration-related functions. It doesn't contains definitions. To generate them you have to add - - GENERATE_ENUM_SERIALIZATION_WITH_HEADER(your_header_with_your_enum.h) + + GENERATE_ENUM_SERIALIZATION_WITH_HEADER(your_header_with_your_enum.h) or GENERATE_ENUM_SERIALIZATION(your_header_with_your_enum.h) - + in your ya.make - -@see https://st.yandex-team.ru/IGNIETFERRO-333 -@see https://wiki.yandex-team.ru/PoiskovajaPlatforma/Build/WritingCmakefiles/#generate-enum-with-header - -*/ - -/** - * Returns number of distinct items in enum or enum class - * - * @tparam EnumT enum type - */ -template <typename EnumT> + +@see https://st.yandex-team.ru/IGNIETFERRO-333 +@see https://wiki.yandex-team.ru/PoiskovajaPlatforma/Build/WritingCmakefiles/#generate-enum-with-header + +*/ + +/** + * Returns number of distinct items in enum or enum class + * + * @tparam EnumT enum type + */ +template <typename EnumT> Y_CONST_FUNCTION constexpr size_t GetEnumItemsCount(); namespace NEnumSerializationRuntime { diff --git a/util/generic/set.h b/util/generic/set.h index 4c437ca26f..6a5f639e0c 100644 --- a/util/generic/set.h +++ b/util/generic/set.h @@ -10,7 +10,7 @@ #include <set> template <class K, class L, class A> -class TSet: public std::set<K, L, TReboundAllocator<A, K>> { +class TSet: public std::set<K, L, TReboundAllocator<A, K>> { public: using TBase = std::set<K, L, TReboundAllocator<A, K>>; using TBase::TBase; @@ -26,7 +26,7 @@ public: }; template <class K, class L, class A> -class TMultiSet: public std::multiset<K, L, TReboundAllocator<A, K>> { +class TMultiSet: public std::multiset<K, L, TReboundAllocator<A, K>> { public: using TBase = std::multiset<K, L, TReboundAllocator<A, K>>; using TBase::TBase; diff --git a/util/generic/set_ut.cpp b/util/generic/set_ut.cpp index d2769d327f..00938e3999 100644 --- a/util/generic/set_ut.cpp +++ b/util/generic/set_ut.cpp @@ -8,7 +8,7 @@ Y_UNIT_TEST_SUITE(YSetTest) { Y_UNIT_TEST(TestSet1) { - TSet<int, TLess<int>> s; + TSet<int, TLess<int>> s; UNIT_ASSERT(!s); UNIT_ASSERT(s.count(42) == 0); s.insert(42); @@ -21,7 +21,7 @@ Y_UNIT_TEST_SUITE(YSetTest) { } Y_UNIT_TEST(TestSet2) { - using int_set = TSet<int, TLess<int>>; + using int_set = TSet<int, TLess<int>>; int_set s; std::pair<int_set::iterator, bool> p = s.insert(42); UNIT_ASSERT(p.second == true); @@ -46,7 +46,7 @@ Y_UNIT_TEST_SUITE(YSetTest) { } Y_UNIT_TEST(TestErase) { - TSet<int, TLess<int>> s; + TSet<int, TLess<int>> s; s.insert(1); s.erase(s.begin()); UNIT_ASSERT(s.empty()); @@ -56,26 +56,26 @@ Y_UNIT_TEST_SUITE(YSetTest) { } Y_UNIT_TEST(TestInsert) { - TSet<int> s; - TSet<int>::iterator i = s.insert(s.end(), 0); + TSet<int> s; + TSet<int>::iterator i = s.insert(s.end(), 0); UNIT_ASSERT(*i == 0); } Y_UNIT_TEST(TestFind) { - TSet<int> s; + TSet<int> s; UNIT_ASSERT(s.find(0) == s.end()); - TSet<int> const& crs = s; + TSet<int> const& crs = s; UNIT_ASSERT(crs.find(0) == crs.end()); } Y_UNIT_TEST(TestHas) { - TSet<int> s; + TSet<int> s; UNIT_ASSERT(!s.contains(0)); - TSet<int> const& crs = s; + TSet<int> const& crs = s; UNIT_ASSERT(!crs.contains(0)); s.insert(1); @@ -91,13 +91,13 @@ Y_UNIT_TEST_SUITE(YSetTest) { Y_UNIT_TEST(TestBounds) { int array1[] = {1, 3, 6, 7}; - TSet<int> s(array1, array1 + sizeof(array1) / sizeof(array1[0])); - TSet<int> const& crs = s; + TSet<int> s(array1, array1 + sizeof(array1) / sizeof(array1[0])); + TSet<int> const& crs = s; - TSet<int>::iterator sit; - TSet<int>::const_iterator scit; - std::pair<TSet<int>::iterator, TSet<int>::iterator> pit; - std::pair<TSet<int>::const_iterator, TSet<int>::const_iterator> pcit; + TSet<int>::iterator sit; + TSet<int>::const_iterator scit; + std::pair<TSet<int>::iterator, TSet<int>::iterator> pit; + std::pair<TSet<int>::const_iterator, TSet<int>::const_iterator> pcit; //Check iterator on mutable set sit = s.lower_bound(2); @@ -156,35 +156,35 @@ Y_UNIT_TEST_SUITE(YSetTest) { } Y_UNIT_TEST(TestImplementationCheck) { - TSet<int> tree; + TSet<int> tree; tree.insert(1); - TSet<int>::iterator it = tree.begin(); + TSet<int>::iterator it = tree.begin(); int const& int_ref = *it++; UNIT_ASSERT(int_ref == 1); UNIT_ASSERT(it == tree.end()); UNIT_ASSERT(it != tree.begin()); - TSet<int>::const_iterator cit = tree.begin(); + TSet<int>::const_iterator cit = tree.begin(); int const& int_cref = *cit++; UNIT_ASSERT(int_cref == 1); } Y_UNIT_TEST(TestReverseIteratorTest) { - TSet<int> tree; + TSet<int> tree; tree.insert(1); tree.insert(2); { - TSet<int>::reverse_iterator rit(tree.rbegin()); + TSet<int>::reverse_iterator rit(tree.rbegin()); UNIT_ASSERT(*(rit++) == 2); UNIT_ASSERT(*(rit++) == 1); UNIT_ASSERT(rit == tree.rend()); } { - TSet<int> const& ctree = tree; - TSet<int>::const_reverse_iterator rit(ctree.rbegin()); + TSet<int> const& ctree = tree; + TSet<int>::const_reverse_iterator rit(ctree.rbegin()); UNIT_ASSERT(*(rit++) == 2); UNIT_ASSERT(*(rit++) == 1); UNIT_ASSERT(rit == ctree.rend()); @@ -193,7 +193,7 @@ Y_UNIT_TEST_SUITE(YSetTest) { Y_UNIT_TEST(TestConstructorsAndAssignments) { { - using container = TSet<int>; + using container = TSet<int>; container c1; c1.insert(100); @@ -228,7 +228,7 @@ Y_UNIT_TEST_SUITE(YSetTest) { } { - using container = TMultiSet<int>; + using container = TMultiSet<int>; container c1; c1.insert(100); @@ -311,7 +311,7 @@ Y_UNIT_TEST_SUITE(YSetTest) { Y_UNIT_TEST(TestTemplateMethods) { { - using KeySet = TSet<TKey, TKeyCmp>; + using KeySet = TSet<TKey, TKeyCmp>; KeySet keySet; keySet.insert(TKey(1)); keySet.insert(TKey(2)); @@ -335,7 +335,7 @@ Y_UNIT_TEST_SUITE(YSetTest) { } { - using KeySet = TSet<TKey*, TKeyCmpPtr>; + using KeySet = TSet<TKey*, TKeyCmpPtr>; KeySet keySet; TKey key1(1), key2(2), key3(3), key4(4); keySet.insert(&key1); @@ -358,7 +358,7 @@ Y_UNIT_TEST_SUITE(YSetTest) { UNIT_ASSERT(ckeySet.equal_range(2) != std::make_pair(ckeySet.begin(), ckeySet.end())); } { - using KeySet = TMultiSet<TKey, TKeyCmp>; + using KeySet = TMultiSet<TKey, TKeyCmp>; KeySet keySet; keySet.insert(TKey(1)); keySet.insert(TKey(2)); @@ -382,7 +382,7 @@ Y_UNIT_TEST_SUITE(YSetTest) { } { - using KeySet = TMultiSet<TKey const volatile*, TKeyCmpPtr>; + using KeySet = TMultiSet<TKey const volatile*, TKeyCmpPtr>; KeySet keySet; TKey key1(1), key2(2), key3(3), key4(4); keySet.insert(&key1); diff --git a/util/generic/singleton.cpp b/util/generic/singleton.cpp index eb5a0662f8..cec1e997f1 100644 --- a/util/generic/singleton.cpp +++ b/util/generic/singleton.cpp @@ -7,15 +7,15 @@ #include <cstring> namespace { - static inline bool MyAtomicTryLock(TAtomic& a, TAtomicBase v) noexcept { + static inline bool MyAtomicTryLock(TAtomic& a, TAtomicBase v) noexcept { return AtomicCas(&a, v, 0); } - static inline bool MyAtomicTryAndTryLock(TAtomic& a, TAtomicBase v) noexcept { + static inline bool MyAtomicTryAndTryLock(TAtomic& a, TAtomicBase v) noexcept { return (AtomicGet(a) == 0) && MyAtomicTryLock(a, v); } - static inline TAtomicBase MyThreadId() noexcept { + static inline TAtomicBase MyThreadId() noexcept { const TAtomicBase ret = TThread::CurrentThreadId(); if (ret) { @@ -41,7 +41,7 @@ void NPrivate::FillWithTrash(void* ptr, size_t len) { #endif } -void NPrivate::LockRecursive(TAtomic& lock) noexcept { +void NPrivate::LockRecursive(TAtomic& lock) noexcept { const TAtomicBase id = MyThreadId(); Y_VERIFY(AtomicGet(lock) != id, "recursive singleton initialization"); @@ -55,7 +55,7 @@ void NPrivate::LockRecursive(TAtomic& lock) noexcept { } } -void NPrivate::UnlockRecursive(TAtomic& lock) noexcept { +void NPrivate::UnlockRecursive(TAtomic& lock) noexcept { Y_VERIFY(AtomicGet(lock) == MyThreadId(), "unlock from another thread?!?!"); AtomicUnlock(&lock); } diff --git a/util/generic/singleton.h b/util/generic/singleton.h index f5fa047f5c..5b118b4221 100644 --- a/util/generic/singleton.h +++ b/util/generic/singleton.h @@ -14,8 +14,8 @@ struct TSingletonTraits { namespace NPrivate { void FillWithTrash(void* ptr, size_t len); - void LockRecursive(TAtomic& lock) noexcept; - void UnlockRecursive(TAtomic& lock) noexcept; + void LockRecursive(TAtomic& lock) noexcept; + void UnlockRecursive(TAtomic& lock) noexcept; template <class T> void Destroyer(void* ptr) { @@ -80,7 +80,7 @@ namespace NPrivate { { } - inline const T* Get() const noexcept { + inline const T* Get() const noexcept { return &T_; } @@ -96,7 +96,7 @@ namespace NPrivate { { } - inline ~THeapStore() { + inline ~THeapStore() { delete D; } diff --git a/util/generic/stack.h b/util/generic/stack.h index dbcbf2b5c9..fd3848b154 100644 --- a/util/generic/stack.h +++ b/util/generic/stack.h @@ -6,7 +6,7 @@ #include <stack> template <class T, class S> -class TStack: public std::stack<T, S> { +class TStack: public std::stack<T, S> { using TBase = std::stack<T, S>; public: diff --git a/util/generic/stack_ut.cpp b/util/generic/stack_ut.cpp index 248127d326..68ceda4bdd 100644 --- a/util/generic/stack_ut.cpp +++ b/util/generic/stack_ut.cpp @@ -4,7 +4,7 @@ Y_UNIT_TEST_SUITE(TYStackTest) { Y_UNIT_TEST(ExplicitBool) { - TStack<int> s; + TStack<int> s; UNIT_ASSERT(!s); UNIT_ASSERT(s.empty()); diff --git a/util/generic/strbase.h b/util/generic/strbase.h index ab39fc7537..1592afc85d 100644 --- a/util/generic/strbase.h +++ b/util/generic/strbase.h @@ -127,27 +127,27 @@ public: * @param Pointer to character inside the string, or nullptr. * @return Offset from string beginning (in chars), or npos on nullptr. */ - inline size_t off(const TCharType* ret) const noexcept { + inline size_t off(const TCharType* ret) const noexcept { return ret ? (size_t)(ret - Ptr()) : npos; } - inline size_t IterOff(const_iterator it) const noexcept { + inline size_t IterOff(const_iterator it) const noexcept { return begin() <= it && end() > it ? size_t(it - begin()) : npos; } - inline const_iterator begin() const noexcept { + inline const_iterator begin() const noexcept { return Ptr(); } - inline const_iterator end() const noexcept { + inline const_iterator end() const noexcept { return Ptr() + size(); } - inline const_iterator cbegin() const noexcept { + inline const_iterator cbegin() const noexcept { return begin(); } - inline const_iterator cend() const noexcept { + inline const_iterator cend() const noexcept { return end(); } @@ -167,7 +167,7 @@ public: return rend(); } - inline TCharType back() const noexcept { + inline TCharType back() const noexcept { Y_ASSERT(!this->empty()); return Ptr()[Len() - 1]; } @@ -181,11 +181,11 @@ public: return Ptr(); } - constexpr inline size_t size() const noexcept { + constexpr inline size_t size() const noexcept { return Len(); } - constexpr inline bool is_null() const noexcept { + constexpr inline bool is_null() const noexcept { return *Ptr() == 0; } @@ -193,16 +193,16 @@ public: return Len() == 0; } - constexpr inline explicit operator bool() const noexcept { + constexpr inline explicit operator bool() const noexcept { return !empty(); } public: // style-guide compliant methods - constexpr const TCharType* Data() const noexcept { + constexpr const TCharType* Data() const noexcept { return Ptr(); } - constexpr size_t Size() const noexcept { + constexpr size_t Size() const noexcept { return Len(); } @@ -218,16 +218,16 @@ private: public: // ~~~ Comparison ~~~ : FAMILY0(int, compare) - static int compare(const TSelf& s1, const TSelf& s2) noexcept { + static int compare(const TSelf& s1, const TSelf& s2) noexcept { return s1.AsStringView().compare(s2.AsStringView()); } - static int compare(const TCharType* p, const TSelf& s2) noexcept { + static int compare(const TCharType* p, const TSelf& s2) noexcept { TCharType null{0}; return TStringViewWithTraits(p ? p : &null).compare(s2.AsStringView()); } - static int compare(const TSelf& s1, const TCharType* p) noexcept { + static int compare(const TSelf& s1, const TCharType* p) noexcept { TCharType null{0}; return s1.AsStringView().compare(p ? p : &null); } @@ -237,7 +237,7 @@ public: } template <class T> - inline int compare(const T& t) const noexcept { + inline int compare(const T& t) const noexcept { return compare(*this, t); } @@ -257,7 +257,7 @@ public: return compare(*this, TStringView(p, len)); } - static bool equal(const TSelf& s1, const TSelf& s2) noexcept { + static bool equal(const TSelf& s1, const TSelf& s2) noexcept { return s1.AsStringView() == s2.AsStringView(); } @@ -278,7 +278,7 @@ public: } template <class T> - inline bool equal(const T& t) const noexcept { + inline bool equal(const T& t) const noexcept { return equal(*this, t); } @@ -340,12 +340,12 @@ public: } #ifndef __cpp_impl_three_way_comparison - friend bool operator==(const TCharType* pc, const TSelf& s) noexcept { + friend bool operator==(const TCharType* pc, const TSelf& s) noexcept { return equal(pc, s); } template <typename TDerived2, typename TTraits2> - friend bool operator!=(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept { + friend bool operator!=(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept { return !(s1 == s2); } @@ -353,17 +353,17 @@ public: return !(s1 == s2); } - friend bool operator!=(const TSelf& s, const TCharType* pc) noexcept { + friend bool operator!=(const TSelf& s, const TCharType* pc) noexcept { return !(s == pc); } - friend bool operator!=(const TCharType* pc, const TSelf& s) noexcept { + friend bool operator!=(const TCharType* pc, const TSelf& s) noexcept { return !(pc == s); } #endif template <typename TDerived2, typename TTraits2> - friend bool operator<(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept { + friend bool operator<(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept { return compare(s1, s2) < 0; } @@ -371,16 +371,16 @@ public: return compare(s1, s2) < 0; } - friend bool operator<(const TSelf& s, const TCharType* pc) noexcept { + friend bool operator<(const TSelf& s, const TCharType* pc) noexcept { return compare(s, pc) < 0; } - friend bool operator<(const TCharType* pc, const TSelf& s) noexcept { + friend bool operator<(const TCharType* pc, const TSelf& s) noexcept { return compare(pc, s) < 0; } template <typename TDerived2, typename TTraits2> - friend bool operator<=(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept { + friend bool operator<=(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept { return compare(s1, s2) <= 0; } @@ -388,16 +388,16 @@ public: return compare(s1, s2) <= 0; } - friend bool operator<=(const TSelf& s, const TCharType* pc) noexcept { + friend bool operator<=(const TSelf& s, const TCharType* pc) noexcept { return compare(s, pc) <= 0; } - friend bool operator<=(const TCharType* pc, const TSelf& s) noexcept { + friend bool operator<=(const TCharType* pc, const TSelf& s) noexcept { return compare(pc, s) <= 0; } template <typename TDerived2, typename TTraits2> - friend bool operator>(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept { + friend bool operator>(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept { return compare(s1, s2) > 0; } @@ -405,16 +405,16 @@ public: return compare(s1, s2) > 0; } - friend bool operator>(const TSelf& s, const TCharType* pc) noexcept { + friend bool operator>(const TSelf& s, const TCharType* pc) noexcept { return compare(s, pc) > 0; } - friend bool operator>(const TCharType* pc, const TSelf& s) noexcept { + friend bool operator>(const TCharType* pc, const TSelf& s) noexcept { return compare(pc, s) > 0; } template <typename TDerived2, typename TTraits2> - friend bool operator>=(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept { + friend bool operator>=(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept { return compare(s1, s2) >= 0; } @@ -422,23 +422,23 @@ public: return compare(s1, s2) >= 0; } - friend bool operator>=(const TSelf& s, const TCharType* pc) noexcept { + friend bool operator>=(const TSelf& s, const TCharType* pc) noexcept { return compare(s, pc) >= 0; } - friend bool operator>=(const TCharType* pc, const TSelf& s) noexcept { + friend bool operator>=(const TCharType* pc, const TSelf& s) noexcept { return compare(pc, s) >= 0; } // ~~ Read access ~~ - inline TCharType at(size_t pos) const noexcept { + inline TCharType at(size_t pos) const noexcept { if (Y_LIKELY(pos < Len())) { return (Ptr())[pos]; } return 0; } - inline TCharType operator[](size_t pos) const noexcept { + inline TCharType operator[](size_t pos) const noexcept { Y_ASSERT(pos < this->size()); return Ptr()[pos]; @@ -456,15 +456,15 @@ public: return AsStringView().find(s, pos, count); } - inline size_t find(TCharType c, size_t pos = 0) const noexcept { + inline size_t find(TCharType c, size_t pos = 0) const noexcept { return AsStringView().find(c, pos); } - inline size_t rfind(TCharType c) const noexcept { + inline size_t rfind(TCharType c) const noexcept { return AsStringView().rfind(c); } - inline size_t rfind(TCharType c, size_t pos) const noexcept { + inline size_t rfind(TCharType c, size_t pos) const noexcept { if (pos == 0) { return npos; } @@ -492,11 +492,11 @@ public: } //~~~~Character Set Search~~~ - inline size_t find_first_of(TCharType c) const noexcept { + inline size_t find_first_of(TCharType c) const noexcept { return find_first_of(c, 0); } - inline size_t find_first_of(TCharType c, size_t pos) const noexcept { + inline size_t find_first_of(TCharType c, size_t pos) const noexcept { return find(c, pos); } @@ -508,11 +508,11 @@ public: return AsStringView().find_first_of(set.data(), pos, set.size()); } - inline size_t find_first_not_of(TCharType c) const noexcept { + inline size_t find_first_not_of(TCharType c) const noexcept { return find_first_not_of(c, 0); } - inline size_t find_first_not_of(TCharType c, size_t pos) const noexcept { + inline size_t find_first_not_of(TCharType c, size_t pos) const noexcept { return find_first_not_of(TStringView(&c, 1), pos); } @@ -524,7 +524,7 @@ public: return AsStringView().find_first_not_of(set.data(), pos, set.size()); } - inline size_t find_last_of(TCharType c, size_t pos = npos) const noexcept { + inline size_t find_last_of(TCharType c, size_t pos = npos) const noexcept { return find_last_of(&c, pos, 1); } @@ -532,7 +532,7 @@ public: return find_last_of(set.data(), pos, set.length()); } - inline size_t find_last_of(const TCharType* set, size_t pos, size_t n) const noexcept { + inline size_t find_last_of(const TCharType* set, size_t pos, size_t n) const noexcept { return AsStringView().find_last_of(set, pos, n); } @@ -560,7 +560,7 @@ public: return CopyImpl(pc, n, 0); } - inline size_t strcpy(TCharType* pc, size_t n) const noexcept { + inline size_t strcpy(TCharType* pc, size_t n) const noexcept { if (n) { n = copy(pc, n - 1); pc[n] = 0; @@ -585,19 +585,19 @@ private: return static_cast<TStringViewWithTraits>(*this); } - constexpr inline const TCharType* Ptr() const noexcept { + constexpr inline const TCharType* Ptr() const noexcept { return This()->data(); } - constexpr inline size_t Len() const noexcept { + constexpr inline size_t Len() const noexcept { return This()->length(); } - constexpr inline const TDerived* This() const noexcept { + constexpr inline const TDerived* This() const noexcept { return static_cast<const TDerived*>(this); } - inline size_t CopyImpl(TCharType* pc, size_t n, size_t pos) const noexcept { + inline size_t CopyImpl(TCharType* pc, size_t n, size_t pos) const noexcept { const size_t toCopy = Min(Len() - pos, n); TTraits::copy(pc, Ptr() + pos, toCopy); diff --git a/util/generic/strbuf.h b/util/generic/strbuf.h index 70b9360d58..4ec008e267 100644 --- a/util/generic/strbuf.h +++ b/util/generic/strbuf.h @@ -167,7 +167,7 @@ public: *this = TdSelf(); } - constexpr bool IsInited() const noexcept { + constexpr bool IsInited() const noexcept { return data() != nullptr; } @@ -213,7 +213,7 @@ public: * @param[out] r The second part of split result. * @returns Whether the split was actually performed. */ - inline bool TrySplit(TdSelf delim, TdSelf& l, TdSelf& r) const noexcept { + inline bool TrySplit(TdSelf delim, TdSelf& l, TdSelf& r) const noexcept { return TrySplitOn(TBase::find(delim), l, r, delim.size()); } @@ -228,7 +228,7 @@ public: * @param[out] r The second part of split result. * @returns Whether the split was actually performed. */ - inline bool TryRSplit(TdSelf delim, TdSelf& l, TdSelf& r) const noexcept { + inline bool TryRSplit(TdSelf delim, TdSelf& l, TdSelf& r) const noexcept { return TrySplitOn(TBase::rfind(delim), l, r, delim.size()); } @@ -240,17 +240,17 @@ public: RSplitTemplate(delim, l, r); } - inline void Split(TdSelf delim, TdSelf& l, TdSelf& r) const noexcept { + inline void Split(TdSelf delim, TdSelf& l, TdSelf& r) const noexcept { SplitTemplate(delim, l, r); } - inline void RSplit(TdSelf delim, TdSelf& l, TdSelf& r) const noexcept { + inline void RSplit(TdSelf delim, TdSelf& l, TdSelf& r) const noexcept { RSplitTemplate(delim, l, r); } private: // splits on a delimiter at a given position; delimiter is excluded - void DoSplitOn(size_t pos, TdSelf& l, TdSelf& r, size_t len) const noexcept { + void DoSplitOn(size_t pos, TdSelf& l, TdSelf& r, size_t len) const noexcept { Y_ASSERT(pos != TBase::npos); // make a copy in case one of l/r is really *this @@ -267,7 +267,7 @@ public: // For example, for TStringBuf s("abc"): // s.TrySplitOn(s.find('z'), ...) is false, but s.TrySplitOn(100500, ...) is true. - bool TrySplitOn(size_t pos, TdSelf& l, TdSelf& r, size_t len = 1) const noexcept { + bool TrySplitOn(size_t pos, TdSelf& l, TdSelf& r, size_t len = 1) const noexcept { if (TBase::npos == pos) return false; @@ -275,25 +275,25 @@ public: return true; } - void SplitOn(size_t pos, TdSelf& l, TdSelf& r, size_t len = 1) const noexcept { + void SplitOn(size_t pos, TdSelf& l, TdSelf& r, size_t len = 1) const noexcept { if (!TrySplitOn(pos, l, r, len)) { l = *this; r = TdSelf(); } } - bool TrySplitAt(size_t pos, TdSelf& l, TdSelf& r) const noexcept { + bool TrySplitAt(size_t pos, TdSelf& l, TdSelf& r) const noexcept { return TrySplitOn(pos, l, r, 0); } - void SplitAt(size_t pos, TdSelf& l, TdSelf& r) const noexcept { + void SplitAt(size_t pos, TdSelf& l, TdSelf& r) const noexcept { SplitOn(pos, l, r, 0); } /* // Not implemented intentionally, use TrySplitOn() instead - void RSplitOn(size_t pos, TdSelf& l, TdSelf& r) const noexcept; - void RSplitAt(size_t pos, TdSelf& l, TdSelf& r) const noexcept; + void RSplitOn(size_t pos, TdSelf& l, TdSelf& r) const noexcept; + void RSplitAt(size_t pos, TdSelf& l, TdSelf& r) const noexcept; */ public: @@ -318,7 +318,7 @@ public: } public: - inline bool AfterPrefix(const TdSelf& prefix, TdSelf& result) const noexcept { + inline bool AfterPrefix(const TdSelf& prefix, TdSelf& result) const noexcept { if (this->StartsWith(prefix)) { result = Tail(prefix.size()); return true; @@ -326,7 +326,7 @@ public: return false; } - inline bool BeforeSuffix(const TdSelf& suffix, TdSelf& result) const noexcept { + inline bool BeforeSuffix(const TdSelf& suffix, TdSelf& result) const noexcept { if (this->EndsWith(suffix)) { result = Head(size() - suffix.size()); return true; @@ -335,12 +335,12 @@ public: } // returns true if string started with `prefix`, false otherwise - inline bool SkipPrefix(const TdSelf& prefix) noexcept { + inline bool SkipPrefix(const TdSelf& prefix) noexcept { return AfterPrefix(prefix, *this); } // returns true if string ended with `suffix`, false otherwise - inline bool ChopSuffix(const TdSelf& suffix) noexcept { + inline bool ChopSuffix(const TdSelf& suffix) noexcept { return BeforeSuffix(suffix, *this); } @@ -435,13 +435,13 @@ public: public: // string subsequences /// Cut last @c shift characters (or less if length is less than @c shift) - inline TdSelf& Chop(size_t shift) noexcept { + inline TdSelf& Chop(size_t shift) noexcept { this->remove_suffix(std::min(shift, size())); return *this; } /// Cut first @c shift characters (or less if length is less than @c shift) - inline TdSelf& Skip(size_t shift) noexcept { + inline TdSelf& Skip(size_t shift) noexcept { this->remove_prefix(std::min(shift, size())); return *this; } @@ -520,7 +520,7 @@ private: } template <typename TDelimiterType> - inline void SplitTemplate(TDelimiterType delim, TdSelf& l, TdSelf& r) const noexcept { + inline void SplitTemplate(TDelimiterType delim, TdSelf& l, TdSelf& r) const noexcept { if (!TrySplit(delim, l, r)) { l = *this; r = TdSelf(); @@ -528,7 +528,7 @@ private: } template <typename TDelimiterType> - inline void RSplitTemplate(TDelimiterType delim, TdSelf& l, TdSelf& r) const noexcept { + inline void RSplitTemplate(TDelimiterType delim, TdSelf& l, TdSelf& r) const noexcept { if (!TryRSplit(delim, l, r)) { r = *this; l = TdSelf(); diff --git a/util/generic/strbuf_ut.cpp b/util/generic/strbuf_ut.cpp index 69cde785af..4bec3f1ab0 100644 --- a/util/generic/strbuf_ut.cpp +++ b/util/generic/strbuf_ut.cpp @@ -150,7 +150,7 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { str = qw; UNIT_ASSERT_EQUAL(str.SubStr(2), TStringBuf("erty")); - UNIT_ASSERT_EQUAL(str.Skip(3), qw.SubStr(3)); + UNIT_ASSERT_EQUAL(str.Skip(3), qw.SubStr(3)); str.Chop(1); UNIT_ASSERT_EQUAL(str, TStringBuf("rt")); } diff --git a/util/generic/string.cpp b/util/generic/string.cpp index 3c655f1f66..0c949f814e 100644 --- a/util/generic/string.cpp +++ b/util/generic/string.cpp @@ -1,4 +1,4 @@ -#include "string.h" +#include "string.h" #include <util/string/ascii.h> #include <util/system/sanitizers.h> diff --git a/util/generic/string.h b/util/generic/string.h index 8cd8aa6917..89fd6cd2fa 100644 --- a/util/generic/string.h +++ b/util/generic/string.h @@ -20,10 +20,10 @@ #include "strbuf.h" #include "string_hash.h" -#if defined(address_sanitizer_enabled) || defined(thread_sanitizer_enabled) +#if defined(address_sanitizer_enabled) || defined(thread_sanitizer_enabled) #include "hide_ptr.h" -#endif - +#endif + template <class TCharType, class TCharTraits, class TAllocator> void ResizeUninitialized(std::basic_string<TCharType, TCharTraits, TAllocator>& s, size_t len) { #if defined(_YNDX_LIBCXX_ENABLE_STRING_RESIZE_UNINITIALIZED) @@ -103,12 +103,12 @@ private: } }; -template <class TStringType> +template <class TStringType> class TBasicCharRef { public: - using TChar = typename TStringType::TChar; + using TChar = typename TStringType::TChar; - TBasicCharRef(TStringType& s, size_t pos) + TBasicCharRef(TStringType& s, size_t pos) : S_(s) , Pos_(pos) { @@ -150,7 +150,7 @@ public: TBasicCharRef(const TBasicCharRef&) = default; private: - TStringType& S_; + TStringType& S_; size_t Pos_; }; #endif @@ -294,11 +294,11 @@ public: #endif } - inline size_t length() const noexcept { + inline size_t length() const noexcept { return ConstRef().length(); } - inline const TCharType* data() const noexcept { + inline const TCharType* data() const noexcept { return ConstRef().data(); } @@ -541,7 +541,7 @@ private: return 1 + SumLength(r...); } - static constexpr size_t SumLength() noexcept { + static constexpr size_t SumLength() noexcept { return 0; } @@ -557,11 +557,11 @@ private: CopyAll(p + 1, r...); } - static void CopyAll(TCharType*) noexcept { + static void CopyAll(TCharType*) noexcept { } public: - inline void clear() noexcept { + inline void clear() noexcept { #ifdef TSTRING_IS_STD_STRING Storage_.clear(); #else @@ -623,7 +623,7 @@ public: } TBasicString& assign(const TCharType* first, const TCharType* last) { - return assign(first, last - first); + return assign(first, last - first); } TBasicString& assign(const TCharType* pc, size_t pos, size_t n) { diff --git a/util/generic/string.pxd b/util/generic/string.pxd index c25f7392a1..1b3850c0b2 100644 --- a/util/generic/string.pxd +++ b/util/generic/string.pxd @@ -12,22 +12,22 @@ cdef extern from "<util/generic/strbuf.h>" nogil: size_t Size() -cdef extern from "<util/generic/string.h>" nogil: +cdef extern from "<util/generic/string.h>" nogil: - size_t npos "TString::npos" + size_t npos "TString::npos" # Inheritance is bogus, but it's safe to assume TString is-a TStringBuf via implicit cast cdef cppclass TString(TStringBuf): - TString() except + - TString(TString&) except + - TString(_std_string&) except + - TString(TString&, size_t, size_t) except + - TString(char*) except + - TString(char*, size_t) except + - TString(char*, size_t, size_t) except + - # as a TString formed by a repetition of character c, n times. - TString(size_t, char) except + - TString(char*, char*) except + + TString() except + + TString(TString&) except + + TString(_std_string&) except + + TString(TString&, size_t, size_t) except + + TString(char*) except + + TString(char*, size_t) except + + TString(char*, size_t, size_t) except + + # as a TString formed by a repetition of character c, n times. + TString(size_t, char) except + + TString(char*, char*) except + TString(TStringBuf&) except + TString(TStringBuf&, TStringBuf&) except + TString(TStringBuf&, TStringBuf&, TStringBuf&) except + @@ -48,22 +48,22 @@ cdef extern from "<util/generic/string.h>" nogil: TString& append(TStringBuf&) except + TString& append(TStringBuf&, size_t, size_t) except + - TString& append(char *) except + - TString& append(char *, size_t) except + - TString& append(size_t, char) except + + TString& append(char *) except + + TString& append(char *, size_t) except + + TString& append(size_t, char) except + void push_back(char c) except + TString& assign(TStringBuf&) except + TString& assign(TStringBuf&, size_t, size_t) except + - TString& assign(char *) except + - TString& assign(char *, size_t) except + + TString& assign(char *) except + + TString& assign(char *, size_t) except + - TString& insert(size_t, TString&) except + - TString& insert(size_t, TString&, size_t, size_t) except + - TString& insert(size_t, char* s) except + - TString& insert(size_t, char* s, size_t) except + - TString& insert(size_t, size_t, char c) except + + TString& insert(size_t, TString&) except + + TString& insert(size_t, TString&, size_t, size_t) except + + TString& insert(size_t, char* s) except + + TString& insert(size_t, char* s, size_t) except + + TString& insert(size_t, size_t, char c) except + size_t copy(char *, size_t) except + size_t copy(char *, size_t, size_t) except + @@ -93,11 +93,11 @@ cdef extern from "<util/generic/string.h>" nogil: size_t find_last_of(TStringBuf& set) size_t find_last_of(TStringBuf& set, size_t pos) - TString substr(size_t pos) except + - TString substr(size_t pos, size_t n) except + + TString substr(size_t pos) except + + TString substr(size_t pos, size_t n) except + TString operator+(TStringBuf& rhs) except + - TString operator+(char* rhs) except + + TString operator+(char* rhs) except + bint operator==(TStringBuf&) bint operator==(char*) diff --git a/util/generic/string_transparent_hash_ut.cpp b/util/generic/string_transparent_hash_ut.cpp index b87fa2843e..99aaeb55c4 100644 --- a/util/generic/string_transparent_hash_ut.cpp +++ b/util/generic/string_transparent_hash_ut.cpp @@ -1,4 +1,4 @@ -#include "string.h" +#include "string.h" #include "vector.h" #include "strbuf.h" diff --git a/util/generic/string_ut.cpp b/util/generic/string_ut.cpp index ac82e9091d..e1ca6d358e 100644 --- a/util/generic/string_ut.cpp +++ b/util/generic/string_ut.cpp @@ -17,7 +17,7 @@ #ifdef TSTRING_IS_STD_STRING static_assert(sizeof(TString) == sizeof(std::string), "expect sizeof(TString) == sizeof(std::string)"); #else -static_assert(sizeof(TString) == sizeof(const char*), "expect sizeof(TString) == sizeof(const char*)"); +static_assert(sizeof(TString) == sizeof(const char*), "expect sizeof(TString) == sizeof(const char*)"); #endif class TStringTestZero: public TTestBase { @@ -28,7 +28,7 @@ class TStringTestZero: public TTestBase { public: void TestZero() { const char data[] = "abc\0def\0"; - TString s(data, sizeof(data)); + TString s(data, sizeof(data)); UNIT_ASSERT(s.size() == sizeof(data)); UNIT_ASSERT(s.StartsWith(s)); UNIT_ASSERT(s.EndsWith(s)); @@ -36,8 +36,8 @@ public: const char raw_def[] = "def"; const char raw_zero[] = "\0"; - TString def(raw_def, sizeof(raw_def) - 1); - TString zero(raw_zero, sizeof(raw_zero) - 1); + TString def(raw_def, sizeof(raw_def) - 1); + TString zero(raw_zero, sizeof(raw_zero) - 1); UNIT_ASSERT_EQUAL(4, s.find(raw_def)); UNIT_ASSERT_EQUAL(4, s.find(def)); UNIT_ASSERT_EQUAL(4, s.find_first_of(raw_def)); @@ -45,15 +45,15 @@ public: UNIT_ASSERT_EQUAL(7, s.find_first_not_of(def, 4)); const char nonSubstring[] = "def\0ghi"; - UNIT_ASSERT_EQUAL(TString::npos, s.find(TString(nonSubstring, sizeof(nonSubstring)))); + UNIT_ASSERT_EQUAL(TString::npos, s.find(TString(nonSubstring, sizeof(nonSubstring)))); - TString copy = s; + TString copy = s; copy.replace(copy.size() - 1, 1, "z"); UNIT_ASSERT(s != copy); copy.replace(copy.size() - 1, 1, "\0", 0, 1); UNIT_ASSERT(s == copy); - TString prefix(data, 5); + TString prefix(data, 5); UNIT_ASSERT(s.StartsWith(prefix)); UNIT_ASSERT(s != prefix); UNIT_ASSERT(s > prefix); @@ -68,7 +68,7 @@ public: UNIT_TEST_SUITE_REGISTRATION(TStringTestZero); -template <typename TStringType, typename TTestData> +template <typename TStringType, typename TTestData> class TStringStdTestImpl { using TChar = typename TStringType::char_type; using TTraits = typename TStringType::traits_type; @@ -92,7 +92,7 @@ protected: void reserve() { #if 0 - TStringType s; + TStringType s; // @todo use UNIT_TEST_EXCEPTION try { s.reserve(s.max_size() + 1); @@ -129,7 +129,7 @@ protected: #ifndef TSTRING_IS_STD_STRING // Shared behaviour - always reallocate, just as much as requisted - TStringType holder = s; + TStringType holder = s; UNIT_ASSERT(s.capacity() >= 256); @@ -152,22 +152,22 @@ protected: void short_string() { TStringType const ref_short_str1(Data_.str1()), ref_short_str2(Data_.str2()); - TStringType short_str1(ref_short_str1), short_str2(ref_short_str2); + TStringType short_str1(ref_short_str1), short_str2(ref_short_str2); TStringType const ref_long_str1(Data_.str__________________________________________________1()); TStringType const ref_long_str2(Data_.str__________________________________________________2()); - TStringType long_str1(ref_long_str1), long_str2(ref_long_str2); + TStringType long_str1(ref_long_str1), long_str2(ref_long_str2); UNIT_ASSERT(short_str1 == ref_short_str1); UNIT_ASSERT(long_str1 == ref_long_str1); { - TStringType str1(short_str1); + TStringType str1(short_str1); str1 = long_str1; UNIT_ASSERT(str1 == ref_long_str1); } { - TStringType str1(long_str1); + TStringType str1(long_str1); str1 = short_str1; UNIT_ASSERT(str1 == ref_short_str1); } @@ -198,7 +198,7 @@ protected: { //This is to test move constructor - TVector<TStringType> str_vect; + TVector<TStringType> str_vect; str_vect.push_back(short_str1); str_vect.push_back(long_str1); @@ -214,7 +214,7 @@ protected: void erase() { TChar const* c_str = Data_.Hello_World(); - TStringType str(c_str); + TStringType str(c_str); UNIT_ASSERT(str == c_str); str.erase(str.begin() + 1, str.end() - 1); // Erase all but first and last. @@ -266,7 +266,7 @@ protected: } void data() { - TStringType xx; + TStringType xx; // ISO-IEC-14882:1998(E), 21.3.6, paragraph 3 UNIT_ASSERT(xx.data() != nullptr); @@ -274,8 +274,8 @@ protected: void c_str() { TStringType low(Data_._2004_01_01()); - TStringType xx; - TStringType yy; + TStringType xx; + TStringType yy; // ISO-IEC-14882:1998(E), 21.3.6, paragraph 1 UNIT_ASSERT(*(yy.c_str()) == 0); @@ -357,10 +357,10 @@ protected: void insert() { TStringType strorg = Data_.This_is_test_string_for_string_calls(); - TStringType str; + TStringType str; // In case of reallocation there is no auto reference problem - // so we reserve a big enough TStringType to be sure to test this + // so we reserve a big enough TStringType to be sure to test this // particular point. str.reserve(100); @@ -383,9 +383,9 @@ protected: UNIT_ASSERT(str == Data_.ng_for_string_callsThis_is_test_string_for_string_calls()); str = strorg; - typename TStringType::iterator b = str.begin(); - typename TStringType::const_iterator s = str.begin() + str.size() / 2 - 1; - typename TStringType::const_iterator e = str.end(); + typename TStringType::iterator b = str.begin(); + typename TStringType::const_iterator s = str.begin() + str.size() / 2 - 1; + typename TStringType::const_iterator e = str.end(); str.insert(b, s, e); UNIT_ASSERT(str == Data_.ng_for_string_callsThis_is_test_string_for_string_calls()); @@ -396,13 +396,13 @@ protected: UNIT_ASSERT(str == Data.ng_for_string_callsThis_is_test_string_for_string_calls()); #endif - TStringType str0; + TStringType str0; str0.insert(str0.begin(), 5, *Data_._0()); UNIT_ASSERT(str0 == Data_._00000()); - TStringType str1; + TStringType str1; { - typename TStringType::size_type pos = 0, nb = 2; + typename TStringType::size_type pos = 0, nb = 2; str1.insert(pos, nb, *Data_._1()); } UNIT_ASSERT(str1 == Data_._11()); @@ -428,7 +428,7 @@ protected: } void resize() { - TStringType s; + TStringType s; s.resize(0); @@ -472,7 +472,7 @@ protected: } void capacity() { - TStringType s; + TStringType s; UNIT_ASSERT(s.capacity() < s.max_size()); UNIT_ASSERT(s.capacity() >= s.size()); @@ -487,7 +487,7 @@ protected: } void assign() { - TStringType s; + TStringType s; TChar const* cstr = Data_.test_string_for_assign(); s.assign(cstr, cstr + 22); @@ -497,12 +497,12 @@ protected: s.assign(s2); UNIT_ASSERT(s == s2); - static TStringType str1; - static TStringType str2; + static TStringType str1; + static TStringType str2; - // short TStringType optim: + // short TStringType optim: str1 = Data_._123456(); - // longer than short TStringType: + // longer than short TStringType: str2 = Data_._1234567890123456789012345678901234567890(); UNIT_ASSERT(str1[5] == *Data_._6()); @@ -539,7 +539,7 @@ protected: void cbegin_cend() { const char helloThere[] = "Hello there"; - TString s = helloThere; + TString s = helloThere; size_t index = 0; for (auto it = s.cbegin(); s.cend() != it; ++it, ++index) { UNIT_ASSERT_VALUES_EQUAL(helloThere[index], *it); @@ -548,7 +548,7 @@ protected: void compare() { TStringType str1(Data_.abcdef()); - TStringType str2; + TStringType str2; str2 = Data_.abcdef(); UNIT_ASSERT(str1.compare(str2) == 0); @@ -601,14 +601,14 @@ protected: #if 0 void rfind() { // 21.3.6.2 - TStringType s(Data.one_two_three_one_two_three()); + TStringType s(Data.one_two_three_one_two_three()); UNIT_ASSERT(s.rfind(Data.two()) == 18); - UNIT_ASSERT(s.rfind(Data.two(), 0) == TStringType::npos); + UNIT_ASSERT(s.rfind(Data.two(), 0) == TStringType::npos); UNIT_ASSERT(s.rfind(Data.two(), 11) == 4); UNIT_ASSERT(s.rfind(*Data.w()) == 19); - TStringType test(Data.aba()); + TStringType test(Data.aba()); UNIT_ASSERT(test.rfind(Data.a(), 2, 1) == 2); UNIT_ASSERT(test.rfind(Data.a(), 1, 1) == 0); @@ -643,15 +643,15 @@ protected: } #if 0 void replace() { - // This test case is for the non template basic_TString::replace method, + // This test case is for the non template basic_TString::replace method, // this is why we play with the const iterators and reference to guaranty // that the right method is called. - const TStringType v(Data._78()); - TStringType s(Data._123456()); - TStringType const& cs = s; + const TStringType v(Data._78()); + TStringType s(Data._123456()); + TStringType const& cs = s; - typename TStringType::iterator i = s.begin() + 1; + typename TStringType::iterator i = s.begin() + 1; s.replace(i, i + 3, v.begin(), v.end()); UNIT_ASSERT(s == Data._17856()); @@ -662,7 +662,7 @@ protected: s = Data._123456(); i = s.begin() + 1; - typename TStringType::const_iterator ci = s.begin() + 1; + typename TStringType::const_iterator ci = s.begin() + 1; s.replace(i, i + 3, ci + 3, cs.end()); UNIT_ASSERT(s == Data._15656()); @@ -691,10 +691,10 @@ protected: // This is the test for the template replace method. s = Data._123456(); - typename TStringType::iterator b = s.begin() + 4; - typename TStringType::iterator e = s.end(); - typename TStringType::const_iterator rb = s.begin(); - typename TStringType::const_iterator re = s.end(); + typename TStringType::iterator b = s.begin() + 4; + typename TStringType::iterator e = s.end(); + typename TStringType::const_iterator rb = s.begin(); + typename TStringType::const_iterator re = s.end(); s.replace(b, e, rb, re); UNIT_ASSERT(s == Data._1234123456()); @@ -702,8 +702,8 @@ protected: s.replace(s.begin() + 4, s.end(), s.begin(), s.end()); UNIT_ASSERT(s == Data._1234123456()); - TStringType strorg(Data.This_is_test_StringT_for_StringT_calls()); - TStringType str = strorg; + TStringType strorg(Data.This_is_test_StringT_for_StringT_calls()); + TStringType str = strorg; str.replace(5, 15, str.c_str(), 10); UNIT_ASSERT(str == Data.This_This_is_tefor_StringT_calls()); @@ -721,7 +721,7 @@ protected: #endif }; // TStringStdTestImpl -class TStringTest: public TTestBase, private TStringTestImpl<TString, TTestData<char>> { +class TStringTest: public TTestBase, private TStringTestImpl<TString, TTestData<char>> { public: UNIT_TEST_SUITE(TStringTest); UNIT_TEST(TestMaxSize); @@ -783,7 +783,7 @@ public: UNIT_TEST_SUITE_REGISTRATION(TStringTest); -class TWideStringTest: public TTestBase, private TStringTestImpl<TUtf16String, TTestData<wchar16>> { +class TWideStringTest: public TTestBase, private TStringTestImpl<TUtf16String, TTestData<wchar16>> { public: UNIT_TEST_SUITE(TWideStringTest); UNIT_TEST(TestConstructors); @@ -816,21 +816,21 @@ public: private: void TestDecodingMethods() { - UNIT_ASSERT(TUtf16String::FromAscii("").empty()); - UNIT_ASSERT(TUtf16String::FromAscii("abc") == ASCIIToWide("abc")); + UNIT_ASSERT(TUtf16String::FromAscii("").empty()); + UNIT_ASSERT(TUtf16String::FromAscii("abc") == ASCIIToWide("abc")); const char* text = "123kx83abcd ej)#$%ddja&%J&"; - TUtf16String wtext = ASCIIToWide(text); + TUtf16String wtext = ASCIIToWide(text); - UNIT_ASSERT(wtext == TUtf16String::FromAscii(text)); + UNIT_ASSERT(wtext == TUtf16String::FromAscii(text)); - TString strtext(text); - UNIT_ASSERT(wtext == TUtf16String::FromAscii(strtext)); + TString strtext(text); + UNIT_ASSERT(wtext == TUtf16String::FromAscii(strtext)); TStringBuf strbuftext(text); - UNIT_ASSERT(wtext == TUtf16String::FromAscii(strbuftext)); + UNIT_ASSERT(wtext == TUtf16String::FromAscii(strbuftext)); - UNIT_ASSERT(wtext.substr(5) == TUtf16String::FromAscii(text + 5)); + UNIT_ASSERT(wtext.substr(5) == TUtf16String::FromAscii(text + 5)); const wchar16 wideCyrillicAlphabet[] = { 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, @@ -839,16 +839,16 @@ private: 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F, 0x00}; - TUtf16String strWide(wideCyrillicAlphabet); - TString strUtf8 = WideToUTF8(strWide); + TUtf16String strWide(wideCyrillicAlphabet); + TString strUtf8 = WideToUTF8(strWide); - UNIT_ASSERT(strWide == TUtf16String::FromUtf8(strUtf8.c_str())); - UNIT_ASSERT(strWide == TUtf16String::FromUtf8(strUtf8)); - UNIT_ASSERT(strWide == TUtf16String::FromUtf8(TStringBuf(strUtf8))); + UNIT_ASSERT(strWide == TUtf16String::FromUtf8(strUtf8.c_str())); + UNIT_ASSERT(strWide == TUtf16String::FromUtf8(strUtf8)); + UNIT_ASSERT(strWide == TUtf16String::FromUtf8(TStringBuf(strUtf8))); // assign - TUtf16String s1; + TUtf16String s1; s1.AssignAscii("1234"); UNIT_ASSERT(s1 == ASCIIToWide("1234")); @@ -860,8 +860,8 @@ private: // append - TUtf16String s2; - TUtf16String testAppend = strWide; + TUtf16String s2; + TUtf16String testAppend = strWide; s2.AppendUtf8(strUtf8); UNIT_ASSERT(testAppend == s2); @@ -883,12 +883,12 @@ private: } void TestLetOperator() { - TUtf16String str; + TUtf16String str; str = wchar16('X'); - UNIT_ASSERT(str == TUtf16String::FromAscii("X")); + UNIT_ASSERT(str == TUtf16String::FromAscii("X")); - const TUtf16String hello = TUtf16String::FromAscii("hello"); + const TUtf16String hello = TUtf16String::FromAscii("hello"); str = hello.data(); UNIT_ASSERT(str == hello); @@ -1105,7 +1105,7 @@ private: UNIT_TEST_SUITE_REGISTRATION(TUtf32StringTest); -class TStringStdTest: public TTestBase, private TStringStdTestImpl<TString, TTestData<char>> { +class TStringStdTest: public TTestBase, private TStringStdTestImpl<TString, TTestData<char>> { public: UNIT_TEST_SUITE(TStringStdTest); UNIT_TEST(Constructor); @@ -1141,7 +1141,7 @@ public: UNIT_TEST_SUITE_REGISTRATION(TStringStdTest); -class TWideStringStdTest: public TTestBase, private TStringStdTestImpl<TUtf16String, TTestData<wchar16>> { +class TWideStringStdTest: public TTestBase, private TStringStdTestImpl<TUtf16String, TTestData<wchar16>> { public: UNIT_TEST_SUITE(TWideStringStdTest); UNIT_TEST(Constructor); diff --git a/util/generic/string_ut.h b/util/generic/string_ut.h index 44bb10bdeb..548b735453 100644 --- a/util/generic/string_ut.h +++ b/util/generic/string_ut.h @@ -1,6 +1,6 @@ #pragma once -#include "string.h" +#include "string.h" #include <library/cpp/testing/unittest/registar.h> @@ -508,11 +508,11 @@ size_t TTestData<wchar16>::HashOf_0123456() { return 2775195331ul; } -template <class TStringType, typename TTestData> +template <class TStringType, typename TTestData> class TStringTestImpl { protected: - using char_type = typename TStringType::char_type; - using traits_type = typename TStringType::traits_type; + using char_type = typename TStringType::char_type; + using traits_type = typename TStringType::traits_type; TTestData Data; @@ -525,13 +525,13 @@ public: } void TestConstructors() { - TStringType s0(nullptr); + TStringType s0(nullptr); UNIT_ASSERT(s0.size() == 0); - UNIT_ASSERT_EQUAL(s0, TStringType()); + UNIT_ASSERT_EQUAL(s0, TStringType()); - TStringType s; - TStringType s1(*Data._0()); - TStringType s2(Data._0()); + TStringType s; + TStringType s1(*Data._0()); + TStringType s2(Data._0()); UNIT_ASSERT(s1 == s2); TStringType fromZero(0); @@ -542,37 +542,37 @@ public: UNIT_ASSERT_VALUES_EQUAL(fromChar[0], char_type('a')); #ifndef TSTRING_IS_STD_STRING - TStringType s3 = TStringType::Uninitialized(10); + TStringType s3 = TStringType::Uninitialized(10); UNIT_ASSERT(s3.size() == 10); #endif - TStringType s4(Data._0123456(), 1, 3); + TStringType s4(Data._0123456(), 1, 3); UNIT_ASSERT(s4 == Data._123()); - TStringType s5(5, *Data._0()); + TStringType s5(5, *Data._0()); UNIT_ASSERT(s5 == Data._00000()); - TStringType s6(Data._0123456()); + TStringType s6(Data._0123456()); UNIT_ASSERT(s6 == Data._0123456()); - TStringType s7(s6); + TStringType s7(s6); UNIT_ASSERT(s7 == s6); #ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s7.c_str() == s6.c_str()); #endif - TStringType s8(s7, 1, 3); + TStringType s8(s7, 1, 3); UNIT_ASSERT(s8 == Data._123()); - TStringType s9(*Data._1()); + TStringType s9(*Data._1()); UNIT_ASSERT(s9 == Data._1()); - TStringType s10(Reserve(100)); + TStringType s10(Reserve(100)); UNIT_ASSERT(s10.empty()); UNIT_ASSERT(s10.capacity() >= 100); } void TestReplace() { - TStringType s(Data._0123456()); + TStringType s(Data._0123456()); UNIT_ASSERT(s.copy() == Data._0123456()); // append family @@ -586,10 +586,10 @@ public: #endif UNIT_ASSERT(s == Data._0123456xy()); - s.append(TStringType(Data.z())); + s.append(TStringType(Data.z())); UNIT_ASSERT(s == Data._0123456xyz()); - s.append(TStringType(Data.XYZ()), 2, 1); + s.append(TStringType(Data.XYZ()), 2, 1); UNIT_ASSERT(s == Data._0123456xyzZ()); s.append(*Data._0()); @@ -597,10 +597,10 @@ public: // prepend family s = Data._0123456xyz(); - s.prepend(TStringType(Data.abc())); + s.prepend(TStringType(Data.abc())); UNIT_ASSERT(s == Data.abc0123456xyz()); - s.prepend(TStringType(Data.ABC()), 1, 2); + s.prepend(TStringType(Data.ABC()), 1, 2); UNIT_ASSERT(s == Data.BCabc0123456xyz()); s.prepend(Data.qwe()); @@ -618,10 +618,10 @@ public: s.insert(2, Data.abc()); UNIT_ASSERT(s == Data._01abc23456()); - s.insert(2, TStringType(Data.ABC())); + s.insert(2, TStringType(Data.ABC())); UNIT_ASSERT(s == Data._01ABCabc23456()); - s.insert(0, TStringType(Data.QWE()), 1, 1); + s.insert(0, TStringType(Data.QWE()), 1, 1); UNIT_ASSERT(s == Data.W01ABCabc23456()); // replace family @@ -629,10 +629,10 @@ public: s.replace(0, 7, Data.abcd()); UNIT_ASSERT(s == Data.abcd456()); - s.replace(4, 3, TStringType(Data.ABCD())); + s.replace(4, 3, TStringType(Data.ABCD())); UNIT_ASSERT(s == Data.abcdABCD()); - s.replace(7, 10, TStringType(Data._01234()), 1, 3); + s.replace(7, 10, TStringType(Data._01234()), 1, 3); UNIT_ASSERT(s == Data.abcdABC123()); UNIT_ASSERT(Data.abcdABC123() == s); @@ -677,18 +677,18 @@ public: // Find family void TestFind() { - const TStringType s(Data._0123456_12345()); - const TStringType s2(Data._0123()); + const TStringType s(Data._0123456_12345()); + const TStringType s2(Data._0123()); UNIT_ASSERT(s.find(Data._345()) == 3); UNIT_ASSERT(s.find(Data._345(), 5) == 10); - UNIT_ASSERT(s.find(Data._345(), 20) == TStringType::npos); + UNIT_ASSERT(s.find(Data._345(), 20) == TStringType::npos); UNIT_ASSERT(s.find(*Data._3()) == 3); - UNIT_ASSERT(s.find(TStringType(Data._345())) == 3); - UNIT_ASSERT(s.find(TStringType(Data._345()), 2) == 3); + UNIT_ASSERT(s.find(TStringType(Data._345())) == 3); + UNIT_ASSERT(s.find(TStringType(Data._345()), 2) == 3); - UNIT_ASSERT(s.find_first_of(TStringType(Data._389())) == 3); + UNIT_ASSERT(s.find_first_of(TStringType(Data._389())) == 3); UNIT_ASSERT(s.find_first_of(Data._389()) == 3); UNIT_ASSERT(s.find_first_of(Data._389(), s.size()) == TStringType::npos); UNIT_ASSERT(s.find_first_not_of(Data._123()) == 0); @@ -697,34 +697,34 @@ public: UNIT_ASSERT(s.find_first_not_of('0') == 1); UNIT_ASSERT(s.find_first_not_of('1', 1) == 2); - const TStringType rs = Data._0123401234(); + const TStringType rs = Data._0123401234(); UNIT_ASSERT(rs.rfind(*Data._3()) == 8); - const TStringType empty; + const TStringType empty; UNIT_ASSERT(empty.find(empty) == 0); UNIT_ASSERT(s.find(empty, 0) == 0); UNIT_ASSERT(s.find(empty, 1) == 1); UNIT_ASSERT(s.find(empty, s.length()) == s.length()); - UNIT_ASSERT(s.find(empty, s.length() + 1) == TStringType::npos); + UNIT_ASSERT(s.find(empty, s.length() + 1) == TStringType::npos); UNIT_ASSERT(s.rfind(empty) == s.length()); UNIT_ASSERT(empty.rfind(empty) == 0); - UNIT_ASSERT(empty.rfind(s) == TStringType::npos); + UNIT_ASSERT(empty.rfind(s) == TStringType::npos); - UNIT_ASSERT(s2.rfind(s) == TStringType::npos); + UNIT_ASSERT(s2.rfind(s) == TStringType::npos); UNIT_ASSERT(s.rfind(s2) == 0); - UNIT_ASSERT(s.rfind(TStringType(Data._345())) == 10); - UNIT_ASSERT(s.rfind(TStringType(Data._345()), 13) == 10); - UNIT_ASSERT(s.rfind(TStringType(Data._345()), 10) == 10); - UNIT_ASSERT(s.rfind(TStringType(Data._345()), 9) == 3); - UNIT_ASSERT(s.rfind(TStringType(Data._345()), 6) == 3); - UNIT_ASSERT(s.rfind(TStringType(Data._345()), 3) == 3); - UNIT_ASSERT(s.rfind(TStringType(Data._345()), 2) == TStringType::npos); + UNIT_ASSERT(s.rfind(TStringType(Data._345())) == 10); + UNIT_ASSERT(s.rfind(TStringType(Data._345()), 13) == 10); + UNIT_ASSERT(s.rfind(TStringType(Data._345()), 10) == 10); + UNIT_ASSERT(s.rfind(TStringType(Data._345()), 9) == 3); + UNIT_ASSERT(s.rfind(TStringType(Data._345()), 6) == 3); + UNIT_ASSERT(s.rfind(TStringType(Data._345()), 3) == 3); + UNIT_ASSERT(s.rfind(TStringType(Data._345()), 2) == TStringType::npos); } void TestContains() { - const TStringType s(Data._0123456_12345()); - const TStringType s2(Data._0123()); + const TStringType s(Data._0123456_12345()); + const TStringType s2(Data._0123()); UNIT_ASSERT(s.Contains(Data._345())); UNIT_ASSERT(!s2.Contains(Data._345())); @@ -732,7 +732,7 @@ public: UNIT_ASSERT(s.Contains('1')); UNIT_ASSERT(!s.Contains('*')); - TStringType empty; + TStringType empty; UNIT_ASSERT(s.Contains(empty)); UNIT_ASSERT(!empty.Contains(s)); UNIT_ASSERT(empty.Contains(empty)); @@ -742,10 +742,10 @@ public: // Operators void TestOperators() { - TStringType s(Data._0123456()); + TStringType s(Data._0123456()); // operator += - s += TStringType(Data.x()); + s += TStringType(Data.x()); UNIT_ASSERT(s == Data._0123456x()); s += Data.y(); @@ -756,7 +756,7 @@ public: // operator + s = Data._0123456(); - s = s + TStringType(Data.x()); + s = s + TStringType(Data.x()); UNIT_ASSERT(s == Data._0123456x()); s = s + Data.y(); @@ -767,33 +767,33 @@ public: // operator != s = Data._012345(); - UNIT_ASSERT(s != TStringType(Data.xyz())); + UNIT_ASSERT(s != TStringType(Data.xyz())); UNIT_ASSERT(s != Data.xyz()); UNIT_ASSERT(Data.xyz() != s); // operator < - UNIT_ASSERT_EQUAL(s < TStringType(Data.xyz()), true); + UNIT_ASSERT_EQUAL(s < TStringType(Data.xyz()), true); UNIT_ASSERT_EQUAL(s < Data.xyz(), true); UNIT_ASSERT_EQUAL(Data.xyz() < s, false); // operator <= - UNIT_ASSERT_EQUAL(s <= TStringType(Data.xyz()), true); + UNIT_ASSERT_EQUAL(s <= TStringType(Data.xyz()), true); UNIT_ASSERT_EQUAL(s <= Data.xyz(), true); UNIT_ASSERT_EQUAL(Data.xyz() <= s, false); // operator > - UNIT_ASSERT_EQUAL(s > TStringType(Data.xyz()), false); + UNIT_ASSERT_EQUAL(s > TStringType(Data.xyz()), false); UNIT_ASSERT_EQUAL(s > Data.xyz(), false); UNIT_ASSERT_EQUAL(Data.xyz() > s, true); // operator >= - UNIT_ASSERT_EQUAL(s >= TStringType(Data.xyz()), false); + UNIT_ASSERT_EQUAL(s >= TStringType(Data.xyz()), false); UNIT_ASSERT_EQUAL(s >= Data.xyz(), false); UNIT_ASSERT_EQUAL(Data.xyz() >= s, true); } void TestOperatorsCI() { - TStringType s(Data.ABCD()); + TStringType s(Data.ABCD()); UNIT_ASSERT(s > Data.abc0123456xyz()); UNIT_ASSERT(s == Data.abcd()); @@ -806,20 +806,20 @@ public: void TestMulOperators() { { - TStringType s(Data._0()); + TStringType s(Data._0()); s *= 10; - UNIT_ASSERT_EQUAL(s, TStringType(Data._0000000000())); + UNIT_ASSERT_EQUAL(s, TStringType(Data._0000000000())); } { - TStringType s = TStringType(Data._0()) * 2; - UNIT_ASSERT_EQUAL(s, TStringType(Data._00())); + TStringType s = TStringType(Data._0()) * 2; + UNIT_ASSERT_EQUAL(s, TStringType(Data._00())); } } // Test any other functions void TestFuncs() { - TStringType s(Data._0123456()); + TStringType s(Data._0123456()); UNIT_ASSERT(s.c_str() == s.data()); // length() @@ -827,12 +827,12 @@ public: UNIT_ASSERT(s.length() == traits_type::length(s.data())); // is_null() - TStringType s1(Data.Empty()); + TStringType s1(Data.Empty()); UNIT_ASSERT(s1.is_null() == true); UNIT_ASSERT(s1.is_null() == s1.empty()); UNIT_ASSERT(s1.is_null() == !s1); - TStringType s2(s); + TStringType s2(s); UNIT_ASSERT(s2 == s); // reverse() @@ -859,7 +859,7 @@ public: // Friend functions s2 = Data.asdf1234qwer(); - TStringType s3 = to_upper(s2); + TStringType s3 = to_upper(s2); UNIT_ASSERT(s3 == Data.ASDF1234QWER()); s3 = to_lower(s2); UNIT_ASSERT(s3 == Data.asdf1234qwer()); @@ -892,7 +892,7 @@ public: UNIT_ASSERT(s2 == Data._0123456()); // hash() - TStringType sS = s2; // type 'TStringType' is used as is + TStringType sS = s2; // type 'TStringType' is used as is ComputeHash(sS); /*size_t hash_val = sS.hash(); @@ -908,42 +908,42 @@ public: //s2.reserve(); - TStringType s5(Data.abcde()); + TStringType s5(Data.abcde()); s5.clear(); UNIT_ASSERT(s5 == Data.Empty()); } void TestUtils() { - TStringType s; + TStringType s; s = Data._01230123(); - TStringType from = Data._0(); - TStringType to = Data.z(); + TStringType from = Data._0(); + TStringType to = Data.z(); SubstGlobal(s, from, to); UNIT_ASSERT(s == Data.z123z123()); } void TestEmpty() { - TStringType s; + TStringType s; s = Data._2(); - s = TStringType(Data.fdfdsfds(), (size_t)0, (size_t)0); + s = TStringType(Data.fdfdsfds(), (size_t)0, (size_t)0); UNIT_ASSERT(s.empty()); } void TestJoin() { - UNIT_ASSERT_EQUAL(TStringType::Join(Data._12(), Data._3456()), Data._123456()); - UNIT_ASSERT_EQUAL(TStringType::Join(Data._12(), TStringType(Data._3456())), Data._123456()); - UNIT_ASSERT_EQUAL(TStringType::Join(TStringType(Data._12()), Data._3456()), Data._123456()); - UNIT_ASSERT_EQUAL(TStringType::Join(Data._12(), Data._345(), Data._6()), Data._123456()); - UNIT_ASSERT_EQUAL(TStringType::Join(Data._12(), TStringType(Data._345()), Data._6()), Data._123456()); - UNIT_ASSERT_EQUAL(TStringType::Join(TStringType(Data._12()), TStringType(Data._345()), Data._6()), Data._123456()); - UNIT_ASSERT_EQUAL(TStringType::Join(TStringType(Data.a()), Data.b(), TStringType(Data.cd()), TStringType(Data.e()), Data.fg(), TStringType(Data.h())), Data.abcdefgh()); + UNIT_ASSERT_EQUAL(TStringType::Join(Data._12(), Data._3456()), Data._123456()); + UNIT_ASSERT_EQUAL(TStringType::Join(Data._12(), TStringType(Data._3456())), Data._123456()); + UNIT_ASSERT_EQUAL(TStringType::Join(TStringType(Data._12()), Data._3456()), Data._123456()); + UNIT_ASSERT_EQUAL(TStringType::Join(Data._12(), Data._345(), Data._6()), Data._123456()); + UNIT_ASSERT_EQUAL(TStringType::Join(Data._12(), TStringType(Data._345()), Data._6()), Data._123456()); + UNIT_ASSERT_EQUAL(TStringType::Join(TStringType(Data._12()), TStringType(Data._345()), Data._6()), Data._123456()); + UNIT_ASSERT_EQUAL(TStringType::Join(TStringType(Data.a()), Data.b(), TStringType(Data.cd()), TStringType(Data.e()), Data.fg(), TStringType(Data.h())), Data.abcdefgh()); UNIT_ASSERT_EQUAL(TStringType::Join(TStringType(Data.a()), static_cast<typename TStringType::char_type>('b'), TStringType(Data.cd()), TStringType(Data.e()), Data.fg(), TStringType(Data.h())), Data.abcdefgh()); } void TestCopy() { - TStringType s(Data.abcd()); - TStringType c = s.copy(); + TStringType s(Data.abcd()); + TStringType c = s.copy(); UNIT_ASSERT_EQUAL(s, c); UNIT_ASSERT(s.end() != c.end()); @@ -951,7 +951,7 @@ public: void TestStrCpy() { { - TStringType s(Data.abcd()); + TStringType s(Data.abcd()); char_type data[5]; data[4] = 1; @@ -966,7 +966,7 @@ public: } { - TStringType s(Data.abcd()); + TStringType s(Data.abcd()); char_type data[5]; s.strcpy(data, 5); @@ -980,7 +980,7 @@ public: } void TestPrefixSuffix() { - const TStringType emptyStr; + const TStringType emptyStr; UNIT_ASSERT_EQUAL(emptyStr.StartsWith('x'), false); UNIT_ASSERT_EQUAL(emptyStr.EndsWith('x'), false); UNIT_ASSERT_EQUAL(emptyStr.StartsWith(0), false); @@ -989,7 +989,7 @@ public: UNIT_ASSERT_EQUAL(emptyStr.EndsWith(emptyStr), true); const char_type chars[] = {'h', 'e', 'l', 'l', 'o', 0}; - const TStringType str(chars); + const TStringType str(chars); UNIT_ASSERT_EQUAL(str.StartsWith('h'), true); UNIT_ASSERT_EQUAL(str.StartsWith('o'), false); UNIT_ASSERT_EQUAL(str.EndsWith('o'), true); @@ -1004,8 +1004,8 @@ public: const char_type bbc[] = {'b', 'b', 'c', 0}; const char_type cbc[] = {'c', 'b', 'c', 0}; - TStringType s0 = abc; - TStringType s1 = s0; + TStringType s0 = abc; + TStringType s1 = s0; UNIT_ASSERT(!s0.IsDetached()); UNIT_ASSERT(!s1.IsDetached()); @@ -1017,7 +1017,7 @@ public: /* Writing should detach. */ s1[0] = (ui8)'b'; - TStringType s2 = s0; + TStringType s2 = s0; s0[0] = (ui8)'c'; UNIT_ASSERT_VALUES_EQUAL(s0, cbc); @@ -1050,8 +1050,8 @@ public: void TestBack() { const char_type chars[] = {'f', 'o', 'o', 0}; - TStringType str = chars; - const TStringType constStr = str; + TStringType str = chars; + const TStringType constStr = str; UNIT_ASSERT_VALUES_EQUAL(constStr.back(), (ui8)'o'); UNIT_ASSERT_VALUES_EQUAL(str.back(), (ui8)'o'); diff --git a/util/generic/string_ut.pyx b/util/generic/string_ut.pyx index 5407f5b4c1..2149748e33 100644 --- a/util/generic/string_ut.pyx +++ b/util/generic/string_ut.pyx @@ -1,7 +1,7 @@ # cython: c_string_type=str, c_string_encoding=utf8 from libcpp.string cimport string as std_string -from util.generic.string cimport TString, npos +from util.generic.string cimport TString, npos import pytest import unittest @@ -16,39 +16,39 @@ class TestStroka(unittest.TestCase): def test_ctor1(self): - cdef TString tmp = TString() - cdef TString tmp2 = TString(tmp) + cdef TString tmp = TString() + cdef TString tmp2 = TString(tmp) self.assertEquals(tmp2, "") def test_ctor2(self): cdef std_string tmp = b"hello" - cdef TString tmp2 = TString(tmp) + cdef TString tmp2 = TString(tmp) self.assertEquals(tmp2, "hello") def test_ctor3(self): cdef TString tmp = b"hello" - cdef TString tmp2 = TString(tmp, 0, 4) + cdef TString tmp2 = TString(tmp, 0, 4) self.assertEquals(tmp2, "hell") def test_ctor4(self): - cdef TString tmp = TString(<char*>b"hello") + cdef TString tmp = TString(<char*>b"hello") self.assertEquals(tmp, "hello") def test_ctor5(self): - cdef TString tmp = TString(<char*>b"hello", 4) + cdef TString tmp = TString(<char*>b"hello", 4) self.assertEquals(tmp, "hell") def test_ctor6(self): - cdef TString tmp = TString(<char*>b"hello", 1, 3) + cdef TString tmp = TString(<char*>b"hello", 1, 3) self.assertEquals(tmp, "ell") def test_ctor7(self): - cdef TString tmp = TString(3, <char>'x') + cdef TString tmp = TString(3, <char>'x') self.assertEquals(tmp, "xxx") def test_ctor8(self): cdef bytes tmp = b"hello" - cdef TString tmp2 = TString(<char*>tmp, <char*>tmp + 4) + cdef TString tmp2 = TString(<char*>tmp, <char*>tmp + 4) self.assertEquals(tmp2, "hell") def test_compare(self): @@ -71,7 +71,7 @@ class TestStroka(unittest.TestCase): def test_operator_assign(self): cdef TString tmp = b"hello" - cdef TString tmp2 = tmp + cdef TString tmp2 = tmp self.assertEquals(tmp2, "hello") def test_operator_plus(self): @@ -98,12 +98,12 @@ class TestStroka(unittest.TestCase): self.assertEquals(<bytes>tmp[4], b'o') self.assertEquals(<bytes>tmp.at(4), b'o') - # Actually, TString::at() is noexcept + # Actually, TString::at() is noexcept # with pytest.raises(IndexError): # tmp.at(100) def test_append(self): - cdef TString tmp + cdef TString tmp cdef TString tmp2 = b"fuu" tmp.append(tmp2) @@ -125,7 +125,7 @@ class TestStroka(unittest.TestCase): self.assertEquals(tmp, "fuuuull of gooz") def test_assign(self): - cdef TString tmp + cdef TString tmp tmp.assign(b"one") self.assertEquals(tmp, "one") @@ -140,7 +140,7 @@ class TestStroka(unittest.TestCase): self.assertEquals(tmp, "three") def test_insert(self): - cdef TString tmp + cdef TString tmp tmp = b"xx" tmp.insert(1, b"foo") diff --git a/util/generic/typelist_ut.cpp b/util/generic/typelist_ut.cpp index eeabfa97b1..18fad0efbf 100644 --- a/util/generic/typelist_ut.cpp +++ b/util/generic/typelist_ut.cpp @@ -16,24 +16,24 @@ class TTypeListTest: public TTestBase { public: void TestGet() { - using TListType = TTypeList<int, char, float>; + using TListType = TTypeList<int, char, float>; - UNIT_ASSERT_TYPES_EQUAL(TListType::TGet<0>, int); - UNIT_ASSERT_TYPES_EQUAL(TListType::TGet<1>, char); - UNIT_ASSERT_TYPES_EQUAL(TListType::TGet<2>, float); + UNIT_ASSERT_TYPES_EQUAL(TListType::TGet<0>, int); + UNIT_ASSERT_TYPES_EQUAL(TListType::TGet<1>, char); + UNIT_ASSERT_TYPES_EQUAL(TListType::TGet<2>, float); } void TestSimple() { - using TListType = TTypeList<int, char, float>; - UNIT_ASSERT_EQUAL(TListType::Length, 3); - UNIT_ASSERT_TYPES_EQUAL(TListType::THead, int); + using TListType = TTypeList<int, char, float>; + UNIT_ASSERT_EQUAL(TListType::Length, 3); + UNIT_ASSERT_TYPES_EQUAL(TListType::THead, int); } struct TA {}; struct TB {}; struct TC {}; void TestHave() { - using TListType = TTypeList<TA, TB*, const TC&>; + using TListType = TTypeList<TA, TB*, const TC&>; UNIT_ASSERT(TListType::THave<TA>::value); UNIT_ASSERT(TListType::THave<TB*>::value); UNIT_ASSERT(!TListType::THave<TB>::value); @@ -66,7 +66,7 @@ public: struct TMyMap {}; void TestSelectBy() { - using TListType = TTypeList<TA, TB, TMyMap<TA*, TB>, TMyVector<TA>, TC>; + using TListType = TTypeList<TA, TB, TMyMap<TA*, TB>, TMyVector<TA>, TC>; UNIT_ASSERT_TYPES_EQUAL(TListType::TSelectBy<TAnyType>::type, TA); UNIT_ASSERT_TYPES_EQUAL(TListType::TSelectBy<TIs1ArgTemplate>::type, TMyVector<TA>); diff --git a/util/generic/typetraits.h b/util/generic/typetraits.h index d165bd1a06..fc46648080 100644 --- a/util/generic/typetraits.h +++ b/util/generic/typetraits.h @@ -90,11 +90,11 @@ public: TPodTraits<std::remove_cv_t<std::remove_all_extents_t<T>>>::IsPod); }; -namespace NPrivate { - template <class T> +namespace NPrivate { + template <class T> struct TIsSmall: std::integral_constant<bool, (sizeof(T) <= sizeof(void*))> {}; -} - +} + template <class T> class TTypeTraits: public TTypeTraitsBase<T> { using TBase = TTypeTraitsBase<T>; @@ -102,10 +102,10 @@ class TTypeTraits: public TTypeTraitsBase<T> { /* * can be effectively passed to function as value */ - static constexpr bool IsValueType = std::is_scalar<T>::value || - std::is_array<T>::value || - std::is_reference<T>::value || - (TBase::IsPod && + static constexpr bool IsValueType = std::is_scalar<T>::value || + std::is_array<T>::value || + std::is_reference<T>::value || + (TBase::IsPod && std::conditional_t< std::is_function<T>::value, std::false_type, @@ -222,8 +222,8 @@ class TTypeTraits<void>: public TTypeTraitsBase<void> {}; * std::false_type, * >; * - * static_assert(TIsAssocCont<TVector<int>>::value == false, ""); - * static_assert(TIsAssocCont<THashMap<int>>::value == true, ""); + * static_assert(TIsAssocCont<TVector<int>>::value == false, ""); + * static_assert(TIsAssocCont<THashMap<int>>::value == true, ""); * @endcode */ #define Y_HAS_SUBTYPE(...) Y_PASS_VA_ARGS(Y_MACRO_IMPL_DISPATCHER_2(__VA_ARGS__, Y_HAS_SUBTYPE_IMPL_2, Y_HAS_SUBTYPE_IMPL_1)(__VA_ARGS__)) diff --git a/util/generic/typetraits_ut.cpp b/util/generic/typetraits_ut.cpp index e7571c75ec..8a9a2de1ce 100644 --- a/util/generic/typetraits_ut.cpp +++ b/util/generic/typetraits_ut.cpp @@ -97,23 +97,23 @@ Y_UNIT_TEST_SUITE(TTypeTraitsTest) { } Y_UNIT_TEST(TestRemoveConst) { - ASSERT_SAME_TYPE(std::remove_const_t<const int>, int); + ASSERT_SAME_TYPE(std::remove_const_t<const int>, int); } Y_UNIT_TEST(TestRemoveVolatile) { - ASSERT_SAME_TYPE(std::remove_volatile_t<volatile int>, int); + ASSERT_SAME_TYPE(std::remove_volatile_t<volatile int>, int); } Y_UNIT_TEST(TestRemoveCV) { - ASSERT_SAME_TYPE(std::remove_cv_t<const volatile int>, int); + ASSERT_SAME_TYPE(std::remove_cv_t<const volatile int>, int); } Y_UNIT_TEST(TestAddCV) { - ASSERT_SAME_TYPE(std::add_cv_t<int>, const volatile int); + ASSERT_SAME_TYPE(std::add_cv_t<int>, const volatile int); } Y_UNIT_TEST(TestClass) { - UNIT_ASSERT(std::is_class<TString>::value); + UNIT_ASSERT(std::is_class<TString>::value); UNIT_ASSERT(!std::is_class<ETestEnum>::value); UNIT_ASSERT(!std::is_class<int>::value); UNIT_ASSERT(!std::is_class<void*>::value); @@ -197,12 +197,12 @@ Y_UNIT_TEST_SUITE(TTypeTraitsTest) { } Y_UNIT_TEST(TestAddRValueReference) { - ASSERT_SAME_TYPE(std::add_rvalue_reference_t<int>, int&&); - ASSERT_SAME_TYPE(std::add_rvalue_reference_t<int const&>, int const&); - ASSERT_SAME_TYPE(std::add_rvalue_reference_t<int*>, int*&&); - ASSERT_SAME_TYPE(std::add_rvalue_reference_t<int*&>, int*&); - ASSERT_SAME_TYPE(std::add_rvalue_reference_t<int&&>, int&&); - ASSERT_SAME_TYPE(std::add_rvalue_reference_t<void>, void); + ASSERT_SAME_TYPE(std::add_rvalue_reference_t<int>, int&&); + ASSERT_SAME_TYPE(std::add_rvalue_reference_t<int const&>, int const&); + ASSERT_SAME_TYPE(std::add_rvalue_reference_t<int*>, int*&&); + ASSERT_SAME_TYPE(std::add_rvalue_reference_t<int*&>, int*&); + ASSERT_SAME_TYPE(std::add_rvalue_reference_t<int&&>, int&&); + ASSERT_SAME_TYPE(std::add_rvalue_reference_t<void>, void); } Y_UNIT_TEST(TestIsEmpty) { @@ -228,7 +228,7 @@ Y_UNIT_TEST_SUITE(TTypeTraitsTest) { } template <class T> - using TTrySum = decltype(std::declval<T>() + std::declval<T>()); + using TTrySum = decltype(std::declval<T>() + std::declval<T>()); Y_UNIT_TEST(TestIsTriviallyCopyable) { struct TPod { diff --git a/util/generic/ut/ya.make b/util/generic/ut/ya.make index 6eaf24cc5f..fed74217f0 100644 --- a/util/generic/ut/ya.make +++ b/util/generic/ut/ya.make @@ -8,7 +8,7 @@ FORK_TESTS() SRCS( generic/adaptor_ut.cpp generic/algorithm_ut.cpp - generic/array_ref_ut.cpp + generic/array_ref_ut.cpp generic/array_size_ut.cpp generic/bitmap_ut.cpp generic/bitops_ut.cpp @@ -42,7 +42,7 @@ SRCS( generic/stack_ut.cpp generic/store_policy_ut.cpp generic/strbuf_ut.cpp - generic/string_ut.cpp + generic/string_ut.cpp generic/typelist_ut.cpp generic/typetraits_ut.cpp generic/utility_ut.cpp diff --git a/util/generic/utility.cpp b/util/generic/utility.cpp index e1ed101c76..a4173d06ee 100644 --- a/util/generic/utility.cpp +++ b/util/generic/utility.cpp @@ -1,21 +1,21 @@ #include "utility.h" - -#ifdef _MSC_VER + +#ifdef _MSC_VER #include <Windows.h> -#endif - -void SecureZero(void* pointer, size_t count) noexcept { -#ifdef _MSC_VER - SecureZeroMemory(pointer, count); -#elif defined(memset_s) - memset_s(pointer, count, 0, count); -#else +#endif + +void SecureZero(void* pointer, size_t count) noexcept { +#ifdef _MSC_VER + SecureZeroMemory(pointer, count); +#elif defined(memset_s) + memset_s(pointer, count, 0, count); +#else volatile char* vPointer = (volatile char*)pointer; - - while (count) { - *vPointer = 0; - vPointer++; - count--; - } -#endif -} + + while (count) { + *vPointer = 0; + vPointer++; + count--; + } +#endif +} diff --git a/util/generic/utility.h b/util/generic/utility.h index 43b98eeafc..876d67a89f 100644 --- a/util/generic/utility.h +++ b/util/generic/utility.h @@ -43,28 +43,28 @@ static T Mean(const Args&... other) noexcept { } template <class T> -static inline void Zero(T& t) noexcept { +static inline void Zero(T& t) noexcept { memset((void*)&t, 0, sizeof(t)); } -/** - * Securely zero memory (compiler does not optimize this out) - * - * @param pointer void pointer to start of memory block to be zeroed - * @param count size of memory block to be zeroed (in bytes) - */ -void SecureZero(void* pointer, size_t count) noexcept; - -/** - * Securely zero memory of given object (compiler does not optimize this out) - * - * @param t reference to object, which must be zeroed - */ -template <class T> -static inline void SecureZero(T& t) noexcept { - SecureZero((void*)&t, sizeof(t)); -} - +/** + * Securely zero memory (compiler does not optimize this out) + * + * @param pointer void pointer to start of memory block to be zeroed + * @param count size of memory block to be zeroed (in bytes) + */ +void SecureZero(void* pointer, size_t count) noexcept; + +/** + * Securely zero memory of given object (compiler does not optimize this out) + * + * @param t reference to object, which must be zeroed + */ +template <class T> +static inline void SecureZero(T& t) noexcept { + SecureZero((void*)&t, sizeof(t)); +} + namespace NSwapCheck { Y_HAS_MEMBER(swap); Y_HAS_MEMBER(Swap); @@ -111,18 +111,18 @@ struct TNullTmpl { }; using TNull = TNullTmpl<0>; - -/* - * Class for zero-initialize padding bytes in derived classes - */ -template <typename TDerived> -class TZeroInit { -protected: - TZeroInit() { - // Actually, safe because this as TDerived is not initialized yet. - Zero(*static_cast<TDerived*>(this)); - } -}; + +/* + * Class for zero-initialize padding bytes in derived classes + */ +template <typename TDerived> +class TZeroInit { +protected: + TZeroInit() { + // Actually, safe because this as TDerived is not initialized yet. + Zero(*static_cast<TDerived*>(this)); + } +}; struct TIdentity { template <class T> diff --git a/util/generic/utility_ut.cpp b/util/generic/utility_ut.cpp index 8e9d5afff9..fab7984aea 100644 --- a/util/generic/utility_ut.cpp +++ b/util/generic/utility_ut.cpp @@ -74,7 +74,7 @@ Y_UNIT_TEST_SUITE(TUtilityTest) { UNIT_ASSERT_EQUAL(Mean(1, 2), 1.5); UNIT_ASSERT(Abs(Mean(1., 2., 7.5) - 3.5) < std::numeric_limits<double>::epsilon()); } - + Y_UNIT_TEST(TestZeroInitWithDefaultZeros) { struct TStructWithPaddingBytes: public TZeroInit<TStructWithPaddingBytes> { TStructWithPaddingBytes() @@ -84,17 +84,17 @@ Y_UNIT_TEST_SUITE(TUtilityTest) { // here between Field1_ and Field2_ will be padding bytes i64 Field2_ = 0; }; - + TStructWithPaddingBytes foo{}; - + // all bytes must be zeroes, and MSAN will not complain about reading from padding bytes const char* const fooPtr = (char*)&foo; for (size_t i = 0; i < sizeof(TStructWithPaddingBytes); ++i) { const char byte = fooPtr[i]; UNIT_ASSERT_EQUAL(byte, 0); } - } - + } + Y_UNIT_TEST(TestZeroInitWithDefaultNonZeros) { struct TStructWithPaddingBytes: public TZeroInit<TStructWithPaddingBytes> { TStructWithPaddingBytes() @@ -104,20 +104,20 @@ Y_UNIT_TEST_SUITE(TUtilityTest) { // here between Field1_ and Field2_ will be padding bytes i64 Field2_ = 100500; }; - + TStructWithPaddingBytes foo{}; - + // check that default values are set correctly UNIT_ASSERT_EQUAL(foo.Field1_, true); UNIT_ASSERT_EQUAL(foo.Field2_, 100500); - + const char* const fooPtr = (char*)&foo; // just reading all bytes, and MSAN must not complain about reading padding bytes for (size_t i = 0; i < sizeof(TStructWithPaddingBytes); ++i) { const char byte = fooPtr[i]; UNIT_ASSERT_EQUAL(byte, byte); } - } + } Y_UNIT_TEST(TestClampValNoClamp) { double val = 2; @@ -145,36 +145,36 @@ Y_UNIT_TEST_SUITE(TUtilityTest) { UNIT_ASSERT_EQUAL(clamped, hi); UNIT_ASSERT_EQUAL(&clamped, &hi); } - + Y_UNIT_TEST(TestSecureZero) { constexpr size_t checkSize = 128; char test[checkSize]; - + // fill with garbage for (size_t i = 0; i < checkSize; ++i) { test[i] = i; } - + SecureZero(test, checkSize); - + for (size_t i = 0; i < checkSize; ++i) { UNIT_ASSERT_EQUAL(test[i], 0); } - } - + } + Y_UNIT_TEST(TestSecureZeroTemplate) { constexpr size_t checkSize = 128; char test[checkSize]; - + // fill with garbage for (size_t i = 0; i < checkSize; ++i) { test[i] = i; } - + SecureZero(test); - + for (size_t i = 0; i < checkSize; ++i) { UNIT_ASSERT_EQUAL(test[i], 0); } - } + } }; diff --git a/util/generic/vector.h b/util/generic/vector.h index a5b258955a..c24bc5b8c5 100644 --- a/util/generic/vector.h +++ b/util/generic/vector.h @@ -9,35 +9,35 @@ #include <initializer_list> template <class T, class A> -class TVector: public std::vector<T, TReboundAllocator<A, T>> { +class TVector: public std::vector<T, TReboundAllocator<A, T>> { public: using TBase = std::vector<T, TReboundAllocator<A, T>>; - using TSelf = TVector<T, A>; + using TSelf = TVector<T, A>; using size_type = typename TBase::size_type; - inline TVector() + inline TVector() : TBase() { } - inline TVector(const typename TBase::allocator_type& a) + inline TVector(const typename TBase::allocator_type& a) : TBase(a) { } - inline explicit TVector(::NDetail::TReserveTag rt) + inline explicit TVector(::NDetail::TReserveTag rt) : TBase() { this->reserve(rt.Capacity); } - inline explicit TVector(::NDetail::TReserveTag rt, const typename TBase::allocator_type& a) + inline explicit TVector(::NDetail::TReserveTag rt, const typename TBase::allocator_type& a) : TBase(a) { this->reserve(rt.Capacity); } - inline explicit TVector(size_type count) + inline explicit TVector(size_type count) : TBase(count) { } @@ -47,38 +47,38 @@ public: { } - inline TVector(size_type count, const T& val) + inline TVector(size_type count, const T& val) : TBase(count, val) { } - inline TVector(size_type count, const T& val, const typename TBase::allocator_type& a) + inline TVector(size_type count, const T& val, const typename TBase::allocator_type& a) : TBase(count, val, a) { } - inline TVector(std::initializer_list<T> il) + inline TVector(std::initializer_list<T> il) : TBase(il) { } - inline TVector(std::initializer_list<T> il, const typename TBase::allocator_type& a) + inline TVector(std::initializer_list<T> il, const typename TBase::allocator_type& a) : TBase(il, a) { } - inline TVector(const TSelf& src) + inline TVector(const TSelf& src) : TBase(src) { } - inline TVector(TSelf&& src) noexcept + inline TVector(TSelf&& src) noexcept : TBase(std::forward<TSelf>(src)) { } template <class TIter> - inline TVector(TIter first, TIter last) + inline TVector(TIter first, TIter last) : TBase(first, last) { } diff --git a/util/generic/vector.pxd b/util/generic/vector.pxd index 99dde95d48..459da7eb40 100644 --- a/util/generic/vector.pxd +++ b/util/generic/vector.pxd @@ -1,5 +1,5 @@ cdef extern from "<util/generic/vector.h>" nogil: - cdef cppclass TVector[T]: + cdef cppclass TVector[T]: cppclass iterator: T& operator*() iterator operator++() @@ -32,17 +32,17 @@ cdef extern from "<util/generic/vector.h>" nogil: cppclass const_reverse_iterator(reverse_iterator): pass - TVector() except + - TVector(TVector&) except + - TVector(size_t) except + - TVector(size_t, T&) except + + TVector() except + + TVector(TVector&) except + + TVector(size_t) except + + TVector(size_t, T&) except + - bint operator==(TVector&) - bint operator!=(TVector&) - bint operator<(TVector&) - bint operator>(TVector&) - bint operator<=(TVector&) - bint operator>=(TVector&) + bint operator==(TVector&) + bint operator!=(TVector&) + bint operator<(TVector&) + bint operator>(TVector&) + bint operator<=(TVector&) + bint operator>=(TVector&) void assign(size_t, const T&) except + void assign[input_iterator](input_iterator, input_iterator) except + @@ -76,7 +76,7 @@ cdef extern from "<util/generic/vector.h>" nogil: void resize(size_t) except + void resize(size_t, T&) except + size_t size() - void swap(TVector&) except + + void swap(TVector&) except + # C++11 methods T* data() diff --git a/util/generic/vector_ut.cpp b/util/generic/vector_ut.cpp index 0f6b4037a0..59ed6f3b95 100644 --- a/util/generic/vector_ut.cpp +++ b/util/generic/vector_ut.cpp @@ -34,7 +34,7 @@ class TYVectorTest: public TTestBase { private: void TestConstructorsAndAssignments() { - using container = TVector<int>; + using container = TVector<int>; container c1; c1.push_back(100); @@ -69,12 +69,12 @@ private: } inline void TestTildeEmptyToNull() { - TVector<int> v; + TVector<int> v; UNIT_ASSERT_EQUAL(nullptr, v.data()); } inline void TestTilde() { - TVector<int> v; + TVector<int> v; v.push_back(10); v.push_back(20); @@ -94,7 +94,7 @@ private: // Copy-paste of STLPort tests void Test1() { - TVector<int> v1; // Empty vector of integers. + TVector<int> v1; // Empty vector of integers. UNIT_ASSERT(v1.empty() == true); UNIT_ASSERT(v1.size() == 0); @@ -110,8 +110,8 @@ private: UNIT_ASSERT(v1[0] == 42); { - TVector<TVector<int>> vect(10); - TVector<TVector<int>>::iterator it(vect.begin()), end(vect.end()); + TVector<TVector<int>> vect(10); + TVector<TVector<int>>::iterator it(vect.begin()), end(vect.end()); for (; it != end; ++it) { UNIT_ASSERT((*it).empty()); UNIT_ASSERT((*it).size() == 0); @@ -122,10 +122,10 @@ private: } void Test2() { - TVector<double> v1; // Empty vector of doubles. + TVector<double> v1; // Empty vector of doubles. v1.push_back(32.1); v1.push_back(40.5); - TVector<double> v2; // Another empty vector of doubles. + TVector<double> v2; // Another empty vector of doubles. v2.push_back(3.56); UNIT_ASSERT(v1.size() == 2); @@ -150,7 +150,7 @@ private: } void Test3() { - using vec_type = TVector<char>; + using vec_type = TVector<char>; vec_type v1; // Empty vector of characters. v1.push_back('h'); @@ -173,7 +173,7 @@ private: } void Test4() { - TVector<int> v(4); + TVector<int> v(4); v[0] = 1; v[1] = 4; @@ -197,7 +197,7 @@ private: void Test5() { int array[] = {1, 4, 9, 16}; - TVector<int> v(array, array + 4); + TVector<int> v(array, array + 4); UNIT_ASSERT(v.size() == 4); @@ -210,8 +210,8 @@ private: void Test6() { int array[] = {1, 4, 9, 16, 25, 36}; - TVector<int> v(array, array + 6); - TVector<int>::iterator vit; + TVector<int> v(array, array + 6); + TVector<int>::iterator vit; UNIT_ASSERT(v.size() == 6); UNIT_ASSERT(v[0] == 1); @@ -251,8 +251,8 @@ private: int array1[] = {1, 4, 25}; int array2[] = {9, 16}; - TVector<int> v(array1, array1 + 3); - TVector<int>::iterator vit; + TVector<int> v(array1, array1 + 3); + TVector<int>::iterator vit; vit = v.insert(v.begin(), 0); // Insert before first element. UNIT_ASSERT(*vit == 0); @@ -301,7 +301,7 @@ private: void TestCapacity() { { - TVector<int> v; + TVector<int> v; UNIT_ASSERT(v.capacity() == 0); v.push_back(42); @@ -311,7 +311,7 @@ private: } { - TVector<int> v(Reserve(100)); + TVector<int> v(Reserve(100)); UNIT_ASSERT(v.capacity() >= 100); UNIT_ASSERT(v.size() == 0); @@ -319,15 +319,15 @@ private: { //Test that used to generate an assertion when using __debug_alloc. - TVector<TestStruct> va; + TVector<TestStruct> va; va.reserve(1); va.reserve(2); } } void TestAt() { - TVector<int> v; - TVector<int> const& cv = v; + TVector<int> v; + TVector<int> const& cv = v; v.push_back(10); UNIT_ASSERT(v.at(0) == 10); @@ -347,27 +347,27 @@ private: } void TestPointer() { - TVector<int*> v1; - TVector<int*> v2 = v1; - TVector<int*> v3; + TVector<int*> v1; + TVector<int*> v2 = v1; + TVector<int*> v3; v3.insert(v3.end(), v1.begin(), v1.end()); } void TestAutoRef() { - TVector<int> ref; + TVector<int> ref; for (int i = 0; i < 5; ++i) { ref.push_back(i); } - TVector<TVector<int>> v_v_int(1, ref); + TVector<TVector<int>> v_v_int(1, ref); v_v_int.push_back(v_v_int[0]); v_v_int.push_back(ref); v_v_int.push_back(v_v_int[0]); v_v_int.push_back(v_v_int[0]); v_v_int.push_back(ref); - TVector<TVector<int>>::iterator vvit(v_v_int.begin()), vvitEnd(v_v_int.end()); + TVector<TVector<int>>::iterator vvit(v_v_int.begin()), vvitEnd(v_v_int.end()); for (; vvit != vvitEnd; ++vvit) { UNIT_ASSERT(*vvit == ref); } @@ -391,8 +391,8 @@ private: }; void TestIterators() { - TVector<int> vint(10, 0); - TVector<int> const& crvint = vint; + TVector<int> vint(10, 0); + TVector<int> const& crvint = vint; UNIT_ASSERT(vint.begin() == vint.begin()); UNIT_ASSERT(crvint.begin() == vint.begin()); @@ -418,7 +418,7 @@ private: } void TestShrink() { - TVector<int> v; + TVector<int> v; v.resize(1000); v.resize(10); v.shrink_to_fit(); @@ -436,7 +436,7 @@ private: // representation making executable crash on vector destructor invocation. // We prefer a simple memory leak, internal corruption should be reveal // by size or capacity checks. - using V = TVector<int>; + using V = TVector<int>; V* pv1 = new V(1, 1); V* pv2 = new V(10, 2); @@ -459,7 +459,7 @@ private: void TestFillInConstructor() { for (int k = 0; k < 3; ++k) { - TVector<int> v(100); + TVector<int> v(100); UNIT_ASSERT_VALUES_EQUAL(100u, v.size()); for (size_t i = 0; i < v.size(); ++i) { UNIT_ASSERT_VALUES_EQUAL(0, v[i]); @@ -517,7 +517,7 @@ private: constexpr bool ALLOW_UNINITIALIZED = false; #endif - TVector<T, TDebugAlloc<T>> v; + TVector<T, TDebugAlloc<T>> v; v.reserve(5); auto firstBegin = v.begin(); @@ -564,7 +564,7 @@ private: TestYResize<TNonPod>(); } - void CheckInitializeList(const TVector<int>& v) { + void CheckInitializeList(const TVector<int>& v) { for (size_t i = 0; i < v.size(); ++i) { UNIT_ASSERT_EQUAL(v[i], static_cast<int>(i)); } @@ -572,21 +572,21 @@ private: void TestInitializeList() { { - TVector<int> v; + TVector<int> v; v.assign({0, 1, 2}); CheckInitializeList(v); } { - TVector<int> v = {0, 1, 2}; + TVector<int> v = {0, 1, 2}; CheckInitializeList(v); } { - TVector<int> v; + TVector<int> v; v = {0, 1, 2}; CheckInitializeList(v); } { - TVector<int> v = {0, 3}; + TVector<int> v = {0, 3}; v.insert(v.begin() + 1, {1, 2}); CheckInitializeList(v); } diff --git a/util/generic/vector_ut.pyx b/util/generic/vector_ut.pyx index 904e67733b..631b73fa63 100644 --- a/util/generic/vector_ut.pyx +++ b/util/generic/vector_ut.pyx @@ -1,44 +1,44 @@ # cython: c_string_type=str, c_string_encoding=utf8 -from util.generic.vector cimport TVector +from util.generic.vector cimport TVector from util.generic.string cimport TString import pytest import unittest -def _check_convert(TVector[TString] x): +def _check_convert(TVector[TString] x): return x class TestVector(unittest.TestCase): def test_ctor1(self): - cdef TVector[int] tmp = TVector[int]() + cdef TVector[int] tmp = TVector[int]() self.assertEqual(tmp.size(), 0) def test_ctor2(self): - cdef TVector[int] tmp = TVector[int](10) + cdef TVector[int] tmp = TVector[int](10) self.assertEqual(tmp.size(), 10) self.assertEqual(tmp[0], 0) def test_ctor3(self): - cdef TVector[int] tmp = TVector[int](10, 42) + cdef TVector[int] tmp = TVector[int](10, 42) self.assertEqual(tmp.size(), 10) self.assertEqual(tmp[0], 42) def test_ctor4(self): - cdef TVector[int] tmp = TVector[int](10, 42) - cdef TVector[int] tmp2 = TVector[int](tmp) + cdef TVector[int] tmp = TVector[int](10, 42) + cdef TVector[int] tmp2 = TVector[int](tmp) self.assertEqual(tmp2.size(), 10) self.assertEqual(tmp2[0], 42) def test_operator_assign(self): - cdef TVector[int] tmp2 + cdef TVector[int] tmp2 tmp2.push_back(1) tmp2.push_back(2) - cdef TVector[int] tmp3 + cdef TVector[int] tmp3 tmp3.push_back(1) tmp3.push_back(3) @@ -51,15 +51,15 @@ class TestVector(unittest.TestCase): self.assertEqual(tmp3[1], 2) def test_compare(self): - cdef TVector[int] tmp1 + cdef TVector[int] tmp1 tmp1.push_back(1) tmp1.push_back(2) - cdef TVector[int] tmp2 + cdef TVector[int] tmp2 tmp2.push_back(1) tmp2.push_back(2) - cdef TVector[int] tmp3 + cdef TVector[int] tmp3 tmp3.push_back(1) tmp3.push_back(3) @@ -73,7 +73,7 @@ class TestVector(unittest.TestCase): self.assertTrue(tmp3 >= tmp1) def test_index(self): - cdef TVector[int] tmp = TVector[int](10, 42) + cdef TVector[int] tmp = TVector[int](10, 42) self.assertEqual(tmp[0], 42) self.assertEqual(tmp[5], 42) @@ -88,7 +88,7 @@ class TestVector(unittest.TestCase): tmp.at(100) def test_push_pop_back(self): - cdef TVector[int] tmp + cdef TVector[int] tmp self.assertEqual(tmp.size(), 0) tmp.push_back(42) @@ -107,22 +107,22 @@ class TestVector(unittest.TestCase): self.assertEqual(tmp.size(), 0) def test_front(self): - cdef TVector[int] tmp + cdef TVector[int] tmp tmp.push_back(42) self.assertEqual(tmp.front(), 42) def test_empty(self): - cdef TVector[int] tmp + cdef TVector[int] tmp self.assertTrue(tmp.empty()) tmp.push_back(42) self.assertFalse(tmp.empty()) def test_max_size(self): - cdef TVector[int] tmp + cdef TVector[int] tmp self.assertTrue(tmp.max_size() > 0) def test_reserve_resize(self): - cdef TVector[int] tmp + cdef TVector[int] tmp tmp.reserve(1000) self.assertEqual(tmp.capacity(), 1000) @@ -140,7 +140,7 @@ class TestVector(unittest.TestCase): self.assertEqual(tmp.back(), 42) def test_iter(self): - cdef TVector[int] tmp + cdef TVector[int] tmp tmp.push_back(1) tmp.push_back(20) tmp.push_back(300) @@ -148,7 +148,7 @@ class TestVector(unittest.TestCase): self.assertEqual([i for i in tmp], [1, 20, 300]) def test_iterator(self): - cdef TVector[int] tmp + cdef TVector[int] tmp self.assertTrue(tmp.begin() == tmp.end()) self.assertTrue(tmp.rbegin() == tmp.rend()) @@ -173,7 +173,7 @@ class TestVector(unittest.TestCase): self.assertTrue(tmp.const_rbegin() + 1 == tmp.const_rend()) def test_assign(self): - cdef TVector[int] tmp + cdef TVector[int] tmp tmp.assign(10, 42) self.assertEqual(tmp.size(), 10) @@ -181,12 +181,12 @@ class TestVector(unittest.TestCase): self.assertEqual(tmp.back(), 42) def test_insert(self): - cdef TVector[int] tmp + cdef TVector[int] tmp tmp.push_back(1) tmp.push_back(2) tmp.push_back(3) - cdef TVector[int] tmp2 + cdef TVector[int] tmp2 tmp2.push_back(7) tmp2.push_back(9) @@ -200,7 +200,7 @@ class TestVector(unittest.TestCase): self.assertEqual([i for i in tmp], [7, 9, 6, 6, 8, 1, 2, 3]) def test_erase(self): - cdef TVector[int] tmp + cdef TVector[int] tmp tmp.push_back(1) tmp.push_back(2) tmp.push_back(3) diff --git a/util/generic/xrange.h b/util/generic/xrange.h index 5fc8c82912..89c773002e 100644 --- a/util/generic/xrange.h +++ b/util/generic/xrange.h @@ -14,7 +14,7 @@ * DoSomething(i, MyVector[i]); * } * - * TVector<int> arithmeticSeq = xrange(10); // instead: TVector<int> arithmeticSeq; for(size_t i = 0; i < 10; ++i) { arithmeticSeq.push_back(i); } + * TVector<int> arithmeticSeq = xrange(10); // instead: TVector<int> arithmeticSeq; for(size_t i = 0; i < 10; ++i) { arithmeticSeq.push_back(i); } * */ diff --git a/util/generic/xrange_ut.cpp b/util/generic/xrange_ut.cpp index 8106da03e7..66c8b1d83a 100644 --- a/util/generic/xrange_ut.cpp +++ b/util/generic/xrange_ut.cpp @@ -30,7 +30,7 @@ Y_UNIT_TEST_SUITE(XRange) { UNIT_ASSERT_VALUES_EQUAL(sum, count * (first + last) / 2); } - void TestSteppedXRangeImpl(int begin, int end, int step, const TVector<int>& expected) { + void TestSteppedXRangeImpl(int begin, int end, int step, const TVector<int>& expected) { size_t expInd = 0; for (auto i : xrange(begin, end, step)) { UNIT_ASSERT(expInd < expected.size()); @@ -65,7 +65,7 @@ Y_UNIT_TEST_SUITE(XRange) { } Y_UNIT_TEST(PointersWorks) { - TVector<size_t> data = {3, 1, 4, 1, 5, 9, 2, 6}; + TVector<size_t> data = {3, 1, 4, 1, 5, 9, 2, 6}; const size_t digSumExpected = Accumulate(data.begin(), data.end(), static_cast<size_t>(0)); size_t digSumByIt = 0; for (auto ptr : xrange(data.begin(), data.end())) { @@ -85,19 +85,19 @@ Y_UNIT_TEST_SUITE(XRange) { UNIT_ASSERT_VALUES_EQUAL(xrange(0, 6, 2).size(), 3); } - class TVectorChild: public TVector<size_t> { + class TVectorChild: public TVector<size_t> { public: template <typename TIterator> TVectorChild(TIterator a, TIterator b) - : TVector<size_t>(a, b) + : TVector<size_t>(a, b) { } }; Y_UNIT_TEST(ConvertionWorks) { - TVector<size_t> data = {0, 1, 2, 3, 4, 5, 6, 7, 8}; + TVector<size_t> data = {0, 1, 2, 3, 4, 5, 6, 7, 8}; - TVector<size_t> convertionResults[] = {xrange<size_t>(9), + TVector<size_t> convertionResults[] = {xrange<size_t>(9), xrange<ui32>(0, 9), xrange(0, 9, 1)}; @@ -124,7 +124,7 @@ Y_UNIT_TEST_SUITE(XRange) { } using TValueType = decltype(*emptyRange.begin()); - const TVector<TValueType> asVector = emptyRange; + const TVector<TValueType> asVector = emptyRange; UNIT_ASSERT(asVector.empty()); } } diff --git a/util/generic/yexception.cpp b/util/generic/yexception.cpp index 2ce6c4369d..5508a63ec6 100644 --- a/util/generic/yexception.cpp +++ b/util/generic/yexception.cpp @@ -14,31 +14,31 @@ TString FormatExc(const std::exception& exception) { return TString::Join(TStringBuf("("), TypeName(exception), TStringBuf(") "), exception.what()); } -TString CurrentExceptionMessage() { - auto exceptionPtr = std::current_exception(); - if (exceptionPtr) { - try { - std::rethrow_exception(exceptionPtr); - } catch (const yexception& e) { - const TBackTrace* bt = e.BackTrace(); - - if (bt) { +TString CurrentExceptionMessage() { + auto exceptionPtr = std::current_exception(); + if (exceptionPtr) { + try { + std::rethrow_exception(exceptionPtr); + } catch (const yexception& e) { + const TBackTrace* bt = e.BackTrace(); + + if (bt) { return TString::Join(bt->PrintToString(), TStringBuf("\n"), FormatExc(e)); - } - - return FormatExc(e); - } catch (const std::exception& e) { - return FormatExc(e); - } catch (...) { + } + + return FormatExc(e); + } catch (const std::exception& e) { + return FormatExc(e); + } catch (...) { } - return "unknown error"; + return "unknown error"; } - return "(NO EXCEPTION)"; + return "(NO EXCEPTION)"; } -bool UncaughtException() noexcept { +bool UncaughtException() noexcept { // FIXME: use std::uncaught_exceptions() unconditionally after DEVTOOLS-8811 #if defined(__cpp_lib_uncaught_exceptions) && !defined(_LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS) return std::uncaught_exceptions() > 0; @@ -97,11 +97,11 @@ void NPrivateException::yexception::ZeroTerminate() noexcept { *end = 0; } -const char* NPrivateException::yexception::what() const noexcept { +const char* NPrivateException::yexception::what() const noexcept { return Buf_.Data(); } -const TBackTrace* NPrivateException::yexception::BackTrace() const noexcept { +const TBackTrace* NPrivateException::yexception::BackTrace() const noexcept { return nullptr; } diff --git a/util/generic/yexception.h b/util/generic/yexception.h index b0c604e8c4..10fa8c7c70 100644 --- a/util/generic/yexception.h +++ b/util/generic/yexception.h @@ -2,7 +2,7 @@ #include "bt_exception.h" #include "strbuf.h" -#include "string.h" +#include "string.h" #include "utility.h" #include "va_args.h" #include <utility> @@ -46,8 +46,8 @@ namespace NPrivateException { yexception& operator=(const yexception&) = default; yexception& operator=(yexception&&) = default; - const char* what() const noexcept override; - virtual const TBackTrace* BackTrace() const noexcept; + const char* what() const noexcept override; + virtual const TBackTrace* BackTrace() const noexcept; template <class T> inline void Append(const T& t) { @@ -154,7 +154,7 @@ namespace NPrivate { void fputs(const std::exception& e, FILE* f = stderr); -TString CurrentExceptionMessage(); +TString CurrentExceptionMessage(); /* * A neat method that detects wrether stack unwinding is in progress. @@ -169,7 +169,7 @@ TString CurrentExceptionMessage(); * * DO NOT USE THIS METHOD IN DESTRUCTORS. */ -bool UncaughtException() noexcept; +bool UncaughtException() noexcept; std::string CurrentExceptionTypeName(); diff --git a/util/generic/yexception_ut.cpp b/util/generic/yexception_ut.cpp index cb3e29fed8..cbdab1740c 100644 --- a/util/generic/yexception_ut.cpp +++ b/util/generic/yexception_ut.cpp @@ -39,7 +39,7 @@ class TExceptionTest: public TTestBase { UNIT_TEST_SUITE(TExceptionTest); UNIT_TEST_EXCEPTION(TestException, yexception) UNIT_TEST_EXCEPTION(TestLineInfo, yexception) - UNIT_TEST(TestCurrentExceptionMessageWhenThereisNoException) + UNIT_TEST(TestCurrentExceptionMessageWhenThereisNoException) UNIT_TEST(TestFormat1) UNIT_TEST(TestRaise1) UNIT_TEST(TestVirtuality) @@ -70,15 +70,15 @@ private: } } - inline void TestCurrentExceptionMessageWhenThereisNoException() { - UNIT_ASSERT(CurrentExceptionMessage() == "(NO EXCEPTION)"); - } - + inline void TestCurrentExceptionMessageWhenThereisNoException() { + UNIT_ASSERT(CurrentExceptionMessage() == "(NO EXCEPTION)"); + } + inline void TestBackTrace() { try { ythrow TWithBackTrace<TIoSystemError>() << "test"; } catch (...) { - UNIT_ASSERT(CurrentExceptionMessage().find('\n') != TString::npos); + UNIT_ASSERT(CurrentExceptionMessage().find('\n') != TString::npos); return; } @@ -212,14 +212,14 @@ private: throw yexception() << 1 << " qw " << 12.1; UNIT_ASSERT(false); } catch (...) { - const TString err = CurrentExceptionMessage(); + const TString err = CurrentExceptionMessage(); UNIT_ASSERT(err.Contains("1 qw 12.1")); } } static inline void CheckCurrentExceptionContains(const char* message) { - TString err = CurrentExceptionMessage(); + TString err = CurrentExceptionMessage(); SubstGlobal(err, '\\', '/'); // remove backslashes from path in message UNIT_ASSERT(err.Contains(message)); } diff --git a/util/generic/ylimits.h b/util/generic/ylimits.h index fe42b4dfc0..61a311e43e 100644 --- a/util/generic/ylimits.h +++ b/util/generic/ylimits.h @@ -7,12 +7,12 @@ #endif template <class T> -static constexpr T Max() noexcept { +static constexpr T Max() noexcept { return std::numeric_limits<T>::max(); } template <class T> -static constexpr T Min() noexcept { +static constexpr T Min() noexcept { return std::numeric_limits<T>::min(); } @@ -32,11 +32,11 @@ namespace NPrivate { }; } -static constexpr ::NPrivate::TMax Max() noexcept { +static constexpr ::NPrivate::TMax Max() noexcept { return {}; } -static constexpr ::NPrivate::TMin Min() noexcept { +static constexpr ::NPrivate::TMin Min() noexcept { return {}; } diff --git a/util/generic/ymath_ut.cpp b/util/generic/ymath_ut.cpp index 29190b55eb..3e3009540c 100644 --- a/util/generic/ymath_ut.cpp +++ b/util/generic/ymath_ut.cpp @@ -9,7 +9,7 @@ #include <limits> template <class T> -static inline T SlowClp2(T t) noexcept { +static inline T SlowClp2(T t) noexcept { Y_ASSERT(t > 0); T ret = 1; |