1 // class template array -*- C++ -*-
3 // Copyright (C) 2004 Free Software Foundation, Inc.
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 2, or (at your option)
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.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
41 // [6.2.2] Class template array template
42 // Requires complete type _Tp.
43 // Use of char array allows _Tp to skirt default constructable requirement.
44 template<typename _Tp, size_t _Nm = 1>
47 enum { _S_index = _Nm };
49 typedef _Tp value_type;
50 typedef value_type& reference;
51 typedef const value_type& const_reference;
52 typedef value_type* iterator;
53 typedef const value_type* const_iterator;
54 typedef size_t size_type;
55 typedef ptrdiff_t difference_type;
56 typedef std::reverse_iterator<iterator> reverse_iterator;
57 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
59 value_type _M_instance[_Nm];
61 // No explicit construct/copy/destroy for aggregate type.
64 assign(const value_type& u);
72 { return reinterpret_cast<iterator>(&_M_instance[0]); }
76 { return reinterpret_cast<const_iterator>(&_M_instance[0]); }
80 { return reinterpret_cast<iterator>(&_M_instance[_S_index - 1]); }
84 { return reinterpret_cast<const_iterator>(&_M_instance[_S_index - 1]); }
88 { return reverse_iterator(this->end()); }
90 const_reverse_iterator
92 { return const_reverse_iterator(this->end()); }
96 { return reverse_iterator(this->begin()); }
98 const_reverse_iterator
100 { return const_reverse_iterator(this->begin()); }
104 size() const { return _S_index; }
109 // XXX Not specified. Unnecessary, this is fixed-size.
118 operator[](size_type __n)
119 { return reinterpret_cast<reference>(_M_instance[__n]); }
122 operator[](size_type __n) const
123 { return reinterpret_cast<const_reference>(_M_instance[__n]); }
126 at(size_type __n) const
128 if (__builtin_expect(__n > _S_index, false))
129 throw std::bad_alloc();
130 return reinterpret_cast<const_reference>(_M_instance[__n]);
136 if (__builtin_expect(__n > _S_index, false))
137 throw std::bad_alloc();
138 return reinterpret_cast<reference>(_M_instance[__n]);
160 // Array comparisons.
161 template<typename _Tp, size_t _Nm>
163 operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
166 template<typename _Tp, size_t _Nm>
168 operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
169 { return !(__one == __two); }
171 template<typename _Tp, size_t _Nm>
173 operator<(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
176 template<typename _Tp, size_t _Nm>
178 operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
181 template<typename _Tp, size_t _Nm>
183 operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
186 template<typename _Tp, size_t _Nm>
188 operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
191 // [6.2.2.2] Specialized algorithms.
192 template<typename _Tp, size_t _Nm>
194 swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
195 { swap_ranges(__one.begin(), __one.end(), __two.begin()); }
196 } // namespace std::tr1