Struct EqualsMatcher

Synopsis

#include <include/internal/catch_matchers_vector.h>

template<typename T, typename AllocComp, typename AllocMatch>
struct EqualsMatcher : MatcherBase<std::vector<T, AllocMatch>>

Description

No description yet.

Inheritance

Ancestors: MatcherBase

Methods

EqualsMatcher
describe
match

Source

Lines 71-92 in include/internal/catch_matchers_vector.h.

template<typename T, typename AllocComp, typename AllocMatch>
struct EqualsMatcher : MatcherBase<std::vector<T, AllocMatch>> {
    EqualsMatcher(std::vector<T, AllocComp> const &comparator) : m_comparator( comparator ) {}
    bool match(std::vector<T, AllocMatch> const &v) const override {
        // !TBD: This currently works if all elements can be compared using !=
        // - a more general approach would be via a compare template that defaults
        // to using !=. but could be specialised for, e.g. std::vector<T, Alloc> etc
        // - then just call that directly
        if (m_comparator.size() != v.size())
            return false;
        for (std::size_t i = 0; i < v.size(); ++i)
            if (m_comparator[i] != v[i])
                return false;
        return true;
    }
    std::string describe() const override {
        return "Equals: " + ::Catch::Detail::stringify( m_comparator );
    }
    std::vector<T, AllocComp> const& m_comparator;
};





Add Discussion as Guest

Log in