title: C++ filtration using lazy iterator 2
body: <p>I have written this code to print out 17.5, 25.0</p>
  
  <pre><code>template&lt;typename Iterator, typename Callable&gt;
  struct FilteringIterator : Iterator {
      using OriginalIterator = Iterator; // required for accessing the used Iterator type from other locations
  
      Iterator m_end;
      Callable callable;
  
      FilteringIterator(Iterator m_begin, Iterator m_end, Callable callable) : Iterator{m_begin}, m_end{m_end}, callable{callable} { }
      Iterator&amp; get_orig_iter() { return ((Iterator&amp;)*this); }
      double operator*() {
          while (true) {
              if (get_orig_iter() != m_end) {
                  if(callable(*get_orig_iter()) == 1) {
                      return *get_orig_iter();
                  } else {
                      get_orig_iter()++;
                  }
              } else {
                  break;
              }
          }
          if(callable(*get_orig_iter()) == 1) {
              return *get_orig_iter();
          } 
          return *get_orig_iter();
      }
  };
  
  auto filter = [](auto action) {
      return [=](auto&amp; container) {
          using Container = std::decay_t&lt;decltype(container)&gt;;
          using Iterator = typename Container::iterator;
          using IteratorX = FilteringIterator&lt;Iterator, decltype(action)&gt;;
          return Range{IteratorX{container.begin(), container.end(), action}, IteratorX{container.end(), container.end(), action}};
      };
  };
  </code></pre>
  
  <p>I need a lazy iterator that will traverse over a range and filter it lazily. For example,</p>
  
  <pre><code>auto v = std::vector&lt;double&gt;{};
  auto odd_gen = views::odds();
  
  for(int i=0; i&lt;5; ++i)
      v.push_back(odd_gen() * 2.5);
  // v contains {2.5, 7.5, 12.5, 17.5, 22.5} here
  
  new_line();
  for(auto a : v | filter(greater_than(15))) // filter is applied lazily as the range is traversed
      std::cout &lt;&lt; a  &lt;&lt; std::endl;
  </code></pre>
  
  <p>// print { 17.5, 22.5} here</p>
  
  <pre><code>     new_line();
  for(auto a : v | filter(less_than(15))) // filter is applied lazily as the range is traversed
      std::cout &lt;&lt; a &lt;&lt; std::endl; 
  </code></pre>
  
  <p>//  prints 2.5, 7.5 and 12.5</p>
  
  <p>but now, I want it to print out <code>2.5, 7.5, 12.5</code> but i couldn't manage to do that. What can I do?</p>