1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_VALARRAY
11#define _LIBCPP_VALARRAY
12
13/*
14 valarray synopsis
15
16namespace std
17{
18
19template<class T>
20class valarray
21{
22public:
23 typedef T value_type;
24
25 // construct/destroy:
26 valarray();
27 explicit valarray(size_t n);
28 valarray(const value_type& x, size_t n);
29 valarray(const value_type* px, size_t n);
30 valarray(const valarray& v);
31 valarray(valarray&& v) noexcept;
32 valarray(const slice_array<value_type>& sa);
33 valarray(const gslice_array<value_type>& ga);
34 valarray(const mask_array<value_type>& ma);
35 valarray(const indirect_array<value_type>& ia);
36 valarray(initializer_list<value_type> il);
37 ~valarray();
38
39 // assignment:
40 valarray& operator=(const valarray& v);
41 valarray& operator=(valarray&& v) noexcept;
42 valarray& operator=(initializer_list<value_type> il);
43 valarray& operator=(const value_type& x);
44 valarray& operator=(const slice_array<value_type>& sa);
45 valarray& operator=(const gslice_array<value_type>& ga);
46 valarray& operator=(const mask_array<value_type>& ma);
47 valarray& operator=(const indirect_array<value_type>& ia);
48
49 // element access:
50 const value_type& operator[](size_t i) const;
51 value_type& operator[](size_t i);
52
53 // subset operations:
54 valarray operator[](slice s) const;
55 slice_array<value_type> operator[](slice s);
56 valarray operator[](const gslice& gs) const;
57 gslice_array<value_type> operator[](const gslice& gs);
58 valarray operator[](const valarray<bool>& vb) const;
59 mask_array<value_type> operator[](const valarray<bool>& vb);
60 valarray operator[](const valarray<size_t>& vs) const;
61 indirect_array<value_type> operator[](const valarray<size_t>& vs);
62
63 // unary operators:
64 valarray operator+() const;
65 valarray operator-() const;
66 valarray operator~() const;
67 valarray<bool> operator!() const;
68
69 // computed assignment:
70 valarray& operator*= (const value_type& x);
71 valarray& operator/= (const value_type& x);
72 valarray& operator%= (const value_type& x);
73 valarray& operator+= (const value_type& x);
74 valarray& operator-= (const value_type& x);
75 valarray& operator^= (const value_type& x);
76 valarray& operator&= (const value_type& x);
77 valarray& operator|= (const value_type& x);
78 valarray& operator<<=(const value_type& x);
79 valarray& operator>>=(const value_type& x);
80
81 valarray& operator*= (const valarray& v);
82 valarray& operator/= (const valarray& v);
83 valarray& operator%= (const valarray& v);
84 valarray& operator+= (const valarray& v);
85 valarray& operator-= (const valarray& v);
86 valarray& operator^= (const valarray& v);
87 valarray& operator|= (const valarray& v);
88 valarray& operator&= (const valarray& v);
89 valarray& operator<<=(const valarray& v);
90 valarray& operator>>=(const valarray& v);
91
92 // member functions:
93 void swap(valarray& v) noexcept;
94
95 size_t size() const;
96
97 value_type sum() const;
98 value_type min() const;
99 value_type max() const;
100
101 valarray shift (int i) const;
102 valarray cshift(int i) const;
103 valarray apply(value_type f(value_type)) const;
104 valarray apply(value_type f(const value_type&)) const;
105 void resize(size_t n, value_type x = value_type());
106};
107
108template<class T, size_t cnt> valarray(const T(&)[cnt], size_t) -> valarray<T>;
109
110class slice
111{
112public:
113 slice();
114 slice(size_t start, size_t size, size_t stride);
115
116 size_t start() const;
117 size_t size() const;
118 size_t stride() const;
119
120 friend bool operator==(const slice& x, const slice& y); // since C++20
121};
122
123template <class T>
124class slice_array
125{
126public:
127 typedef T value_type;
128
129 const slice_array& operator=(const slice_array& sa) const;
130 void operator= (const valarray<value_type>& v) const;
131 void operator*= (const valarray<value_type>& v) const;
132 void operator/= (const valarray<value_type>& v) const;
133 void operator%= (const valarray<value_type>& v) const;
134 void operator+= (const valarray<value_type>& v) const;
135 void operator-= (const valarray<value_type>& v) const;
136 void operator^= (const valarray<value_type>& v) const;
137 void operator&= (const valarray<value_type>& v) const;
138 void operator|= (const valarray<value_type>& v) const;
139 void operator<<=(const valarray<value_type>& v) const;
140 void operator>>=(const valarray<value_type>& v) const;
141
142 void operator=(const value_type& x) const;
143 void operator=(const valarray<T>& val_arr) const;
144
145 slice_array() = delete;
146};
147
148class gslice
149{
150public:
151 gslice();
152 gslice(size_t start, const valarray<size_t>& size,
153 const valarray<size_t>& stride);
154
155 size_t start() const;
156 valarray<size_t> size() const;
157 valarray<size_t> stride() const;
158};
159
160template <class T>
161class gslice_array
162{
163public:
164 typedef T value_type;
165
166 void operator= (const valarray<value_type>& v) const;
167 void operator*= (const valarray<value_type>& v) const;
168 void operator/= (const valarray<value_type>& v) const;
169 void operator%= (const valarray<value_type>& v) const;
170 void operator+= (const valarray<value_type>& v) const;
171 void operator-= (const valarray<value_type>& v) const;
172 void operator^= (const valarray<value_type>& v) const;
173 void operator&= (const valarray<value_type>& v) const;
174 void operator|= (const valarray<value_type>& v) const;
175 void operator<<=(const valarray<value_type>& v) const;
176 void operator>>=(const valarray<value_type>& v) const;
177
178 gslice_array(const gslice_array& ga);
179 ~gslice_array();
180 const gslice_array& operator=(const gslice_array& ga) const;
181 void operator=(const value_type& x) const;
182
183 gslice_array() = delete;
184};
185
186template <class T>
187class mask_array
188{
189public:
190 typedef T value_type;
191
192 void operator= (const valarray<value_type>& v) const;
193 void operator*= (const valarray<value_type>& v) const;
194 void operator/= (const valarray<value_type>& v) const;
195 void operator%= (const valarray<value_type>& v) const;
196 void operator+= (const valarray<value_type>& v) const;
197 void operator-= (const valarray<value_type>& v) const;
198 void operator^= (const valarray<value_type>& v) const;
199 void operator&= (const valarray<value_type>& v) const;
200 void operator|= (const valarray<value_type>& v) const;
201 void operator<<=(const valarray<value_type>& v) const;
202 void operator>>=(const valarray<value_type>& v) const;
203
204 mask_array(const mask_array& ma);
205 ~mask_array();
206 const mask_array& operator=(const mask_array& ma) const;
207 void operator=(const value_type& x) const;
208
209 mask_array() = delete;
210};
211
212template <class T>
213class indirect_array
214{
215public:
216 typedef T value_type;
217
218 void operator= (const valarray<value_type>& v) const;
219 void operator*= (const valarray<value_type>& v) const;
220 void operator/= (const valarray<value_type>& v) const;
221 void operator%= (const valarray<value_type>& v) const;
222 void operator+= (const valarray<value_type>& v) const;
223 void operator-= (const valarray<value_type>& v) const;
224 void operator^= (const valarray<value_type>& v) const;
225 void operator&= (const valarray<value_type>& v) const;
226 void operator|= (const valarray<value_type>& v) const;
227 void operator<<=(const valarray<value_type>& v) const;
228 void operator>>=(const valarray<value_type>& v) const;
229
230 indirect_array(const indirect_array& ia);
231 ~indirect_array();
232 const indirect_array& operator=(const indirect_array& ia) const;
233 void operator=(const value_type& x) const;
234
235 indirect_array() = delete;
236};
237
238template<class T> void swap(valarray<T>& x, valarray<T>& y) noexcept;
239
240template<class T> valarray<T> operator* (const valarray<T>& x, const valarray<T>& y);
241template<class T> valarray<T> operator* (const valarray<T>& x, const T& y);
242template<class T> valarray<T> operator* (const T& x, const valarray<T>& y);
243
244template<class T> valarray<T> operator/ (const valarray<T>& x, const valarray<T>& y);
245template<class T> valarray<T> operator/ (const valarray<T>& x, const T& y);
246template<class T> valarray<T> operator/ (const T& x, const valarray<T>& y);
247
248template<class T> valarray<T> operator% (const valarray<T>& x, const valarray<T>& y);
249template<class T> valarray<T> operator% (const valarray<T>& x, const T& y);
250template<class T> valarray<T> operator% (const T& x, const valarray<T>& y);
251
252template<class T> valarray<T> operator+ (const valarray<T>& x, const valarray<T>& y);
253template<class T> valarray<T> operator+ (const valarray<T>& x, const T& y);
254template<class T> valarray<T> operator+ (const T& x, const valarray<T>& y);
255
256template<class T> valarray<T> operator- (const valarray<T>& x, const valarray<T>& y);
257template<class T> valarray<T> operator- (const valarray<T>& x, const T& y);
258template<class T> valarray<T> operator- (const T& x, const valarray<T>& y);
259
260template<class T> valarray<T> operator^ (const valarray<T>& x, const valarray<T>& y);
261template<class T> valarray<T> operator^ (const valarray<T>& x, const T& y);
262template<class T> valarray<T> operator^ (const T& x, const valarray<T>& y);
263
264template<class T> valarray<T> operator& (const valarray<T>& x, const valarray<T>& y);
265template<class T> valarray<T> operator& (const valarray<T>& x, const T& y);
266template<class T> valarray<T> operator& (const T& x, const valarray<T>& y);
267
268template<class T> valarray<T> operator| (const valarray<T>& x, const valarray<T>& y);
269template<class T> valarray<T> operator| (const valarray<T>& x, const T& y);
270template<class T> valarray<T> operator| (const T& x, const valarray<T>& y);
271
272template<class T> valarray<T> operator<<(const valarray<T>& x, const valarray<T>& y);
273template<class T> valarray<T> operator<<(const valarray<T>& x, const T& y);
274template<class T> valarray<T> operator<<(const T& x, const valarray<T>& y);
275
276template<class T> valarray<T> operator>>(const valarray<T>& x, const valarray<T>& y);
277template<class T> valarray<T> operator>>(const valarray<T>& x, const T& y);
278template<class T> valarray<T> operator>>(const T& x, const valarray<T>& y);
279
280template<class T> valarray<bool> operator&&(const valarray<T>& x, const valarray<T>& y);
281template<class T> valarray<bool> operator&&(const valarray<T>& x, const T& y);
282template<class T> valarray<bool> operator&&(const T& x, const valarray<T>& y);
283
284template<class T> valarray<bool> operator||(const valarray<T>& x, const valarray<T>& y);
285template<class T> valarray<bool> operator||(const valarray<T>& x, const T& y);
286template<class T> valarray<bool> operator||(const T& x, const valarray<T>& y);
287
288template<class T> valarray<bool> operator==(const valarray<T>& x, const valarray<T>& y);
289template<class T> valarray<bool> operator==(const valarray<T>& x, const T& y);
290template<class T> valarray<bool> operator==(const T& x, const valarray<T>& y);
291
292template<class T> valarray<bool> operator!=(const valarray<T>& x, const valarray<T>& y);
293template<class T> valarray<bool> operator!=(const valarray<T>& x, const T& y);
294template<class T> valarray<bool> operator!=(const T& x, const valarray<T>& y);
295
296template<class T> valarray<bool> operator< (const valarray<T>& x, const valarray<T>& y);
297template<class T> valarray<bool> operator< (const valarray<T>& x, const T& y);
298template<class T> valarray<bool> operator< (const T& x, const valarray<T>& y);
299
300template<class T> valarray<bool> operator> (const valarray<T>& x, const valarray<T>& y);
301template<class T> valarray<bool> operator> (const valarray<T>& x, const T& y);
302template<class T> valarray<bool> operator> (const T& x, const valarray<T>& y);
303
304template<class T> valarray<bool> operator<=(const valarray<T>& x, const valarray<T>& y);
305template<class T> valarray<bool> operator<=(const valarray<T>& x, const T& y);
306template<class T> valarray<bool> operator<=(const T& x, const valarray<T>& y);
307
308template<class T> valarray<bool> operator>=(const valarray<T>& x, const valarray<T>& y);
309template<class T> valarray<bool> operator>=(const valarray<T>& x, const T& y);
310template<class T> valarray<bool> operator>=(const T& x, const valarray<T>& y);
311
312template<class T> valarray<T> abs (const valarray<T>& x);
313template<class T> valarray<T> acos (const valarray<T>& x);
314template<class T> valarray<T> asin (const valarray<T>& x);
315template<class T> valarray<T> atan (const valarray<T>& x);
316
317template<class T> valarray<T> atan2(const valarray<T>& x, const valarray<T>& y);
318template<class T> valarray<T> atan2(const valarray<T>& x, const T& y);
319template<class T> valarray<T> atan2(const T& x, const valarray<T>& y);
320
321template<class T> valarray<T> cos (const valarray<T>& x);
322template<class T> valarray<T> cosh (const valarray<T>& x);
323template<class T> valarray<T> exp (const valarray<T>& x);
324template<class T> valarray<T> log (const valarray<T>& x);
325template<class T> valarray<T> log10(const valarray<T>& x);
326
327template<class T> valarray<T> pow(const valarray<T>& x, const valarray<T>& y);
328template<class T> valarray<T> pow(const valarray<T>& x, const T& y);
329template<class T> valarray<T> pow(const T& x, const valarray<T>& y);
330
331template<class T> valarray<T> sin (const valarray<T>& x);
332template<class T> valarray<T> sinh (const valarray<T>& x);
333template<class T> valarray<T> sqrt (const valarray<T>& x);
334template<class T> valarray<T> tan (const valarray<T>& x);
335template<class T> valarray<T> tanh (const valarray<T>& x);
336
337template <class T> unspecified1 begin(valarray<T>& v);
338template <class T> unspecified2 begin(const valarray<T>& v);
339template <class T> unspecified1 end(valarray<T>& v);
340template <class T> unspecified2 end(const valarray<T>& v);
341
342} // std
343
344*/
345
346#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
347# include <__cxx03/valarray>
348#else
349# include <__algorithm/copy.h>
350# include <__algorithm/count.h>
351# include <__algorithm/fill.h>
352# include <__algorithm/max_element.h>
353# include <__algorithm/min.h>
354# include <__algorithm/min_element.h>
355# include <__algorithm/unwrap_iter.h>
356# include <__assert>
357# include <__config>
358# include <__cstddef/ptrdiff_t.h>
359# include <__functional/operations.h>
360# include <__memory/addressof.h>
361# include <__memory/allocator.h>
362# include <__memory/uninitialized_algorithms.h>
363# include <__type_traits/decay.h>
364# include <__type_traits/remove_reference.h>
365# include <__utility/exception_guard.h>
366# include <__utility/move.h>
367# include <__utility/swap.h>
368# include <cmath>
369# include <version>
370
371// standard-mandated includes
372
373// [valarray.syn]
374# include <initializer_list>
375
376# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
377# pragma GCC system_header
378# endif
379
380_LIBCPP_PUSH_MACROS
381# include <__undef_macros>
382
383_LIBCPP_BEGIN_NAMESPACE_STD
384_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS
385
386template <class _Tp>
387class valarray;
388
389class slice {
390 size_t __start_;
391 size_t __size_;
392 size_t __stride_;
393
394public:
395 _LIBCPP_HIDE_FROM_ABI slice() : __start_(0), __size_(0), __stride_(0) {}
396
397 _LIBCPP_HIDE_FROM_ABI slice(size_t __start, size_t __size, size_t __stride)
398 : __start_(__start), __size_(__size), __stride_(__stride) {}
399
400 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t start() const { return __start_; }
401 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t size() const { return __size_; }
402 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t stride() const { return __stride_; }
403
404# if _LIBCPP_STD_VER >= 20
405
406 _LIBCPP_HIDE_FROM_ABI friend bool operator==(const slice& __x, const slice& __y) {
407 return __x.start() == __y.start() && __x.size() == __y.size() && __x.stride() == __y.stride();
408 }
409
410# endif
411};
412
413template <class _Tp>
414class slice_array;
415class _LIBCPP_EXPORTED_FROM_ABI gslice;
416template <class _Tp>
417class gslice_array;
418template <class _Tp>
419class mask_array;
420template <class _Tp>
421class indirect_array;
422
423template <class _Tp>
424_LIBCPP_HIDE_FROM_ABI _Tp* begin(valarray<_Tp>& __v);
425
426template <class _Tp>
427_LIBCPP_HIDE_FROM_ABI const _Tp* begin(const valarray<_Tp>& __v);
428
429template <class _Tp>
430_LIBCPP_HIDE_FROM_ABI _Tp* end(valarray<_Tp>& __v);
431
432template <class _Tp>
433_LIBCPP_HIDE_FROM_ABI const _Tp* end(const valarray<_Tp>& __v);
434
435template <class _Op, class _A0>
436struct _UnaryOp {
437 typedef typename _Op::__result_type __result_type;
438 using value_type = __decay_t<__result_type>;
439
440 _Op __op_;
441 _A0 __a0_;
442
443 _LIBCPP_HIDE_FROM_ABI _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {}
444
445 _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i]); }
446
447 _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); }
448};
449
450template <class _Op, class _A0, class _A1>
451struct _BinaryOp {
452 typedef typename _Op::__result_type __result_type;
453 using value_type = __decay_t<__result_type>;
454
455 _Op __op_;
456 _A0 __a0_;
457 _A1 __a1_;
458
459 _LIBCPP_HIDE_FROM_ABI _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1)
460 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
461
462 _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i], __a1_[__i]); }
463
464 _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); }
465};
466
467template <class _Tp>
468class __scalar_expr {
469public:
470 typedef _Tp value_type;
471 typedef const _Tp& __result_type;
472
473private:
474 const value_type& __t_;
475 size_t __s_;
476
477public:
478 _LIBCPP_HIDE_FROM_ABI explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {}
479
480 _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t) const { return __t_; }
481
482 _LIBCPP_HIDE_FROM_ABI size_t size() const { return __s_; }
483};
484
485template <class _Tp>
486struct __unary_plus {
487 typedef _Tp __result_type;
488 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return +__x; }
489};
490
491template <class _Tp>
492struct __bit_not {
493 typedef _Tp __result_type;
494 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return ~__x; }
495};
496
497template <class _Tp>
498struct __bit_shift_left {
499 typedef _Tp __result_type;
500 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x << __y; }
501};
502
503template <class _Tp>
504struct __bit_shift_right {
505 typedef _Tp __result_type;
506 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x >> __y; }
507};
508
509template <class _Tp, class _Fp>
510struct __apply_expr {
511private:
512 _Fp __f_;
513
514public:
515 typedef _Tp __result_type;
516
517 _LIBCPP_HIDE_FROM_ABI explicit __apply_expr(_Fp __f) : __f_(__f) {}
518
519 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return __f_(__x); }
520};
521
522template <class _Tp>
523struct __abs_expr {
524 typedef _Tp __result_type;
525 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::abs(__x); }
526};
527
528template <class _Tp>
529struct __acos_expr {
530 typedef _Tp __result_type;
531 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::acos(__x); }
532};
533
534template <class _Tp>
535struct __asin_expr {
536 typedef _Tp __result_type;
537 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::asin(__x); }
538};
539
540template <class _Tp>
541struct __atan_expr {
542 typedef _Tp __result_type;
543 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::atan(__x); }
544};
545
546template <class _Tp>
547struct __atan2_expr {
548 typedef _Tp __result_type;
549 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return std::atan2(__x, __y); }
550};
551
552template <class _Tp>
553struct __cos_expr {
554 typedef _Tp __result_type;
555 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::cos(__x); }
556};
557
558template <class _Tp>
559struct __cosh_expr {
560 typedef _Tp __result_type;
561 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::cosh(__x); }
562};
563
564template <class _Tp>
565struct __exp_expr {
566 typedef _Tp __result_type;
567 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::exp(__x); }
568};
569
570template <class _Tp>
571struct __log_expr {
572 typedef _Tp __result_type;
573 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::log(__x); }
574};
575
576template <class _Tp>
577struct __log10_expr {
578 typedef _Tp __result_type;
579 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::log10(__x); }
580};
581
582template <class _Tp>
583struct __pow_expr {
584 typedef _Tp __result_type;
585 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return std::pow(__x, __y); }
586};
587
588template <class _Tp>
589struct __sin_expr {
590 typedef _Tp __result_type;
591 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::sin(__x); }
592};
593
594template <class _Tp>
595struct __sinh_expr {
596 typedef _Tp __result_type;
597 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::sinh(__x); }
598};
599
600template <class _Tp>
601struct __sqrt_expr {
602 typedef _Tp __result_type;
603 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::sqrt(__x); }
604};
605
606template <class _Tp>
607struct __tan_expr {
608 typedef _Tp __result_type;
609 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::tan(__x); }
610};
611
612template <class _Tp>
613struct __tanh_expr {
614 typedef _Tp __result_type;
615 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::tanh(__x); }
616};
617
618template <class _ValExpr>
619class __slice_expr {
620 typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
621
622public:
623 typedef typename _RmExpr::value_type value_type;
624 typedef value_type __result_type;
625
626private:
627 _ValExpr __expr_;
628 size_t __start_;
629 size_t __size_;
630 size_t __stride_;
631
632 _LIBCPP_HIDE_FROM_ABI __slice_expr(const slice& __sl, const _RmExpr& __e)
633 : __expr_(__e), __start_(__sl.start()), __size_(__sl.size()), __stride_(__sl.stride()) {}
634
635public:
636 _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __expr_[__start_ + __i * __stride_]; }
637
638 _LIBCPP_HIDE_FROM_ABI size_t size() const { return __size_; }
639
640 template <class>
641 friend class __val_expr;
642 template <class>
643 friend class valarray;
644};
645
646template <class _ValExpr>
647class __mask_expr;
648
649template <class _ValExpr>
650class __indirect_expr;
651
652template <class _ValExpr>
653class __shift_expr {
654 typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
655
656public:
657 typedef typename _RmExpr::value_type value_type;
658 typedef value_type __result_type;
659
660private:
661 _ValExpr __expr_;
662 size_t __size_;
663 ptrdiff_t __ul_;
664 ptrdiff_t __sn_;
665 ptrdiff_t __n_;
666 static const ptrdiff_t _Np = static_cast<ptrdiff_t>(sizeof(ptrdiff_t) * __CHAR_BIT__ - 1);
667
668 _LIBCPP_HIDE_FROM_ABI __shift_expr(int __n, const _RmExpr& __e) : __expr_(__e), __size_(__e.size()), __n_(__n) {
669 ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _Np);
670 __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _Np);
671 __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n);
672 }
673
674public:
675 _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __j) const {
676 ptrdiff_t __i = static_cast<ptrdiff_t>(__j);
677 ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np;
678 return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
679 }
680
681 _LIBCPP_HIDE_FROM_ABI size_t size() const { return __size_; }
682
683 template <class>
684 friend class __val_expr;
685};
686
687template <class _ValExpr>
688class __cshift_expr {
689 typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
690
691public:
692 typedef typename _RmExpr::value_type value_type;
693 typedef value_type __result_type;
694
695private:
696 _ValExpr __expr_;
697 size_t __size_;
698 size_t __m_;
699 size_t __o1_;
700 size_t __o2_;
701
702 _LIBCPP_HIDE_FROM_ABI __cshift_expr(int __n, const _RmExpr& __e) : __expr_(__e), __size_(__e.size()) {
703 __n %= static_cast<int>(__size_);
704 if (__n >= 0) {
705 __m_ = __size_ - __n;
706 __o1_ = __n;
707 __o2_ = __n - __size_;
708 } else {
709 __m_ = -__n;
710 __o1_ = __n + __size_;
711 __o2_ = __n;
712 }
713 }
714
715public:
716 _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const {
717 if (__i < __m_)
718 return __expr_[__i + __o1_];
719 return __expr_[__i + __o2_];
720 }
721
722 _LIBCPP_HIDE_FROM_ABI size_t size() const { return __size_; }
723
724 template <class>
725 friend class __val_expr;
726};
727
728template <class _ValExpr>
729class __val_expr;
730
731template <class _ValExpr>
732struct __is_val_expr : false_type {};
733
734template <class _ValExpr>
735struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
736
737template <class _Tp>
738struct __is_val_expr<valarray<_Tp> > : true_type {};
739
740template <class _Tp>
741struct __is_val_expr<slice_array<_Tp> > : true_type {};
742
743template <class _Tp>
744struct __is_val_expr<gslice_array<_Tp> > : true_type {};
745
746template <class _Tp>
747struct __is_val_expr<mask_array<_Tp> > : true_type {};
748
749template <class _Tp>
750struct __is_val_expr<indirect_array<_Tp> > : true_type {};
751
752// The functions using a __val_expr access the elements by their index.
753// valarray and the libc++ lazy proxies have an operator[]. The
754// Standard proxy array's don't have this operator, instead they have a
755// implementation specific accessor
756// __get(size_t)
757//
758// The functions use the non-member function
759// __get(__val_expr, size_t)
760//
761// If the __val_expr is a specialization of __val_expr_use_member_functions it
762// uses the __val_expr's member function
763// __get(size_t)
764// else it uses the __val_expr's member function
765// operator[](size_t)
766template <class _ValExpr>
767struct __val_expr_use_member_functions;
768
769template <class>
770struct __val_expr_use_member_functions : false_type {};
771
772template <class _Tp>
773struct __val_expr_use_member_functions<slice_array<_Tp> > : true_type {};
774
775template <class _Tp>
776struct __val_expr_use_member_functions<gslice_array<_Tp> > : true_type {};
777
778template <class _Tp>
779struct __val_expr_use_member_functions<mask_array<_Tp> > : true_type {};
780
781template <class _Tp>
782struct __val_expr_use_member_functions<indirect_array<_Tp> > : true_type {};
783
784template <class _Tp>
785class valarray {
786public:
787 typedef _Tp value_type;
788 typedef _Tp __result_type;
789
790private:
791 value_type* __begin_;
792 value_type* __end_;
793
794public:
795 // construct/destroy:
796 _LIBCPP_HIDE_FROM_ABI valarray() : __begin_(nullptr), __end_(nullptr) {}
797 inline _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 explicit valarray(size_t __n);
798 _LIBCPP_HIDE_FROM_ABI valarray(const value_type& __x, size_t __n);
799 valarray(const value_type* __p, size_t __n);
800 valarray(const valarray& __v);
801# ifndef _LIBCPP_CXX03_LANG
802 _LIBCPP_HIDE_FROM_ABI valarray(valarray&& __v) _NOEXCEPT;
803 valarray(initializer_list<value_type> __il);
804# endif // _LIBCPP_CXX03_LANG
805 valarray(const slice_array<value_type>& __sa);
806 valarray(const gslice_array<value_type>& __ga);
807 valarray(const mask_array<value_type>& __ma);
808 valarray(const indirect_array<value_type>& __ia);
809 inline _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 ~valarray();
810
811 // assignment:
812 valarray& operator=(const valarray& __v);
813# ifndef _LIBCPP_CXX03_LANG
814 _LIBCPP_HIDE_FROM_ABI valarray& operator=(valarray&& __v) _NOEXCEPT;
815 _LIBCPP_HIDE_FROM_ABI valarray& operator=(initializer_list<value_type>);
816# endif // _LIBCPP_CXX03_LANG
817 _LIBCPP_HIDE_FROM_ABI valarray& operator=(const value_type& __x);
818 _LIBCPP_HIDE_FROM_ABI valarray& operator=(const slice_array<value_type>& __sa);
819 _LIBCPP_HIDE_FROM_ABI valarray& operator=(const gslice_array<value_type>& __ga);
820 _LIBCPP_HIDE_FROM_ABI valarray& operator=(const mask_array<value_type>& __ma);
821 _LIBCPP_HIDE_FROM_ABI valarray& operator=(const indirect_array<value_type>& __ia);
822 template <class _ValExpr>
823 _LIBCPP_HIDE_FROM_ABI valarray& operator=(const __val_expr<_ValExpr>& __v);
824
825 // element access:
826 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const value_type& operator[](size_t __i) const {
827 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < size(), "valarray::operator[] index out of bounds");
828 return __begin_[__i];
829 }
830
831 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI value_type& operator[](size_t __i) {
832 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < size(), "valarray::operator[] index out of bounds");
833 return __begin_[__i];
834 }
835
836 // subset operations:
837 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const;
838 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI slice_array<value_type> operator[](slice __s);
839 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> >
840 operator[](const gslice& __gs) const;
841 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI gslice_array<value_type> operator[](const gslice& __gs);
842# ifndef _LIBCPP_CXX03_LANG
843 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
844 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI gslice_array<value_type> operator[](gslice&& __gs);
845# endif // _LIBCPP_CXX03_LANG
846 [[__nodiscard__]]
847 _LIBCPP_HIDE_FROM_ABI __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const;
848 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI mask_array<value_type> operator[](const valarray<bool>& __vb);
849# ifndef _LIBCPP_CXX03_LANG
850 [[__nodiscard__]]
851 _LIBCPP_HIDE_FROM_ABI __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const;
852 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI mask_array<value_type> operator[](valarray<bool>&& __vb);
853# endif // _LIBCPP_CXX03_LANG
854 [[__nodiscard__]]
855 _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
856 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI indirect_array<value_type> operator[](const valarray<size_t>& __vs);
857# ifndef _LIBCPP_CXX03_LANG
858 [[__nodiscard__]]
859 _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
860 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI indirect_array<value_type> operator[](valarray<size_t>&& __vs);
861# endif // _LIBCPP_CXX03_LANG
862
863 // unary operators:
864 _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__unary_plus<_Tp>, const valarray&> > operator+() const;
865 _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<negate<_Tp>, const valarray&> > operator-() const;
866 _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__bit_not<_Tp>, const valarray&> > operator~() const;
867 _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<logical_not<_Tp>, const valarray&> > operator!() const;
868
869 // computed assignment:
870 _LIBCPP_HIDE_FROM_ABI valarray& operator*=(const value_type& __x);
871 _LIBCPP_HIDE_FROM_ABI valarray& operator/=(const value_type& __x);
872 _LIBCPP_HIDE_FROM_ABI valarray& operator%=(const value_type& __x);
873 _LIBCPP_HIDE_FROM_ABI valarray& operator+=(const value_type& __x);
874 _LIBCPP_HIDE_FROM_ABI valarray& operator-=(const value_type& __x);
875 _LIBCPP_HIDE_FROM_ABI valarray& operator^=(const value_type& __x);
876 _LIBCPP_HIDE_FROM_ABI valarray& operator&=(const value_type& __x);
877 _LIBCPP_HIDE_FROM_ABI valarray& operator|=(const value_type& __x);
878 _LIBCPP_HIDE_FROM_ABI valarray& operator<<=(const value_type& __x);
879 _LIBCPP_HIDE_FROM_ABI valarray& operator>>=(const value_type& __x);
880
881 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
882 _LIBCPP_HIDE_FROM_ABI valarray& operator*=(const _Expr& __v);
883
884 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
885 _LIBCPP_HIDE_FROM_ABI valarray& operator/=(const _Expr& __v);
886
887 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
888 _LIBCPP_HIDE_FROM_ABI valarray& operator%=(const _Expr& __v);
889
890 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
891 _LIBCPP_HIDE_FROM_ABI valarray& operator+=(const _Expr& __v);
892
893 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
894 _LIBCPP_HIDE_FROM_ABI valarray& operator-=(const _Expr& __v);
895
896 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
897 _LIBCPP_HIDE_FROM_ABI valarray& operator^=(const _Expr& __v);
898
899 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
900 _LIBCPP_HIDE_FROM_ABI valarray& operator|=(const _Expr& __v);
901
902 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
903 _LIBCPP_HIDE_FROM_ABI valarray& operator&=(const _Expr& __v);
904
905 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
906 _LIBCPP_HIDE_FROM_ABI valarray& operator<<=(const _Expr& __v);
907
908 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
909 _LIBCPP_HIDE_FROM_ABI valarray& operator>>=(const _Expr& __v);
910
911 // member functions:
912 _LIBCPP_HIDE_FROM_ABI void swap(valarray& __v) _NOEXCEPT;
913
914 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t size() const { return static_cast<size_t>(__end_ - __begin_); }
915
916 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI value_type sum() const;
917 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI value_type min() const;
918 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI value_type max() const;
919
920 [[__nodiscard__]] valarray shift(int __i) const;
921 [[__nodiscard__]] valarray cshift(int __i) const;
922 [[__nodiscard__]] valarray apply(value_type __f(value_type)) const;
923 [[__nodiscard__]] valarray apply(value_type __f(const value_type&)) const;
924 void resize(size_t __n, value_type __x = value_type());
925
926private:
927 template <class>
928 friend class valarray;
929 template <class>
930 friend class slice_array;
931 template <class>
932 friend class gslice_array;
933 template <class>
934 friend class mask_array;
935 template <class>
936 friend class __mask_expr;
937 template <class>
938 friend class indirect_array;
939 template <class>
940 friend class __indirect_expr;
941 template <class>
942 friend class __val_expr;
943
944 template <class _Up>
945 friend _Up* begin(valarray<_Up>& __v);
946
947 template <class _Up>
948 friend const _Up* begin(const valarray<_Up>& __v);
949
950 template <class _Up>
951 friend _Up* end(valarray<_Up>& __v);
952
953 template <class _Up>
954 friend const _Up* end(const valarray<_Up>& __v);
955
956 _LIBCPP_HIDE_FROM_ABI void __clear(size_t __capacity);
957 valarray& __assign_range(const value_type* __f, const value_type* __l);
958};
959
960# if _LIBCPP_STD_VER >= 17
961template <class _Tp, size_t _Size>
962valarray(const _Tp (&)[_Size], size_t) -> valarray<_Tp>;
963# endif
964
965template <class _Expr,
966 __enable_if_t<__is_val_expr<_Expr>::value && __val_expr_use_member_functions<_Expr>::value, int> = 0>
967_LIBCPP_HIDE_FROM_ABI typename _Expr::value_type __get(const _Expr& __v, size_t __i) {
968 return __v.__get(__i);
969}
970
971template <class _Expr,
972 __enable_if_t<__is_val_expr<_Expr>::value && !__val_expr_use_member_functions<_Expr>::value, int> = 0>
973_LIBCPP_HIDE_FROM_ABI typename _Expr::value_type __get(const _Expr& __v, size_t __i) {
974 return __v[__i];
975}
976
977extern template _LIBCPP_EXPORTED_FROM_ABI void valarray<size_t>::resize(size_t, size_t);
978
979template <class _Op, class _Tp>
980struct _UnaryOp<_Op, valarray<_Tp> > {
981 typedef typename _Op::__result_type __result_type;
982 using value_type = __decay_t<__result_type>;
983
984 _Op __op_;
985 const valarray<_Tp>& __a0_;
986
987 _LIBCPP_HIDE_FROM_ABI _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
988
989 _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i]); }
990
991 _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); }
992};
993
994template <class _Op, class _Tp, class _A1>
995struct _BinaryOp<_Op, valarray<_Tp>, _A1> {
996 typedef typename _Op::__result_type __result_type;
997 using value_type = __decay_t<__result_type>;
998
999 _Op __op_;
1000 const valarray<_Tp>& __a0_;
1001 _A1 __a1_;
1002
1003 _LIBCPP_HIDE_FROM_ABI _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
1004 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1005
1006 _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i], __a1_[__i]); }
1007
1008 _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); }
1009};
1010
1011template <class _Op, class _A0, class _Tp>
1012struct _BinaryOp<_Op, _A0, valarray<_Tp> > {
1013 typedef typename _Op::__result_type __result_type;
1014 using value_type = __decay_t<__result_type>;
1015
1016 _Op __op_;
1017 _A0 __a0_;
1018 const valarray<_Tp>& __a1_;
1019
1020 _LIBCPP_HIDE_FROM_ABI _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
1021 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1022
1023 _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i], __a1_[__i]); }
1024
1025 _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); }
1026};
1027
1028template <class _Op, class _Tp>
1029struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> > {
1030 typedef typename _Op::__result_type __result_type;
1031 using value_type = __decay_t<__result_type>;
1032
1033 _Op __op_;
1034 const valarray<_Tp>& __a0_;
1035 const valarray<_Tp>& __a1_;
1036
1037 _LIBCPP_HIDE_FROM_ABI _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
1038 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1039
1040 _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i], __a1_[__i]); }
1041
1042 _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); }
1043};
1044
1045// slice_array
1046
1047template <class _Tp>
1048class slice_array {
1049public:
1050 typedef _Tp value_type;
1051
1052private:
1053 value_type* __vp_;
1054 size_t __size_;
1055 size_t __stride_;
1056
1057public:
1058 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1059 void _LIBCPP_HIDE_FROM_ABI operator=(const _Expr& __v) const;
1060
1061 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1062 void _LIBCPP_HIDE_FROM_ABI operator*=(const _Expr& __v) const;
1063
1064 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1065 void _LIBCPP_HIDE_FROM_ABI operator/=(const _Expr& __v) const;
1066
1067 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1068 void _LIBCPP_HIDE_FROM_ABI operator%=(const _Expr& __v) const;
1069
1070 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1071 void _LIBCPP_HIDE_FROM_ABI operator+=(const _Expr& __v) const;
1072
1073 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1074 void _LIBCPP_HIDE_FROM_ABI operator-=(const _Expr& __v) const;
1075
1076 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1077 void _LIBCPP_HIDE_FROM_ABI operator^=(const _Expr& __v) const;
1078
1079 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1080 void _LIBCPP_HIDE_FROM_ABI operator&=(const _Expr& __v) const;
1081
1082 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1083 void _LIBCPP_HIDE_FROM_ABI operator|=(const _Expr& __v) const;
1084
1085 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1086 void _LIBCPP_HIDE_FROM_ABI operator<<=(const _Expr& __v) const;
1087
1088 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1089 void _LIBCPP_HIDE_FROM_ABI operator>>=(const _Expr& __v) const;
1090
1091 slice_array(slice_array const&) = default;
1092
1093 _LIBCPP_HIDE_FROM_ABI const slice_array& operator=(const slice_array& __sa) const;
1094
1095 _LIBCPP_HIDE_FROM_ABI void operator=(const value_type& __x) const;
1096
1097 _LIBCPP_HIDE_FROM_ABI void operator=(const valarray<value_type>& __va) const;
1098
1099 // Behaves like __val_expr::operator[], which returns by value.
1100 _LIBCPP_HIDE_FROM_ABI value_type __get(size_t __i) const {
1101 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __size_, "slice_array.__get() index out of bounds");
1102 return __vp_[__i * __stride_];
1103 }
1104
1105private:
1106 _LIBCPP_HIDE_FROM_ABI slice_array(const slice& __sl, const valarray<value_type>& __v)
1107 : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())), __size_(__sl.size()), __stride_(__sl.stride()) {}
1108
1109 template <class>
1110 friend class valarray;
1111};
1112
1113template <class _Tp>
1114inline const slice_array<_Tp>& slice_array<_Tp>::operator=(const slice_array& __sa) const {
1115 value_type* __t = __vp_;
1116 const value_type* __s = __sa.__vp_;
1117 for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
1118 *__t = *__s;
1119 return *this;
1120}
1121
1122template <class _Tp>
1123template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1124inline void slice_array<_Tp>::operator=(const _Expr& __v) const {
1125 value_type* __t = __vp_;
1126 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1127 *__t = __v[__i];
1128}
1129
1130template <class _Tp>
1131inline void slice_array<_Tp>::operator=(const valarray<value_type>& __va) const {
1132 value_type* __t = __vp_;
1133 for (size_t __i = 0; __i < __va.size(); ++__i, __t += __stride_)
1134 *__t = __va[__i];
1135}
1136
1137template <class _Tp>
1138template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1139inline void slice_array<_Tp>::operator*=(const _Expr& __v) const {
1140 value_type* __t = __vp_;
1141 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1142 *__t *= __v[__i];
1143}
1144
1145template <class _Tp>
1146template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1147inline void slice_array<_Tp>::operator/=(const _Expr& __v) const {
1148 value_type* __t = __vp_;
1149 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1150 *__t /= __v[__i];
1151}
1152
1153template <class _Tp>
1154template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1155inline void slice_array<_Tp>::operator%=(const _Expr& __v) const {
1156 value_type* __t = __vp_;
1157 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1158 *__t %= __v[__i];
1159}
1160
1161template <class _Tp>
1162template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1163inline void slice_array<_Tp>::operator+=(const _Expr& __v) const {
1164 value_type* __t = __vp_;
1165 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1166 *__t += __v[__i];
1167}
1168
1169template <class _Tp>
1170template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1171inline void slice_array<_Tp>::operator-=(const _Expr& __v) const {
1172 value_type* __t = __vp_;
1173 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1174 *__t -= __v[__i];
1175}
1176
1177template <class _Tp>
1178template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1179inline void slice_array<_Tp>::operator^=(const _Expr& __v) const {
1180 value_type* __t = __vp_;
1181 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1182 *__t ^= __v[__i];
1183}
1184
1185template <class _Tp>
1186template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1187inline void slice_array<_Tp>::operator&=(const _Expr& __v) const {
1188 value_type* __t = __vp_;
1189 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1190 *__t &= __v[__i];
1191}
1192
1193template <class _Tp>
1194template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1195inline void slice_array<_Tp>::operator|=(const _Expr& __v) const {
1196 value_type* __t = __vp_;
1197 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1198 *__t |= __v[__i];
1199}
1200
1201template <class _Tp>
1202template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1203inline void slice_array<_Tp>::operator<<=(const _Expr& __v) const {
1204 value_type* __t = __vp_;
1205 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1206 *__t <<= __v[__i];
1207}
1208
1209template <class _Tp>
1210template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1211inline void slice_array<_Tp>::operator>>=(const _Expr& __v) const {
1212 value_type* __t = __vp_;
1213 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1214 *__t >>= __v[__i];
1215}
1216
1217template <class _Tp>
1218inline void slice_array<_Tp>::operator=(const value_type& __x) const {
1219 value_type* __t = __vp_;
1220 for (size_t __n = __size_; __n; --__n, __t += __stride_)
1221 *__t = __x;
1222}
1223
1224// gslice
1225
1226class _LIBCPP_EXPORTED_FROM_ABI gslice {
1227 valarray<size_t> __size_;
1228 valarray<size_t> __stride_;
1229 valarray<size_t> __1d_;
1230
1231public:
1232 _LIBCPP_HIDE_FROM_ABI gslice() {}
1233
1234 _LIBCPP_HIDE_FROM_ABI gslice(size_t __start, const valarray<size_t>& __size, const valarray<size_t>& __stride)
1235 : __size_(__size), __stride_(__stride) {
1236 __init(__start);
1237 }
1238
1239# ifndef _LIBCPP_CXX03_LANG
1240
1241 _LIBCPP_HIDE_FROM_ABI gslice(size_t __start, const valarray<size_t>& __size, valarray<size_t>&& __stride)
1242 : __size_(__size), __stride_(std::move(__stride)) {
1243 __init(__start);
1244 }
1245
1246 _LIBCPP_HIDE_FROM_ABI gslice(size_t __start, valarray<size_t>&& __size, const valarray<size_t>& __stride)
1247 : __size_(std::move(__size)), __stride_(__stride) {
1248 __init(__start);
1249 }
1250
1251 _LIBCPP_HIDE_FROM_ABI gslice(size_t __start, valarray<size_t>&& __size, valarray<size_t>&& __stride)
1252 : __size_(std::move(__size)), __stride_(std::move(__stride)) {
1253 __init(__start);
1254 }
1255
1256# endif // _LIBCPP_CXX03_LANG
1257
1258 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t start() const { return __1d_.size() ? __1d_[0] : 0; }
1259
1260 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI valarray<size_t> size() const { return __size_; }
1261
1262 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI valarray<size_t> stride() const { return __stride_; }
1263
1264private:
1265 void __init(size_t __start);
1266
1267 template <class>
1268 friend class gslice_array;
1269 template <class>
1270 friend class valarray;
1271 template <class>
1272 friend class __val_expr;
1273};
1274
1275// gslice_array
1276
1277template <class _Tp>
1278class gslice_array {
1279public:
1280 typedef _Tp value_type;
1281
1282private:
1283 value_type* __vp_;
1284 valarray<size_t> __1d_;
1285
1286public:
1287 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1288 void _LIBCPP_HIDE_FROM_ABI operator=(const _Expr& __v) const;
1289
1290 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1291 void _LIBCPP_HIDE_FROM_ABI operator*=(const _Expr& __v) const;
1292
1293 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1294 void _LIBCPP_HIDE_FROM_ABI operator/=(const _Expr& __v) const;
1295
1296 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1297 void _LIBCPP_HIDE_FROM_ABI operator%=(const _Expr& __v) const;
1298
1299 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1300 void _LIBCPP_HIDE_FROM_ABI operator+=(const _Expr& __v) const;
1301
1302 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1303 void _LIBCPP_HIDE_FROM_ABI operator-=(const _Expr& __v) const;
1304
1305 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1306 void _LIBCPP_HIDE_FROM_ABI operator^=(const _Expr& __v) const;
1307
1308 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1309 void _LIBCPP_HIDE_FROM_ABI operator&=(const _Expr& __v) const;
1310
1311 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1312 void _LIBCPP_HIDE_FROM_ABI operator|=(const _Expr& __v) const;
1313
1314 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1315 void _LIBCPP_HIDE_FROM_ABI operator<<=(const _Expr& __v) const;
1316
1317 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1318 void _LIBCPP_HIDE_FROM_ABI operator>>=(const _Expr& __v) const;
1319
1320 _LIBCPP_HIDE_FROM_ABI const gslice_array& operator=(const gslice_array& __ga) const;
1321
1322 _LIBCPP_HIDE_FROM_ABI void operator=(const value_type& __x) const;
1323
1324 gslice_array(const gslice_array&) = default;
1325
1326 // Behaves like __val_expr::operator[], which returns by value.
1327 _LIBCPP_HIDE_FROM_ABI value_type __get(size_t __i) const {
1328 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __1d_.size(), "gslice_array.__get() index out of bounds");
1329 return __vp_[__1d_[__i]];
1330 }
1331
1332private:
1333 gslice_array(const gslice& __gs, const valarray<value_type>& __v)
1334 : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(__gs.__1d_) {}
1335
1336# ifndef _LIBCPP_CXX03_LANG
1337 gslice_array(gslice&& __gs, const valarray<value_type>& __v)
1338 : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(std::move(__gs.__1d_)) {}
1339# endif // _LIBCPP_CXX03_LANG
1340
1341 template <class>
1342 friend class valarray;
1343};
1344
1345template <class _Tp>
1346template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1347inline void gslice_array<_Tp>::operator=(const _Expr& __v) const {
1348 typedef const size_t* _Ip;
1349 size_t __j = 0;
1350 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1351 __vp_[*__i] = __v[__j];
1352}
1353
1354template <class _Tp>
1355template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1356inline void gslice_array<_Tp>::operator*=(const _Expr& __v) const {
1357 typedef const size_t* _Ip;
1358 size_t __j = 0;
1359 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1360 __vp_[*__i] *= __v[__j];
1361}
1362
1363template <class _Tp>
1364template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1365inline void gslice_array<_Tp>::operator/=(const _Expr& __v) const {
1366 typedef const size_t* _Ip;
1367 size_t __j = 0;
1368 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1369 __vp_[*__i] /= __v[__j];
1370}
1371
1372template <class _Tp>
1373template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1374inline void gslice_array<_Tp>::operator%=(const _Expr& __v) const {
1375 typedef const size_t* _Ip;
1376 size_t __j = 0;
1377 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1378 __vp_[*__i] %= __v[__j];
1379}
1380
1381template <class _Tp>
1382template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1383inline void gslice_array<_Tp>::operator+=(const _Expr& __v) const {
1384 typedef const size_t* _Ip;
1385 size_t __j = 0;
1386 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1387 __vp_[*__i] += __v[__j];
1388}
1389
1390template <class _Tp>
1391template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1392inline void gslice_array<_Tp>::operator-=(const _Expr& __v) const {
1393 typedef const size_t* _Ip;
1394 size_t __j = 0;
1395 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1396 __vp_[*__i] -= __v[__j];
1397}
1398
1399template <class _Tp>
1400template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1401inline void gslice_array<_Tp>::operator^=(const _Expr& __v) const {
1402 typedef const size_t* _Ip;
1403 size_t __j = 0;
1404 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1405 __vp_[*__i] ^= __v[__j];
1406}
1407
1408template <class _Tp>
1409template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1410inline void gslice_array<_Tp>::operator&=(const _Expr& __v) const {
1411 typedef const size_t* _Ip;
1412 size_t __j = 0;
1413 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1414 __vp_[*__i] &= __v[__j];
1415}
1416
1417template <class _Tp>
1418template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1419inline void gslice_array<_Tp>::operator|=(const _Expr& __v) const {
1420 typedef const size_t* _Ip;
1421 size_t __j = 0;
1422 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1423 __vp_[*__i] |= __v[__j];
1424}
1425
1426template <class _Tp>
1427template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1428inline void gslice_array<_Tp>::operator<<=(const _Expr& __v) const {
1429 typedef const size_t* _Ip;
1430 size_t __j = 0;
1431 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1432 __vp_[*__i] <<= __v[__j];
1433}
1434
1435template <class _Tp>
1436template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1437inline void gslice_array<_Tp>::operator>>=(const _Expr& __v) const {
1438 typedef const size_t* _Ip;
1439 size_t __j = 0;
1440 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1441 __vp_[*__i] >>= __v[__j];
1442}
1443
1444template <class _Tp>
1445inline const gslice_array<_Tp>& gslice_array<_Tp>::operator=(const gslice_array& __ga) const {
1446 typedef const size_t* _Ip;
1447 const value_type* __s = __ga.__vp_;
1448 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_; __i != __e; ++__i, ++__j)
1449 __vp_[*__i] = __s[*__j];
1450 return *this;
1451}
1452
1453template <class _Tp>
1454inline void gslice_array<_Tp>::operator=(const value_type& __x) const {
1455 typedef const size_t* _Ip;
1456 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1457 __vp_[*__i] = __x;
1458}
1459
1460// mask_array
1461
1462template <class _Tp>
1463class mask_array {
1464public:
1465 typedef _Tp value_type;
1466
1467private:
1468 value_type* __vp_;
1469 valarray<size_t> __1d_;
1470
1471public:
1472 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1473 void _LIBCPP_HIDE_FROM_ABI operator=(const _Expr& __v) const;
1474
1475 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1476 void _LIBCPP_HIDE_FROM_ABI operator*=(const _Expr& __v) const;
1477
1478 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1479 void _LIBCPP_HIDE_FROM_ABI operator/=(const _Expr& __v) const;
1480
1481 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1482 void _LIBCPP_HIDE_FROM_ABI operator%=(const _Expr& __v) const;
1483
1484 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1485 void _LIBCPP_HIDE_FROM_ABI operator+=(const _Expr& __v) const;
1486
1487 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1488 void _LIBCPP_HIDE_FROM_ABI operator-=(const _Expr& __v) const;
1489
1490 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1491 void _LIBCPP_HIDE_FROM_ABI operator^=(const _Expr& __v) const;
1492
1493 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1494 void _LIBCPP_HIDE_FROM_ABI operator&=(const _Expr& __v) const;
1495
1496 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1497 void _LIBCPP_HIDE_FROM_ABI operator|=(const _Expr& __v) const;
1498
1499 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1500 void _LIBCPP_HIDE_FROM_ABI operator<<=(const _Expr& __v) const;
1501
1502 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1503 void _LIBCPP_HIDE_FROM_ABI operator>>=(const _Expr& __v) const;
1504
1505 mask_array(const mask_array&) = default;
1506
1507 _LIBCPP_HIDE_FROM_ABI const mask_array& operator=(const mask_array& __ma) const;
1508
1509 _LIBCPP_HIDE_FROM_ABI void operator=(const value_type& __x) const;
1510
1511 // Behaves like __val_expr::operator[], which returns by value.
1512 _LIBCPP_HIDE_FROM_ABI value_type __get(size_t __i) const {
1513 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __1d_.size(), "mask_array.__get() index out of bounds");
1514 return __vp_[__1d_[__i]];
1515 }
1516
1517private:
1518 _LIBCPP_HIDE_FROM_ABI mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
1519 : __vp_(const_cast<value_type*>(__v.__begin_)),
1520 __1d_(static_cast<size_t>(count(first: __vb.__begin_, last: __vb.__end_, value: true))) {
1521 size_t __j = 0;
1522 for (size_t __i = 0; __i < __vb.size(); ++__i)
1523 if (__vb[__i])
1524 __1d_[__j++] = __i;
1525 }
1526
1527 template <class>
1528 friend class valarray;
1529};
1530
1531template <class _Tp>
1532template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1533inline void mask_array<_Tp>::operator=(const _Expr& __v) const {
1534 size_t __n = __1d_.size();
1535 for (size_t __i = 0; __i < __n; ++__i)
1536 __vp_[__1d_[__i]] = __v[__i];
1537}
1538
1539template <class _Tp>
1540template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1541inline void mask_array<_Tp>::operator*=(const _Expr& __v) const {
1542 size_t __n = __1d_.size();
1543 for (size_t __i = 0; __i < __n; ++__i)
1544 __vp_[__1d_[__i]] *= __v[__i];
1545}
1546
1547template <class _Tp>
1548template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1549inline void mask_array<_Tp>::operator/=(const _Expr& __v) const {
1550 size_t __n = __1d_.size();
1551 for (size_t __i = 0; __i < __n; ++__i)
1552 __vp_[__1d_[__i]] /= __v[__i];
1553}
1554
1555template <class _Tp>
1556template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1557inline void mask_array<_Tp>::operator%=(const _Expr& __v) const {
1558 size_t __n = __1d_.size();
1559 for (size_t __i = 0; __i < __n; ++__i)
1560 __vp_[__1d_[__i]] %= __v[__i];
1561}
1562
1563template <class _Tp>
1564template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1565inline void mask_array<_Tp>::operator+=(const _Expr& __v) const {
1566 size_t __n = __1d_.size();
1567 for (size_t __i = 0; __i < __n; ++__i)
1568 __vp_[__1d_[__i]] += __v[__i];
1569}
1570
1571template <class _Tp>
1572template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1573inline void mask_array<_Tp>::operator-=(const _Expr& __v) const {
1574 size_t __n = __1d_.size();
1575 for (size_t __i = 0; __i < __n; ++__i)
1576 __vp_[__1d_[__i]] -= __v[__i];
1577}
1578
1579template <class _Tp>
1580template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1581inline void mask_array<_Tp>::operator^=(const _Expr& __v) const {
1582 size_t __n = __1d_.size();
1583 for (size_t __i = 0; __i < __n; ++__i)
1584 __vp_[__1d_[__i]] ^= __v[__i];
1585}
1586
1587template <class _Tp>
1588template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1589inline void mask_array<_Tp>::operator&=(const _Expr& __v) const {
1590 size_t __n = __1d_.size();
1591 for (size_t __i = 0; __i < __n; ++__i)
1592 __vp_[__1d_[__i]] &= __v[__i];
1593}
1594
1595template <class _Tp>
1596template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1597inline void mask_array<_Tp>::operator|=(const _Expr& __v) const {
1598 size_t __n = __1d_.size();
1599 for (size_t __i = 0; __i < __n; ++__i)
1600 __vp_[__1d_[__i]] |= __v[__i];
1601}
1602
1603template <class _Tp>
1604template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1605inline void mask_array<_Tp>::operator<<=(const _Expr& __v) const {
1606 size_t __n = __1d_.size();
1607 for (size_t __i = 0; __i < __n; ++__i)
1608 __vp_[__1d_[__i]] <<= __v[__i];
1609}
1610
1611template <class _Tp>
1612template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1613inline void mask_array<_Tp>::operator>>=(const _Expr& __v) const {
1614 size_t __n = __1d_.size();
1615 for (size_t __i = 0; __i < __n; ++__i)
1616 __vp_[__1d_[__i]] >>= __v[__i];
1617}
1618
1619template <class _Tp>
1620inline const mask_array<_Tp>& mask_array<_Tp>::operator=(const mask_array& __ma) const {
1621 size_t __n = __1d_.size();
1622 for (size_t __i = 0; __i < __n; ++__i)
1623 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
1624 return *this;
1625}
1626
1627template <class _Tp>
1628inline void mask_array<_Tp>::operator=(const value_type& __x) const {
1629 size_t __n = __1d_.size();
1630 for (size_t __i = 0; __i < __n; ++__i)
1631 __vp_[__1d_[__i]] = __x;
1632}
1633
1634template <class _ValExpr>
1635class __mask_expr {
1636 typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
1637
1638public:
1639 typedef typename _RmExpr::value_type value_type;
1640 typedef value_type __result_type;
1641
1642private:
1643 _ValExpr __expr_;
1644 valarray<size_t> __1d_;
1645
1646 _LIBCPP_HIDE_FROM_ABI __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
1647 : __expr_(__e), __1d_(static_cast<size_t>(count(first: __vb.__begin_, last: __vb.__end_, value: true))) {
1648 size_t __j = 0;
1649 for (size_t __i = 0; __i < __vb.size(); ++__i)
1650 if (__vb[__i])
1651 __1d_[__j++] = __i;
1652 }
1653
1654public:
1655 _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __expr_[__1d_[__i]]; }
1656
1657 _LIBCPP_HIDE_FROM_ABI size_t size() const { return __1d_.size(); }
1658
1659 template <class>
1660 friend class __val_expr;
1661 template <class>
1662 friend class valarray;
1663};
1664
1665// indirect_array
1666
1667template <class _Tp>
1668class indirect_array {
1669public:
1670 typedef _Tp value_type;
1671
1672private:
1673 value_type* __vp_;
1674 valarray<size_t> __1d_;
1675
1676public:
1677 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1678 void _LIBCPP_HIDE_FROM_ABI operator=(const _Expr& __v) const;
1679
1680 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1681 void _LIBCPP_HIDE_FROM_ABI operator*=(const _Expr& __v) const;
1682
1683 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1684 void _LIBCPP_HIDE_FROM_ABI operator/=(const _Expr& __v) const;
1685
1686 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1687 void _LIBCPP_HIDE_FROM_ABI operator%=(const _Expr& __v) const;
1688
1689 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1690 void _LIBCPP_HIDE_FROM_ABI operator+=(const _Expr& __v) const;
1691
1692 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1693 void _LIBCPP_HIDE_FROM_ABI operator-=(const _Expr& __v) const;
1694
1695 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1696 void _LIBCPP_HIDE_FROM_ABI operator^=(const _Expr& __v) const;
1697
1698 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1699 void _LIBCPP_HIDE_FROM_ABI operator&=(const _Expr& __v) const;
1700
1701 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1702 void _LIBCPP_HIDE_FROM_ABI operator|=(const _Expr& __v) const;
1703
1704 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1705 void _LIBCPP_HIDE_FROM_ABI operator<<=(const _Expr& __v) const;
1706
1707 template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1708 void _LIBCPP_HIDE_FROM_ABI operator>>=(const _Expr& __v) const;
1709
1710 indirect_array(const indirect_array&) = default;
1711
1712 _LIBCPP_HIDE_FROM_ABI const indirect_array& operator=(const indirect_array& __ia) const;
1713
1714 _LIBCPP_HIDE_FROM_ABI void operator=(const value_type& __x) const;
1715
1716 // Behaves like __val_expr::operator[], which returns by value.
1717 _LIBCPP_HIDE_FROM_ABI value_type __get(size_t __i) const {
1718 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __1d_.size(), "indirect_array.__get() index out of bounds");
1719 return __vp_[__1d_[__i]];
1720 }
1721
1722private:
1723 _LIBCPP_HIDE_FROM_ABI indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
1724 : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(__ia) {}
1725
1726# ifndef _LIBCPP_CXX03_LANG
1727
1728 _LIBCPP_HIDE_FROM_ABI indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
1729 : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(std::move(__ia)) {}
1730
1731# endif // _LIBCPP_CXX03_LANG
1732
1733 template <class>
1734 friend class valarray;
1735};
1736
1737template <class _Tp>
1738template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1739inline void indirect_array<_Tp>::operator=(const _Expr& __v) const {
1740 size_t __n = __1d_.size();
1741 for (size_t __i = 0; __i < __n; ++__i)
1742 __vp_[__1d_[__i]] = __v[__i];
1743}
1744
1745template <class _Tp>
1746template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1747inline void indirect_array<_Tp>::operator*=(const _Expr& __v) const {
1748 size_t __n = __1d_.size();
1749 for (size_t __i = 0; __i < __n; ++__i)
1750 __vp_[__1d_[__i]] *= __v[__i];
1751}
1752
1753template <class _Tp>
1754template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1755inline void indirect_array<_Tp>::operator/=(const _Expr& __v) const {
1756 size_t __n = __1d_.size();
1757 for (size_t __i = 0; __i < __n; ++__i)
1758 __vp_[__1d_[__i]] /= __v[__i];
1759}
1760
1761template <class _Tp>
1762template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1763inline void indirect_array<_Tp>::operator%=(const _Expr& __v) const {
1764 size_t __n = __1d_.size();
1765 for (size_t __i = 0; __i < __n; ++__i)
1766 __vp_[__1d_[__i]] %= __v[__i];
1767}
1768
1769template <class _Tp>
1770template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1771inline void indirect_array<_Tp>::operator+=(const _Expr& __v) const {
1772 size_t __n = __1d_.size();
1773 for (size_t __i = 0; __i < __n; ++__i)
1774 __vp_[__1d_[__i]] += __v[__i];
1775}
1776
1777template <class _Tp>
1778template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1779inline void indirect_array<_Tp>::operator-=(const _Expr& __v) const {
1780 size_t __n = __1d_.size();
1781 for (size_t __i = 0; __i < __n; ++__i)
1782 __vp_[__1d_[__i]] -= __v[__i];
1783}
1784
1785template <class _Tp>
1786template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1787inline void indirect_array<_Tp>::operator^=(const _Expr& __v) const {
1788 size_t __n = __1d_.size();
1789 for (size_t __i = 0; __i < __n; ++__i)
1790 __vp_[__1d_[__i]] ^= __v[__i];
1791}
1792
1793template <class _Tp>
1794template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1795inline void indirect_array<_Tp>::operator&=(const _Expr& __v) const {
1796 size_t __n = __1d_.size();
1797 for (size_t __i = 0; __i < __n; ++__i)
1798 __vp_[__1d_[__i]] &= __v[__i];
1799}
1800
1801template <class _Tp>
1802template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1803inline void indirect_array<_Tp>::operator|=(const _Expr& __v) const {
1804 size_t __n = __1d_.size();
1805 for (size_t __i = 0; __i < __n; ++__i)
1806 __vp_[__1d_[__i]] |= __v[__i];
1807}
1808
1809template <class _Tp>
1810template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1811inline void indirect_array<_Tp>::operator<<=(const _Expr& __v) const {
1812 size_t __n = __1d_.size();
1813 for (size_t __i = 0; __i < __n; ++__i)
1814 __vp_[__1d_[__i]] <<= __v[__i];
1815}
1816
1817template <class _Tp>
1818template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1819inline void indirect_array<_Tp>::operator>>=(const _Expr& __v) const {
1820 size_t __n = __1d_.size();
1821 for (size_t __i = 0; __i < __n; ++__i)
1822 __vp_[__1d_[__i]] >>= __v[__i];
1823}
1824
1825template <class _Tp>
1826inline const indirect_array<_Tp>& indirect_array<_Tp>::operator=(const indirect_array& __ia) const {
1827 typedef const size_t* _Ip;
1828 const value_type* __s = __ia.__vp_;
1829 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_; __i != __e; ++__i, ++__j)
1830 __vp_[*__i] = __s[*__j];
1831 return *this;
1832}
1833
1834template <class _Tp>
1835inline void indirect_array<_Tp>::operator=(const value_type& __x) const {
1836 typedef const size_t* _Ip;
1837 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1838 __vp_[*__i] = __x;
1839}
1840
1841template <class _ValExpr>
1842class __indirect_expr {
1843 typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
1844
1845public:
1846 typedef typename _RmExpr::value_type value_type;
1847 typedef value_type __result_type;
1848
1849private:
1850 _ValExpr __expr_;
1851 valarray<size_t> __1d_;
1852
1853 _LIBCPP_HIDE_FROM_ABI __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e) : __expr_(__e), __1d_(__ia) {}
1854
1855# ifndef _LIBCPP_CXX03_LANG
1856
1857 _LIBCPP_HIDE_FROM_ABI __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
1858 : __expr_(__e), __1d_(std::move(__ia)) {}
1859
1860# endif // _LIBCPP_CXX03_LANG
1861
1862public:
1863 _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __expr_[__1d_[__i]]; }
1864
1865 _LIBCPP_HIDE_FROM_ABI size_t size() const { return __1d_.size(); }
1866
1867 template <class>
1868 friend class __val_expr;
1869 template <class>
1870 friend class valarray;
1871};
1872
1873template <class _ValExpr>
1874class __val_expr {
1875 typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
1876
1877 _ValExpr __expr_;
1878
1879public:
1880 typedef typename _RmExpr::value_type value_type;
1881 typedef typename _RmExpr::__result_type __result_type;
1882
1883 _LIBCPP_HIDE_FROM_ABI explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
1884
1885 _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __expr_[__i]; }
1886
1887 _LIBCPP_HIDE_FROM_ABI __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const {
1888 typedef __slice_expr<_ValExpr> _NewExpr;
1889 return __val_expr< _NewExpr >(_NewExpr(__s, __expr_));
1890 }
1891
1892 _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const {
1893 typedef __indirect_expr<_ValExpr> _NewExpr;
1894 return __val_expr<_NewExpr >(_NewExpr(__gs.__1d_, __expr_));
1895 }
1896
1897 _LIBCPP_HIDE_FROM_ABI __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const {
1898 typedef __mask_expr<_ValExpr> _NewExpr;
1899 return __val_expr< _NewExpr >(_NewExpr(__vb, __expr_));
1900 }
1901
1902 _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const {
1903 typedef __indirect_expr<_ValExpr> _NewExpr;
1904 return __val_expr< _NewExpr >(_NewExpr(__vs, __expr_));
1905 }
1906
1907 _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> > operator+() const {
1908 typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
1909 return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
1910 }
1911
1912 _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<negate<value_type>, _ValExpr> > operator-() const {
1913 typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
1914 return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
1915 }
1916
1917 _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> > operator~() const {
1918 typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
1919 return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
1920 }
1921
1922 _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> > operator!() const {
1923 typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
1924 return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
1925 }
1926
1927 operator valarray<__result_type>() const;
1928
1929 _LIBCPP_HIDE_FROM_ABI size_t size() const { return __expr_.size(); }
1930
1931 _LIBCPP_HIDE_FROM_ABI __result_type sum() const {
1932 size_t __n = __expr_.size();
1933 __result_type __r = __n ? __expr_[0] : __result_type();
1934 for (size_t __i = 1; __i < __n; ++__i)
1935 __r += __expr_[__i];
1936 return __r;
1937 }
1938
1939 _LIBCPP_HIDE_FROM_ABI __result_type min() const {
1940 size_t __n = size();
1941 __result_type __r = __n ? (*this)[0] : __result_type();
1942 for (size_t __i = 1; __i < __n; ++__i) {
1943 __result_type __x = __expr_[__i];
1944 if (__x < __r)
1945 __r = __x;
1946 }
1947 return __r;
1948 }
1949
1950 _LIBCPP_HIDE_FROM_ABI __result_type max() const {
1951 size_t __n = size();
1952 __result_type __r = __n ? (*this)[0] : __result_type();
1953 for (size_t __i = 1; __i < __n; ++__i) {
1954 __result_type __x = __expr_[__i];
1955 if (__r < __x)
1956 __r = __x;
1957 }
1958 return __r;
1959 }
1960
1961 _LIBCPP_HIDE_FROM_ABI __val_expr<__shift_expr<_ValExpr> > shift(int __i) const {
1962 return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));
1963 }
1964
1965 _LIBCPP_HIDE_FROM_ABI __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const {
1966 return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));
1967 }
1968
1969 _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__apply_expr<value_type, value_type (*)(value_type)>, _ValExpr> >
1970 apply(value_type __f(value_type)) const {
1971 typedef __apply_expr<value_type, value_type (*)(value_type)> _Op;
1972 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
1973 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
1974 }
1975
1976 _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__apply_expr<value_type, value_type (*)(const value_type&)>, _ValExpr> >
1977 apply(value_type __f(const value_type&)) const {
1978 typedef __apply_expr<value_type, value_type (*)(const value_type&)> _Op;
1979 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
1980 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
1981 }
1982};
1983
1984template <class _ValExpr>
1985__val_expr<_ValExpr>::operator valarray<__val_expr::__result_type>() const {
1986 valarray<__result_type> __r;
1987 size_t __n = __expr_.size();
1988 if (__n) {
1989 __r.__begin_ = __r.__end_ = allocator<__result_type>().allocate(__n);
1990 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
1991 ::new ((void*)__r.__end_) __result_type(__expr_[__i]);
1992 }
1993 return __r;
1994}
1995
1996// valarray
1997
1998template <class _Tp>
1999inline valarray<_Tp>::valarray(size_t __n) : __begin_(nullptr), __end_(nullptr) {
2000 if (__n) {
2001 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2002 auto __guard = std::__make_exception_guard([&] { __clear(capacity: __n); });
2003 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
2004 ::new ((void*)__end_) value_type();
2005 __guard.__complete();
2006 }
2007}
2008
2009template <class _Tp>
2010inline valarray<_Tp>::valarray(const value_type& __x, size_t __n) : __begin_(nullptr), __end_(nullptr) {
2011 resize(__n, __x);
2012}
2013
2014template <class _Tp>
2015valarray<_Tp>::valarray(const value_type* __p, size_t __n) : __begin_(nullptr), __end_(nullptr) {
2016 if (__n) {
2017 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2018 auto __guard = std::__make_exception_guard([&] { __clear(capacity: __n); });
2019 for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left)
2020 ::new ((void*)__end_) value_type(*__p);
2021 __guard.__complete();
2022 }
2023}
2024
2025template <class _Tp>
2026valarray<_Tp>::valarray(const valarray& __v) : __begin_(nullptr), __end_(nullptr) {
2027 if (__v.size()) {
2028 __begin_ = __end_ = allocator<value_type>().allocate(__v.size());
2029 auto __guard = std::__make_exception_guard([&] { __clear(capacity: __v.size()); });
2030 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
2031 ::new ((void*)__end_) value_type(*__p);
2032 __guard.__complete();
2033 }
2034}
2035
2036# ifndef _LIBCPP_CXX03_LANG
2037
2038template <class _Tp>
2039inline valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT : __begin_(__v.__begin_), __end_(__v.__end_) {
2040 __v.__begin_ = __v.__end_ = nullptr;
2041}
2042
2043template <class _Tp>
2044valarray<_Tp>::valarray(initializer_list<value_type> __il) : __begin_(nullptr), __end_(nullptr) {
2045 const size_t __n = __il.size();
2046 if (__n) {
2047 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2048 auto __guard = std::__make_exception_guard([&] { __clear(capacity: __n); });
2049 size_t __n_left = __n;
2050 for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left)
2051 ::new ((void*)__end_) value_type(*__p);
2052 __guard.__complete();
2053 }
2054}
2055
2056# endif // _LIBCPP_CXX03_LANG
2057
2058template <class _Tp>
2059valarray<_Tp>::valarray(const slice_array<value_type>& __sa) : __begin_(nullptr), __end_(nullptr) {
2060 const size_t __n = __sa.__size_;
2061 if (__n) {
2062 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2063 auto __guard = std::__make_exception_guard([&] { __clear(capacity: __n); });
2064 size_t __n_left = __n;
2065 for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left)
2066 ::new ((void*)__end_) value_type(*__p);
2067 __guard.__complete();
2068 }
2069}
2070
2071template <class _Tp>
2072valarray<_Tp>::valarray(const gslice_array<value_type>& __ga) : __begin_(nullptr), __end_(nullptr) {
2073 const size_t __n = __ga.__1d_.size();
2074 if (__n) {
2075 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2076 auto __guard = std::__make_exception_guard([&] { __clear(capacity: __n); });
2077 typedef const size_t* _Ip;
2078 const value_type* __s = __ga.__vp_;
2079 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; __i != __e; ++__i, ++__end_)
2080 ::new ((void*)__end_) value_type(__s[*__i]);
2081 __guard.__complete();
2082 }
2083}
2084
2085template <class _Tp>
2086valarray<_Tp>::valarray(const mask_array<value_type>& __ma) : __begin_(nullptr), __end_(nullptr) {
2087 const size_t __n = __ma.__1d_.size();
2088 if (__n) {
2089 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2090 auto __guard = std::__make_exception_guard([&] { __clear(capacity: __n); });
2091 typedef const size_t* _Ip;
2092 const value_type* __s = __ma.__vp_;
2093 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; __i != __e; ++__i, ++__end_)
2094 ::new ((void*)__end_) value_type(__s[*__i]);
2095 __guard.__complete();
2096 }
2097}
2098
2099template <class _Tp>
2100valarray<_Tp>::valarray(const indirect_array<value_type>& __ia) : __begin_(nullptr), __end_(nullptr) {
2101 const size_t __n = __ia.__1d_.size();
2102 if (__n) {
2103 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2104 auto __guard = std::__make_exception_guard([&] { __clear(capacity: __n); });
2105 typedef const size_t* _Ip;
2106 const value_type* __s = __ia.__vp_;
2107 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; __i != __e; ++__i, ++__end_)
2108 ::new ((void*)__end_) value_type(__s[*__i]);
2109 __guard.__complete();
2110 }
2111}
2112
2113template <class _Tp>
2114inline valarray<_Tp>::~valarray() {
2115 __clear(capacity: size());
2116}
2117
2118template <class _Tp>
2119valarray<_Tp>& valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l) {
2120 size_t __n = __l - __f;
2121 if (size() != __n) {
2122 __clear(capacity: size());
2123 __begin_ = allocator<value_type>().allocate(__n);
2124 __end_ = __begin_ + __n;
2125 std::uninitialized_copy(__f, __l, __begin_);
2126 } else {
2127 std::copy(__f, __l, __begin_);
2128 }
2129 return *this;
2130}
2131
2132template <class _Tp>
2133valarray<_Tp>& valarray<_Tp>::operator=(const valarray& __v) {
2134 if (this != std::addressof(__v))
2135 return __assign_range(f: __v.__begin_, l: __v.__end_);
2136 return *this;
2137}
2138
2139# ifndef _LIBCPP_CXX03_LANG
2140
2141template <class _Tp>
2142inline valarray<_Tp>& valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT {
2143 __clear(capacity: size());
2144 __begin_ = __v.__begin_;
2145 __end_ = __v.__end_;
2146 __v.__begin_ = nullptr;
2147 __v.__end_ = nullptr;
2148 return *this;
2149}
2150
2151template <class _Tp>
2152inline valarray<_Tp>& valarray<_Tp>::operator=(initializer_list<value_type> __il) {
2153 return __assign_range(f: __il.begin(), l: __il.end());
2154}
2155
2156# endif // _LIBCPP_CXX03_LANG
2157
2158template <class _Tp>
2159inline valarray<_Tp>& valarray<_Tp>::operator=(const value_type& __x) {
2160 std::fill(__begin_, __end_, __x);
2161 return *this;
2162}
2163
2164template <class _Tp>
2165inline valarray<_Tp>& valarray<_Tp>::operator=(const slice_array<value_type>& __sa) {
2166 value_type* __t = __begin_;
2167 const value_type* __s = __sa.__vp_;
2168 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
2169 *__t = *__s;
2170 return *this;
2171}
2172
2173template <class _Tp>
2174inline valarray<_Tp>& valarray<_Tp>::operator=(const gslice_array<value_type>& __ga) {
2175 typedef const size_t* _Ip;
2176 value_type* __t = __begin_;
2177 const value_type* __s = __ga.__vp_;
2178 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; __i != __e; ++__i, ++__t)
2179 *__t = __s[*__i];
2180 return *this;
2181}
2182
2183template <class _Tp>
2184inline valarray<_Tp>& valarray<_Tp>::operator=(const mask_array<value_type>& __ma) {
2185 typedef const size_t* _Ip;
2186 value_type* __t = __begin_;
2187 const value_type* __s = __ma.__vp_;
2188 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; __i != __e; ++__i, ++__t)
2189 *__t = __s[*__i];
2190 return *this;
2191}
2192
2193template <class _Tp>
2194inline valarray<_Tp>& valarray<_Tp>::operator=(const indirect_array<value_type>& __ia) {
2195 typedef const size_t* _Ip;
2196 value_type* __t = __begin_;
2197 const value_type* __s = __ia.__vp_;
2198 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; __i != __e; ++__i, ++__t)
2199 *__t = __s[*__i];
2200 return *this;
2201}
2202
2203template <class _Tp>
2204template <class _ValExpr>
2205inline valarray<_Tp>& valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v) {
2206 size_t __n = __v.size();
2207 if (size() != __n)
2208 resize(__n);
2209 value_type* __t = __begin_;
2210 for (size_t __i = 0; __i != __n; ++__t, ++__i)
2211 *__t = __result_type(__v[__i]);
2212 return *this;
2213}
2214
2215template <class _Tp>
2216inline __val_expr<__slice_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](slice __s) const {
2217 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
2218}
2219
2220template <class _Tp>
2221inline slice_array<_Tp> valarray<_Tp>::operator[](slice __s) {
2222 return slice_array<value_type>(__s, *this);
2223}
2224
2225template <class _Tp>
2226inline __val_expr<__indirect_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](const gslice& __gs) const {
2227 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
2228}
2229
2230template <class _Tp>
2231inline gslice_array<_Tp> valarray<_Tp>::operator[](const gslice& __gs) {
2232 return gslice_array<value_type>(__gs, *this);
2233}
2234
2235# ifndef _LIBCPP_CXX03_LANG
2236
2237template <class _Tp>
2238inline __val_expr<__indirect_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](gslice&& __gs) const {
2239 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(std::move(__gs.__1d_), *this));
2240}
2241
2242template <class _Tp>
2243inline gslice_array<_Tp> valarray<_Tp>::operator[](gslice&& __gs) {
2244 return gslice_array<value_type>(std::move(__gs), *this);
2245}
2246
2247# endif // _LIBCPP_CXX03_LANG
2248
2249template <class _Tp>
2250inline __val_expr<__mask_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](const valarray<bool>& __vb) const {
2251 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
2252}
2253
2254template <class _Tp>
2255inline mask_array<_Tp> valarray<_Tp>::operator[](const valarray<bool>& __vb) {
2256 return mask_array<value_type>(__vb, *this);
2257}
2258
2259# ifndef _LIBCPP_CXX03_LANG
2260
2261template <class _Tp>
2262inline __val_expr<__mask_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](valarray<bool>&& __vb) const {
2263 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(std::move(__vb), *this));
2264}
2265
2266template <class _Tp>
2267inline mask_array<_Tp> valarray<_Tp>::operator[](valarray<bool>&& __vb) {
2268 return mask_array<value_type>(std::move(__vb), *this);
2269}
2270
2271# endif // _LIBCPP_CXX03_LANG
2272
2273template <class _Tp>
2274inline __val_expr<__indirect_expr<const valarray<_Tp>&> >
2275valarray<_Tp>::operator[](const valarray<size_t>& __vs) const {
2276 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
2277}
2278
2279template <class _Tp>
2280inline indirect_array<_Tp> valarray<_Tp>::operator[](const valarray<size_t>& __vs) {
2281 return indirect_array<value_type>(__vs, *this);
2282}
2283
2284# ifndef _LIBCPP_CXX03_LANG
2285
2286template <class _Tp>
2287inline __val_expr<__indirect_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](valarray<size_t>&& __vs) const {
2288 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(std::move(__vs), *this));
2289}
2290
2291template <class _Tp>
2292inline indirect_array<_Tp> valarray<_Tp>::operator[](valarray<size_t>&& __vs) {
2293 return indirect_array<value_type>(std::move(__vs), *this);
2294}
2295
2296# endif // _LIBCPP_CXX03_LANG
2297
2298template <class _Tp>
2299inline __val_expr<_UnaryOp<__unary_plus<_Tp>, const valarray<_Tp>&> > valarray<_Tp>::operator+() const {
2300 using _Op = _UnaryOp<__unary_plus<_Tp>, const valarray<_Tp>&>;
2301 return __val_expr<_Op>(_Op(__unary_plus<_Tp>(), *this));
2302}
2303
2304template <class _Tp>
2305inline __val_expr<_UnaryOp<negate<_Tp>, const valarray<_Tp>&> > valarray<_Tp>::operator-() const {
2306 using _Op = _UnaryOp<negate<_Tp>, const valarray<_Tp>&>;
2307 return __val_expr<_Op>(_Op(negate<_Tp>(), *this));
2308}
2309
2310template <class _Tp>
2311inline __val_expr<_UnaryOp<__bit_not<_Tp>, const valarray<_Tp>&> > valarray<_Tp>::operator~() const {
2312 using _Op = _UnaryOp<__bit_not<_Tp>, const valarray<_Tp>&>;
2313 return __val_expr<_Op>(_Op(__bit_not<_Tp>(), *this));
2314}
2315
2316template <class _Tp>
2317inline __val_expr<_UnaryOp<logical_not<_Tp>, const valarray<_Tp>&> > valarray<_Tp>::operator!() const {
2318 using _Op = _UnaryOp<logical_not<_Tp>, const valarray<_Tp>&>;
2319 return __val_expr<_Op>(_Op(logical_not<_Tp>(), *this));
2320}
2321
2322template <class _Tp>
2323inline valarray<_Tp>& valarray<_Tp>::operator*=(const value_type& __x) {
2324 for (value_type* __p = __begin_; __p != __end_; ++__p)
2325 *__p *= __x;
2326 return *this;
2327}
2328
2329template <class _Tp>
2330inline valarray<_Tp>& valarray<_Tp>::operator/=(const value_type& __x) {
2331 for (value_type* __p = __begin_; __p != __end_; ++__p)
2332 *__p /= __x;
2333 return *this;
2334}
2335
2336template <class _Tp>
2337inline valarray<_Tp>& valarray<_Tp>::operator%=(const value_type& __x) {
2338 for (value_type* __p = __begin_; __p != __end_; ++__p)
2339 *__p %= __x;
2340 return *this;
2341}
2342
2343template <class _Tp>
2344inline valarray<_Tp>& valarray<_Tp>::operator+=(const value_type& __x) {
2345 for (value_type* __p = __begin_; __p != __end_; ++__p)
2346 *__p += __x;
2347 return *this;
2348}
2349
2350template <class _Tp>
2351inline valarray<_Tp>& valarray<_Tp>::operator-=(const value_type& __x) {
2352 for (value_type* __p = __begin_; __p != __end_; ++__p)
2353 *__p -= __x;
2354 return *this;
2355}
2356
2357template <class _Tp>
2358inline valarray<_Tp>& valarray<_Tp>::operator^=(const value_type& __x) {
2359 for (value_type* __p = __begin_; __p != __end_; ++__p)
2360 *__p ^= __x;
2361 return *this;
2362}
2363
2364template <class _Tp>
2365inline valarray<_Tp>& valarray<_Tp>::operator&=(const value_type& __x) {
2366 for (value_type* __p = __begin_; __p != __end_; ++__p)
2367 *__p &= __x;
2368 return *this;
2369}
2370
2371template <class _Tp>
2372inline valarray<_Tp>& valarray<_Tp>::operator|=(const value_type& __x) {
2373 for (value_type* __p = __begin_; __p != __end_; ++__p)
2374 *__p |= __x;
2375 return *this;
2376}
2377
2378template <class _Tp>
2379inline valarray<_Tp>& valarray<_Tp>::operator<<=(const value_type& __x) {
2380 for (value_type* __p = __begin_; __p != __end_; ++__p)
2381 *__p <<= __x;
2382 return *this;
2383}
2384
2385template <class _Tp>
2386inline valarray<_Tp>& valarray<_Tp>::operator>>=(const value_type& __x) {
2387 for (value_type* __p = __begin_; __p != __end_; ++__p)
2388 *__p >>= __x;
2389 return *this;
2390}
2391
2392template <class _Tp>
2393template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2394inline valarray<_Tp>& valarray<_Tp>::operator*=(const _Expr& __v) {
2395 size_t __i = 0;
2396 for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2397 *__t *= std::__get(__v, __i);
2398 return *this;
2399}
2400
2401template <class _Tp>
2402template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2403inline valarray<_Tp>& valarray<_Tp>::operator/=(const _Expr& __v) {
2404 size_t __i = 0;
2405 for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2406 *__t /= std::__get(__v, __i);
2407 return *this;
2408}
2409
2410template <class _Tp>
2411template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2412inline valarray<_Tp>& valarray<_Tp>::operator%=(const _Expr& __v) {
2413 size_t __i = 0;
2414 for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2415 *__t %= std::__get(__v, __i);
2416 return *this;
2417}
2418
2419template <class _Tp>
2420template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2421inline valarray<_Tp>& valarray<_Tp>::operator+=(const _Expr& __v) {
2422 size_t __i = 0;
2423 for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2424 *__t += std::__get(__v, __i);
2425 return *this;
2426}
2427
2428template <class _Tp>
2429template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2430inline valarray<_Tp>& valarray<_Tp>::operator-=(const _Expr& __v) {
2431 size_t __i = 0;
2432 for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2433 *__t -= std::__get(__v, __i);
2434 return *this;
2435}
2436
2437template <class _Tp>
2438template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2439inline valarray<_Tp>& valarray<_Tp>::operator^=(const _Expr& __v) {
2440 size_t __i = 0;
2441 for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2442 *__t ^= std::__get(__v, __i);
2443 return *this;
2444}
2445
2446template <class _Tp>
2447template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2448inline valarray<_Tp>& valarray<_Tp>::operator|=(const _Expr& __v) {
2449 size_t __i = 0;
2450 for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2451 *__t |= std::__get(__v, __i);
2452 return *this;
2453}
2454
2455template <class _Tp>
2456template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2457inline valarray<_Tp>& valarray<_Tp>::operator&=(const _Expr& __v) {
2458 size_t __i = 0;
2459 for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2460 *__t &= std::__get(__v, __i);
2461 return *this;
2462}
2463
2464template <class _Tp>
2465template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2466inline valarray<_Tp>& valarray<_Tp>::operator<<=(const _Expr& __v) {
2467 size_t __i = 0;
2468 for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2469 *__t <<= std::__get(__v, __i);
2470 return *this;
2471}
2472
2473template <class _Tp>
2474template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2475inline valarray<_Tp>& valarray<_Tp>::operator>>=(const _Expr& __v) {
2476 size_t __i = 0;
2477 for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2478 *__t >>= std::__get(__v, __i);
2479 return *this;
2480}
2481
2482template <class _Tp>
2483inline void valarray<_Tp>::swap(valarray& __v) _NOEXCEPT {
2484 std::swap(__begin_, __v.__begin_);
2485 std::swap(__end_, __v.__end_);
2486}
2487
2488template <class _Tp>
2489inline _Tp valarray<_Tp>::sum() const {
2490 if (__begin_ == __end_)
2491 return value_type();
2492 const value_type* __p = __begin_;
2493 _Tp __r = *__p;
2494 for (++__p; __p != __end_; ++__p)
2495 __r += *__p;
2496 return __r;
2497}
2498
2499template <class _Tp>
2500inline _Tp valarray<_Tp>::min() const {
2501 if (__begin_ == __end_)
2502 return value_type();
2503 return *std::min_element(__begin_, __end_);
2504}
2505
2506template <class _Tp>
2507inline _Tp valarray<_Tp>::max() const {
2508 if (__begin_ == __end_)
2509 return value_type();
2510 return *std::max_element(__begin_, __end_);
2511}
2512
2513template <class _Tp>
2514valarray<_Tp> valarray<_Tp>::shift(int __i) const {
2515 valarray<value_type> __r;
2516 size_t __n = size();
2517 if (__n) {
2518 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
2519 const value_type* __sb;
2520 value_type* __tb;
2521 value_type* __te;
2522 if (__i >= 0) {
2523 __i = std::min(a: __i, b: static_cast<int>(__n));
2524 __sb = __begin_ + __i;
2525 __tb = __r.__begin_;
2526 __te = __r.__begin_ + (__n - __i);
2527 } else {
2528 __i = std::min(a: -__i, b: static_cast<int>(__n));
2529 __sb = __begin_;
2530 __tb = __r.__begin_ + __i;
2531 __te = __r.__begin_ + __n;
2532 }
2533 for (; __r.__end_ != __tb; ++__r.__end_)
2534 ::new ((void*)__r.__end_) value_type();
2535 for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
2536 ::new ((void*)__r.__end_) value_type(*__sb);
2537 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
2538 ::new ((void*)__r.__end_) value_type();
2539 }
2540 return __r;
2541}
2542
2543template <class _Tp>
2544valarray<_Tp> valarray<_Tp>::cshift(int __i) const {
2545 valarray<value_type> __r;
2546 size_t __n = size();
2547 if (__n) {
2548 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
2549 __i %= static_cast<int>(__n);
2550 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
2551 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
2552 ::new ((void*)__r.__end_) value_type(*__s);
2553 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
2554 ::new ((void*)__r.__end_) value_type(*__s);
2555 }
2556 return __r;
2557}
2558
2559template <class _Tp>
2560valarray<_Tp> valarray<_Tp>::apply(value_type __f(value_type)) const {
2561 valarray<value_type> __r;
2562 size_t __n = size();
2563 if (__n) {
2564 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
2565 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
2566 ::new ((void*)__r.__end_) value_type(__f(*__p));
2567 }
2568 return __r;
2569}
2570
2571template <class _Tp>
2572valarray<_Tp> valarray<_Tp>::apply(value_type __f(const value_type&)) const {
2573 valarray<value_type> __r;
2574 size_t __n = size();
2575 if (__n) {
2576 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
2577 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
2578 ::new ((void*)__r.__end_) value_type(__f(*__p));
2579 }
2580 return __r;
2581}
2582
2583template <class _Tp>
2584inline void valarray<_Tp>::__clear(size_t __capacity) {
2585 if (__begin_ != nullptr) {
2586 while (__end_ != __begin_)
2587 (--__end_)->~value_type();
2588 allocator<value_type>().deallocate(__begin_, __capacity);
2589 __begin_ = __end_ = nullptr;
2590 }
2591}
2592
2593template <class _Tp>
2594void valarray<_Tp>::resize(size_t __n, value_type __x) {
2595 __clear(capacity: size());
2596 if (__n) {
2597 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2598 auto __guard = std::__make_exception_guard([&] { __clear(capacity: __n); });
2599 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
2600 ::new ((void*)__end_) value_type(__x);
2601 __guard.__complete();
2602 }
2603}
2604
2605template <class _Tp>
2606inline _LIBCPP_HIDE_FROM_ABI void swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT {
2607 __x.swap(__y);
2608}
2609
2610template <class _Expr1,
2611 class _Expr2,
2612 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2613inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
2614operator*(const _Expr1& __x, const _Expr2& __y) {
2615 typedef typename _Expr1::value_type value_type;
2616 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
2617 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
2618}
2619
2620template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2621inline _LIBCPP_HIDE_FROM_ABI
2622__val_expr<_BinaryOp<multiplies<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2623operator*(const _Expr& __x, const typename _Expr::value_type& __y) {
2624 typedef typename _Expr::value_type value_type;
2625 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2626 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2627}
2628
2629template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2630inline _LIBCPP_HIDE_FROM_ABI
2631__val_expr<_BinaryOp<multiplies<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2632operator*(const typename _Expr::value_type& __x, const _Expr& __y) {
2633 typedef typename _Expr::value_type value_type;
2634 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2635 return __val_expr<_Op>(_Op(multiplies<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2636}
2637
2638template <class _Expr1,
2639 class _Expr2,
2640 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2641inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
2642operator/(const _Expr1& __x, const _Expr2& __y) {
2643 typedef typename _Expr1::value_type value_type;
2644 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
2645 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
2646}
2647
2648template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2649inline _LIBCPP_HIDE_FROM_ABI
2650__val_expr<_BinaryOp<divides<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2651operator/(const _Expr& __x, const typename _Expr::value_type& __y) {
2652 typedef typename _Expr::value_type value_type;
2653 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2654 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2655}
2656
2657template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2658inline _LIBCPP_HIDE_FROM_ABI
2659__val_expr<_BinaryOp<divides<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2660operator/(const typename _Expr::value_type& __x, const _Expr& __y) {
2661 typedef typename _Expr::value_type value_type;
2662 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2663 return __val_expr<_Op>(_Op(divides<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2664}
2665
2666template <class _Expr1,
2667 class _Expr2,
2668 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2669inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
2670operator%(const _Expr1& __x, const _Expr2& __y) {
2671 typedef typename _Expr1::value_type value_type;
2672 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
2673 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
2674}
2675
2676template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2677inline _LIBCPP_HIDE_FROM_ABI
2678__val_expr<_BinaryOp<modulus<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2679operator%(const _Expr& __x, const typename _Expr::value_type& __y) {
2680 typedef typename _Expr::value_type value_type;
2681 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2682 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2683}
2684
2685template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2686inline _LIBCPP_HIDE_FROM_ABI
2687__val_expr<_BinaryOp<modulus<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2688operator%(const typename _Expr::value_type& __x, const _Expr& __y) {
2689 typedef typename _Expr::value_type value_type;
2690 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2691 return __val_expr<_Op>(_Op(modulus<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2692}
2693
2694template <class _Expr1,
2695 class _Expr2,
2696 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2697inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
2698operator+(const _Expr1& __x, const _Expr2& __y) {
2699 typedef typename _Expr1::value_type value_type;
2700 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
2701 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
2702}
2703
2704template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2705inline _LIBCPP_HIDE_FROM_ABI
2706__val_expr<_BinaryOp<plus<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2707operator+(const _Expr& __x, const typename _Expr::value_type& __y) {
2708 typedef typename _Expr::value_type value_type;
2709 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2710 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2711}
2712
2713template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2714inline _LIBCPP_HIDE_FROM_ABI
2715__val_expr<_BinaryOp<plus<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2716operator+(const typename _Expr::value_type& __x, const _Expr& __y) {
2717 typedef typename _Expr::value_type value_type;
2718 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2719 return __val_expr<_Op>(_Op(plus<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2720}
2721
2722template <class _Expr1,
2723 class _Expr2,
2724 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2725inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
2726operator-(const _Expr1& __x, const _Expr2& __y) {
2727 typedef typename _Expr1::value_type value_type;
2728 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
2729 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
2730}
2731
2732template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2733inline _LIBCPP_HIDE_FROM_ABI
2734__val_expr<_BinaryOp<minus<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2735operator-(const _Expr& __x, const typename _Expr::value_type& __y) {
2736 typedef typename _Expr::value_type value_type;
2737 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2738 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2739}
2740
2741template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2742inline _LIBCPP_HIDE_FROM_ABI
2743__val_expr<_BinaryOp<minus<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2744operator-(const typename _Expr::value_type& __x, const _Expr& __y) {
2745 typedef typename _Expr::value_type value_type;
2746 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2747 return __val_expr<_Op>(_Op(minus<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2748}
2749
2750template <class _Expr1,
2751 class _Expr2,
2752 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2753inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
2754operator^(const _Expr1& __x, const _Expr2& __y) {
2755 typedef typename _Expr1::value_type value_type;
2756 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
2757 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
2758}
2759
2760template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2761inline _LIBCPP_HIDE_FROM_ABI
2762__val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2763operator^(const _Expr& __x, const typename _Expr::value_type& __y) {
2764 typedef typename _Expr::value_type value_type;
2765 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2766 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2767}
2768
2769template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2770inline _LIBCPP_HIDE_FROM_ABI
2771__val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2772operator^(const typename _Expr::value_type& __x, const _Expr& __y) {
2773 typedef typename _Expr::value_type value_type;
2774 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2775 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2776}
2777
2778template <class _Expr1,
2779 class _Expr2,
2780 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2781inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
2782operator&(const _Expr1& __x, const _Expr2& __y) {
2783 typedef typename _Expr1::value_type value_type;
2784 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
2785 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
2786}
2787
2788template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2789inline _LIBCPP_HIDE_FROM_ABI
2790__val_expr<_BinaryOp<bit_and<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2791operator&(const _Expr& __x, const typename _Expr::value_type& __y) {
2792 typedef typename _Expr::value_type value_type;
2793 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2794 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2795}
2796
2797template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2798inline _LIBCPP_HIDE_FROM_ABI
2799__val_expr<_BinaryOp<bit_and<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2800operator&(const typename _Expr::value_type& __x, const _Expr& __y) {
2801 typedef typename _Expr::value_type value_type;
2802 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2803 return __val_expr<_Op>(_Op(bit_and<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2804}
2805
2806template <class _Expr1,
2807 class _Expr2,
2808 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2809inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
2810operator|(const _Expr1& __x, const _Expr2& __y) {
2811 typedef typename _Expr1::value_type value_type;
2812 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
2813 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
2814}
2815
2816template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2817inline _LIBCPP_HIDE_FROM_ABI
2818__val_expr<_BinaryOp<bit_or<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2819operator|(const _Expr& __x, const typename _Expr::value_type& __y) {
2820 typedef typename _Expr::value_type value_type;
2821 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2822 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2823}
2824
2825template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2826inline _LIBCPP_HIDE_FROM_ABI
2827__val_expr<_BinaryOp<bit_or<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2828operator|(const typename _Expr::value_type& __x, const _Expr& __y) {
2829 typedef typename _Expr::value_type value_type;
2830 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2831 return __val_expr<_Op>(_Op(bit_or<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2832}
2833
2834template <class _Expr1,
2835 class _Expr2,
2836 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2837inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
2838operator<<(const _Expr1& __x, const _Expr2& __y) {
2839 typedef typename _Expr1::value_type value_type;
2840 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
2841 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
2842}
2843
2844template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2845inline _LIBCPP_HIDE_FROM_ABI
2846__val_expr< _BinaryOp<__bit_shift_left<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2847operator<<(const _Expr& __x, const typename _Expr::value_type& __y) {
2848 typedef typename _Expr::value_type value_type;
2849 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2850 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2851}
2852
2853template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2854inline _LIBCPP_HIDE_FROM_ABI
2855__val_expr< _BinaryOp<__bit_shift_left<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2856operator<<(const typename _Expr::value_type& __x, const _Expr& __y) {
2857 typedef typename _Expr::value_type value_type;
2858 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2859 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2860}
2861
2862template <class _Expr1,
2863 class _Expr2,
2864 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2865inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
2866operator>>(const _Expr1& __x, const _Expr2& __y) {
2867 typedef typename _Expr1::value_type value_type;
2868 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
2869 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
2870}
2871
2872template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2873inline _LIBCPP_HIDE_FROM_ABI __val_expr<
2874 _BinaryOp<__bit_shift_right<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2875operator>>(const _Expr& __x, const typename _Expr::value_type& __y) {
2876 typedef typename _Expr::value_type value_type;
2877 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2878 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2879}
2880
2881template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2882inline _LIBCPP_HIDE_FROM_ABI
2883__val_expr< _BinaryOp<__bit_shift_right<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2884operator>>(const typename _Expr::value_type& __x, const _Expr& __y) {
2885 typedef typename _Expr::value_type value_type;
2886 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2887 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2888}
2889
2890template <class _Expr1,
2891 class _Expr2,
2892 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2893inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
2894operator&&(const _Expr1& __x, const _Expr2& __y) {
2895 typedef typename _Expr1::value_type value_type;
2896 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
2897 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
2898}
2899
2900template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2901inline _LIBCPP_HIDE_FROM_ABI
2902__val_expr<_BinaryOp<logical_and<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2903operator&&(const _Expr& __x, const typename _Expr::value_type& __y) {
2904 typedef typename _Expr::value_type value_type;
2905 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2906 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2907}
2908
2909template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2910inline _LIBCPP_HIDE_FROM_ABI
2911__val_expr<_BinaryOp<logical_and<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2912operator&&(const typename _Expr::value_type& __x, const _Expr& __y) {
2913 typedef typename _Expr::value_type value_type;
2914 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2915 return __val_expr<_Op>(_Op(logical_and<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2916}
2917
2918template <class _Expr1,
2919 class _Expr2,
2920 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2921inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
2922operator||(const _Expr1& __x, const _Expr2& __y) {
2923 typedef typename _Expr1::value_type value_type;
2924 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
2925 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
2926}
2927
2928template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2929inline _LIBCPP_HIDE_FROM_ABI
2930__val_expr<_BinaryOp<logical_or<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2931operator||(const _Expr& __x, const typename _Expr::value_type& __y) {
2932 typedef typename _Expr::value_type value_type;
2933 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2934 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2935}
2936
2937template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2938inline _LIBCPP_HIDE_FROM_ABI
2939__val_expr<_BinaryOp<logical_or<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2940operator||(const typename _Expr::value_type& __x, const _Expr& __y) {
2941 typedef typename _Expr::value_type value_type;
2942 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2943 return __val_expr<_Op>(_Op(logical_or<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2944}
2945
2946template <class _Expr1,
2947 class _Expr2,
2948 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2949inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
2950operator==(const _Expr1& __x, const _Expr2& __y) {
2951 typedef typename _Expr1::value_type value_type;
2952 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
2953 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
2954}
2955
2956template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2957inline _LIBCPP_HIDE_FROM_ABI
2958__val_expr<_BinaryOp<equal_to<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2959operator==(const _Expr& __x, const typename _Expr::value_type& __y) {
2960 typedef typename _Expr::value_type value_type;
2961 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2962 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2963}
2964
2965template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2966inline _LIBCPP_HIDE_FROM_ABI
2967__val_expr<_BinaryOp<equal_to<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2968operator==(const typename _Expr::value_type& __x, const _Expr& __y) {
2969 typedef typename _Expr::value_type value_type;
2970 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2971 return __val_expr<_Op>(_Op(equal_to<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2972}
2973
2974template <class _Expr1,
2975 class _Expr2,
2976 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2977inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
2978operator!=(const _Expr1& __x, const _Expr2& __y) {
2979 typedef typename _Expr1::value_type value_type;
2980 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
2981 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
2982}
2983
2984template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2985inline _LIBCPP_HIDE_FROM_ABI
2986__val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2987operator!=(const _Expr& __x, const typename _Expr::value_type& __y) {
2988 typedef typename _Expr::value_type value_type;
2989 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2990 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2991}
2992
2993template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2994inline _LIBCPP_HIDE_FROM_ABI
2995__val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2996operator!=(const typename _Expr::value_type& __x, const _Expr& __y) {
2997 typedef typename _Expr::value_type value_type;
2998 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2999 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
3000}
3001
3002template <class _Expr1,
3003 class _Expr2,
3004 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
3005inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
3006operator<(const _Expr1& __x, const _Expr2& __y) {
3007 typedef typename _Expr1::value_type value_type;
3008 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
3009 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
3010}
3011
3012template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3013inline _LIBCPP_HIDE_FROM_ABI
3014__val_expr<_BinaryOp<less<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
3015operator<(const _Expr& __x, const typename _Expr::value_type& __y) {
3016 typedef typename _Expr::value_type value_type;
3017 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3018 return __val_expr<_Op>(_Op(less<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
3019}
3020
3021template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3022inline _LIBCPP_HIDE_FROM_ABI
3023__val_expr<_BinaryOp<less<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
3024operator<(const typename _Expr::value_type& __x, const _Expr& __y) {
3025 typedef typename _Expr::value_type value_type;
3026 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3027 return __val_expr<_Op>(_Op(less<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
3028}
3029
3030template <class _Expr1,
3031 class _Expr2,
3032 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
3033inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
3034operator>(const _Expr1& __x, const _Expr2& __y) {
3035 typedef typename _Expr1::value_type value_type;
3036 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
3037 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
3038}
3039
3040template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3041inline _LIBCPP_HIDE_FROM_ABI
3042__val_expr<_BinaryOp<greater<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
3043operator>(const _Expr& __x, const typename _Expr::value_type& __y) {
3044 typedef typename _Expr::value_type value_type;
3045 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3046 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
3047}
3048
3049template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3050inline _LIBCPP_HIDE_FROM_ABI
3051__val_expr<_BinaryOp<greater<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
3052operator>(const typename _Expr::value_type& __x, const _Expr& __y) {
3053 typedef typename _Expr::value_type value_type;
3054 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3055 return __val_expr<_Op>(_Op(greater<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
3056}
3057
3058template <class _Expr1,
3059 class _Expr2,
3060 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
3061inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
3062operator<=(const _Expr1& __x, const _Expr2& __y) {
3063 typedef typename _Expr1::value_type value_type;
3064 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
3065 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
3066}
3067
3068template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3069inline _LIBCPP_HIDE_FROM_ABI
3070__val_expr<_BinaryOp<less_equal<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
3071operator<=(const _Expr& __x, const typename _Expr::value_type& __y) {
3072 typedef typename _Expr::value_type value_type;
3073 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3074 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
3075}
3076
3077template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3078inline _LIBCPP_HIDE_FROM_ABI
3079__val_expr<_BinaryOp<less_equal<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
3080operator<=(const typename _Expr::value_type& __x, const _Expr& __y) {
3081 typedef typename _Expr::value_type value_type;
3082 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3083 return __val_expr<_Op>(_Op(less_equal<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
3084}
3085
3086template <class _Expr1,
3087 class _Expr2,
3088 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
3089inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
3090operator>=(const _Expr1& __x, const _Expr2& __y) {
3091 typedef typename _Expr1::value_type value_type;
3092 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
3093 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
3094}
3095
3096template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3097inline _LIBCPP_HIDE_FROM_ABI
3098__val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
3099operator>=(const _Expr& __x, const typename _Expr::value_type& __y) {
3100 typedef typename _Expr::value_type value_type;
3101 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3102 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
3103}
3104
3105template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3106inline _LIBCPP_HIDE_FROM_ABI
3107__val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
3108operator>=(const typename _Expr::value_type& __x, const _Expr& __y) {
3109 typedef typename _Expr::value_type value_type;
3110 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3111 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
3112}
3113
3114template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3115[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
3116abs(const _Expr& __x) {
3117 typedef typename _Expr::value_type value_type;
3118 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
3119 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
3120}
3121
3122template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3123[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
3124acos(const _Expr& __x) {
3125 typedef typename _Expr::value_type value_type;
3126 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
3127 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
3128}
3129
3130template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3131[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
3132asin(const _Expr& __x) {
3133 typedef typename _Expr::value_type value_type;
3134 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
3135 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
3136}
3137
3138template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3139[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
3140atan(const _Expr& __x) {
3141 typedef typename _Expr::value_type value_type;
3142 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
3143 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
3144}
3145
3146template <class _Expr1,
3147 class _Expr2,
3148 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
3149[[__nodiscard__]] inline
3150 _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
3151 atan2(const _Expr1& __x, const _Expr2& __y) {
3152 typedef typename _Expr1::value_type value_type;
3153 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
3154 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
3155}
3156
3157template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3158[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI
3159__val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
3160atan2(const _Expr& __x, const typename _Expr::value_type& __y) {
3161 typedef typename _Expr::value_type value_type;
3162 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3163 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
3164}
3165
3166template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3167[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI
3168__val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
3169atan2(const typename _Expr::value_type& __x, const _Expr& __y) {
3170 typedef typename _Expr::value_type value_type;
3171 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3172 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
3173}
3174
3175template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3176[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
3177cos(const _Expr& __x) {
3178 typedef typename _Expr::value_type value_type;
3179 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
3180 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
3181}
3182
3183template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3184[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
3185cosh(const _Expr& __x) {
3186 typedef typename _Expr::value_type value_type;
3187 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
3188 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
3189}
3190
3191template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3192[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
3193exp(const _Expr& __x) {
3194 typedef typename _Expr::value_type value_type;
3195 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
3196 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
3197}
3198
3199template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3200[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
3201log(const _Expr& __x) {
3202 typedef typename _Expr::value_type value_type;
3203 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
3204 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
3205}
3206
3207template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3208[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
3209log10(const _Expr& __x) {
3210 typedef typename _Expr::value_type value_type;
3211 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
3212 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
3213}
3214
3215template <class _Expr1,
3216 class _Expr2,
3217 __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
3218[[__nodiscard__]] inline
3219 _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
3220 pow(const _Expr1& __x, const _Expr2& __y) {
3221 typedef typename _Expr1::value_type value_type;
3222 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
3223 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
3224}
3225
3226template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3227[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI
3228__val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
3229pow(const _Expr& __x, const typename _Expr::value_type& __y) {
3230 typedef typename _Expr::value_type value_type;
3231 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3232 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
3233}
3234
3235template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3236[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI
3237__val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
3238pow(const typename _Expr::value_type& __x, const _Expr& __y) {
3239 typedef typename _Expr::value_type value_type;
3240 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3241 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
3242}
3243
3244template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3245[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
3246sin(const _Expr& __x) {
3247 typedef typename _Expr::value_type value_type;
3248 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
3249 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
3250}
3251
3252template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3253[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
3254sinh(const _Expr& __x) {
3255 typedef typename _Expr::value_type value_type;
3256 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
3257 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
3258}
3259
3260template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3261[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
3262sqrt(const _Expr& __x) {
3263 typedef typename _Expr::value_type value_type;
3264 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
3265 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
3266}
3267
3268template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3269[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
3270tan(const _Expr& __x) {
3271 typedef typename _Expr::value_type value_type;
3272 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
3273 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
3274}
3275
3276template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3277[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
3278tanh(const _Expr& __x) {
3279 typedef typename _Expr::value_type value_type;
3280 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
3281 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
3282}
3283
3284template <class _Tp>
3285[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _Tp* begin(valarray<_Tp>& __v) {
3286 return __v.__begin_;
3287}
3288
3289template <class _Tp>
3290[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI const _Tp* begin(const valarray<_Tp>& __v) {
3291 return __v.__begin_;
3292}
3293
3294template <class _Tp>
3295[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _Tp* end(valarray<_Tp>& __v) {
3296 return __v.__end_;
3297}
3298
3299template <class _Tp>
3300[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI const _Tp* end(const valarray<_Tp>& __v) {
3301 return __v.__end_;
3302}
3303
3304_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS
3305_LIBCPP_END_NAMESPACE_STD
3306
3307_LIBCPP_POP_MACROS
3308
3309# if defined(_LIBCPP_KEEP_TRANSITIVE_INCLUDES_LLVM23) && _LIBCPP_STD_VER <= 20
3310# include <algorithm>
3311# include <concepts>
3312# include <cstdlib>
3313# include <cstring>
3314# include <functional>
3315# include <stdexcept>
3316# include <type_traits>
3317# endif
3318#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
3319
3320#endif // _LIBCPP_VALARRAY
3321