diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2016-09-09 11:08:48 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2016-09-26 11:50:09 +0300 |
commit | b8197602fa4068cbaff8913e61afb2d2110c6f49 (patch) | |
tree | a77fc1810e6165eb421cfae1450c0e5fcf92f074 /base | |
parent | 9f96e176172930d569518e64e297bb26d9c50474 (diff) |
Refactoring SortUnique and EraseIf. Now they can work with deque as well.
Diffstat (limited to 'base')
-rw-r--r-- | base/internal/message.hpp | 6 | ||||
-rw-r--r-- | base/stl_helpers.hpp | 30 |
2 files changed, 22 insertions, 14 deletions
diff --git a/base/internal/message.hpp b/base/internal/message.hpp index ee6487b9cd..f9775a9a15 100644 --- a/base/internal/message.hpp +++ b/base/internal/message.hpp @@ -1,5 +1,6 @@ #pragma once #include "std/array.hpp" +#include "std/deque.hpp" #include "std/functional.hpp" #include "std/initializer_list.hpp" #include "std/iterator.hpp" @@ -100,6 +101,11 @@ template <typename T> inline string DebugPrint(vector<T> const & v) return ::my::impl::DebugPrintSequence(v.begin(), v.end()); } +template <typename T> inline string DebugPrint(deque<T> const & d) +{ + return ::my::impl::DebugPrintSequence(d.begin(), d.end()); +} + template <typename T> inline string DebugPrint(list<T> const & v) { return ::my::impl::DebugPrintSequence(v.begin(), v.end()); diff --git a/base/stl_helpers.hpp b/base/stl_helpers.hpp index 0121e12613..99ff06305a 100644 --- a/base/stl_helpers.hpp +++ b/base/stl_helpers.hpp @@ -1,6 +1,7 @@ #pragma once #include "std/algorithm.hpp" +#include "std/auto_ptr.hpp" #include "std/functional.hpp" #include "std/utility.hpp" #include "std/vector.hpp" @@ -80,28 +81,29 @@ struct Equals<false, T, C> }; } // namespace impl -// Sorts and removes duplicate entries from |v|. -template <typename T> -void SortUnique(vector<T> & v) +// Sorts and removes duplicate entries from |c|. +template <typename T, template <typename, typename = allocator<T>> class Container> +void SortUnique(Container<T> & c) { - sort(v.begin(), v.end()); - v.erase(unique(v.begin(), v.end()), v.end()); + sort(c.begin(), c.end()); + c.erase(unique(c.begin(), c.end()), c.end()); } -// Sorts according to |comp| and removes duplicate entries according to |pred| from |v|. +// 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 |v| after a call of this function. -template <typename T, typename TLess, typename TEquals> -void SortUnique(vector<T> & v, TLess && less, TEquals && equals) +// 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) { - sort(v.begin(), v.end(), forward<TLess>(less)); - v.erase(unique(v.begin(), v.end(), forward<TEquals>(equals)), v.end()); + sort(c.begin(), c.end(), forward<TLess>(less)); + c.erase(unique(c.begin(), c.end(), forward<TEquals>(equals)), c.end()); } -template <typename T, class TFn> -void EraseIf(vector<T> & v, TFn && fn) +template <typename T, template <typename, typename = allocator<T>> class Container, class TFn> +void EraseIf(Container<T> & c, TFn && fn) { - v.erase(remove_if(v.begin(), v.end(), forward<TFn>(fn)), v.end()); + c.erase(remove_if(c.begin(), c.end(), forward<TFn>(fn)), c.end()); } // Creates a comparer being able to compare two instances of class C |