Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/c++/15/tr1/array
1 // class template array -*- C++ -*- 2 3 // Copyright (C) 2004-2025 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 // <http://www.gnu.org/licenses/>. 24 25 /** @file tr1/array 26 * This is a TR1 C++ Library header. 27 */ 28 29 #ifndef _GLIBCXX_TR1_ARRAY 30 #define _GLIBCXX_TR1_ARRAY 1 31 32 #ifdef _GLIBCXX_SYSHDR 33 #pragma GCC system_header 34 #endif 35 36 #include <bits/requires_hosted.h> // TR1 37 38 #include <bits/stl_algobase.h> 39 40 namespace std _GLIBCXX_VISIBILITY(default) 41 { 42 _GLIBCXX_BEGIN_NAMESPACE_VERSION 43 44 namespace tr1 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 <a href="tables.html#65">container</a>, a 52 * <a href="tables.html#66">reversible container</a>, and a 53 * <a href="tables.html#67">sequence</a>. 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<typename _Tp, std::size_t _Nm> 61 struct array 62 { 63 typedef _Tp value_type; 64 typedef value_type& reference; 65 typedef const value_type& const_reference; 66 typedef value_type* iterator; 67 typedef const value_type* const_iterator; 68 typedef std::size_t size_type; 69 typedef std::ptrdiff_t difference_type; 70 typedef std::reverse_iterator<iterator> reverse_iterator; 71 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 72 73 // Support for zero-sized arrays mandatory. 74 value_type _M_instance[_Nm ? _Nm : 1]; 75 76 // No explicit construct/copy/destroy for aggregate type. 77 78 void 79 assign(const value_type& __u) 80 { std::fill_n(begin(), size(), __u); } 81 82 void 83 swap(array& __other) 84 { std::swap_ranges(begin(), end(), __other.begin()); } 85 86 // Iterators. 87 iterator 88 begin() 89 { return iterator(std::__addressof(_M_instance[0])); } 90 91 const_iterator 92 begin() const 93 { return const_iterator(std::__addressof(_M_instance[0])); } 94 95 iterator 96 end() 97 { return iterator(std::__addressof(_M_instance[_Nm])); } 98 99 const_iterator 100 end() const 101 { return const_iterator(std::__addressof(_M_instance[_Nm])); } 102 103 reverse_iterator 104 rbegin() 105 { return reverse_iterator(end()); } 106 107 const_reverse_iterator 108 rbegin() const 109 { return const_reverse_iterator(end()); } 110 111 reverse_iterator 112 rend() 113 { return reverse_iterator(begin()); } 114 115 const_reverse_iterator 116 rend() const 117 { return const_reverse_iterator(begin()); } 118 119 // Capacity. 120 size_type 121 size() const { return _Nm; } 122 123 size_type 124 max_size() const { return _Nm; } 125 126 _GLIBCXX_NODISCARD bool 127 empty() const { return size() == 0; } 128 129 // Element access. 130 reference 131 operator[](size_type __n) 132 { return _M_instance[__n]; } 133 134 const_reference 135 operator[](size_type __n) const 136 { return _M_instance[__n]; } 137 138 reference 139 at(size_type __n) 140 { 141 if (__n >= _Nm) 142 std::__throw_out_of_range(__N("array::at")); 143 return _M_instance[__n]; 144 } 145 146 const_reference 147 at(size_type __n) const 148 { 149 if (__n >= _Nm) 150 std::__throw_out_of_range(__N("array::at")); 151 return _M_instance[__n]; 152 } 153 154 reference 155 front() 156 { return *begin(); } 157 158 const_reference 159 front() const 160 { return *begin(); } 161 162 reference 163 back() 164 { return _Nm ? *(end() - 1) : *end(); } 165 166 const_reference 167 back() const 168 { return _Nm ? *(end() - 1) : *end(); } 169 170 _Tp* 171 data() 172 { return std::__addressof(_M_instance[0]); } 173 174 const _Tp* 175 data() const 176 { return std::__addressof(_M_instance[0]); } 177 }; 178 179 // Array comparisons. 180 template<typename _Tp, std::size_t _Nm> 181 inline bool 182 operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) 183 { return std::equal(__one.begin(), __one.end(), __two.begin()); } 184 185 template<typename _Tp, std::size_t _Nm> 186 inline bool 187 operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) 188 { return !(__one == __two); } 189 190 template<typename _Tp, std::size_t _Nm> 191 inline bool 192 operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b) 193 { 194 return std::lexicographical_compare(__a.begin(), __a.end(), 195 __b.begin(), __b.end()); 196 } 197 198 template<typename _Tp, std::size_t _Nm> 199 inline bool 200 operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) 201 { return __two < __one; } 202 203 template<typename _Tp, std::size_t _Nm> 204 inline bool 205 operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) 206 { return !(__one > __two); } 207 208 template<typename _Tp, std::size_t _Nm> 209 inline bool 210 operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) 211 { return !(__one < __two); } 212 213 // Specialized algorithms [6.2.2.2]. 214 template<typename _Tp, std::size_t _Nm> 215 inline void 216 swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two) 217 { __one.swap(__two); } 218 219 // Tuple interface to class template array [6.2.2.5]. 220 221 /// tuple_size 222 template<typename _Tp> 223 class tuple_size; 224 225 /// tuple_element 226 template<int _Int, typename _Tp> 227 class tuple_element; 228 229 template<typename _Tp, std::size_t _Nm> 230 struct tuple_size<array<_Tp, _Nm> > 231 { static const int value = _Nm; }; 232 233 template<typename _Tp, std::size_t _Nm> 234 const int 235 tuple_size<array<_Tp, _Nm> >::value; 236 237 template<int _Int, typename _Tp, std::size_t _Nm> 238 struct tuple_element<_Int, array<_Tp, _Nm> > 239 { typedef _Tp type; }; 240 241 template<int _Int, typename _Tp, std::size_t _Nm> 242 inline _Tp& 243 get(array<_Tp, _Nm>& __arr) 244 { return __arr[_Int]; } 245 246 template<int _Int, typename _Tp, std::size_t _Nm> 247 inline const _Tp& 248 get(const array<_Tp, _Nm>& __arr) 249 { return __arr[_Int]; } 250 } 251 252 _GLIBCXX_END_NAMESPACE_VERSION 253 } 254 255 #endif // _GLIBCXX_TR1_ARRAY