Created
August 30, 2013 12:05
-
-
Save MiSawa/6389184 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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