diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2016-09-26 11:03:47 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2016-09-26 11:50:15 +0300 |
commit | f86e56f898062087976580e2ebb28d8f18b429d6 (patch) | |
tree | dfd54dc136125b8479aefc6389538e66b74cb30b /base | |
parent | c109c425112abd9e17c93ec695505e363aea0da2 (diff) |
Review fixes.
Diffstat (limited to 'base')
-rw-r--r-- | base/base_tests/stl_helpers_test.cpp | 40 | ||||
-rw-r--r-- | base/stl_helpers.hpp | 4 |
2 files changed, 22 insertions, 22 deletions
diff --git a/base/base_tests/stl_helpers_test.cpp b/base/base_tests/stl_helpers_test.cpp index 39b823aa02..029df6af98 100644 --- a/base/base_tests/stl_helpers_test.cpp +++ b/base/base_tests/stl_helpers_test.cpp @@ -30,29 +30,29 @@ void TestSortUnique() TEST_EQUAL(actual, expected, ()); } { - using TValue = int; - using TPair = pair<TValue, int>; - Cont<TPair> d = + using Value = int; + using Pair = pair<Value, int>; + Cont<Pair> d = {{1, 22}, {2, 33}, {1, 23}, {4, 54}, {3, 34}, {5, 23}, {2, 23}, {7, 32}, {1, 12}}; - my::SortUnique(d, my::LessBy(&TPair::first), my::EqualsBy(&TPair::first)); + my::SortUnique(d, my::LessBy(&Pair::first), my::EqualsBy(&Pair::first)); - Cont<TValue> const expected = {1, 2, 3, 4, 5, 7}; + Cont<Value> const expected = {1, 2, 3, 4, 5, 7}; TEST_EQUAL(d.size(), expected.size(), ()); - for (int i = 0; i < d.size(); ++i) + for (size_t i = 0; i < d.size(); ++i) TEST_EQUAL(d[i].first, expected[i], (i)); } { - using TValue = double; - using TPair = pair<TValue, int>; - Cont<TPair> d = + using Value = double; + using Pair = pair<Value, int>; + Cont<Pair> d = {{0.5, 11}, {1000.99, 234}, {0.5, 23}, {1234.56789, 54}, {1000.99, 34}}; - my::SortUnique(d, my::LessBy(&TPair::first), my::EqualsBy(&TPair::first)); + my::SortUnique(d, my::LessBy(&Pair::first), my::EqualsBy(&Pair::first)); - Cont<TValue> const expected = {0.5, 1000.99, 1234.56789}; + Cont<Value> const expected = {0.5, 1000.99, 1234.56789}; TEST_EQUAL(d.size(), expected.size(), ()); - for (int i = 0; i < d.size(); ++i) + for (size_t i = 0; i < d.size(); ++i) TEST_EQUAL(d[i].first, expected[i], (i)); } } @@ -61,9 +61,9 @@ template <template <typename...> class Cont> void TestEqualsBy() { { - using TValue = pair<int, int>; - Cont<TValue> actual = {{1, 2}, {1, 3}, {2, 100}, {3, 7}, {3, 8}, {2, 500}}; - actual.erase(unique(actual.begin(), actual.end(), my::EqualsBy(&TValue::first)), actual.end()); + using Value = pair<int, int>; + Cont<Value> actual = {{1, 2}, {1, 3}, {2, 100}, {3, 7}, {3, 8}, {2, 500}}; + actual.erase(unique(actual.begin(), actual.end(), my::EqualsBy(&Value::first)), actual.end()); Cont<int> const expected = {{1, 2, 3, 2}}; TEST_EQUAL(expected.size(), actual.size(), ()); @@ -87,18 +87,18 @@ void TestEqualsBy() UNIT_TEST(LessBy) { { - using TValue = pair<int, int>; + using Value = pair<int, int>; - vector<TValue> v = {{2, 2}, {0, 4}, {3, 1}, {4, 0}, {1, 3}}; - sort(v.begin(), v.end(), my::LessBy(&TValue::first)); + vector<Value> v = {{2, 2}, {0, 4}, {3, 1}, {4, 0}, {1, 3}}; + sort(v.begin(), v.end(), my::LessBy(&Value::first)); for (size_t i = 0; i < v.size(); ++i) TEST_EQUAL(i, v[i].first, ()); - vector<TValue const *> pv; + vector<Value const *> pv; for (auto const & p : v) pv.push_back(&p); - sort(pv.begin(), pv.end(), my::LessBy(&TValue::second)); + sort(pv.begin(), pv.end(), my::LessBy(&Value::second)); for (size_t i = 0; i < pv.size(); ++i) TEST_EQUAL(i, pv[i]->second, ()); } diff --git a/base/stl_helpers.hpp b/base/stl_helpers.hpp index 79d5becf68..3a667766de 100644 --- a/base/stl_helpers.hpp +++ b/base/stl_helpers.hpp @@ -87,8 +87,8 @@ void SortUnique(Cont & c) c.erase(unique(c.begin(), c.end()), c.end()); } -// Sorts according to |comp| and removes duplicate entries according to |pred| from |c|. -// Note. If several entries are equal according to |pred| an arbitrary entry of them +// Sorts according to |less| and removes duplicate entries according to |equals| from |c|. +// Note. If several entries are equal according to |less| an arbitrary entry of them // is left in |c| after a call of this function. template <class Cont, typename Less, typename Equals> void SortUnique(Cont & c, Less && less, Equals && equals) |