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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [include/] [std/] [array] - Blame information for rev 747

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

Line No. Rev Author Line
1 742 jeremybenn
//  -*- C++ -*-
2
 
3
// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4
//
5
// This file is part of the GNU ISO C++ Library.  This library is free
6
// software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the
8
// Free Software Foundation; either version 3, or (at your option)
9
// any later version.
10
 
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
 
16
// Under Section 7 of GPL version 3, you are granted additional
17
// permissions described in the GCC Runtime Library Exception, version
18
// 3.1, as published by the Free Software Foundation.
19
 
20
// You should have received a copy of the GNU General Public License and
21
// a copy of the GCC Runtime Library Exception along with this program;
22
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23
// .
24
 
25
/** @file include/array
26
 *  This is a Standard C++ Library header.
27
 */
28
 
29
#ifndef _GLIBCXX_ARRAY
30
#define _GLIBCXX_ARRAY 1
31
 
32
#pragma GCC system_header
33
 
34
#ifndef __GXX_EXPERIMENTAL_CXX0X__
35
# include 
36
#else
37
 
38
#include 
39
#include 
40
#include 
41
 
42
namespace std _GLIBCXX_VISIBILITY(default)
43
{
44
_GLIBCXX_BEGIN_NAMESPACE_VERSION
45
 
46
  /**
47
   *  @brief A standard container for storing a fixed size sequence of elements.
48
   *
49
   *  @ingroup sequences
50
   *
51
   *  Meets the requirements of a container, a
52
   *  reversible container, and a
53
   *  sequence.
54
   *
55
   *  Sets support random access iterators.
56
   *
57
   *  @param  Tp  Type of element. Required to be a complete type.
58
   *  @param  N  Number of elements.
59
  */
60
  template
61
    struct array
62
    {
63
      typedef _Tp                                     value_type;
64
      typedef value_type*                             pointer;
65
      typedef const value_type*                       const_pointer;
66
      typedef value_type&                   	      reference;
67
      typedef const value_type&             	      const_reference;
68
      typedef value_type*                             iterator;
69
      typedef const value_type*                       const_iterator;
70
      typedef std::size_t                             size_type;
71
      typedef std::ptrdiff_t                          difference_type;
72
      typedef std::reverse_iterator           reverse_iterator;
73
      typedef std::reverse_iterator   const_reverse_iterator;
74
 
75
      // Support for zero-sized arrays mandatory.
76
      value_type _M_instance[_Nm ? _Nm : 1];
77
 
78
      // No explicit construct/copy/destroy for aggregate type.
79
 
80
      // DR 776.
81
      void
82
      fill(const value_type& __u)
83
      { std::fill_n(begin(), size(), __u); }
84
 
85
      void
86
      swap(array& __other)
87
      noexcept(noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>())))
88
      { std::swap_ranges(begin(), end(), __other.begin()); }
89
 
90
      // Iterators.
91
      iterator
92
      begin() noexcept
93
      { return iterator(data()); }
94
 
95
      const_iterator
96
      begin() const noexcept
97
      { return const_iterator(data()); }
98
 
99
      iterator
100
      end() noexcept
101
      { return iterator(data() + _Nm); }
102
 
103
      const_iterator
104
      end() const noexcept
105
      { return const_iterator(data() + _Nm); }
106
 
107
      reverse_iterator
108
      rbegin() noexcept
109
      { return reverse_iterator(end()); }
110
 
111
      const_reverse_iterator
112
      rbegin() const noexcept
113
      { return const_reverse_iterator(end()); }
114
 
115
      reverse_iterator
116
      rend() noexcept
117
      { return reverse_iterator(begin()); }
118
 
119
      const_reverse_iterator
120
      rend() const noexcept
121
      { return const_reverse_iterator(begin()); }
122
 
123
      const_iterator
124
      cbegin() const noexcept
125
      { return const_iterator(std::__addressof(_M_instance[0])); }
126
 
127
      const_iterator
128
      cend() const noexcept
129
      { return const_iterator(std::__addressof(_M_instance[_Nm])); }
130
 
131
      const_reverse_iterator
132
      crbegin() const noexcept
133
      { return const_reverse_iterator(end()); }
