Implement range-based for-statements.
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / range-for3.C
blob947f01ced74d53690c4271f393a492875d96e695
1 // Test for range-based for loop
2 // Test the loop with a custom iterator
3 // with begin/end in std
5 // { dg-do compile }
6 // { dg-options "-std=c++0x" }
8 struct iterator
10     int x;
11     iterator(int v) :x(v) {}
12     iterator &operator ++() { ++x; return *this; }
13     int operator *() { return x; }
14     bool operator != (const iterator &o) { return x != o.x; }
17 struct container
19     int min, max;
20     container(int a, int b) :min(a), max(b) {}
23 namespace std
25     iterator begin(container &c)
26     {
27         return iterator(c.min);
28     }
30     iterator end(container &c)
31     {
32         return iterator(c.max + 1);
33     }
36 int main()
38     container c(1,4);
39     for (iterator it : c)
40     {
41     }