00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef _ARRAY
00035 #define _ARRAY 1
00036
00037 #include <new>
00038 #include <iterator>
00039 #include <algorithm>
00040 #include <cstddef>
00041 #include <bits/functexcept.h>
00042
00043
00044 namespace std
00045 {
00046 namespace tr1
00047 {
00048
00049
00050 template<typename _Tp, std::size_t _Nm = 1>
00051 struct array
00052 {
00053 typedef _Tp value_type;
00054 typedef value_type& reference;
00055 typedef const value_type& const_reference;
00056 typedef value_type* iterator;
00057 typedef const value_type* const_iterator;
00058 typedef std::size_t size_type;
00059 typedef std::ptrdiff_t difference_type;
00060 typedef std::reverse_iterator<iterator> reverse_iterator;
00061 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
00062
00063
00064 enum { _S_index = _Nm };
00065
00066
00067 value_type _M_instance[_Nm ? _Nm : 1];
00068
00069
00070
00071 void
00072 assign(const value_type& u);
00073
00074 void
00075 swap(array&);
00076
00077
00078 iterator
00079 begin()
00080 { return &_M_instance[0]; }
00081
00082 const_iterator
00083 begin() const
00084 { return &_M_instance[0]; }
00085
00086 iterator
00087 end()
00088 { return &_M_instance[_Nm]; }
00089
00090 const_iterator
00091 end() const
00092 { return &_M_instance[_Nm]; }
00093
00094 reverse_iterator
00095 rbegin()
00096 { return reverse_iterator(end()); }
00097
00098 const_reverse_iterator
00099 rbegin() const
00100 { return const_reverse_iterator(end()); }
00101
00102 reverse_iterator
00103 rend()
00104 { return reverse_iterator(begin()); }
00105
00106 const_reverse_iterator
00107 rend() const
00108 { return const_reverse_iterator(begin()); }
00109
00110
00111 size_type
00112 size() const { return _Nm; }
00113
00114 size_type
00115 max_size() const { return _Nm; }
00116
00117 bool
00118 empty() const { return size() == 0; }
00119
00120
00121 reference
00122 operator[](size_type __n)
00123 { return _M_instance[__n]; }
00124
00125 const_reference
00126 operator[](size_type __n) const
00127 { return _M_instance[__n]; }
00128
00129 const_reference
00130 at(size_type __n) const
00131 {
00132 if (__builtin_expect(__n > _Nm, false))
00133 std::__throw_out_of_range("array::at");
00134 return _M_instance[__n];
00135 }
00136
00137 reference
00138 at(size_type __n)
00139 {
00140 if (__builtin_expect(__n > _Nm, false))
00141 std::__throw_out_of_range("array::at");
00142 return _M_instance[__n];
00143 }
00144
00145 reference
00146 front()
00147 { return *begin(); }
00148
00149 const_reference
00150 front() const
00151 { return *begin(); }
00152
00153 reference
00154 back()
00155 { return *(end() - 1); }
00156
00157 const_reference
00158 back() const
00159 { return *(end() - 1); }
00160
00161 _Tp*
00162 data()
00163 { return &_M_instance[0]; }
00164
00165 const _Tp*
00166 data() const
00167 { return &_M_instance[0]; }
00168 };
00169
00170
00171 template<typename _Tp, std::size_t _Nm>
00172 bool
00173 operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
00174 { return std::equal(__one.begin(), __one.end(), __two.begin()); }
00175
00176 template<typename _Tp, std::size_t _Nm>
00177 bool
00178 operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
00179 { return !(__one == __two); }
00180
00181 template<typename _Tp, std::size_t _Nm>
00182 bool
00183 operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b)
00184 {
00185 return std::lexicographical_compare(__a.begin(), __a.end(),
00186 __b.begin(), __b.end());
00187 }
00188
00189 template<typename _Tp, std::size_t _Nm>
00190 bool
00191 operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
00192 { return __two < __one; }
00193
00194 template<typename _Tp, std::size_t _Nm>
00195 bool
00196 operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
00197 { return !(__one > __two); }
00198
00199 template<typename _Tp, std::size_t _Nm>
00200 bool
00201 operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
00202 { return !(__one < __two); }
00203
00204
00205 template<typename _Tp, std::size_t _Nm>
00206 void
00207 swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
00208 { swap_ranges(__one.begin(), __one.end(), __two.begin()); }
00209
00210
00211 template<typename _Tp> class tuple_size;
00212 template<int _Int, typename _Tp> class tuple_element;
00213
00214 template<typename _Tp, std::size_t _Nm>
00215 struct tuple_size<array<_Tp, _Nm> >
00216 { static const int value = _Nm; };
00217
00218 template<int _Int, typename _Tp, std::size_t _Nm>
00219 struct tuple_element<_Int, array<_Tp, _Nm> >
00220 { typedef _Tp type; };
00221
00222 template<int _Int, typename _Tp, std::size_t _Nm>
00223 _Tp&
00224 get(array<_Tp, _Nm>& __arr)
00225 { return __arr[_Int]; }
00226
00227 template<int _Int, typename _Tp, std::size_t _Nm>
00228 const _Tp&
00229 get(const array<_Tp, _Nm>& __arr)
00230 { return __arr[_Int]; }
00231 }
00232 }
00233
00234 #endif