Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2016-09-12 13:54:54 +0300
committerVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2016-09-26 11:50:11 +0300
commit500560a6c2734aaea1f9abc6fa093bb244ece347 (patch)
treef68d1785bc3dd675653f6db146ff2cb447d1e3ed /base
parentceeee1a8ec4254131c1130a1cf45e627671d96e4 (diff)
Review fixes.
Diffstat (limited to 'base')
-rw-r--r--base/base_tests/stl_helpers_test.cpp36
-rw-r--r--base/stl_helpers.hpp19
2 files changed, 23 insertions, 32 deletions
diff --git a/base/base_tests/stl_helpers_test.cpp b/base/base_tests/stl_helpers_test.cpp
index 23246beeff..335e7fc515 100644
--- a/base/base_tests/stl_helpers_test.cpp
+++ b/base/base_tests/stl_helpers_test.cpp
@@ -20,24 +20,24 @@ private:
int m_v;
};
-template<template<class, class> class TContainer>
+template<template<class, class> class Cont>
void TestSortUnique()
{
{
- TContainer<int, allocator<int>> actual = {1, 2, 1, 4, 3, 5, 2, 7, 1};
+ Cont<int, allocator<int>> actual = {1, 2, 1, 4, 3, 5, 2, 7, 1};
my::SortUnique(actual);
- TContainer<int, allocator<int>> const expected = {1, 2, 3, 4, 5, 7};
+ Cont<int, allocator<int>> const expected = {1, 2, 3, 4, 5, 7};
TEST_EQUAL(actual, expected, ());
}
{
using TValue = int;
using TPair = pair<TValue, int>;
- TContainer<TPair, allocator<TPair>> d =
+ Cont<TPair, allocator<TPair>> d =
{{1, 22}, {2, 33}, {1, 23}, {4, 54}, {3, 34}, {5, 23}, {2, 23}, {7, 32}, {1, 12}};
- my::SortUnique<TPair>(d, my::LessBy(&TPair::first), my::EqualsBy(&TPair::first));
+ my::SortUnique(d, my::LessBy(&TPair::first), my::EqualsBy(&TPair::first));
- TContainer<TValue, allocator<TValue>> const expected = {1, 2, 3, 4, 5, 7};
+ Cont<TValue, allocator<TValue>> const expected = {1, 2, 3, 4, 5, 7};
TEST_EQUAL(d.size(), expected.size(), ());
for (int i = 0; i < d.size(); ++i)
TEST_EQUAL(d[i].first, expected[i], (i));
@@ -45,39 +45,39 @@ void TestSortUnique()
{
using TValue = double;
using TPair = pair<TValue, int>;
- TContainer<TPair, allocator<TPair>> d =
+ Cont<TPair, allocator<TPair>> d =
{{0.5, 11}, {1000.99, 234}, {0.5, 23}, {1234.56789, 54}, {1000.99, 34}};
- my::SortUnique<TPair>(d, my::LessBy(&TPair::first), my::EqualsBy(&TPair::first));
+ my::SortUnique(d, my::LessBy(&TPair::first), my::EqualsBy(&TPair::first));
- TContainer<TValue, allocator<TValue>> const expected = {0.5, 1000.99, 1234.56789};
+ Cont<TValue, allocator<TValue>> const expected = {0.5, 1000.99, 1234.56789};
TEST_EQUAL(d.size(), expected.size(), ());
for (int i = 0; i < d.size(); ++i)
TEST_EQUAL(d[i].first, expected[i], (i));
}
}
-template<template<class, class> class TContainer>
+template<template<class, class> class Cont>
void TestEqualsBy()
{
{
using TValue = pair<int, int>;
- TContainer<TValue, allocator<TValue>> actual = {{1, 2}, {1, 3}, {2, 100}, {3, 7}, {3, 8}, {2, 500}};
+ Cont<TValue, allocator<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());
- TContainer<int, allocator<int>> const expected = {{1, 2, 3, 2}};
+ Cont<int, allocator<int>> const expected = {{1, 2, 3, 2}};
TEST_EQUAL(expected.size(), actual.size(), ());
for (size_t i = 0; i < actual.size(); ++i)
TEST_EQUAL(expected[i], actual[i].first, ());
}
{
- TContainer<Int, allocator<Int>> actual;
+ Cont<Int, allocator<Int>> actual;
for (auto const v : {0, 0, 1, 2, 2, 0})
actual.emplace_back(v);
actual.erase(unique(actual.begin(), actual.end(), my::EqualsBy(&Int::Get)), actual.end());
- TContainer<int, allocator<int>> const expected = {{0, 1, 2, 0}};
+ Cont<int, allocator<int>> const expected = {{0, 1, 2, 0}};
TEST_EQUAL(expected.size(), actual.size(), ());
for (size_t i = 0; i < actual.size(); ++i)
TEST_EQUAL(expected[i], actual[i].Get(), ());
@@ -117,20 +117,12 @@ UNIT_TEST(LessBy)
UNIT_TEST(EqualsBy_VectorTest)
{
TestEqualsBy<vector>();
-}
-
-UNIT_TEST(EqualsBy_DequeTest)
-{
TestEqualsBy<deque>();
}
UNIT_TEST(SortUnique_VectorTest)
{
TestSortUnique<vector>();
-}
-
-UNIT_TEST(SortUnique_DequeTest)
-{
TestSortUnique<deque>();
}
} // namespace
diff --git a/base/stl_helpers.hpp b/base/stl_helpers.hpp
index 99ff06305a..98d5b64c69 100644
--- a/base/stl_helpers.hpp
+++ b/base/stl_helpers.hpp
@@ -82,8 +82,8 @@ struct Equals<false, T, C>
} // namespace impl
// Sorts and removes duplicate entries from |c|.
-template <typename T, template <typename, typename = allocator<T>> class Container>
-void SortUnique(Container<T> & c)
+template <typename T, template <typename, typename = allocator<T>> class Cont>
+void SortUnique(Cont<T> & c)
{
sort(c.begin(), c.end());
c.erase(unique(c.begin(), c.end()), c.end());
@@ -92,18 +92,17 @@ void SortUnique(Container<T> & c)
// 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
// is left in |c| after a call of this function.
-template <typename T, template <typename, typename = allocator<T>> class Container,
- typename TLess, typename TEquals>
-void SortUnique(Container<T> & c, TLess && less, TEquals && equals)
+template <class Cont, typename Less, typename Equals>
+void SortUnique(Cont & c, Less && less, Equals && equals)
{
- sort(c.begin(), c.end(), forward<TLess>(less));
- c.erase(unique(c.begin(), c.end(), forward<TEquals>(equals)), c.end());
+ sort(c.begin(), c.end(), forward<Less>(less));
+ c.erase(unique(c.begin(), c.end(), forward<Equals>(equals)), c.end());
}
-template <typename T, template <typename, typename = allocator<T>> class Container, class TFn>
-void EraseIf(Container<T> & c, TFn && fn)
+template <class Cont, class Fn>
+void EraseIf(Cont & c, Fn && fn)
{
- c.erase(remove_if(c.begin(), c.end(), forward<TFn>(fn)), c.end());
+ c.erase(remove_if(c.begin(), c.end(), forward<Fn>(fn)), c.end());
}
// Creates a comparer being able to compare two instances of class C