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

Subversion Repositories openrisc

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

Go to most recent revision | 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 in an associated namespace
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
 
25
    iterator begin(container &c)
26
    {
27
        return iterator(c.min);
28
    }
29
 
30
    iterator end(container &c)
31
    {
32
        return iterator(c.max + 1);
33
    }
34
}
35
 
36
int main()
37
{
38
    foo::container c(1,4);
39
    for (int it : c)
40
        ;
41
}

powered by: WebSVN 2.1.0

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