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

Subversion Repositories openrisc

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

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
 
3
// { dg-do run }
4
// { dg-options "-std=c++0x" }
5
 
6
/* Preliminary declarations */
7
namespace pre
8
{
9
  struct iterator
10
  {
11
    int x;
12
    iterator (int v) :x(v) {}
13
    iterator &operator ++() { ++x; return *this; }
14
    int operator *() { return x; }
15
    bool operator != (const iterator &o) { return x != o.x; }
16
  };
17
 
18
  struct container
19
  {
20
    int min, max;
21
    container(int a, int b) :min(a), max(b) {}
22
  };
23
 
24
  iterator begin(const container &c)
25
  {
26
    return iterator(c.min);
27
  }
28
 
29
  iterator end(const container &c)
30
  {
31
    return iterator(c.max);
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.