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:
authorYuri Gorshenin <y@maps.me>2016-05-27 11:29:21 +0300
committerYuri Gorshenin <y@maps.me>2016-05-27 11:29:21 +0300
commit03f67d43f74ffe7bc9c6565e3d3fb70e98318a32 (patch)
tree9a981df8e5a70f275546525a5df570f63ade5847 /base
parent60e74b995a0d8bd6a00c08c8d5483ea090c2d20e (diff)
Review fixes.
Diffstat (limited to 'base')
-rw-r--r--base/base_tests/stl_helpers_test.cpp34
-rw-r--r--base/stl_helpers.hpp32
2 files changed, 40 insertions, 26 deletions
diff --git a/base/base_tests/stl_helpers_test.cpp b/base/base_tests/stl_helpers_test.cpp
index f898d69e5b..dddb028508 100644
--- a/base/base_tests/stl_helpers_test.cpp
+++ b/base/base_tests/stl_helpers_test.cpp
@@ -21,9 +21,9 @@ private:
UNIT_TEST(LessBy)
{
- using TValue = pair<int, int>;
-
{
+ using TValue = 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));
for (size_t i = 0; i < v.size(); ++i)
@@ -51,13 +51,27 @@ UNIT_TEST(LessBy)
UNIT_TEST(EqualsBy)
{
- using TValue = pair<int, int>;
- vector<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());
-
- vector<int> 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, ());
+ {
+ using TValue = pair<int, int>;
+ vector<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());
+
+ vector<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, ());
+ }
+
+ {
+ vector<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());
+
+ vector<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(), ());
+ }
}
} // namespace
diff --git a/base/stl_helpers.hpp b/base/stl_helpers.hpp
index c01fbc5b99..832f53b829 100644
--- a/base/stl_helpers.hpp
+++ b/base/stl_helpers.hpp
@@ -16,31 +16,31 @@ struct Less;
template <typename T, typename C>
struct Less<true, T, C>
{
- Less(T(C::*p)) : p_(p) {}
+ Less(T(C::*p)) : m_p(p) {}
- inline bool operator()(C const & lhs, C const & rhs) const { return lhs.*p_ < rhs.*p_; }
+ inline bool operator()(C const & lhs, C const & rhs) const { return lhs.*m_p < rhs.*m_p; }
inline bool operator()(C const * const lhs, C const * const rhs) const
{
- return lhs->*p_ < rhs->*p_;
+ return lhs->*m_p < rhs->*m_p;
}
- T(C::*p_);
+ T(C::*m_p);
};
template <typename T, typename C>
struct Less<false, T, C>
{
- Less(T (C::*p)() const) : p_(p) {}
+ Less(T (C::*p)() const) : m_p(p) {}
- inline bool operator()(C const & lhs, C const & rhs) const { return (lhs.*p_)() < (rhs.*p_)(); }
+ inline bool operator()(C const & lhs, C const & rhs) const { return (lhs.*m_p)() < (rhs.*m_p)(); }
inline bool operator()(C const * const lhs, C const * const rhs) const
{
- return (lhs->*p_)() < (rhs->*p_)();
+ return (lhs->*m_p)() < (rhs->*m_p)();
}
- T (C::*p_)() const;
+ T (C::*m_p)() const;
};
template <bool isField, typename T, typename C>
@@ -49,31 +49,31 @@ struct Equals;
template <typename T, typename C>
struct Equals<true, T, C>
{
- Equals(T(C::*p)) : p_(p) {}
+ Equals(T(C::*p)) : m_p(p) {}
- inline bool operator()(C const & lhs, C const & rhs) const { return lhs.*p_ == rhs.*p_; }
+ inline bool operator()(C const & lhs, C const & rhs) const { return lhs.*m_p == rhs.*m_p; }
inline bool operator()(C const * const lhs, C const * const rhs) const
{
- return lhs->*p_ == rhs->*p_;
+ return lhs->*m_p == rhs->*m_p;
}
- T(C::*p_);
+ T(C::*m_p);
};
template <typename T, typename C>
struct Equals<false, T, C>
{
- Equals(T (C::*p)() const) : p_(p) {}
+ Equals(T (C::*p)() const) : m_p(p) {}
- inline bool operator()(C const & lhs, C const & rhs) const { return (lhs.*p_)() == (rhs.*p_)(); }
+ inline bool operator()(C const & lhs, C const & rhs) const { return (lhs.*m_p)() == (rhs.*m_p)(); }
inline bool operator()(C const * const lhs, C const * const rhs) const
{
- return (lhs->*p_)() == (rhs->*p_)();
+ return (lhs->*m_p)() == (rhs->*m_p)();
}
- T (C::*p_)() const;
+ T (C::*m_p)() const;
};
} // namespace impl