From 45e552528dec3145c86b8c5ef39e018517a8e481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Fri, 19 Apr 2019 17:54:21 +0200 Subject: [PATCH] Remove home-rolled algorithm replacements Previously we had them to avoid including in the vector matchers, but * we included it anyway, even though we did not use it * we use anyways in the generators --- include/internal/catch_matchers_vector.h | 45 +----------------------- 1 file changed, 1 insertion(+), 44 deletions(-) diff --git a/include/internal/catch_matchers_vector.h b/include/internal/catch_matchers_vector.h index 1e29cc94..347c5d50 100644 --- a/include/internal/catch_matchers_vector.h +++ b/include/internal/catch_matchers_vector.h @@ -16,28 +16,6 @@ namespace Catch { namespace Matchers { namespace Vector { - namespace Detail { - template - size_t count(InputIterator first, InputIterator last, T const& item) { - size_t cnt = 0; - for (; first != last; ++first) { - if (*first == item) { - ++cnt; - } - } - return cnt; - } - template - bool contains(InputIterator first, InputIterator last, T const& item) { - for (; first != last; ++first) { - if (*first == item) { - return true; - } - } - return false; - } - } - template struct ContainsElementMatcher : MatcherBase> { @@ -121,28 +99,7 @@ namespace Matchers { if (m_target.size() != vec.size()) { return false; } - auto lfirst = m_target.begin(), llast = m_target.end(); - auto rfirst = vec.begin(), rlast = vec.end(); - // Cut common prefix to optimize checking of permuted parts - while (lfirst != llast && *lfirst == *rfirst) { - ++lfirst; ++rfirst; - } - if (lfirst == llast) { - return true; - } - - for (auto mid = lfirst; mid != llast; ++mid) { - // Skip already counted items - if (Detail::contains(lfirst, mid, *mid)) { - continue; - } - size_t num_vec = Detail::count(rfirst, rlast, *mid); - if (num_vec == 0 || Detail::count(lfirst, llast, *mid) != num_vec) { - return false; - } - } - - return true; + return std::is_permutation(m_target.begin(), m_target.end(), vec.begin()); } std::string describe() const override {