diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2016-09-26 10:30:36 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2016-09-26 11:50:12 +0300 |
commit | c109c425112abd9e17c93ec695505e363aea0da2 (patch) | |
tree | bb433d6d2da0c94e5e2f4a33f58984fcdda70331 /base | |
parent | 500560a6c2734aaea1f9abc6fa093bb244ece347 (diff) |
Getting rid of std::allocator and using variadic templates intead.
Diffstat (limited to 'base')
-rw-r--r-- | base/base_tests/stl_helpers_test.cpp | 24 | ||||
-rw-r--r-- | base/stl_helpers.hpp | 6 |
2 files changed, 14 insertions, 16 deletions
diff --git a/base/base_tests/stl_helpers_test.cpp b/base/base_tests/stl_helpers_test.cpp index 335e7fc515..39b823aa02 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 Cont> +template <template <typename...> class Cont> void TestSortUnique() { { - Cont<int, allocator<int>> actual = {1, 2, 1, 4, 3, 5, 2, 7, 1}; + Cont<int> actual = {1, 2, 1, 4, 3, 5, 2, 7, 1}; my::SortUnique(actual); - Cont<int, allocator<int>> const expected = {1, 2, 3, 4, 5, 7}; + Cont<int> const expected = {1, 2, 3, 4, 5, 7}; TEST_EQUAL(actual, expected, ()); } { using TValue = int; using TPair = pair<TValue, int>; - Cont<TPair, allocator<TPair>> d = + Cont<TPair> 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)); - Cont<TValue, allocator<TValue>> const expected = {1, 2, 3, 4, 5, 7}; + Cont<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>; - Cont<TPair, allocator<TPair>> d = + Cont<TPair> 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)); - Cont<TValue, allocator<TValue>> const expected = {0.5, 1000.99, 1234.56789}; + Cont<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 Cont> +template <template <typename...> class Cont> void TestEqualsBy() { { using TValue = pair<int, int>; - Cont<TValue, allocator<TValue>> actual = {{1, 2}, {1, 3}, {2, 100}, {3, 7}, {3, 8}, {2, 500}}; + 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()); - Cont<int, allocator<int>> const expected = {{1, 2, 3, 2}}; + Cont<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, ()); } { - Cont<Int, allocator<Int>> actual; + Cont<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()); - Cont<int, allocator<int>> const expected = {{0, 1, 2, 0}}; + Cont<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(), ()); diff --git a/base/stl_helpers.hpp b/base/stl_helpers.hpp index 98d5b64c69..79d5becf68 100644 --- a/base/stl_helpers.hpp +++ b/base/stl_helpers.hpp @@ -1,12 +1,10 @@ #pragma once #include "std/algorithm.hpp" -#include "std/auto_ptr.hpp" #include "std/functional.hpp" #include "std/utility.hpp" #include "std/vector.hpp" - namespace my { namespace impl @@ -82,8 +80,8 @@ struct Equals<false, T, C> } // namespace impl // Sorts and removes duplicate entries from |c|. -template <typename T, template <typename, typename = allocator<T>> class Cont> -void SortUnique(Cont<T> & c) +template <typename Cont> +void SortUnique(Cont & c) { sort(c.begin(), c.end()); c.erase(unique(c.begin(), c.end()), c.end()); |