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

Subversion Repositories openrisc

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

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 std
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
struct container
18
{
19
    int min, max;
20
    container(int a, int b) :min(a), max(b) {}
21
};
22
 
23
namespace std
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
    container c(1,4);
39
    for (int it : c)
40
    {
41
    }
42
}

powered by: WebSVN 2.1.0

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