MCPcopy Create free account
hub / github.com/RenderKit/oidn / FilterGenerator

Class FilterGenerator

external/catch.hpp:4154–4185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4152
4153 template <typename T, typename Predicate>
4154 class FilterGenerator : public IGenerator<T> {
4155 GeneratorWrapper<T> m_generator;
4156 Predicate m_predicate;
4157 public:
4158 template <typename P = Predicate>
4159 FilterGenerator(P&& pred, GeneratorWrapper<T>&& generator):
4160 m_generator(std::move(generator)),
4161 m_predicate(std::forward<P>(pred))
4162 {
4163 if (!m_predicate(m_generator.get())) {
4164 // It might happen that there are no values that pass the
4165 // filter. In that case we throw an exception.
4166 auto has_initial_value = next();
4167 if (!has_initial_value) {
4168 Catch::throw_exception(GeneratorException("No valid value found in filtered generator"));
4169 }
4170 }
4171 }
4172
4173 T const& get() const override {
4174 return m_generator.get();
4175 }
4176
4177 bool next() override {
4178 bool success = m_generator.next();
4179 if (!success) {
4180 return false;
4181 }
4182 while (!m_predicate(m_generator.get()) && (success = m_generator.next()) == true);
4183 return success;
4184 }
4185 };
4186
4187 template <typename T, typename Predicate>
4188 GeneratorWrapper<T> filter(Predicate&& pred, GeneratorWrapper<T>&& generator) {

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected