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