STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
array File Reference
#include <bits/c++0x_warning.h>
#include <bits/stl_algobase.h>

Macros

#define _GLIBCXX_ARRAY   1
 
#define _GLIBCXX_TR1_ARRAY   1
 

Functions

namespace std _GLIBCXX_VISIBILITY (default)
 

Detailed Description

This is a TR1 C++ Library header.

Macro Definition Documentation

#define _GLIBCXX_ARRAY   1
#define _GLIBCXX_TR1_ARRAY   1

Function Documentation

namespace std _GLIBCXX_VISIBILITY ( default  )

A standard container for storing a fixed size sequence of elements.

Meets the requirements of a container, a reversible container, and a sequence.

Sets support random access iterators.

Parameters
TpType of element. Required to be a complete type.
NNumber of elements.

tuple_size

tuple_element

37 {
38 namespace tr1
39 {
40 _GLIBCXX_BEGIN_NAMESPACE_VERSION
41 
56  template<typename _Tp, std::size_t _Nm>
57  struct array
58  {
59  typedef _Tp value_type;
60  typedef value_type& reference;
61  typedef const value_type& const_reference;
62  typedef value_type* iterator;
63  typedef const value_type* const_iterator;
64  typedef std::size_t size_type;
65  typedef std::ptrdiff_t difference_type;
66  typedef std::reverse_iterator<iterator> reverse_iterator;
67  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
68 
69  // Support for zero-sized arrays mandatory.
70  value_type _M_instance[_Nm ? _Nm : 1];
71 
72  // No explicit construct/copy/destroy for aggregate type.
73 
74  void
75  assign(const value_type& __u)
76  { std::fill_n(begin(), size(), __u); }
77 
78  void
79  swap(array& __other)
80  { std::swap_ranges(begin(), end(), __other.begin()); }
81 
82  // Iterators.
83  iterator
84  begin()
85  { return iterator(std::__addressof(_M_instance[0])); }
86 
87  const_iterator
88  begin() const
89  { return const_iterator(std::__addressof(_M_instance[0])); }
90 
91  iterator
92  end()
93  { return iterator(std::__addressof(_M_instance[_Nm])); }
94 
95  const_iterator
96  end() const
97  { return const_iterator(std::__addressof(_M_instance[_Nm])); }
98 
99  reverse_iterator
100  rbegin()
101  { return reverse_iterator(end()); }
102 
103  const_reverse_iterator
104  rbegin() const
105  { return const_reverse_iterator(end()); }
106 
107  reverse_iterator
108  rend()
109  { return reverse_iterator(begin()); }
110 
111  const_reverse_iterator
112  rend() const
113  { return const_reverse_iterator(begin()); }
114 
115  // Capacity.
116  size_type
117  size() const { return _Nm; }
118 
119  size_type
120  max_size() const { return _Nm; }
121 
122  bool
123  empty() const { return size() == 0; }
124 
125  // Element access.
126  reference
127  operator[](size_type __n)
128  { return _M_instance[__n]; }
129 
130  const_reference
131  operator[](size_type __n) const
132  { return _M_instance[__n]; }
133 
134  reference
135  at(size_type __n)
136  {
137  if (__n >= _Nm)
138  std::__throw_out_of_range(__N("array::at"));
139  return _M_instance[__n];
140  }
141 
142  const_reference
143  at(size_type __n) const
144  {
145  if (__n >= _Nm)
146  std::__throw_out_of_range(__N("array::at"));
147  return _M_instance[__n];
148  }
149 
150  reference
151  front()
152  { return *begin(); }
153 
154  const_reference
155  front() const
156  { return *begin(); }
157 
158  reference
159  back()
160  { return _Nm ? *(end() - 1) : *end(); }
161 
162  const_reference
163  back() const
164  { return _Nm ? *(end() - 1) : *end(); }
165 
166  _Tp*
167  data()
168  { return std::__addressof(_M_instance[0]); }
169 
170  const _Tp*
171  data() const
172  { return std::__addressof(_M_instance[0]); }
173  };
174 
175  // Array comparisons.
176  template<typename _Tp, std::size_t _Nm>
177  inline bool
178  operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
179  { return std::equal(__one.begin(), __one.end(), __two.begin()); }
180 
181  template<typename _Tp, std::size_t _Nm>
182  inline bool
183  operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
184  { return !(__one == __two); }
185 
186  template<typename _Tp, std::size_t _Nm>
187  inline bool
188  operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b)
189  {
190  return std::lexicographical_compare(__a.begin(), __a.end(),
191  __b.begin(), __b.end());
192  }
193 
194  template<typename _Tp, std::size_t _Nm>
195  inline bool
196  operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
197  { return __two < __one; }
198 
199  template<typename _Tp, std::size_t _Nm>
200  inline bool
201  operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
202  { return !(__one > __two); }
203 
204  template<typename _Tp, std::size_t _Nm>
205  inline bool
206  operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
207  { return !(__one < __two); }
208 
209  // Specialized algorithms [6.2.2.2].
210  template<typename _Tp, std::size_t _Nm>
211  inline void
212  swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
213  { __one.swap(__two); }
214 
215  // Tuple interface to class template array [6.2.2.5].
216 
218  template<typename _Tp>
219  class tuple_size;
220 
222  template<int _Int, typename _Tp>
223  class tuple_element;
224 
225  template<typename _Tp, std::size_t _Nm>
226  struct tuple_size<array<_Tp, _Nm> >
227  { static const int value = _Nm; };
228 
229  template<typename _Tp, std::size_t _Nm>
230  const int
231  tuple_size<array<_Tp, _Nm> >::value;
232 
233  template<int _Int, typename _Tp, std::size_t _Nm>
234  struct tuple_element<_Int, array<_Tp, _Nm> >
235  { typedef _Tp type; };
236 
237  template<int _Int, typename _Tp, std::size_t _Nm>
238  inline _Tp&
239  get(array<_Tp, _Nm>& __arr)
240  { return __arr[_Int]; }
241 
242  template<int _Int, typename _Tp, std::size_t _Nm>
243  inline const _Tp&
244  get(const array<_Tp, _Nm>& __arr)
245  { return __arr[_Int]; }
246 
247 _GLIBCXX_END_NAMESPACE_VERSION
248 }
249 }
bool operator>=(const _Safe_iterator< _IteratorL, _Sequence > &__lhs, const _Safe_iterator< _IteratorR, _Sequence > &__rhs)
Definition: safe_iterator.h:644
bool operator==(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
bool operator>(const _Safe_iterator< _IteratorL, _Sequence > &__lhs, const _Safe_iterator< _IteratorR, _Sequence > &__rhs)
Definition: safe_iterator.h:612
bool operator!=(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
__SIZE_TYPE__ size_t
Definition: stddef.h:212
__PTRDIFF_TYPE__ ptrdiff_t
Definition: stddef.h:147
void swap(exception_ptr &__lhs, exception_ptr &__rhs)
Definition: exception_ptr.h:160