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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.dg/] [cpp0x/] [range-for12.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 with templates
2
// and begin/end as member functions
3
 
4
// { dg-do run }
5
// { dg-options "-std=c++0x" }
6
 
7
/* Preliminary declarations */
8
namespace pre
9
{
10
  struct iterator
11
  {
12
    int x;
13
    explicit iterator (int v) :x(v) {}
14
    iterator &operator ++() { ++x; return *this; }
15
    int operator *() { return x; }
16
    bool operator != (const iterator &o) { return x != o.x; }
17
  };
18
 
19
  struct container
20
  {
21
    int min, max;
22
    container(int a, int b) :min(a), max(b) {}
23
    iterator begin() const
24
    {
25
        return iterator(min);
26
    }
27
    iterator end() const
28
    {
29
        return iterator(max);
30
    }
31
 
32
  };
33
 
34
} //namespace pre
35
 
36
using pre::container;
37
extern "C" void abort(void);
38
 
39
container run_me_just_once()
40
{
41
    static bool run = false;
42
    if (run)
43
        abort();
44
    run = true;
45
    return container(1,2);
46
}
47
 
48
/* Template with dependent expression. */
49
template int test1(const T &r)
50
{
51
  int t = 0;
52
  for (int i : r)
53
    t += i;
54
  return t;
55
}
56
 
57
/* Template with non-dependent expression and dependent declaration. */
58
template int test2(const container &r)
59
{
60
  int t = 0;
61
  for (T i : r)
62
    t += i;
63
  return t;
64
}
65
 
66
/* Template with non-dependent expression (array) and dependent declaration. */
67
template int test2(const int (&r)[4])
68
{
69
  int t = 0;
70
  for (T i : r)
71
    t += i;
72
  return t;
73
}
74
 
75
/* Template with non-dependent expression and auto declaration. */
76
template int test3(const container &r)
77
{
78
  int t = 0;
79
  for (auto i : r)
80
    t += i;
81
  return t;
82
}
83
 
84
/* Template with non-dependent expression (array) and auto declaration. */
85
template int test3(const int (&r)[4])
86
{
87
  int t = 0;
88
  for (auto i : r)
89
    t += i;
90
  return t;
91
}
92
 
93
int main ()
94
{
95
  container c(1,5);
96
  int a[4] = {5,6,7,8};
97
 
98
  for (auto x : run_me_just_once())
99
      ;
100
 
101
  if (test1 (c) != 10)
102
    abort();
103
  if (test1 (a) != 26)
104
    abort();
105
 
106
  if (test2 (c) != 10)
107
    abort();
108
  if (test2 (a) != 26)
109
    abort();
110
 
111
  if (test3 (c) != 10)
112
    abort();
113
  if (test3 (a) != 26)
114
    abort();
115
  return 0;
116
}

powered by: WebSVN 2.1.0

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