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

Class FilterGenerator

tutorials/external/catch.hpp:3734–3765  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3732
3733 template <typename T, typename Predicate>
3734 class FilterGenerator : public IGenerator<T> {
3735 GeneratorWrapper<T> m_generator;
3736 Predicate m_predicate;
3737 public:
3738 template <typename P = Predicate>
3739 FilterGenerator(P&& pred, GeneratorWrapper<T>&& generator):
3740 m_generator(std::move(generator)),
3741 m_predicate(std::forward<P>(pred))
3742 {
3743 if (!m_predicate(m_generator.get())) {
3744 // It might happen that there are no values that pass the
3745 // filter. In that case we throw an exception.
3746 auto has_initial_value = next();
3747 if (!has_initial_value) {
3748 Catch::throw_exception(GeneratorException("No valid value found in filtered generator"));
3749 }
3750 }
3751 }
3752
3753 T const& get() const override {
3754 return m_generator.get();
3755 }
3756
3757 bool next() override {
3758 bool success = m_generator.next();
3759 if (!success) {
3760 return false;
3761 }
3762 while (!m_predicate(m_generator.get()) && (success = m_generator.next()) == true);
3763 return success;
3764 }
3765 };
3766
3767 template <typename T, typename Predicate>
3768 GeneratorWrapper<T> filter(Predicate&& pred, GeneratorWrapper<T>&& generator) {

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected