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