/work/workdir/UnpackedTarball/boost/boost/array.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef BOOST_ARRAY_HPP_INCLUDED |
2 | | #define BOOST_ARRAY_HPP_INCLUDED |
3 | | |
4 | | /* The following code declares class array, |
5 | | * an STL container (as wrapper) for arrays of constant size. |
6 | | * |
7 | | * See |
8 | | * http://www.boost.org/libs/array/ |
9 | | * for documentation. |
10 | | * |
11 | | * The original author site is at: http://www.josuttis.com/ |
12 | | * |
13 | | * (C) Copyright Nicolai M. Josuttis 2001. |
14 | | * |
15 | | * Distributed under the Boost Software License, Version 1.0. (See |
16 | | * accompanying file LICENSE_1_0.txt or copy at |
17 | | * http://www.boost.org/LICENSE_1_0.txt) |
18 | | * |
19 | | * 9 Jan 2013 - (mtc) Added constexpr |
20 | | * 14 Apr 2012 - (mtc) Added support for boost::hash |
21 | | * 28 Dec 2010 - (mtc) Added cbegin and cend (and crbegin and crend) for C++Ox compatibility. |
22 | | * 10 Mar 2010 - (mtc) fill method added, matching resolution of the standard library working group. |
23 | | * See <http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#776> or Trac issue #3168 |
24 | | * Eventually, we should remove "assign" which is now a synonym for "fill" (Marshall Clow) |
25 | | * 10 Mar 2010 - added workaround for SUNCC and !STLPort [trac #3893] (Marshall Clow) |
26 | | * 29 Jan 2004 - c_array() added, BOOST_NO_PRIVATE_IN_AGGREGATE removed (Nico Josuttis) |
27 | | * 23 Aug 2002 - fix for Non-MSVC compilers combined with MSVC libraries. |
28 | | * 05 Aug 2001 - minor update (Nico Josuttis) |
29 | | * 20 Jan 2001 - STLport fix (Beman Dawes) |
30 | | * 29 Sep 2000 - Initial Revision (Nico Josuttis) |
31 | | * |
32 | | * Jan 29, 2004 |
33 | | */ |
34 | | |
35 | | #include <boost/config.hpp> |
36 | | #include <boost/config/workaround.hpp> |
37 | | |
38 | | #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) |
39 | | # pragma warning(push) |
40 | | # pragma warning(disable: 4510) // boost::array<T,N>' : default constructor could not be generated |
41 | | # pragma warning(disable: 4512) // boost::array<T,N>' : assignment operator could not be generated |
42 | | # pragma warning(disable: 4610) // class 'boost::array<T,N>' can never be instantiated - user defined constructor required |
43 | | # pragma warning(disable: 4702) // unreachable code |
44 | | #endif |
45 | | |
46 | | #include <boost/assert.hpp> |
47 | | #include <boost/static_assert.hpp> |
48 | | #include <boost/throw_exception.hpp> |
49 | | #include <iterator> |
50 | | #include <stdexcept> |
51 | | #include <utility> |
52 | | #include <cstddef> |
53 | | |
54 | | #if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L |
55 | | # if __has_include(<compare>) |
56 | | # include <compare> |
57 | | # endif |
58 | | #endif |
59 | | |
60 | | namespace boost { |
61 | | |
62 | | template<class T, std::size_t N> |
63 | | class array { |
64 | | public: |
65 | | T elems[N]; // fixed-size array of elements of type T |
66 | | |
67 | | public: |
68 | | // type definitions |
69 | | typedef T value_type; |
70 | | typedef T* iterator; |
71 | | typedef const T* const_iterator; |
72 | | typedef T& reference; |
73 | | typedef const T& const_reference; |
74 | | typedef std::size_t size_type; |
75 | | typedef std::ptrdiff_t difference_type; |
76 | | |
77 | | // iterator support |
78 | 0 | BOOST_CXX14_CONSTEXPR iterator begin() BOOST_NOEXCEPT { return elems; } Unexecuted instantiation: boost::array<long, 2ul>::begin() Unexecuted instantiation: boost::array<unsigned long, 2ul>::begin() Unexecuted instantiation: boost::array<boost::detail::multi_array::index_range<long, unsigned long>, 2ul>::begin() Unexecuted instantiation: boost::array<boost::detail::multi_array::extent_range<long, unsigned long>, 1ul>::begin() Unexecuted instantiation: boost::array<boost::detail::multi_array::extent_range<long, unsigned long>, 2ul>::begin() Unexecuted instantiation: boost::array<boost::detail::multi_array::index_range<long, unsigned long>, 1ul>::begin() Unexecuted instantiation: boost::array<unsigned long, 1ul>::begin() Unexecuted instantiation: boost::array<long, 1ul>::begin() |
79 | 0 | BOOST_CONSTEXPR const_iterator begin() const BOOST_NOEXCEPT { return elems; } Unexecuted instantiation: boost::array<bool, 2ul>::begin() const Unexecuted instantiation: boost::array<boost::detail::multi_array::extent_range<long, unsigned long>, 2ul>::begin() const Unexecuted instantiation: boost::array<long, 2ul>::begin() const Unexecuted instantiation: boost::array<boost::detail::multi_array::extent_range<long, unsigned long>, 1ul>::begin() const Unexecuted instantiation: boost::array<boost::detail::multi_array::index_range<long, unsigned long>, 1ul>::begin() const Unexecuted instantiation: boost::array<long, 1ul>::begin() const |
80 | | BOOST_CONSTEXPR const_iterator cbegin() const BOOST_NOEXCEPT { return elems; } |
81 | | |
82 | 0 | BOOST_CXX14_CONSTEXPR iterator end() BOOST_NOEXCEPT { return elems+N; } Unexecuted instantiation: boost::array<unsigned long, 2ul>::end() Unexecuted instantiation: boost::array<long, 2ul>::end() Unexecuted instantiation: boost::array<boost::detail::multi_array::extent_range<long, unsigned long>, 1ul>::end() Unexecuted instantiation: boost::array<boost::detail::multi_array::extent_range<long, unsigned long>, 2ul>::end() Unexecuted instantiation: boost::array<boost::detail::multi_array::index_range<long, unsigned long>, 1ul>::end() Unexecuted instantiation: boost::array<unsigned long, 1ul>::end() |
83 | 0 | BOOST_CONSTEXPR const_iterator end() const BOOST_NOEXCEPT { return elems+N; } Unexecuted instantiation: boost::array<bool, 2ul>::end() const Unexecuted instantiation: boost::array<boost::detail::multi_array::extent_range<long, unsigned long>, 2ul>::end() const Unexecuted instantiation: boost::array<boost::detail::multi_array::extent_range<long, unsigned long>, 1ul>::end() const Unexecuted instantiation: boost::array<boost::detail::multi_array::index_range<long, unsigned long>, 1ul>::end() const |
84 | | BOOST_CONSTEXPR const_iterator cend() const BOOST_NOEXCEPT { return elems+N; } |
85 | | |
86 | | // reverse iterator support |
87 | | typedef std::reverse_iterator<iterator> reverse_iterator; |
88 | | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
89 | | |
90 | 0 | reverse_iterator rbegin() BOOST_NOEXCEPT { return reverse_iterator(end()); } Unexecuted instantiation: boost::array<boost::detail::multi_array::extent_range<long, unsigned long>, 1ul>::rbegin() Unexecuted instantiation: boost::array<boost::detail::multi_array::extent_range<long, unsigned long>, 2ul>::rbegin() Unexecuted instantiation: boost::array<boost::detail::multi_array::index_range<long, unsigned long>, 1ul>::rbegin() |
91 | | const_reverse_iterator rbegin() const BOOST_NOEXCEPT { |
92 | | return const_reverse_iterator(end()); |
93 | | } |
94 | | const_reverse_iterator crbegin() const BOOST_NOEXCEPT { |
95 | | return const_reverse_iterator(end()); |
96 | | } |
97 | | |
98 | | reverse_iterator rend() BOOST_NOEXCEPT { return reverse_iterator(begin()); } |
99 | | const_reverse_iterator rend() const BOOST_NOEXCEPT { |
100 | | return const_reverse_iterator(begin()); |
101 | | } |
102 | | const_reverse_iterator crend() const BOOST_NOEXCEPT { |
103 | | return const_reverse_iterator(begin()); |
104 | | } |
105 | | |
106 | | // operator[] |
107 | | BOOST_CXX14_CONSTEXPR reference operator[](size_type i) |
108 | 0 | { |
109 | 0 | return BOOST_ASSERT_MSG( i < N, "out of range" ), elems[i]; |
110 | 0 | } Unexecuted instantiation: boost::array<unsigned long, 2ul>::operator[](unsigned long) Unexecuted instantiation: boost::array<long, 2ul>::operator[](unsigned long) Unexecuted instantiation: boost::array<unsigned long, 1ul>::operator[](unsigned long) Unexecuted instantiation: boost::array<long, 1ul>::operator[](unsigned long) |
111 | | |
112 | | #if !BOOST_WORKAROUND(BOOST_GCC, < 50000) |
113 | | BOOST_CONSTEXPR |
114 | | #endif |
115 | | const_reference operator[](size_type i) const |
116 | 0 | { |
117 | 0 | return BOOST_ASSERT_MSG( i < N, "out of range" ), elems[i]; |
118 | 0 | } Unexecuted instantiation: boost::array<bool, 2ul>::operator[](unsigned long) const Unexecuted instantiation: boost::array<unsigned long, 2ul>::operator[](unsigned long) const Unexecuted instantiation: boost::array<long, 2ul>::operator[](unsigned long) const Unexecuted instantiation: boost::array<boost::detail::multi_array::index_range<long, unsigned long>, 2ul>::operator[](unsigned long) const Unexecuted instantiation: boost::array<boost::detail::multi_array::index_range<long, unsigned long>, 1ul>::operator[](unsigned long) const |
119 | | |
120 | | // at() with range check |
121 | | BOOST_CXX14_CONSTEXPR reference at(size_type i) { return rangecheck(i), elems[i]; } |
122 | | BOOST_CONSTEXPR const_reference at(size_type i) const { return rangecheck(i), elems[i]; } |
123 | | |
124 | | // front() and back() |
125 | | BOOST_CXX14_CONSTEXPR reference front() |
126 | | { |
127 | | return elems[0]; |
128 | | } |
129 | | |
130 | | BOOST_CONSTEXPR const_reference front() const |
131 | | { |
132 | | return elems[0]; |
133 | | } |
134 | | |
135 | | BOOST_CXX14_CONSTEXPR reference back() |
136 | | { |
137 | | return elems[N-1]; |
138 | | } |
139 | | |
140 | | BOOST_CONSTEXPR const_reference back() const |
141 | | { |
142 | | return elems[N-1]; |
143 | | } |
144 | | |
145 | | // size is constant |
146 | | static BOOST_CONSTEXPR size_type size() BOOST_NOEXCEPT { return N; } |
147 | | static BOOST_CONSTEXPR bool empty() BOOST_NOEXCEPT { return false; } |
148 | | static BOOST_CONSTEXPR size_type max_size() BOOST_NOEXCEPT { return N; } |
149 | | enum { static_size = N }; |
150 | | |
151 | | // swap (note: linear complexity) |
152 | | BOOST_CXX14_CONSTEXPR void swap (array<T,N>& y) |
153 | 0 | { |
154 | 0 | std::swap( elems, y.elems ); |
155 | 0 | } Unexecuted instantiation: boost::array<unsigned long, 2ul>::swap(boost::array<unsigned long, 2ul>&) Unexecuted instantiation: boost::array<long, 2ul>::swap(boost::array<long, 2ul>&) |
156 | | |
157 | | // direct access to data |
158 | 0 | BOOST_CONSTEXPR const T* data() const BOOST_NOEXCEPT { return elems; } Unexecuted instantiation: boost::array<long, 2ul>::data() const Unexecuted instantiation: boost::array<unsigned long, 2ul>::data() const |
159 | | BOOST_CXX14_CONSTEXPR T* data() BOOST_NOEXCEPT { return elems; } |
160 | | |
161 | | // obsolete |
162 | | BOOST_DEPRECATED( "please use `data()` instead" ) |
163 | | T* c_array() BOOST_NOEXCEPT { return elems; } |
164 | | |
165 | | // assignment with type conversion |
166 | | template <typename T2> |
167 | | array<T,N>& operator= (const array<T2,N>& rhs) |
168 | | { |
169 | | for( std::size_t i = 0; i < N; ++i ) |
170 | | { |
171 | | elems[ i ] = rhs.elems[ i ]; |
172 | | } |
173 | | |
174 | | return *this; |
175 | | } |
176 | | |
177 | | // fill with one value |
178 | | BOOST_CXX14_CONSTEXPR void fill (const T& value) |
179 | 0 | { |
180 | | // using elems[ 0 ] as a temporary copy |
181 | | // avoids the aliasing opportunity betw. |
182 | | // `value` and `elems` |
183 | |
|
184 | 0 | elems[ 0 ] = value; |
185 | |
|
186 | 0 | for( std::size_t i = 1; i < N; ++i ) |
187 | 0 | { |
188 | 0 | elems[ i ] = elems[ 0 ]; |
189 | 0 | } |
190 | 0 | } Unexecuted instantiation: boost::array<bool, 2ul>::fill(bool const&) Unexecuted instantiation: boost::array<long, 2ul>::fill(long const&) Unexecuted instantiation: boost::array<bool, 1ul>::fill(bool const&) Unexecuted instantiation: boost::array<long, 1ul>::fill(long const&) |
191 | | |
192 | | // an obsolete synonym for fill |
193 | | BOOST_DEPRECATED( "please use `fill` instead" ) |
194 | 0 | void assign (const T& value) { fill ( value ); } Unexecuted instantiation: boost::array<bool, 2ul>::assign(bool const&) Unexecuted instantiation: boost::array<long, 2ul>::assign(long const&) Unexecuted instantiation: boost::array<bool, 1ul>::assign(bool const&) Unexecuted instantiation: boost::array<long, 1ul>::assign(long const&) |
195 | | |
196 | | // check range (may be private because it is static) |
197 | | static BOOST_CONSTEXPR bool rangecheck (size_type i) { |
198 | | return i >= size() ? boost::throw_exception(std::out_of_range ("array<>: index out of range")), true : true; |
199 | | } |
200 | | |
201 | | }; |
202 | | |
203 | | template< class T > |
204 | | class array< T, 0 > { |
205 | | public: |
206 | | struct {} elems; // enables initialization with = {{}} |
207 | | |
208 | | public: |
209 | | // type definitions |
210 | | typedef T value_type; |
211 | | typedef T* iterator; |
212 | | typedef const T* const_iterator; |
213 | | typedef T& reference; |
214 | | typedef const T& const_reference; |
215 | | typedef std::size_t size_type; |
216 | | typedef std::ptrdiff_t difference_type; |
217 | | |
218 | | // iterator support |
219 | | BOOST_CXX14_CONSTEXPR iterator begin() BOOST_NOEXCEPT { return data(); } |
220 | | BOOST_CONSTEXPR const_iterator begin() const BOOST_NOEXCEPT { return data(); } |
221 | | BOOST_CONSTEXPR const_iterator cbegin() const BOOST_NOEXCEPT { return data(); } |
222 | | |
223 | | BOOST_CXX14_CONSTEXPR iterator end() BOOST_NOEXCEPT { return begin(); } |
224 | | BOOST_CONSTEXPR const_iterator end() const BOOST_NOEXCEPT { return begin(); } |
225 | | BOOST_CONSTEXPR const_iterator cend() const BOOST_NOEXCEPT { return cbegin(); } |
226 | | |
227 | | // reverse iterator support |
228 | | typedef std::reverse_iterator<iterator> reverse_iterator; |
229 | | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
230 | | |
231 | | reverse_iterator rbegin() BOOST_NOEXCEPT { return reverse_iterator(end()); } |
232 | | const_reverse_iterator rbegin() const BOOST_NOEXCEPT { |
233 | | return const_reverse_iterator(end()); |
234 | | } |
235 | | const_reverse_iterator crbegin() const BOOST_NOEXCEPT { |
236 | | return const_reverse_iterator(end()); |
237 | | } |
238 | | |
239 | | reverse_iterator rend() BOOST_NOEXCEPT { return reverse_iterator(begin()); } |
240 | | const_reverse_iterator rend() const BOOST_NOEXCEPT { |
241 | | return const_reverse_iterator(begin()); |
242 | | } |
243 | | const_reverse_iterator crend() const BOOST_NOEXCEPT { |
244 | | return const_reverse_iterator(begin()); |
245 | | } |
246 | | |
247 | | // operator[] |
248 | | reference operator[](size_type /*i*/) |
249 | | { |
250 | | return failed_rangecheck(); |
251 | | } |
252 | | |
253 | | const_reference operator[](size_type /*i*/) const |
254 | | { |
255 | | return failed_rangecheck(); |
256 | | } |
257 | | |
258 | | // at() with range check |
259 | | reference at(size_type /*i*/) { return failed_rangecheck(); } |
260 | | const_reference at(size_type /*i*/) const { return failed_rangecheck(); } |
261 | | |
262 | | // front() and back() |
263 | | reference front() |
264 | | { |
265 | | return failed_rangecheck(); |
266 | | } |
267 | | |
268 | | const_reference front() const |
269 | | { |
270 | | return failed_rangecheck(); |
271 | | } |
272 | | |
273 | | reference back() |
274 | | { |
275 | | return failed_rangecheck(); |
276 | | } |
277 | | |
278 | | const_reference back() const |
279 | | { |
280 | | return failed_rangecheck(); |
281 | | } |
282 | | |
283 | | // size is constant |
284 | | static BOOST_CONSTEXPR size_type size() BOOST_NOEXCEPT { return 0; } |
285 | | static BOOST_CONSTEXPR bool empty() BOOST_NOEXCEPT { return true; } |
286 | | static BOOST_CONSTEXPR size_type max_size() BOOST_NOEXCEPT { return 0; } |
287 | | enum { static_size = 0 }; |
288 | | |
289 | | BOOST_CXX14_CONSTEXPR void swap (array<T,0>& /*y*/) |
290 | | { |
291 | | } |
292 | | |
293 | | // direct access to data |
294 | | BOOST_CONSTEXPR const T* data() const BOOST_NOEXCEPT { return 0; } |
295 | | BOOST_CXX14_CONSTEXPR T* data() BOOST_NOEXCEPT { return 0; } |
296 | | |
297 | | // obsolete |
298 | | BOOST_DEPRECATED( "please use `data()` instead" ) |
299 | | T* c_array() BOOST_NOEXCEPT { return 0; } |
300 | | |
301 | | // assignment with type conversion |
302 | | template <typename T2> |
303 | | array<T,0>& operator= (const array<T2,0>& ) { |
304 | | return *this; |
305 | | } |
306 | | |
307 | | // an obsolete synonym for fill |
308 | | BOOST_DEPRECATED( "please use `fill` instead" ) |
309 | | void assign (const T& value) { fill ( value ); } |
310 | | |
311 | | // fill with one value |
312 | | BOOST_CXX14_CONSTEXPR void fill (const T& ) {} |
313 | | |
314 | | // check range (may be private because it is static) |
315 | | static reference failed_rangecheck () |
316 | | { |
317 | | boost::throw_exception( std::out_of_range( "attempt to access element of an empty array" ) ); |
318 | | } |
319 | | }; |
320 | | |
321 | | // comparisons |
322 | | template<class T, std::size_t N> |
323 | | BOOST_CXX14_CONSTEXPR bool operator== (const array<T,N>& x, const array<T,N>& y) |
324 | | { |
325 | | for( std::size_t i = 0; i < N; ++i ) |
326 | | { |
327 | | if( !( x[ i ] == y[ i ] ) ) return false; |
328 | | } |
329 | | |
330 | | return true; |
331 | | } |
332 | | |
333 | | #if BOOST_WORKAROUND(BOOST_GCC, < 90000) |
334 | | |
335 | | template<class T> |
336 | | BOOST_CXX14_CONSTEXPR bool operator== (const array<T, 0>& /*x*/, const array<T, 0>& /*y*/) |
337 | | { |
338 | | return true; |
339 | | } |
340 | | |
341 | | #endif |
342 | | |
343 | | template<class T, std::size_t N> |
344 | | BOOST_CXX14_CONSTEXPR bool operator!= (const array<T,N>& x, const array<T,N>& y) { |
345 | | return !(x==y); |
346 | | } |
347 | | |
348 | | template<class T, std::size_t N> |
349 | | BOOST_CXX14_CONSTEXPR bool operator< (const array<T,N>& x, const array<T,N>& y) |
350 | | { |
351 | | for( std::size_t i = 0; i < N; ++i ) |
352 | | { |
353 | | if( x[ i ] < y[ i ] ) return true; |
354 | | if( y[ i ] < x[ i ] ) return false; |
355 | | } |
356 | | |
357 | | return false; |
358 | | } |
359 | | |
360 | | #if BOOST_WORKAROUND(BOOST_GCC, < 90000) |
361 | | |
362 | | template<class T> |
363 | | BOOST_CXX14_CONSTEXPR bool operator< (const array<T, 0>& /*x*/, const array<T, 0>& /*y*/) |
364 | | { |
365 | | return false; |
366 | | } |
367 | | |
368 | | #endif |
369 | | |
370 | | template<class T, std::size_t N> |
371 | | BOOST_CXX14_CONSTEXPR bool operator> (const array<T,N>& x, const array<T,N>& y) { |
372 | | return y<x; |
373 | | } |
374 | | |
375 | | template<class T, std::size_t N> |
376 | | BOOST_CXX14_CONSTEXPR bool operator<= (const array<T,N>& x, const array<T,N>& y) { |
377 | | return !(y<x); |
378 | | } |
379 | | |
380 | | template<class T, std::size_t N> |
381 | | BOOST_CXX14_CONSTEXPR bool operator>= (const array<T,N>& x, const array<T,N>& y) { |
382 | | return !(x<y); |
383 | | } |
384 | | |
385 | | // global swap() |
386 | | template<class T, std::size_t N> |
387 | 0 | BOOST_CXX14_CONSTEXPR inline void swap (array<T,N>& x, array<T,N>& y) { |
388 | 0 | x.swap(y); |
389 | 0 | } Unexecuted instantiation: void boost::swap<unsigned long, 2ul>(boost::array<unsigned long, 2ul>&, boost::array<unsigned long, 2ul>&) Unexecuted instantiation: void boost::swap<long, 2ul>(boost::array<long, 2ul>&, boost::array<long, 2ul>&) |
390 | | |
391 | | #if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L |
392 | | # if __has_include(<compare>) |
393 | | |
394 | | template<class T, std::size_t N> |
395 | | constexpr auto operator<=> (const array<T,N>& x, const array<T,N>& y) |
396 | | -> decltype( x.elems[ 0 ] <=> y.elems[ 0 ] ) |
397 | | { |
398 | | for( std::size_t i = 0; i < N; ++i ) |
399 | | { |
400 | | auto r = x.elems[ i ] <=> y.elems[ i ]; |
401 | | if( r != 0 ) return r; |
402 | | } |
403 | | |
404 | | return std::strong_ordering::equal; |
405 | | } |
406 | | |
407 | | template<class T> |
408 | | constexpr auto operator<=> (const array<T,0>& /*x*/, const array<T,0>& /*y*/) |
409 | | -> std::strong_ordering |
410 | | { |
411 | | return std::strong_ordering::equal; |
412 | | } |
413 | | |
414 | | # endif |
415 | | #endif |
416 | | |
417 | | // undocumented and obsolete |
418 | | template <typename T, std::size_t N> |
419 | | BOOST_DEPRECATED( "please use `elems` instead" ) |
420 | | T(&get_c_array(boost::array<T,N>& arg))[N] |
421 | | { |
422 | | return arg.elems; |
423 | | } |
424 | | |
425 | | // Const version. |
426 | | template <typename T, std::size_t N> |
427 | | BOOST_DEPRECATED( "please use `elems` instead" ) |
428 | | const T(&get_c_array(const boost::array<T,N>& arg))[N] |
429 | | { |
430 | | return arg.elems; |
431 | | } |
432 | | |
433 | | template <size_t Idx, typename T, size_t N> |
434 | | BOOST_CXX14_CONSTEXPR T &get(boost::array<T,N> &arr) BOOST_NOEXCEPT |
435 | | { |
436 | | BOOST_STATIC_ASSERT_MSG ( Idx < N, "boost::get<>(boost::array &) index out of range" ); |
437 | | return arr[Idx]; |
438 | | } |
439 | | |
440 | | template <size_t Idx, typename T, size_t N> |
441 | | BOOST_CONSTEXPR const T &get(const boost::array<T,N> &arr) BOOST_NOEXCEPT |
442 | | { |
443 | | BOOST_STATIC_ASSERT_MSG ( Idx < N, "boost::get<>(const boost::array &) index out of range" ); |
444 | | return arr[Idx]; |
445 | | } |
446 | | |
447 | | template<class T, std::size_t N> |
448 | | BOOST_CXX14_CONSTEXPR array<T, N> to_array( T const (&a)[ N ] ) |
449 | | { |
450 | | array<T, N> r = {}; |
451 | | |
452 | | for( std::size_t i = 0; i < N; ++i ) |
453 | | { |
454 | | r[ i ] = a[ i ]; |
455 | | } |
456 | | |
457 | | return r; |
458 | | } |
459 | | |
460 | | #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) |
461 | | |
462 | | template<class T, std::size_t N> |
463 | | BOOST_CXX14_CONSTEXPR array<T, N> to_array( T (&&a)[ N ] ) |
464 | | { |
465 | | array<T, N> r = {}; |
466 | | |
467 | | for( std::size_t i = 0; i < N; ++i ) |
468 | | { |
469 | | r[ i ] = std::move( a[ i ] ); |
470 | | } |
471 | | |
472 | | return r; |
473 | | } |
474 | | |
475 | | template<class T, std::size_t N> |
476 | | BOOST_CXX14_CONSTEXPR array<T, N> to_array( T const (&&a)[ N ] ) |
477 | | { |
478 | | array<T, N> r = {}; |
479 | | |
480 | | for( std::size_t i = 0; i < N; ++i ) |
481 | | { |
482 | | r[ i ] = a[ i ]; |
483 | | } |
484 | | |
485 | | return r; |
486 | | } |
487 | | |
488 | | #endif |
489 | | |
490 | | } /* namespace boost */ |
491 | | |
492 | | #ifndef BOOST_NO_CXX11_HDR_ARRAY |
493 | | // If we don't have std::array, I'm assuming that we don't have std::get |
494 | | namespace std { |
495 | | template <size_t Idx, typename T, size_t N> |
496 | | BOOST_DEPRECATED( "please use `boost::get` instead" ) |
497 | | T &get(boost::array<T,N> &arr) BOOST_NOEXCEPT { |
498 | | BOOST_STATIC_ASSERT_MSG ( Idx < N, "std::get<>(boost::array &) index out of range" ); |
499 | | return arr[Idx]; |
500 | | } |
501 | | |
502 | | template <size_t Idx, typename T, size_t N> |
503 | | BOOST_DEPRECATED( "please use `boost::get` instead" ) |
504 | | const T &get(const boost::array<T,N> &arr) BOOST_NOEXCEPT { |
505 | | BOOST_STATIC_ASSERT_MSG ( Idx < N, "std::get<>(const boost::array &) index out of range" ); |
506 | | return arr[Idx]; |
507 | | } |
508 | | } |
509 | | #endif |
510 | | |
511 | | #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) |
512 | | # pragma warning(pop) |
513 | | #endif |
514 | | |
515 | | #endif // #ifndef BOOST_ARRAY_HPP_INCLUDED |