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