libstdc++: valarray Source File

libstdc++

valarray
Go to the documentation of this file.
1// The template and inlines for the -*- C++ -*- valarray class.
2
3// Copyright (C) 1997-2026 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 include/valarray
26 * This is a Standard C++ Library header.
27 */
28
29// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
30
31#ifndef _GLIBCXX_VALARRAY
32#define _GLIBCXX_VALARRAY 1
33
34#ifdef _GLIBCXX_SYSHDR
35#pragma GCC system_header
36#endif
37
38#include <bits/requires_hosted.h> // <cmath> dependant
39
40#include <bits/c++config.h>
41#include <cmath>
42#include <algorithm>
43#include <debug/debug.h>
44#if __cplusplus >= 201103L
45#include <initializer_list>
46#include <bits/range_access.h>
47#endif
48
49#define __glibcxx_want_hardened_valarray
50#define __glibcxx_want_valarray
51#include <bits/version.h>
52
53namespace std _GLIBCXX_VISIBILITY(default)
54{
55_GLIBCXX_BEGIN_NAMESPACE_VERSION
56
57 template<class _Clos, typename _Tp>
58 class _Expr;
59
60 template<typename _Tp1, typename _Tp2>
61 class _ValArray;
62
63namespace __detail
64{
65 template<class _Oper, template<class, class> class _Meta, class _Dom>
66 struct _UnClos;
67
68 template<class _Oper,
69 template<class, class> class _Meta1,
70 template<class, class> class _Meta2,
71 class _Dom1, class _Dom2>
72 struct _BinClos;
73
74 template<template<class, class> class _Meta, class _Dom>
75 struct _SClos;
76
77 template<template<class, class> class _Meta, class _Dom>
78 struct _GClos;
79
80 template<template<class, class> class _Meta, class _Dom>
81 struct _IClos;
82
83 template<template<class, class> class _Meta, class _Dom>
84 struct _ValFunClos;
85
86 template<template<class, class> class _Meta, class _Dom>
87 struct _RefFunClos;
88} // namespace __detail
89
90 using __detail::_UnClos;
91 using __detail::_BinClos;
92 using __detail::_SClos;
93 using __detail::_GClos;
94 using __detail::_IClos;
95 using __detail::_ValFunClos;
96 using __detail::_RefFunClos;
97
98 template<class _Tp> class valarray; // An array of type _Tp
99 class slice; // BLAS-like slice out of an array
100 template<class _Tp> class slice_array;
101 class gslice; // generalized slice out of an array
102 template<class _Tp> class gslice_array;
103 template<class _Tp> class mask_array; // masked array
104 template<class _Tp> class indirect_array; // indirected array
105
106_GLIBCXX_END_NAMESPACE_VERSION
107} // namespace
108
109#include <bits/valarray_array.h>
110#include <bits/valarray_before.h>
111
112namespace std _GLIBCXX_VISIBILITY(default)
113{
114_GLIBCXX_BEGIN_NAMESPACE_VERSION
115
116 /**
117 * @defgroup numeric_arrays Numeric Arrays
118 * @ingroup numerics
119 *
120 * Classes and functions for representing and manipulating arrays of elements.
121 * @{
122 */
123
124 /**
125 * @brief Smart array designed to support numeric processing.
126 *
127 * A valarray is an array that provides constraints intended to allow for
128 * effective optimization of numeric array processing by reducing the
129 * aliasing that can result from pointer representations. It represents a
130 * one-dimensional array from which different multidimensional subsets can
131 * be accessed and modified.
132 *
133 * @tparam _Tp Type of object in the array.
134 */
135 template<class _Tp>
136 class valarray
137 {
138 template<class _Op>
139 struct _UnaryOp
140 {
141 typedef typename __fun<_Op, _Tp>::result_type __rt;
142 typedef _Expr<_UnClos<_Op, _ValArray, _Tp>, __rt> _Rt;
143 };
144 public:
145 typedef _Tp value_type;
146#if __glibcxx_valarray >= 202511L
147 typedef _Tp* iterator;
148 typedef const _Tp* const_iterator;
149#endif
150
151 // _lib.valarray.cons_ construct/destroy:
152 /// Construct an empty array.
153 valarray() _GLIBCXX_NOTHROW;
154
155 /// Construct an array with @a n elements.
156 explicit valarray(size_t);
157
158 /// Construct an array with @a n elements initialized to @a t.
159 valarray(const _Tp&, size_t);
160
161 /// Construct an array initialized to the first @a n elements of @a t.
162 valarray(const _Tp* __restrict__, size_t);
163
164 /// Copy constructor.
165 valarray(const valarray&);
166
167#if __cplusplus >= 201103L
168 /// Move constructor.
169 valarray(valarray&&) noexcept;
170#endif
171
172 /// Construct an array with the same size and values in @a sa.
173 valarray(const slice_array<_Tp>&);
174
175 /// Construct an array with the same size and values in @a ga.
176 valarray(const gslice_array<_Tp>&);
177
178 /// Construct an array with the same size and values in @a ma.
179 valarray(const mask_array<_Tp>&);
180
181 /// Construct an array with the same size and values in @a ia.
182 valarray(const indirect_array<_Tp>&);
183
184#if __cplusplus >= 201103L
185 /// Construct an array with an initializer_list of values.
186 valarray(initializer_list<_Tp>);
187#endif
188
189 template<class _Dom>
190 valarray(const _Expr<_Dom, _Tp>& __e);
191
192 ~valarray() _GLIBCXX_NOEXCEPT;
193
194 // _lib.valarray.assign_ assignment:
195 /**
196 * @brief Assign elements to an array.
197 *
198 * Assign elements of array to values in @a v.
199 *
200 * @param __v Valarray to get values from.
201 */
202 valarray<_Tp>& operator=(const valarray<_Tp>& __v);
203
204#if __cplusplus >= 201103L
205 /**
206 * @brief Move assign elements to an array.
207 *
208 * Move assign elements of array to values in @a v.
209 *
210 * @param __v Valarray to get values from.
211 */
212 valarray<_Tp>& operator=(valarray<_Tp>&& __v) noexcept;
213#endif
214
215 /**
216 * @brief Assign elements to a value.
217 *
218 * Assign all elements of array to @a t.
219 *
220 * @param __t Value for elements.
221 */
222 valarray<_Tp>& operator=(const _Tp& __t);
223
224 /**
225 * @brief Assign elements to an array subset.
226 *
227 * Assign elements of array to values in @a sa. Results are undefined
228 * if @a sa does not have the same size as this array.
229 *
230 * @param __sa Array slice to get values from.
231 */
232 valarray<_Tp>& operator=(const slice_array<_Tp>& __sa);
233
234 /**
235 * @brief Assign elements to an array subset.
236 *
237 * Assign elements of array to values in @a ga. Results are undefined
238 * if @a ga does not have the same size as this array.
239 *
240 * @param __ga Array slice to get values from.
241 */
242 valarray<_Tp>& operator=(const gslice_array<_Tp>& __ga);
243
244 /**
245 * @brief Assign elements to an array subset.
246 *
247 * Assign elements of array to values in @a ma. Results are undefined
248 * if @a ma does not have the same size as this array.
249 *
250 * @param __ma Array slice to get values from.
251 */
252 valarray<_Tp>& operator=(const mask_array<_Tp>& __ma);
253
254 /**
255 * @brief Assign elements to an array subset.
256 *
257 * Assign elements of array to values in @a ia. Results are undefined
258 * if @a ia does not have the same size as this array.
259 *
260 * @param __ia Array slice to get values from.
261 */
262 valarray<_Tp>& operator=(const indirect_array<_Tp>& __ia);
263
264#if __cplusplus >= 201103L
265 /**
266 * @brief Assign elements to an initializer_list.
267 *
268 * Assign elements of array to values in @a __l. Results are undefined
269 * if @a __l does not have the same size as this array.
270 *
271 * @param __l initializer_list to get values from.
272 */
273 valarray& operator=(initializer_list<_Tp> __l);
274#endif
275
276 template<class _Dom> valarray<_Tp>&
277 operator= (const _Expr<_Dom, _Tp>&);
278
279 // _lib.valarray.access_ element access:
280 /**
281 * Return a reference to the i'th array element.
282 *
283 * @param __i Index of element to return.
284 * @return Reference to the i'th element.
285 */
286 _Tp& operator[](size_t __i) _GLIBCXX_NOTHROW;
287
288 // _GLIBCXX_RESOLVE_LIB_DEFECTS
289 // 389. Const overload of valarray::operator[] returns by value.
290 const _Tp& operator[](size_t) const _GLIBCXX_NOTHROW;
291
292 // _lib.valarray.sub_ subset operations:
293 /**
294 * @brief Return an array subset.
295 *
296 * Returns a new valarray containing the elements of the array
297 * indicated by the slice argument. The new valarray has the same size
298 * as the input slice. @see slice.
299 *
300 * @param __s The source slice.
301 * @return New valarray containing elements in @a __s.
302 */
303 _Expr<_SClos<_ValArray, _Tp>, _Tp> operator[](slice __s) const;
304
305 /**
306 * @brief Return a reference to an array subset.
307 *
308 * Returns a new valarray containing the elements of the array
309 * indicated by the slice argument. The new valarray has the same size
310 * as the input slice. @see slice.
311 *
312 * @param __s The source slice.
313 * @return New valarray containing elements in @a __s.
314 */
315 slice_array<_Tp> operator[](slice __s);
316
317 /**
318 * @brief Return an array subset.
319 *
320 * Returns a slice_array referencing the elements of the array
321 * indicated by the slice argument. @see gslice.
322 *
323 * @param __s The source slice.
324 * @return Slice_array referencing elements indicated by @a __s.
325 */
326 _Expr<_GClos<_ValArray, _Tp>, _Tp> operator[](const gslice& __s) const;
327
328 /**
329 * @brief Return a reference to an array subset.
330 *
331 * Returns a new valarray containing the elements of the array
332 * indicated by the gslice argument. The new valarray has
333 * the same size as the input gslice. @see gslice.
334 *
335 * @param __s The source gslice.
336 * @return New valarray containing elements in @a __s.
337 */
338 gslice_array<_Tp> operator[](const gslice& __s);
339
340 /**
341 * @brief Return an array subset.
342 *
343 * Returns a new valarray containing the elements of the array
344 * indicated by the argument. The input is a valarray of bool which
345 * represents a bitmask indicating which elements should be copied into
346 * the new valarray. Each element of the array is added to the return
347 * valarray if the corresponding element of the argument is true.
348 *
349 * @param __m The valarray bitmask.
350 * @return New valarray containing elements indicated by @a __m.
351 */
352 valarray<_Tp> operator[](const valarray<bool>& __m) const;
353
354 /**
355 * @brief Return a reference to an array subset.
356 *
357 * Returns a new mask_array referencing the elements of the array
358 * indicated by the argument. The input is a valarray of bool which
359 * represents a bitmask indicating which elements are part of the
360 * subset. Elements of the array are part of the subset if the
361 * corresponding element of the argument is true.
362 *
363 * @param __m The valarray bitmask.
364 * @return New valarray containing elements indicated by @a __m.
365 */
366 mask_array<_Tp> operator[](const valarray<bool>& __m);
367
368 /**
369 * @brief Return an array subset.
370 *
371 * Returns a new valarray containing the elements of the array
372 * indicated by the argument. The elements in the argument are
373 * interpreted as the indices of elements of this valarray to copy to
374 * the return valarray.
375 *
376 * @param __i The valarray element index list.
377 * @return New valarray containing elements in @a __s.
378 */
379 _Expr<_IClos<_ValArray, _Tp>, _Tp>
380 operator[](const valarray<size_t>& __i) const;
381
382 /**
383 * @brief Return a reference to an array subset.
384 *
385 * Returns an indirect_array referencing the elements of the array
386 * indicated by the argument. The elements in the argument are
387 * interpreted as the indices of elements of this valarray to include
388 * in the subset. The returned indirect_array refers to these
389 * elements.
390 *
391 * @param __i The valarray element index list.
392 * @return Indirect_array referencing elements in @a __i.
393 */
394 indirect_array<_Tp> operator[](const valarray<size_t>& __i);
395
396 // _lib.valarray.unary_ unary operators:
397 /// Return a new valarray by applying unary + to each element.
398 typename _UnaryOp<__unary_plus>::_Rt operator+() const;
399
400 /// Return a new valarray by applying unary - to each element.
401 typename _UnaryOp<__negate>::_Rt operator-() const;
402
403 /// Return a new valarray by applying unary ~ to each element.
404 typename _UnaryOp<__bitwise_not>::_Rt operator~() const;
405
406 /// Return a new valarray by applying unary ! to each element.
407 typename _UnaryOp<__logical_not>::_Rt operator!() const;
408
409 // _lib.valarray.cassign_ computed assignment:
410 /// Multiply each element of array by @a t.
411 valarray<_Tp>& operator*=(const _Tp&);
412
413 /// Divide each element of array by @a t.
414 valarray<_Tp>& operator/=(const _Tp&);
415
416 /// Set each element e of array to e % @a t.
417 valarray<_Tp>& operator%=(const _Tp&);
418
419 /// Add @a t to each element of array.
420 valarray<_Tp>& operator+=(const _Tp&);
421
422 /// Subtract @a t to each element of array.
423 valarray<_Tp>& operator-=(const _Tp&);
424
425 /// Set each element e of array to e ^ @a t.
426 valarray<_Tp>& operator^=(const _Tp&);
427
428 /// Set each element e of array to e & @a t.
429 valarray<_Tp>& operator&=(const _Tp&);
430
431 /// Set each element e of array to e | @a t.
432 valarray<_Tp>& operator|=(const _Tp&);
433
434 /// Left shift each element e of array by @a t bits.
435 valarray<_Tp>& operator<<=(const _Tp&);
436
437 /// Right shift each element e of array by @a t bits.
438 valarray<_Tp>& operator>>=(const _Tp&);
439
440 /// Multiply elements of array by corresponding elements of @a v.
441 valarray<_Tp>& operator*=(const valarray<_Tp>&);
442
443 /// Divide elements of array by corresponding elements of @a v.
444 valarray<_Tp>& operator/=(const valarray<_Tp>&);
445
446 /// Modulo elements of array by corresponding elements of @a v.
447 valarray<_Tp>& operator%=(const valarray<_Tp>&);
448
449 /// Add corresponding elements of @a v to elements of array.
450 valarray<_Tp>& operator+=(const valarray<_Tp>&);
451
452 /// Subtract corresponding elements of @a v from elements of array.
453 valarray<_Tp>& operator-=(const valarray<_Tp>&);
454
455 /// Logical xor corresponding elements of @a v with elements of array.
456 valarray<_Tp>& operator^=(const valarray<_Tp>&);
457
458 /// Logical or corresponding elements of @a v with elements of array.
459 valarray<_Tp>& operator|=(const valarray<_Tp>&);
460
461 /// Logical and corresponding elements of @a v with elements of array.
462 valarray<_Tp>& operator&=(const valarray<_Tp>&);
463
464 /// Left shift elements of array by corresponding elements of @a v.
465 valarray<_Tp>& operator<<=(const valarray<_Tp>&);
466
467 /// Right shift elements of array by corresponding elements of @a v.
468 valarray<_Tp>& operator>>=(const valarray<_Tp>&);
469
470 template<class _Dom>
471 valarray<_Tp>& operator*=(const _Expr<_Dom, _Tp>&);
472 template<class _Dom>
473 valarray<_Tp>& operator/=(const _Expr<_Dom, _Tp>&);
474 template<class _Dom>
475 valarray<_Tp>& operator%=(const _Expr<_Dom, _Tp>&);
476 template<class _Dom>
477 valarray<_Tp>& operator+=(const _Expr<_Dom, _Tp>&);
478 template<class _Dom>
479 valarray<_Tp>& operator-=(const _Expr<_Dom, _Tp>&);
480 template<class _Dom>
481 valarray<_Tp>& operator^=(const _Expr<_Dom, _Tp>&);
482 template<class _Dom>
483 valarray<_Tp>& operator|=(const _Expr<_Dom, _Tp>&);
484 template<class _Dom>
485 valarray<_Tp>& operator&=(const _Expr<_Dom, _Tp>&);
486 template<class _Dom>
487 valarray<_Tp>& operator<<=(const _Expr<_Dom, _Tp>&);
488 template<class _Dom>
489 valarray<_Tp>& operator>>=(const _Expr<_Dom, _Tp>&);
490
491 // _lib.valarray.members_ member functions:
492#if __cplusplus >= 201103L
493 /// Swap.
494 void swap(valarray<_Tp>& __v) noexcept;
495#endif
496
497 /// Return the number of elements in array.
498 size_t size() const;
499
500 /**
501 * @brief Return the sum of all elements in the array.
502 *
503 * Accumulates the sum of all elements into a Tp using +=. The order
504 * of adding the elements is unspecified.
505 */
506 _Tp sum() const;
507
508 /// Return the minimum element using operator<().
509 _Tp min() const;
510
511 /// Return the maximum element using operator<().
512 _Tp max() const;
513
514 /**
515 * @brief Return a shifted array.
516 *
517 * A new valarray is constructed as a copy of this array with elements
518 * in shifted positions. For an element with index i, the new position
519 * is i - n. The new valarray has the same size as the current one.
520 * New elements without a value are set to 0. Elements whose new
521 * position is outside the bounds of the array are discarded.
522 *
523 * Positive arguments shift toward index 0, discarding elements [0, n).
524 * Negative arguments discard elements from the top of the array.
525 *
526 * @param __n Number of element positions to shift.
527 * @return New valarray with elements in shifted positions.
528 */
529 valarray<_Tp> shift (int __n) const;
530
531 /**
532 * @brief Return a rotated array.
533 *
534 * A new valarray is constructed as a copy of this array with elements
535 * in shifted positions. For an element with index i, the new position
536 * is (i - n) % size(). The new valarray has the same size as the
537 * current one. Elements that are shifted beyond the array bounds are
538 * shifted into the other end of the array. No elements are lost.
539 *
540 * Positive arguments shift toward index 0, wrapping around the top.
541 * Negative arguments shift towards the top, wrapping around to 0.
542 *
543 * @param __n Number of element positions to rotate.
544 * @return New valarray with elements in shifted positions.
545 */
546 valarray<_Tp> cshift(int __n) const;
547
548 /**
549 * @brief Apply a function to the array.
550 *
551 * Returns a new valarray with elements assigned to the result of
552 * applying __func to the corresponding element of this array. The new
553 * array has the same size as this one.
554 *
555 * @param __func Function of Tp returning Tp to apply.
556 * @return New valarray with transformed elements.
557 */
558 _Expr<_ValFunClos<_ValArray, _Tp>, _Tp> apply(_Tp __func(_Tp)) const;
559
560 /**
561 * @brief Apply a function to the array.
562 *
563 * Returns a new valarray with elements assigned to the result of
564 * applying __func to the corresponding element of this array. The new
565 * array has the same size as this one.
566 *
567 * @param __func Function of const Tp& returning Tp to apply.
568 * @return New valarray with transformed elements.
569 */
570 _Expr<_RefFunClos<_ValArray, _Tp>, _Tp> apply(_Tp __func(const _Tp&)) const;
571
572 /**
573 * @brief Resize array.
574 *
575 * Resize this array to @a size and set all elements to @a c. All
576 * references and iterators are invalidated.
577 *
578 * @param __size New array size.
579 * @param __c New value for all elements.
580 */
581 void resize(size_t __size, _Tp __c = _Tp());
582
583#if __glibcxx_valarray >= 202511L
584 /**
585 * @brief Return an iterator pointing to the first element of
586 * the valarray.
587 */
588 [[nodiscard]]
589 iterator
590 begin() noexcept
591 { return _M_data; }
592
593 [[nodiscard]]
594 const_iterator
595 begin() const noexcept
596 { return _M_data; }
597
598 /**
599 * @brief Return an iterator pointing to one past the last element of
600 * the valarray.
601 */
602 [[nodiscard]]
603 iterator
604 end() noexcept
605 { return _M_data + _M_size; }
606
607 [[nodiscard]]
608 const_iterator
609 end() const noexcept
610 { return _M_data + _M_size; }
611#endif
612
613 private:
614 size_t _M_size;
615 _Tp* __restrict__ _M_data;
616
617 friend struct _Array<_Tp>;
618 };
619
620#if __cpp_deduction_guides >= 201606
621 template<typename _Tp, size_t _Nm>
622 valarray(const _Tp(&)[_Nm], size_t) -> valarray<_Tp>;
623#endif
624
625 template<typename _Tp>
626 inline const _Tp&
627 valarray<_Tp>::operator[](size_t __i) const _GLIBCXX_NOTHROW
628 {
629 __glibcxx_requires_subscript(__i);
630 return _M_data[__i];
631 }
632
633 template<typename _Tp>
634 inline _Tp&
635 valarray<_Tp>::operator[](size_t __i) _GLIBCXX_NOTHROW
636 {
637 __glibcxx_requires_subscript(__i);
638 return _M_data[__i];
639 }
640
641 /// @} group numeric_arrays
642
643_GLIBCXX_END_NAMESPACE_VERSION
644} // namespace
645
646#include <bits/valarray_after.h>
647#include <bits/slice_array.h>
648#include <bits/gslice.h>
649#include <bits/gslice_array.h>
650#include <bits/mask_array.h>
651#include <bits/indirect_array.h>
652
653namespace std _GLIBCXX_VISIBILITY(default)
654{
655_GLIBCXX_BEGIN_NAMESPACE_VERSION
656
657 /**
658 * @addtogroup numeric_arrays
659 * @{
660 */
661
662 template<typename _Tp>
663 inline
664 valarray<_Tp>::valarray() _GLIBCXX_NOTHROW : _M_size(0), _M_data(0) {}
665
666 template<typename _Tp>
667 inline
668 valarray<_Tp>::valarray(size_t __n)
669 : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
670 { std::__valarray_default_construct(_M_data, _M_data + __n); }
671
672 template<typename _Tp>
673 inline
674 valarray<_Tp>::valarray(const _Tp& __t, size_t __n)
675 : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
676 { std::__valarray_fill_construct(_M_data, _M_data + __n, __t); }
677
678 template<typename _Tp>
679 inline
680 valarray<_Tp>::valarray(const _Tp* __restrict__ __p, size_t __n)
681 : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
682 {
683 __glibcxx_assert(__p != 0 || __n == 0);
684 std::__valarray_copy_construct(__p, __p + __n, _M_data);
685 }
686
687 template<typename _Tp>
688 inline
689 valarray<_Tp>::valarray(const valarray<_Tp>& __v)
690 : _M_size(__v._M_size), _M_data(__valarray_get_storage<_Tp>(__v._M_size))
691 { std::__valarray_copy_construct(__v._M_data, __v._M_data + _M_size,
692 _M_data); }
693
694#if __cplusplus >= 201103L
695 template<typename _Tp>
696 inline
697 valarray<_Tp>::valarray(valarray<_Tp>&& __v) noexcept
698 : _M_size(__v._M_size), _M_data(__v._M_data)
699 {
700 __v._M_size = 0;
701 __v._M_data = 0;
702 }
703#endif
704
705 template<typename _Tp>
706 inline
707 valarray<_Tp>::valarray(const slice_array<_Tp>& __sa)
708 : _M_size(__sa._M_sz), _M_data(__valarray_get_storage<_Tp>(__sa._M_sz))
709 {
710 std::__valarray_copy_construct
711 (__sa._M_array, __sa._M_sz, __sa._M_stride, _Array<_Tp>(_M_data));
712 }
713
714 template<typename _Tp>
715 inline
716 valarray<_Tp>::valarray(const gslice_array<_Tp>& __ga)
717 : _M_size(__ga._M_index.size()),
718 _M_data(__valarray_get_storage<_Tp>(_M_size))
719 {
720 std::__valarray_copy_construct
721 (__ga._M_array, _Array<size_t>(__ga._M_index),
722 _Array<_Tp>(_M_data), _M_size);
723 }
724
725 template<typename _Tp>
726 inline
727 valarray<_Tp>::valarray(const mask_array<_Tp>& __ma)
728 : _M_size(__ma._M_sz), _M_data(__valarray_get_storage<_Tp>(__ma._M_sz))
729 {
730 std::__valarray_copy_construct
731 (__ma._M_array, __ma._M_mask, _Array<_Tp>(_M_data), _M_size);
732 }
733
734 template<typename _Tp>
735 inline
736 valarray<_Tp>::valarray(const indirect_array<_Tp>& __ia)
737 : _M_size(__ia._M_sz), _M_data(__valarray_get_storage<_Tp>(__ia._M_sz))
738 {
739 std::__valarray_copy_construct
740 (__ia._M_array, __ia._M_index, _Array<_Tp>(_M_data), _M_size);
741 }
742
743#if __cplusplus >= 201103L
744 template<typename _Tp>
745 inline
746 valarray<_Tp>::valarray(initializer_list<_Tp> __l)
747 : _M_size(__l.size()), _M_data(__valarray_get_storage<_Tp>(__l.size()))
748 { std::__valarray_copy_construct(__l.begin(), __l.end(), _M_data); }
749#endif
750
751 template<typename _Tp> template<class _Dom>
752 inline
753 valarray<_Tp>::valarray(const _Expr<_Dom, _Tp>& __e)
754 : _M_size(__e.size()), _M_data(__valarray_get_storage<_Tp>(_M_size))
755 { std::__valarray_copy_construct(__e, _M_size, _Array<_Tp>(_M_data)); }
756
757 template<typename _Tp>
758 inline
759 valarray<_Tp>::~valarray() _GLIBCXX_NOEXCEPT
760 {
761 std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
762 std::__valarray_release_memory(_M_data, _M_size);
763 }
764
765 template<typename _Tp>
766 inline valarray<_Tp>&
767 valarray<_Tp>::operator=(const valarray<_Tp>& __v)
768 {
769 // _GLIBCXX_RESOLVE_LIB_DEFECTS
770 // 630. arrays of valarray.
771 if (_M_size == __v._M_size)
772 std::__valarray_copy(__v._M_data, _M_size, _M_data);
773 else
774 {
775 if (_M_data)
776 {
777 std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
778 std::__valarray_release_memory(_M_data, _M_size);
779 }
780 _M_size = __v._M_size;
781 _M_data = __valarray_get_storage<_Tp>(_M_size);
782 std::__valarray_copy_construct(__v._M_data, __v._M_data + _M_size,
783 _M_data);
784 }
785 return *this;
786 }
787
788#if __cplusplus >= 201103L
789 template<typename _Tp>
790 inline valarray<_Tp>&
791 valarray<_Tp>::operator=(valarray<_Tp>&& __v) noexcept
792 {
793 if (_M_data)
794 {
795 std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
796 std::__valarray_release_memory(_M_data, _M_size);
797 }
798 _M_size = __v._M_size;
799 _M_data = __v._M_data;
800 __v._M_size = 0;
801 __v._M_data = 0;
802 return *this;
803 }
804
805 template<typename _Tp>
806 inline valarray<_Tp>&
807 valarray<_Tp>::operator=(initializer_list<_Tp> __l)
808 {
809 // _GLIBCXX_RESOLVE_LIB_DEFECTS
810 // 630. arrays of valarray.
811 if (_M_size == __l.size())
812 std::__valarray_copy(__l.begin(), __l.size(), _M_data);
813 else
814 {
815 if (_M_data)
816 {
817 std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
818 std::__valarray_release_memory(_M_data, _M_size);
819 }
820 _M_size = __l.size();
821 _M_data = __valarray_get_storage<_Tp>(_M_size);
822 std::__valarray_copy_construct(__l.begin(), __l.begin() + _M_size,
823 _M_data);
824 }
825 return *this;
826 }
827#endif
828
829 template<typename _Tp>
830 inline valarray<_Tp>&
831 valarray<_Tp>::operator=(const _Tp& __t)
832 {
833 std::__valarray_fill(_M_data, _M_size, __t);
834 return *this;
835 }
836
837 template<typename _Tp>
838 inline valarray<_Tp>&
839 valarray<_Tp>::operator=(const slice_array<_Tp>& __sa)
840 {
841 __glibcxx_assert(_M_size == __sa._M_sz);
842 std::__valarray_copy(__sa._M_array, __sa._M_sz,
843 __sa._M_stride, _Array<_Tp>(_M_data));
844 return *this;
845 }
846
847 template<typename _Tp>
848 inline valarray<_Tp>&
849 valarray<_Tp>::operator=(const gslice_array<_Tp>& __ga)
850 {
851 __glibcxx_assert(_M_size == __ga._M_index.size());
852 std::__valarray_copy(__ga._M_array, _Array<size_t>(__ga._M_index),
853 _Array<_Tp>(_M_data), _M_size);
854 return *this;
855 }
856
857 template<typename _Tp>
858 inline valarray<_Tp>&
859 valarray<_Tp>::operator=(const mask_array<_Tp>& __ma)
860 {
861 __glibcxx_assert(_M_size == __ma._M_sz);
862 std::__valarray_copy(__ma._M_array, __ma._M_mask,
863 _Array<_Tp>(_M_data), _M_size);
864 return *this;
865 }
866
867 template<typename _Tp>
868 inline valarray<_Tp>&
869 valarray<_Tp>::operator=(const indirect_array<_Tp>& __ia)
870 {
871 __glibcxx_assert(_M_size == __ia._M_sz);
872 std::__valarray_copy(__ia._M_array, __ia._M_index,
873 _Array<_Tp>(_M_data), _M_size);
874 return *this;
875 }
876
877 template<typename _Tp> template<class _Dom>
878 inline valarray<_Tp>&
879 valarray<_Tp>::operator=(const _Expr<_Dom, _Tp>& __e)
880 {
881 // _GLIBCXX_RESOLVE_LIB_DEFECTS
882 // 630. arrays of valarray.
883 if (_M_size == __e.size())
884 {
885 // Copy manually instead of using __valarray_copy, because __e might
886 // alias _M_data and the _Array param type of __valarray_copy uses
887 // restrict which doesn't allow aliasing.
888 for (size_t __i = 0; __i < _M_size; ++__i)
889 _M_data[__i] = __e[__i];
890 }
891 else
892 {
893 if (_M_data)
894 {
895 std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
896 std::__valarray_release_memory(_M_data, _M_size);
897 }
898 _M_size = __e.size();
899 _M_data = __valarray_get_storage<_Tp>(_M_size);
900 std::__valarray_copy_construct(__e, _M_size, _Array<_Tp>(_M_data));
901 }
902 return *this;
903 }
904
905 template<typename _Tp>
906 inline _Expr<_SClos<_ValArray,_Tp>, _Tp>
907 valarray<_Tp>::operator[](slice __s) const
908 {
909 typedef _SClos<_ValArray,_Tp> _Closure;
910 return _Expr<_Closure, _Tp>(_Closure (_Array<_Tp>(_M_data), __s));
911 }
912
913 template<typename _Tp>
914 inline slice_array<_Tp>
915 valarray<_Tp>::operator[](slice __s)
916 { return slice_array<_Tp>(_Array<_Tp>(_M_data), __s); }
917
918 template<typename _Tp>
919 inline _Expr<_GClos<_ValArray,_Tp>, _Tp>
920 valarray<_Tp>::operator[](const gslice& __gs) const
921 {
922 typedef _GClos<_ValArray,_Tp> _Closure;
923 return _Expr<_Closure, _Tp>
924 (_Closure(_Array<_Tp>(_M_data), __gs._M_index->_M_index));
925 }
926
927 template<typename _Tp>
928 inline gslice_array<_Tp>
929 valarray<_Tp>::operator[](const gslice& __gs)
930 {
931 return gslice_array<_Tp>
932 (_Array<_Tp>(_M_data), __gs._M_index->_M_index);
933 }
934
935 template<typename _Tp>
936 inline valarray<_Tp>
937 valarray<_Tp>::operator[](const valarray<bool>& __m) const
938 {
939 size_t __s = 0;
940 size_t __e = __m.size();
941 for (size_t __i=0; __i<__e; ++__i)
942 if (__m[__i]) ++__s;
943 __glibcxx_assert(__s <= _M_size);
944 return valarray<_Tp>(mask_array<_Tp>(_Array<_Tp>(_M_data), __s,
945 _Array<bool> (__m)));
946 }
947
948 template<typename _Tp>
949 inline mask_array<_Tp>
950 valarray<_Tp>::operator[](const valarray<bool>& __m)
951 {
952 size_t __s = 0;
953 size_t __e = __m.size();
954 for (size_t __i=0; __i<__e; ++__i)
955 if (__m[__i]) ++__s;
956 __glibcxx_assert(__s <= _M_size);
957 return mask_array<_Tp>(_Array<_Tp>(_M_data), __s, _Array<bool>(__m));
958 }
959
960 template<typename _Tp>
961 inline _Expr<_IClos<_ValArray,_Tp>, _Tp>
962 valarray<_Tp>::operator[](const valarray<size_t>& __i) const
963 {
964 typedef _IClos<_ValArray,_Tp> _Closure;
965 return _Expr<_Closure, _Tp>(_Closure(*this, __i));
966 }
967
968 template<typename _Tp>
969 inline indirect_array<_Tp>
970 valarray<_Tp>::operator[](const valarray<size_t>& __i)
971 {
972 return indirect_array<_Tp>(_Array<_Tp>(_M_data), __i.size(),
973 _Array<size_t>(__i));
974 }
975
976#if __cplusplus >= 201103L
977 template<class _Tp>
978 inline void
979 valarray<_Tp>::swap(valarray<_Tp>& __v) noexcept
980 {
981 std::swap(_M_size, __v._M_size);
982 std::swap(_M_data, __v._M_data);
983 }
984#endif
985
986 template<class _Tp>
987 inline size_t
988 valarray<_Tp>::size() const
989 { return _M_size; }
990
991 template<class _Tp>
992 inline _Tp
993 valarray<_Tp>::sum() const
994 {
995 __glibcxx_assert(_M_size > 0);
996 return std::__valarray_sum(_M_data, _M_data + _M_size);
997 }
998
999 template<class _Tp>
1000 inline valarray<_Tp>
1001 valarray<_Tp>::shift(int __n) const
1002 {
1003 valarray<_Tp> __ret;
1004
1005 if (_M_size == 0)
1006 return __ret;
1007
1008 _Tp* __restrict__ __tmp_M_data =
1009 std::__valarray_get_storage<_Tp>(_M_size);
1010
1011 if (__n == 0)
1012 std::__valarray_copy_construct(_M_data,
1013 _M_data + _M_size, __tmp_M_data);
1014 else if (__n > 0) // shift left
1015 {
1016 if (size_t(__n) > _M_size)
1017 __n = int(_M_size);
1018
1019 std::__valarray_copy_construct(_M_data + __n,
1020 _M_data + _M_size, __tmp_M_data);
1021 std::__valarray_default_construct(__tmp_M_data + _M_size - __n,
1022 __tmp_M_data + _M_size);
1023 }
1024 else // shift right
1025 {
1026 if (-size_t(__n) > _M_size)
1027 __n = -int(_M_size);
1028
1029 std::__valarray_copy_construct(_M_data, _M_data + _M_size + __n,
1030 __tmp_M_data - __n);
1031 std::__valarray_default_construct(__tmp_M_data,
1032 __tmp_M_data - __n);
1033 }
1034
1035 __ret._M_size = _M_size;
1036 __ret._M_data = __tmp_M_data;
1037 return __ret;
1038 }
1039
1040 template<class _Tp>
1041 inline valarray<_Tp>
1042 valarray<_Tp>::cshift(int __n) const
1043 {
1044 valarray<_Tp> __ret;
1045
1046 if (_M_size == 0)
1047 return __ret;
1048
1049 _Tp* __restrict__ __tmp_M_data =
1050 std::__valarray_get_storage<_Tp>(_M_size);
1051
1052 if (__n == 0)
1053 std::__valarray_copy_construct(_M_data,
1054 _M_data + _M_size, __tmp_M_data);
1055 else if (__n > 0) // cshift left
1056 {
1057 if (size_t(__n) > _M_size)
1058 __n = int(__n % _M_size);
1059
1060 std::__valarray_copy_construct(_M_data, _M_data + __n,
1061 __tmp_M_data + _M_size - __n);
1062 std::__valarray_copy_construct(_M_data + __n, _M_data + _M_size,
1063 __tmp_M_data);
1064 }
1065 else // cshift right
1066 {
1067 if (-size_t(__n) > _M_size)
1068 __n = -int(-size_t(__n) % _M_size);
1069
1070 std::__valarray_copy_construct(_M_data + _M_size + __n,
1071 _M_data + _M_size, __tmp_M_data);
1072 std::__valarray_copy_construct(_M_data, _M_data + _M_size + __n,
1073 __tmp_M_data - __n);
1074 }
1075
1076 __ret._M_size = _M_size;
1077 __ret._M_data = __tmp_M_data;
1078 return __ret;
1079 }
1080
1081 template<class _Tp>
1082 inline void
1083 valarray<_Tp>::resize(size_t __n, _Tp __c)
1084 {
1085 // This complication is so to make valarray<valarray<T> > work
1086 // even though it is not required by the standard. Nobody should
1087 // be saying valarray<valarray<T> > anyway. See the specs.
1088 std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
1089 if (_M_size != __n)
1090 {
1091 std::__valarray_release_memory(_M_data, _M_size);
1092 _M_size = __n;
1093 _M_data = __valarray_get_storage<_Tp>(__n);
1094 }
1095 std::__valarray_fill_construct(_M_data, _M_data + __n, __c);
1096 }
1097
1098 template<typename _Tp>
1099 inline _Tp
1100 valarray<_Tp>::min() const
1101 {
1102 __glibcxx_assert(_M_size > 0);
1103 return *std::min_element(_M_data, _M_data + _M_size);
1104 }
1105
1106 template<typename _Tp>
1107 inline _Tp
1108 valarray<_Tp>::max() const
1109 {
1110 __glibcxx_assert(_M_size > 0);
1111 return *std::max_element(_M_data, _M_data + _M_size);
1112 }
1113
1114 template<class _Tp>
1115 inline _Expr<_ValFunClos<_ValArray, _Tp>, _Tp>
1116 valarray<_Tp>::apply(_Tp __func(_Tp)) const
1117 {
1118 typedef _ValFunClos<_ValArray, _Tp> _Closure;
1119 return _Expr<_Closure, _Tp>(_Closure(*this, __func));
1120 }
1121
1122 template<class _Tp>
1123 inline _Expr<_RefFunClos<_ValArray, _Tp>, _Tp>
1124 valarray<_Tp>::apply(_Tp __func(const _Tp &)) const
1125 {
1126 typedef _RefFunClos<_ValArray, _Tp> _Closure;
1127 return _Expr<_Closure, _Tp>(_Closure(*this, __func));
1128 }
1129
1130 /// @cond undocumented
1131#define _DEFINE_VALARRAY_UNARY_OPERATOR(_Op, _Name) \
1132 template<typename _Tp> \
1133 inline typename valarray<_Tp>::template _UnaryOp<_Name>::_Rt \
1134 valarray<_Tp>::operator _Op() const \
1135 { \
1136 typedef _UnClos<_Name, _ValArray, _Tp> _Closure; \
1137 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
1138 return _Expr<_Closure, _Rt>(_Closure(*this)); \
1139 }
1140
1141 _DEFINE_VALARRAY_UNARY_OPERATOR(+, __unary_plus)
1142 _DEFINE_VALARRAY_UNARY_OPERATOR(-, __negate)
1143 _DEFINE_VALARRAY_UNARY_OPERATOR(~, __bitwise_not)
1144 _DEFINE_VALARRAY_UNARY_OPERATOR (!, __logical_not)
1145
1146#undef _DEFINE_VALARRAY_UNARY_OPERATOR
1147
1148#define _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(_Op, _Name) \
1149 template<class _Tp> \
1150 inline valarray<_Tp>& \
1151 valarray<_Tp>::operator _Op##=(const _Tp &__t) \
1152 { \
1153 _Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size, __t); \
1154 return *this; \
1155 } \
1156 \
1157 template<class _Tp> \
1158 inline valarray<_Tp>& \
1159 valarray<_Tp>::operator _Op##=(const valarray<_Tp> &__v) \
1160 { \
1161 __glibcxx_assert(_M_size == __v._M_size); \
1162 _Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size, \
1163 _Array<_Tp>(__v._M_data)); \
1164 return *this; \
1165 }
1166
1167_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(+, __plus)
1168_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(-, __minus)
1169_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(*, __multiplies)
1170_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(/, __divides)
1171_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(%, __modulus)
1172_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(^, __bitwise_xor)
1173_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(&, __bitwise_and)
1174_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(|, __bitwise_or)
1175_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(<<, __shift_left)
1176_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(>>, __shift_right)
1177
1178#undef _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT
1179
1180#define _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(_Op, _Name) \
1181 template<class _Tp> template<class _Dom> \
1182 inline valarray<_Tp>& \
1183 valarray<_Tp>::operator _Op##=(const _Expr<_Dom, _Tp>& __e) \
1184 { \
1185 _Array_augmented_##_Name(_Array<_Tp>(_M_data), __e, _M_size); \
1186 return *this; \
1187 }
1188
1189_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(+, __plus)
1190_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(-, __minus)
1191_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(*, __multiplies)
1192_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(/, __divides)
1193_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(%, __modulus)
1194_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(^, __bitwise_xor)
1195_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(&, __bitwise_and)
1196_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(|, __bitwise_or)
1197_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(<<, __shift_left)
1198_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(>>, __shift_right)
1199
1200#undef _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT
1201
1202
1203#define _DEFINE_BINARY_OPERATOR(_Op, _Name) \
1204 template<typename _Tp> \
1205 inline _Expr<_BinClos<_Name, _ValArray, _ValArray, _Tp, _Tp>, \
1206 typename __fun<_Name, _Tp>::result_type> \
1207 operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \
1208 { \
1209 __glibcxx_assert(__v.size() == __w.size()); \
1210 typedef _BinClos<_Name, _ValArray, _ValArray, _Tp, _Tp> _Closure; \
1211 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
1212 return _Expr<_Closure, _Rt>(_Closure(__v, __w)); \
1213 } \
1214 \
1215 template<typename _Tp> \
1216 inline _Expr<_BinClos<_Name, _ValArray,_Constant, _Tp, _Tp>, \
1217 typename __fun<_Name, _Tp>::result_type> \
1218 operator _Op(const valarray<_Tp>& __v, \
1219 const typename valarray<_Tp>::value_type& __t) \
1220 { \
1221 typedef _BinClos<_Name, _ValArray, _Constant, _Tp, _Tp> _Closure; \
1222 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
1223 return _Expr<_Closure, _Rt>(_Closure(__v, __t)); \
1224 } \
1225 \
1226 template<typename _Tp> \
1227 inline _Expr<_BinClos<_Name, _Constant, _ValArray, _Tp, _Tp>, \
1228 typename __fun<_Name, _Tp>::result_type> \
1229 operator _Op(const typename valarray<_Tp>::value_type& __t, \
1230 const valarray<_Tp>& __v) \
1231 { \
1232 typedef _BinClos<_Name, _Constant, _ValArray, _Tp, _Tp> _Closure; \
1233 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
1234 return _Expr<_Closure, _Rt>(_Closure(__t, __v)); \
1235 }
1236
1237_DEFINE_BINARY_OPERATOR(+, __plus)
1238_DEFINE_BINARY_OPERATOR(-, __minus)
1239_DEFINE_BINARY_OPERATOR(*, __multiplies)
1240_DEFINE_BINARY_OPERATOR(/, __divides)
1241_DEFINE_BINARY_OPERATOR(%, __modulus)
1242_DEFINE_BINARY_OPERATOR(^, __bitwise_xor)
1243_DEFINE_BINARY_OPERATOR(&, __bitwise_and)
1244_DEFINE_BINARY_OPERATOR(|, __bitwise_or)
1245_DEFINE_BINARY_OPERATOR(<<, __shift_left)
1246_DEFINE_BINARY_OPERATOR(>>, __shift_right)
1247_DEFINE_BINARY_OPERATOR(&&, __logical_and)
1248_DEFINE_BINARY_OPERATOR(||, __logical_or)
1249_DEFINE_BINARY_OPERATOR(==, __equal_to)
1250_DEFINE_BINARY_OPERATOR(!=, __not_equal_to)
1251_DEFINE_BINARY_OPERATOR(<, __less)
1252_DEFINE_BINARY_OPERATOR(>, __greater)
1253_DEFINE_BINARY_OPERATOR(<=, __less_equal)
1254_DEFINE_BINARY_OPERATOR(>=, __greater_equal)
1255
1256#undef _DEFINE_BINARY_OPERATOR
1257 /// @endcond
1258
1259#if (__cplusplus >= 201103L) && (__glibcxx_valarray < 202511L)
1260 /**
1261 * @brief Return an iterator pointing to the first element of
1262 * the valarray.
1263 * @param __va valarray.
1264 */
1265 template<class _Tp>
1266 [[__nodiscard__]]
1267 inline _Tp*
1268 begin(valarray<_Tp>& __va) noexcept
1269 { return __va.size() ? std::__addressof(__va[0]) : nullptr; }
1270
1271 /**
1272 * @brief Return an iterator pointing to the first element of
1273 * the const valarray.
1274 * @param __va valarray.
1275 */
1276 template<class _Tp>
1277 [[__nodiscard__]]
1278 inline const _Tp*
1279 begin(const valarray<_Tp>& __va) noexcept
1280 { return __va.size() ? std::__addressof(__va[0]) : nullptr; }
1281
1282 /**
1283 * @brief Return an iterator pointing to one past the last element of
1284 * the valarray.
1285 * @param __va valarray.
1286 */
1287 template<class _Tp>
1288 [[__nodiscard__]]
1289 inline _Tp*
1290 end(valarray<_Tp>& __va) noexcept
1291 {
1292 if (auto __n = __va.size())
1293 return std::__addressof(__va[0]) + __n;
1294 else
1295 return nullptr;
1296 }
1297
1298 /**
1299 * @brief Return an iterator pointing to one past the last element of
1300 * the const valarray.
1301 * @param __va valarray.
1302 */
1303 template<class _Tp>
1304 [[__nodiscard__]]
1305 inline const _Tp*
1306 end(const valarray<_Tp>& __va) noexcept
1307 {
1308 if (auto __n = __va.size())
1309 return std::__addressof(__va[0]) + __n;
1310 else
1311 return nullptr;
1312 }
1313#endif // C++11 to C++23
1314
1315 /// @} group numeric_arrays
1316
1317_GLIBCXX_END_NAMESPACE_VERSION
1318} // namespace
1319
1320#endif /* _GLIBCXX_VALARRAY */
initializer_list
algorithm
cmath
range_access.h
version.h
gslice.h
gslice_array.h
indirect_array.h
mask_array.h
requires_hosted.h
slice_array.h
valarray_array.h
valarray_before.h
valarray_after.h
c++config.h
debug.h
std::__addressof
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
Definition move.h:52
std::valarray::size
size_t size() const
Return the number of elements in array.
Definition valarray:988
std::valarray::min
_Tp min() const
Return the minimum element using operator<().
Definition valarray:1100
std::valarray::max
_Tp max() const
Return the maximum element using operator<().
Definition valarray:1108
std::valarray::cshift
valarray< _Tp > cshift(int __n) const
Return a rotated array.
Definition valarray:1042
std::valarray::swap
void swap(valarray< _Tp > &__v) noexcept
Swap.
Definition valarray:979
std::valarray::operator[]
_Tp & operator[](size_t __i) noexcept
Definition valarray:635
std::valarray::resize
void resize(size_t __size, _Tp __c=_Tp())
Resize array.
Definition valarray:1083
std::valarray::sum
_Tp sum() const
Return the sum of all elements in the array.
Definition valarray:993
std::valarray::valarray
valarray() noexcept
Construct an empty array.
Definition valarray:664
std::valarray::shift
valarray< _Tp > shift(int __n) const
Return a shifted array.
Definition valarray:1001
std::valarray::apply
_Expr< _ValFunClos< _ValArray, _Tp >, _Tp > apply(_Tp __func(_Tp)) const
Apply a function to the array.
Definition valarray:1116
std::valarray::operator=
valarray< _Tp > & operator=(const valarray< _Tp > &__v)
Assign elements to an array.
Definition valarray:767
std
ISO C++ entities toplevel namespace is std.
std::end
constexpr auto end(_Container &__cont) noexcept(noexcept(__cont.end())) -> decltype(__cont.end())
Return an iterator pointing to one past the last element of the container.
Definition range_access.h:80
std::size
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
Definition range_access.h:294
std::begin
constexpr auto begin(_Container &__cont) noexcept(noexcept(__cont.begin())) -> decltype(__cont.begin())
Return an iterator pointing to the first element of the container.
Definition range_access.h:55
std::__detail
Implementation details not part of the namespace std interface.
std::initializer_list
initializer_list
Definition initializer_list:53
std::valarray
Smart array designed to support numeric processing.
Definition valarray:137
std::valarray::operator^=
valarray< _Tp > & operator^=(const _Tp &)
Set each element e of array to e ^ t.
std::valarray::operator/=
valarray< _Tp > & operator/=(const _Tp &)
Divide each element of array by t.
std::valarray::valarray
valarray(const _Tp *__restrict__, size_t)
Construct an array initialized to the first n elements of t.
std::valarray::operator|=
valarray< _Tp > & operator|=(const valarray< _Tp > &)
Logical or corresponding elements of v with elements of array.
std::valarray::operator+
_UnaryOp< __unary_plus >::_Rt operator+() const
Return a new valarray by applying unary + to each element.
std::valarray::operator*=
valarray< _Tp > & operator*=(const _Tp &)
Multiply each element of array by t.
std::valarray::operator!
_UnaryOp< __logical_not >::_Rt operator!() const
Return a new valarray by applying unary ! to each element.
std::valarray::begin
iterator begin() noexcept
Return an iterator pointing to the first element of the valarray.
Definition valarray:590
std::valarray::end
iterator end() noexcept
Return an iterator pointing to one past the last element of the valarray.
Definition valarray:604
std::valarray::operator<<=
valarray< _Tp > & operator<<=(const _Tp &)
Left shift each element e of array by t bits.
std::valarray::operator/=
valarray< _Tp > & operator/=(const valarray< _Tp > &)
Divide elements of array by corresponding elements of v.
std::valarray::operator-=
valarray< _Tp > & operator-=(const _Tp &)
Subtract t to each element of array.
std::valarray::operator~
_UnaryOp< __bitwise_not >::_Rt operator~() const
Return a new valarray by applying unary ~ to each element.
std::valarray::operator>>=
valarray< _Tp > & operator>>=(const _Tp &)
Right shift each element e of array by t bits.
std::valarray::operator-=
valarray< _Tp > & operator-=(const valarray< _Tp > &)
Subtract corresponding elements of v from elements of array.
std::valarray::operator%=
valarray< _Tp > & operator%=(const _Tp &)
Set each element e of array to e % t.
std::valarray::operator+=
valarray< _Tp > & operator+=(const _Tp &)
Add t to each element of array.
std::valarray::operator>>=
valarray< _Tp > & operator>>=(const valarray< _Tp > &)
Right shift elements of array by corresponding elements of v.
std::valarray::operator+=
valarray< _Tp > & operator+=(const valarray< _Tp > &)
Add corresponding elements of v to elements of array.
std::valarray::operator^=
valarray< _Tp > & operator^=(const valarray< _Tp > &)
Logical xor corresponding elements of v with elements of array.
std::valarray::operator&=
valarray< _Tp > & operator&=(const valarray< _Tp > &)
Logical and corresponding elements of v with elements of array.
std::valarray::operator*=
valarray< _Tp > & operator*=(const valarray< _Tp > &)
Multiply elements of array by corresponding elements of v.
std::valarray::operator-
_UnaryOp< __negate >::_Rt operator-() const
Return a new valarray by applying unary - to each element.
std::valarray::operator%=
valarray< _Tp > & operator%=(const valarray< _Tp > &)
Modulo elements of array by corresponding elements of v.
std::valarray::operator&=
valarray< _Tp > & operator&=(const _Tp &)
Set each element e of array to e & t.
std::valarray::operator|=
valarray< _Tp > & operator|=(const _Tp &)
Set each element e of array to e | t.
std::slice_array
Reference to one-dimensional subset of an array.
Definition slice_array.h:131
std::gslice_array
Reference to multi-dimensional subset of an array.
Definition gslice_array.h:63
std::mask_array
Reference to selected subset of an array.
Definition mask_array.h:65
std::indirect_array
Reference to arbitrary subset of an array.
Definition indirect_array.h:65
std::gslice
Class defining multi-dimensional subset of an array.
Definition gslice.h:67
std::slice
Class defining one-dimensional subset of an array.
Definition slice_array.h:62