Implement range-based for-statements.
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / range-for2.C
blobbfab37673a141860d0ef42114e368cc239ab568d
1 // Test for range-based for loop
2 // Test the loop with a custom iterator
3 // with begin/end in an associated namespace
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 namespace foo
19     struct container
20     {
21         int min, max;
22         container(int a, int b) :min(a), max(b) {}
23     };
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     foo::container c(1,4);
39     for (iterator it : c)
40         ;