Skip to content

Instantly share code, notes, and snippets.

@MiSawa
Created August 30, 2013 12:05
Show Gist options
  • Save MiSawa/6389184 to your computer and use it in GitHub Desktop.
Save MiSawa/6389184 to your computer and use it in GitHub Desktop.
#include <iostream>
#define let(v, x) __typeof(x) v = (x)
#define foreach(i,v) for(let(i, (v).begin());i!=(v).end();++i)
using namespace std;
template<typename T> struct wrap_itr //{{{
: public iterator<bidirectional_iterator_tag, T>{
typedef wrap_itr<T> It;
T t;
wrap_itr(T t): t(t){}
It& operator++(){++t; return *this;}
It& operator--(){--t; return *this;}
T operator*(){return t;}
friend bool operator!=(const It &x, const It &y){
return x.t != y.t;
}
operator T(){return t;}
It& operator()() {return *this;}
}; //}}}
struct range { //{{{
typedef wrap_itr<int> iterator;
typedef iterator It;
It begin, end;
range(int b, int e=0) : begin(min(b,e)), end(max(b,e)){}
bool include(int x){return begin <= x && x < end;}
}; //}}}
int main(void){
foreach(i, range(10)) cout << i << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment