Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
Catch::Matchers::Vector::UnorderedEqualsMatcher< T > Struct Template Reference

#include <catch.hpp>

Inheritance diagram for Catch::Matchers::Vector::UnorderedEqualsMatcher< T >:
Collaboration diagram for Catch::Matchers::Vector::UnorderedEqualsMatcher< T >:

Public Member Functions

 UnorderedEqualsMatcher (std::vector< T > const &target)
 
bool match (std::vector< T > const &vec) const override
 
std::string describe () const override
 

Private Attributes

std::vector< T > const & m_target
 

Detailed Description

template<typename T>
struct Catch::Matchers::Vector::UnorderedEqualsMatcher< T >

Definition at line 2842 of file catch.hpp.

Constructor & Destructor Documentation

template<typename T >
Catch::Matchers::Vector::UnorderedEqualsMatcher< T >::UnorderedEqualsMatcher ( std::vector< T > const &  target)
inline

Definition at line 2843 of file catch.hpp.

2843 : m_target(target) {}

Member Function Documentation

template<typename T >
std::string Catch::Matchers::Vector::UnorderedEqualsMatcher< T >::describe ( ) const
inlineoverride

Definition at line 2874 of file catch.hpp.

References Catch::Detail::stringify().

2874  {
2875  return "UnorderedEquals: " + ::Catch::Detail::stringify(m_target);
2876  }
std::string stringify(const T &e)
Definition: catch.hpp:955
template<typename T >
bool Catch::Matchers::Vector::UnorderedEqualsMatcher< T >::match ( std::vector< T > const &  vec) const
inlineoverride

Definition at line 2844 of file catch.hpp.

References Catch::Matchers::Vector::Detail::contains(), and Catch::Matchers::Vector::Detail::count().

2844  {
2845  // Note: This is a reimplementation of std::is_permutation,
2846  // because I don't want to include <algorithm> inside the common path
2847  if (m_target.size() != vec.size()) {
2848  return false;
2849  }
2850  auto lfirst = m_target.begin(), llast = m_target.end();
2851  auto rfirst = vec.begin(), rlast = vec.end();
2852  // Cut common prefix to optimize checking of permuted parts
2853  while (lfirst != llast && *lfirst == *rfirst) {
2854  ++lfirst; ++rfirst;
2855  }
2856  if (lfirst == llast) {
2857  return true;
2858  }
2859 
2860  for (auto mid = lfirst; mid != llast; ++mid) {
2861  // Skip already counted items
2862  if (Detail::contains(lfirst, mid, *mid)) {
2863  continue;
2864  }
2865  size_t num_vec = Detail::count(rfirst, rlast, *mid);
2866  if (num_vec == 0 || Detail::count(lfirst, llast, *mid) != num_vec) {
2867  return false;
2868  }
2869  }
2870 
2871  return true;
2872  }
size_t count(InputIterator first, InputIterator last, T const &item)
Definition: catch.hpp:2747
bool contains(InputIterator first, InputIterator last, T const &item)
Definition: catch.hpp:2757

Member Data Documentation

template<typename T >
std::vector<T> const& Catch::Matchers::Vector::UnorderedEqualsMatcher< T >::m_target
private

Definition at line 2878 of file catch.hpp.


The documentation for this struct was generated from the following file: