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