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