MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/TriangleMeshDistance / FilterGenerator

Class FilterGenerator

tests/catch.hpp:3682–3713  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3680
3681 template <typename T, typename Predicate>
3682 class FilterGenerator : public IGenerator<T> {
3683 GeneratorWrapper<T> m_generator;
3684 Predicate m_predicate;
3685 public:
3686 template <typename P = Predicate>
3687 FilterGenerator(P&& pred, GeneratorWrapper<T>&& generator):
3688 m_generator(std::move(generator)),
3689 m_predicate(std::forward<P>(pred))
3690 {
3691 if (!m_predicate(m_generator.get())) {
3692 // It might happen that there are no values that pass the
3693 // filter. In that case we throw an exception.
3694 auto has_initial_value = next();
3695 if (!has_initial_value) {
3696 Catch::throw_exception(GeneratorException("No valid value found in filtered generator"));
3697 }
3698 }
3699 }
3700
3701 T const& get() const override {
3702 return m_generator.get();
3703 }
3704
3705 bool next() override {
3706 bool success = m_generator.next();
3707 if (!success) {
3708 return false;
3709 }
3710 while (!m_predicate(m_generator.get()) && (success = m_generator.next()) == true);
3711 return success;
3712 }
3713 };
3714
3715 template <typename T, typename Predicate>
3716 GeneratorWrapper<T> filter(Predicate&& pred, GeneratorWrapper<T>&& generator) {

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected