MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / FilterGenerator

Class FilterGenerator

extlibs/catch/include/catch/catch.hpp:4053–4084  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4051
4052 template <typename T, typename Predicate>
4053 class FilterGenerator : public IGenerator<T> {
4054 GeneratorWrapper<T> m_generator;
4055 Predicate m_predicate;
4056 public:
4057 template <typename P = Predicate>
4058 FilterGenerator(P&& pred, GeneratorWrapper<T>&& generator):
4059 m_generator(std::move(generator)),
4060 m_predicate(std::forward<P>(pred))
4061 {
4062 if (!m_predicate(m_generator.get())) {
4063 // It might happen that there are no values that pass the
4064 // filter. In that case we throw an exception.
4065 auto has_initial_value = next();
4066 if (!has_initial_value) {
4067 Catch::throw_exception(GeneratorException("No valid value found in filtered generator"));
4068 }
4069 }
4070 }
4071
4072 T const& get() const override {
4073 return m_generator.get();
4074 }
4075
4076 bool next() override {
4077 bool success = m_generator.next();
4078 if (!success) {
4079 return false;
4080 }
4081 while (!m_predicate(m_generator.get()) && (success = m_generator.next()) == true);
4082 return success;
4083 }
4084 };
4085
4086 template <typename T, typename Predicate>
4087 GeneratorWrapper<T> filter(Predicate&& pred, GeneratorWrapper<T>&& generator) {

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected