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 _TR1_ARRAY
00035 #define _TR1_ARRAY 1
00036
00037 #include <new>
00038 #include <iterator>
00039 #include <algorithm>
00040 #include <cstddef>
00041 #include <bits/functexcept.h>
00042 #include <ext/type_traits.h>
00043
00044
00045 namespace std
00046 {
00047 _GLIBCXX_BEGIN_NAMESPACE(tr1)
00048
00049
00050
00051 template<typename _Tp, std::size_t _Nm>
00052 struct array
00053 {
00054 typedef _Tp value_type;
00055 typedef value_type& reference;
00056 typedef const value_type& const_reference;
00057 typedef value_type* iterator;
00058 typedef const value_type* const_iterator;
00059 typedef std::size_t size_type;
00060 typedef std::ptrdiff_t difference_type;
00061 typedef std::reverse_iterator<iterator> reverse_iterator;
00062 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
00063
00064
00065 value_type _M_instance[_Nm ? _Nm : 1] __attribute__((__aligned__));
00066
00067
00068
00069 void
00070 assign(const value_type& __u)
00071 { std::fill_n(begin(), size(), __u); }
00072
00073 void
00074 swap(array& __other)
00075 { std::swap_ranges(begin(), end(), __other.begin()); }
00076
00077
00078 iterator
00079 begin()
00080 { return iterator(&_M_instance[0]); }
00081
00082 const_iterator
00083 begin() const
00084 { return const_iterator(&_M_instance[0]); }
00085
00086 iterator
00087 end()
00088 { return iterator(&_M_instance[_Nm]); }
00089
00090 const_iterator
00091 end() const
00092 { return const_iterator(&_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 reference
00130 at(size_type __n)
00131 {
00132 _M_check<_Nm>(__n);
00133 return _M_instance[__n];
00134 }
00135
00136 const_reference
00137 at(size_type __n) const
00138 {
00139 _M_check<_Nm>(__n);
00140 return _M_instance[__n];
00141 }
00142
00143 reference
00144 front()
00145 { return *begin(); }
00146
00147 const_reference
00148 front() const
00149 { return *begin(); }
00150
00151 reference
00152 back()
00153 { return _Nm ? *(end() - 1) : *end(); }
00154
00155 const_reference
00156 back() const
00157 { return _Nm ? *(end() - 1) : *end(); }
00158
00159 _Tp*
00160 data()
00161 { return &_M_instance[0]; }
00162
00163 const _Tp*
00164 data() const
00165 { return &_M_instance[0]; }
00166
00167 private:
00168 template<std::size_t _Mm>
00169 typename __gnu_cxx::__enable_if<_Mm, void>::__type
00170 _M_check(size_type __n) const
00171 {
00172 if (__builtin_expect(__n >= _Mm, false))
00173 std::__throw_out_of_range(__N("array::_M_check"));
00174 }
00175
00176
00177 template<std::size_t _Mm>
00178 typename __gnu_cxx::__enable_if<!_Mm, void>::__type
00179 _M_check(size_type) const
00180 { std::__throw_out_of_range(__N("array::_M_check")); }
00181 };
00182
00183
00184 template<typename _Tp, std::size_t _Nm>
00185 inline bool
00186 operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
00187 { return std::equal(__one.begin(), __one.end(), __two.begin()); }
00188
00189 template<typename _Tp, std::size_t _Nm>
00190 inline bool
00191 operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
00192 { return !(__one == __two); }
00193
00194 template<typename _Tp, std::size_t _Nm>
00195 inline bool
00196 operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b)
00197 {
00198 return std::lexicographical_compare(__a.begin(), __a.end(),
00199 __b.begin(), __b.end());
00200 }
00201
00202 template<typename _Tp, std::size_t _Nm>
00203 inline bool
00204 operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
00205 { return __two < __one; }
00206
00207 template<typename _Tp, std::size_t _Nm>
00208 inline bool
00209 operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
00210 { return !(__one > __two); }
00211
00212 template<typename _Tp, std::size_t _Nm>
00213 inline bool
00214 operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
00215 { return !(__one < __two); }
00216
00217
00218 template<typename _Tp, std::size_t _Nm>
00219 inline void
00220 swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
00221 { std::swap_ranges(__one.begin(), __one.end(), __two.begin()); }
00222
00223
00224 template<typename _Tp> class tuple_size;
00225 template<int _Int, typename _Tp> class tuple_element;
00226
00227 template<typename _Tp, std::size_t _Nm>
00228 struct tuple_size<array<_Tp, _Nm> >
00229 { static const int value = _Nm; };
00230
00231 template<typename _Tp, std::size_t _Nm>
00232 const int tuple_size<array<_Tp, _Nm> >::value;
00233
00234 template<int _Int, typename _Tp, std::size_t _Nm>
00235 struct tuple_element<_Int, array<_Tp, _Nm> >
00236 { typedef _Tp type; };
00237
00238 template<int _Int, typename _Tp, std::size_t _Nm>
00239 inline _Tp&
00240 get(array<_Tp, _Nm>& __arr)
00241 { return __arr[_Int]; }
00242
00243 template<int _Int, typename _Tp, std::size_t _Nm>
00244 inline const _Tp&
00245 get(const array<_Tp, _Nm>& __arr)
00246 { return __arr[_Int]; }
00247
00248 _GLIBCXX_END_NAMESPACE
00249 }
00250
00251 #endif