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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [libstdc++-v3/] [testsuite/] [util/] [testsuite_rvalref.h] - Blame information for rev 841

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
// -*- C++ -*-
2
// Testing utilities for the rvalue reference.
3
//
4
// Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc.
5
//
6
// This file is part of the GNU ISO C++ Library.  This library is free
7
// software; you can redistribute it and/or modify it under the
8
// terms of the GNU General Public License as published by the
9
// Free Software Foundation; either version 3, or (at your option)
10
// any later version.
11
//
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
// GNU General Public License for more details.
16
//
17
// You should have received a copy of the GNU General Public License along
18
// with this library; see the file COPYING3.  If not see
19
// <http://www.gnu.org/licenses/>.
20
//
21
 
22
#ifndef _GLIBCXX_TESTSUITE_RVALREF_H
23
#define _GLIBCXX_TESTSUITE_RVALREF_H 1
24
 
25
#include <testsuite_hooks.h>
26
 
27
namespace __gnu_test
28
{
29
 
30
  //  This class is designed to test libstdc++'s template-based rvalue
31
  //  reference support. It should fail at compile-time if there is an attempt
32
  //  to copy it (although see note just below).
33
  class rvalstruct
34
  {
35
    bool
36
    operator=(const rvalstruct&);
37
 
38
    rvalstruct(const rvalstruct&);
39
 
40
  public:
41
    int val;
42
    bool valid;
43
 
44
    rvalstruct() : valid(false)
45
    { }
46
 
47
    rvalstruct(int inval) : val(inval), valid(true)
48
    { }
49
 
50
    rvalstruct&
51
    operator=(int newval)
52
    {
53
      VERIFY(valid == false);
54
      val = newval;
55
      valid = true;
56
      return *this;
57
    }
58
 
59
    rvalstruct(rvalstruct&& in)
60
    {
61
      VERIFY(in.valid == true);
62
      val = in.val;
63
      in.valid = false;
64
      valid = true;
65
    }
66
 
67
    rvalstruct&
68
    operator=(rvalstruct&& in)
69
    {
70
      VERIFY(in.valid == true);
71
      val = in.val;
72
      in.valid = false;
73
      valid = true;
74
      return *this;
75
    }
76
  };
77
 
78
  bool
79
  operator==(const rvalstruct& lhs, const rvalstruct& rhs)
80
  { return lhs.val == rhs.val; }
81
 
82
  bool
83
  operator<(const rvalstruct& lhs, const rvalstruct& rhs)
84
  { return lhs.val < rhs.val; }
85
 
86
  void
87
  swap(rvalstruct& lhs, rvalstruct& rhs)
88
  {
89
    VERIFY(lhs.valid && rhs.valid);
90
    int temp = lhs.val;
91
    lhs.val = rhs.val;
92
    rhs.val = temp;
93
  }
94
 
95
  // This is a moveable class which copies how many times it is copied.
96
  // This is mainly of use in the containers, where the an element inserted
97
  // into a container has to be copied once to get there, but we want to check
98
  // nothing else is copied.
99
  struct copycounter
100
  {
101
    static int copycount;
102
    int val;
103
    bool valid;
104
 
105
    copycounter() : val(0), valid(true)
106
    { }
107
 
108
    copycounter(int inval) : val(inval), valid(true)
109
    { }
110
 
111
    copycounter(const copycounter& in) : val(in.val), valid(true)
112
    {
113
      VERIFY(in.valid == true);
114
      ++copycount;
115
    }
116
 
117
    copycounter(copycounter&& in)
118
    {
119
      VERIFY(in.valid == true);
120
      val = in.val;
121
      in.valid = false;
122
      valid = true;
123
    }
124
 
125
    copycounter&
126
    operator=(int newval)
127
    {
128
      val = newval;
129
      valid = true;
130
      return *this;
131
    }
132
 
133
    bool
134
    operator=(const copycounter& in)
135
    {
136
      VERIFY(in.valid == true);
137
      ++copycount;
138
      val = in.val;
139
      valid = true;
140
      return true;
141
    }
142
 
143
    copycounter&
144
    operator=(copycounter&& in)
145
    {
146
      VERIFY(in.valid == true);
147
      val = in.val;
148
      in.valid = false;
149
      valid = true;
150
      return *this;
151
    }
152
 
153
    ~copycounter()
154
    { valid = false; }
155
  };
156
 
157
  int copycounter::copycount = 0;
158
 
159
  bool
160
  operator==(const copycounter& lhs, const copycounter& rhs)
161
  { return lhs.val == rhs.val; }
162
 
163
  bool
164
  operator<(const copycounter& lhs, const copycounter& rhs)
165
  { return lhs.val < rhs.val; }
166
 
167
  void
168
  swap(copycounter& lhs, copycounter& rhs)
169
  {
170
    VERIFY(lhs.valid && rhs.valid);
171
    int temp = lhs.val;
172
    lhs.val = rhs.val;
173
    rhs.val = temp;
174
  }
175
 
176
} // namespace __gnu_test
177
 
178
#endif // _GLIBCXX_TESTSUITE_TR1_H

powered by: WebSVN 2.1.0

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