From eb5d3e5df99de2c3d8da2e8bc7b12ed427465dba Mon Sep 17 00:00:00 2001 From: B Stack Date: Sun, 9 Sep 2018 18:53:23 -0400 Subject: pull in latest 10.4 from upstream --- zen/stl_tools.h | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'zen/stl_tools.h') diff --git a/zen/stl_tools.h b/zen/stl_tools.h index 7365392f..be9bf710 100755 --- a/zen/stl_tools.h +++ b/zen/stl_tools.h @@ -12,7 +12,7 @@ #include #include #include -#include "type_traits.h" +#include "string_traits.h" #include "build_info.h" @@ -42,8 +42,11 @@ void append(std::map& m, const C& c); template void removeDuplicates(std::vector& v); +template +void removeDuplicates(std::vector& v, CompLess less); + //binary search returning an iterator -template +template Iterator binary_search(Iterator first, Iterator last, const T& value, CompLess less); template @@ -70,6 +73,9 @@ struct StringHash }; +//why, oh wy is there no std::optional::get()??? +template inline T* get( std::optional& opt) { return opt ? &*opt : nullptr; } +template inline const T* get(const std::optional& opt) { return opt ? &*opt : nullptr; } @@ -117,15 +123,29 @@ template void append(std::map& m, const C& c) { m.insert(c.begin(), c.end()); } +template inline +void removeDuplicates(std::vector& v, CompLess less, CompEqual eq) +{ + std::sort(v.begin(), v.end(), less); + v.erase(std::unique(v.begin(), v.end(), eq), v.end()); +} + + +template inline +void removeDuplicates(std::vector& v, CompLess less) +{ + removeDuplicates(v, less, [&](const auto& lhs, const auto& rhs) { return !less(lhs, rhs) && !less(rhs, lhs); }); +} + + template inline void removeDuplicates(std::vector& v) { - std::sort(v.begin(), v.end()); - v.erase(std::unique(v.begin(), v.end()), v.end()); + removeDuplicates(v, std::less(), std::equal_to()); } -template inline +template inline Iterator binary_search(Iterator first, Iterator last, const T& value, CompLess less) { static_assert(std::is_same_v::iterator_category, std::random_access_iterator_tag>); -- cgit