Remove home-rolled algorithm replacements

Previously we had them to avoid including <algorithm> in the vector
matchers, but
* we included it anyway, even though we did not use it
* we use <algorithm> anyways in the generators
This commit is contained in:
Martin Hořeňovský 2019-04-19 17:54:21 +02:00
parent 3978e9653b
commit 45e552528d
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A

View File

@ -16,28 +16,6 @@ namespace Catch {
namespace Matchers { namespace Matchers {
namespace Vector { namespace Vector {
namespace Detail {
template <typename InputIterator, typename T>
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 <typename InputIterator, typename T>
bool contains(InputIterator first, InputIterator last, T const& item) {
for (; first != last; ++first) {
if (*first == item) {
return true;
}
}
return false;
}
}
template<typename T> template<typename T>
struct ContainsElementMatcher : MatcherBase<std::vector<T>> { struct ContainsElementMatcher : MatcherBase<std::vector<T>> {
@ -121,28 +99,7 @@ namespace Matchers {
if (m_target.size() != vec.size()) { if (m_target.size() != vec.size()) {
return false; return false;
} }
auto lfirst = m_target.begin(), llast = m_target.end(); return std::is_permutation(m_target.begin(), m_target.end(), vec.begin());
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;
} }
std::string describe() const override { std::string describe() const override {