fork download
  1. #include <iostream>
  2. #include <iterator>
  3.  
  4. template<class B,class E> struct range_iter{
  5. B b; E e;
  6. range_iter(B b_,E e_):b(b_),e(e_){}
  7. B& begin(){return b;} E& end(){return e;}
  8. range_iter<B,E>& operator++(){++b; return *this;}
  9. typename std::iterator_traits<B>::reference operator*(){return *b;}
  10. bool has_next(){return b!=e;}
  11. };
  12. template<class B,class E> range_iter<B,E> to_ri(B b, E e){return range_iter<B,E>(b,e);}
  13.  
  14. int main(){
  15. int a[] = {0,10,20,30,40};
  16. for(auto it=to_ri(a+1, a+3); it.has_next(); ++it){std::cout<<*it<<std::endl;}
  17. //for(auto e : to_ri(a+1, a+3)){...}
  18. return 0;
  19. }
Success #stdin #stdout 0s 2884KB
stdin
Standard input is empty
stdout
10
20