fork download
  1. #include <iostream>
  2. struct range{
  3. struct iterator{
  4. int i;
  5. int operator*() const {return i;}
  6. iterator& operator++() {++i;return *this;}
  7. bool operator!=(iterator const& rhs) const{return i!=rhs.i;}
  8. };
  9. int b;
  10. int e;
  11. explicit range(int e):range(0,e){}
  12. range(int b,int e):b{b},e{e}{}
  13. iterator begin() const{return {b};}
  14. iterator end() const {return {e};}
  15. };
  16.  
  17. int main()
  18. {
  19. for(int i:range(10)) {
  20. std::cout<<i<<std::endl;
  21. }
  22. }
  23.  
  24.  
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
0
1
2
3
4
5
6
7
8
9