134
 
135
      const_reverse_iterator
136
      crend() const noexcept
137
      { return const_reverse_iterator(begin()); }
138
 
139
      // Capacity.
140
      constexpr size_type
141
      size() const noexcept { return _Nm; }
142
 
143
      constexpr size_type
144
      max_size() const noexcept { return _Nm; }
145
 
146
      constexpr bool
147
      empty() const noexcept { return size() == 0; }
148
 
149
      // Element access.
150
      reference
151
      operator[](size_type __n)
152
      { return _M_instance[__n]; }
153
 
154
      constexpr const_reference
155
      operator[](size_type __n) const noexcept
156
      { return _M_instance[__n]; }
157
 
158
      reference
159
      at(size_type __n)
160
      {
161
        if (__n >= _Nm)
162
          std::__throw_out_of_range(__N("array::at"));
163
        return _M_instance[__n];
164
      }
165
 
166
#ifdef __EXCEPTIONS
167
      constexpr const_reference
168
      at(size_type __n) const
169
      {
170
        return __n < _Nm ?
171
               _M_instance[__n] : throw out_of_range(__N("array::at"));
172
      }
173
#else
174
      const_reference
175
      at(size_type __n) const
176
      {
177
        return __n < _Nm ?
178
               _M_instance[__n] : __throw_out_of_range(__N("array::at"));
179
      }
180
#endif
181
 
182
      reference
183
      front()
184
      { return *begin(); }
185
 
186
      const_reference
187
      front() const
188
      { return *begin(); }
189
 
190
      reference
191
      back()
192
      { return _Nm ? *(end() - 1) : *end(); }
193
 
194
      const_reference
195
      back() const
196
      { return _Nm ? *(end() - 1) : *end(); }
197
 
198
      pointer
199
      data() noexcept
200
      { return std::__addressof(_M_instance[0]); }
201
 
202
      const_pointer
203
      data() const noexcept
204
      { return std::__addressof(_M_instance[0]); }
205
    };
206
 
207
  // Array comparisons.
208
  template
209
    inline bool
210
    operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
211
    { return std::equal(__one.begin(), __one.end(), __two.begin()); }
212
 
213
  template
214
    inline bool
215
    operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
216
    { return !(__one == __two); }
217
 
218
  template
219
    inline bool
220
    operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b)
221
    {
222
      return std::lexicographical_compare(__a.begin(), __a.end(),
223
                                          __b.begin(), __b.end());
224
    }
225
 
226
  template
227
    inline bool
228
    operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
229
    { return __two < __one; }
230
 
231
  template
232
    inline bool
233
    operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
234
    { return !(__one > __two); }
235
 
236
  template
237
    inline bool
238
    operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
239
    { return !(__one < __two); }
240
 
241
  // Specialized algorithms.
242
  template
243
    inline void
244
    swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
245
    noexcept(noexcept(__one.swap(__two)))
246
    { __one.swap(__two); }
247
 
248
  // Tuple interface to class template array.
249
 
250
  /// tuple_size
251
  template
252
    class tuple_size;
253
 
254
  template
255
    struct tuple_size>
256
    : public integral_constant { };
257
 
258
  /// tuple_element
259
  template
260
    class tuple_element;
261
 
262
  template
263
    struct tuple_element<_Int, array<_Tp, _Nm> >
264
    { typedef _Tp type; };
265
 
266
  template
267
    constexpr _Tp&
268
    get(array<_Tp, _Nm>& __arr) noexcept
269
    { return __arr._M_instance[_Int]; }
270
 
271
  template
272
    constexpr _Tp&&
273
    get(array<_Tp, _Nm>&& __arr) noexcept
274
    { return std::move(get<_Int>(__arr)); }
275
 
276
  template
277
    constexpr const _Tp&
278
    get(const array<_Tp, _Nm>& __arr) noexcept
279
    { return __arr._M_instance[_Int]; }
280
 
281
_GLIBCXX_END_NAMESPACE_VERSION
282
} // namespace
283
 
284
#endif // __GXX_EXPERIMENTAL_CXX0X__
285
 
286
#endif // _GLIBCXX_ARRAY

powered by: WebSVN 2.1.0

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