OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.dg/] [cpp0x/] [range-for11.C] - Blame information for rev 693

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 693 jeremybenn
// Test for range-based for loop
2
// Test the loop with a custom iterator
3
// with begin/end as member functions
4
 
5
// { dg-do compile }
6
// { dg-options "-std=c++0x" }
7
 
8
struct iterator
9
{
10
    int x;
11
    explicit 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; }
15
};
16
 
17
namespace foo
18
{
19
    struct container
20
    {
21
        int min, max;
22
        container(int a, int b) :min(a), max(b) {}
23
 
24
        iterator begin()
25
        {
26
            return iterator(min);
27
        }
28
        iterator end()
29
        {
30
            return iterator(max + 1);
31
        }
32
    };
33
}
34
 
35
int main()
36
{
37
    foo::container c(1,4);
38
    for (int it : c)
39
        ;
40
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.