Debian Codegraph @

llvm-project/libcxx/include/valarray

raw
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 namespace std
17 {
18
19 template<class T>
20 class valarray
21 {
22 public:
23 typedef T value_type;
24
25 // construct/destroy:
26 valarray();
27 explicit valarray(size_t n);
28 valarray(const value_type& x, size_t n);
29 valarray(const value_type* px, size_t n);
30 valarray(const valarray& v);
31 valarray(valarray&& v) noexcept;
32 valarray(const slice_array<value_type>& sa);
33 valarray(const gslice_array<value_type>& ga);
34 valarray(const mask_array<value_type>& ma);
35 valarray(const indirect_array<value_type>& ia);
36 valarray(initializer_list<value_type> il);
37 ~valarray();
38
39 // assignment:
40 valarray& operator=(const valarray& v);
41 valarray& operator=(valarray&& v) noexcept;
42 valarray& operator=(initializer_list<value_type> il);
43 valarray& operator=(const value_type& x);
44 valarray& operator=(const slice_array<value_type>& sa);
45 valarray& operator=(const gslice_array<value_type>& ga);
46 valarray& operator=(const mask_array<value_type>& ma);
47 valarray& operator=(const indirect_array<value_type>& ia);
48
49 // element access:
50 const value_type& operator[](size_t i) const;
51 value_type& operator[](size_t i);
52
53 // subset operations:
54 valarray operator[](slice s) const;
55 slice_array<value_type> operator[](slice s);
56 valarray operator[](const gslice& gs) const;
57 gslice_array<value_type> operator[](const gslice& gs);
58 valarray operator[](const valarray<bool>& vb) const;
59 mask_array<value_type> operator[](const valarray<bool>& vb);
60 valarray operator[](const valarray<size_t>& vs) const;
61 indirect_array<value_type> operator[](const valarray<size_t>& vs);
62
63 // unary operators:
64 valarray operator+() const;
65 valarray operator-() const;
66 valarray operator~() const;
67 valarray<bool> operator!() const;
68
69 // computed assignment:
70 valarray& operator*= (const value_type& x);
71 valarray& operator/= (const value_type& x);
72 valarray& operator%= (const value_type& x);
73 valarray& operator+= (const value_type& x);
74 valarray& operator-= (const value_type& x);
75 valarray& operator^= (const value_type& x);
76 valarray& operator&= (const value_type& x);
77 valarray& operator|= (const value_type& x);
78 valarray& operator<<=(const value_type& x);
79 valarray& operator>>=(const value_type& x);
80
81 valarray& operator*= (const valarray& v);
82 valarray& operator/= (const valarray& v);
83 valarray& operator%= (const valarray& v);
84 valarray& operator+= (const valarray& v);
85 valarray& operator-= (const valarray& v);
86 valarray& operator^= (const valarray& v);
87 valarray& operator|= (const valarray& v);
88 valarray& operator&= (const valarray& v);
89 valarray& operator<<=(const valarray& v);
90 valarray& operator>>=(const valarray& v);
91
92 // member functions:
93 void swap(valarray& v) noexcept;
94
95 size_t size() const;
96
97 value_type sum() const;
98 value_type min() const;
99 value_type max() const;
100
101 valarray shift (int i) const;
102 valarray cshift(int i) const;
103 valarray apply(value_type f(value_type)) const;
104 valarray apply(value_type f(const value_type&)) const;
105 void resize(size_t n, value_type x = value_type());
106 };
107
108 template<class T, size_t cnt> valarray(const T(&)[cnt], size_t) -> valarray<T>;
109
110 class slice
111 {
112 public:
113 slice();
114 slice(size_t start, size_t size, size_t stride);
115
116 size_t start() const;
117 size_t size() const;
118 size_t stride() const;
119 };
120
121 template <class T>
122 class slice_array
123 {
124 public:
125 typedef T value_type;
126
127 const slice_array& operator=(const slice_array& sa) const;
128 void operator= (const valarray<value_type>& v) const;
129 void operator*= (const valarray<value_type>& v) const;
130 void operator/= (const valarray<value_type>& v) const;
131 void operator%= (const valarray<value_type>& v) const;
132 void operator+= (const valarray<value_type>& v) const;
133 void operator-= (const valarray<value_type>& v) const;
134 void operator^= (const valarray<value_type>& v) const;
135 void operator&= (const valarray<value_type>& v) const;
136 void operator|= (const valarray<value_type>& v) const;
137 void operator<<=(const valarray<value_type>& v) const;
138 void operator>>=(const valarray<value_type>& v) const;
139
140 void operator=(const value_type& x) const;
141 void operator=(const valarray<T>& val_arr) const;
142
143 slice_array() = delete;
144 };
145
146 class gslice
147 {
148 public:
149 gslice();
150 gslice(size_t start, const valarray<size_t>& size,
151 const valarray<size_t>& stride);
152
153 size_t start() const;
154 valarray<size_t> size() const;
155 valarray<size_t> stride() const;
156 };
157
158 template <class T>
159 class gslice_array
160 {
161 public:
162 typedef T value_type;
163
164 void operator= (const valarray<value_type>& v) const;
165 void operator*= (const valarray<value_type>& v) const;
166 void operator/= (const valarray<value_type>& v) const;
167 void operator%= (const valarray<value_type>& v) const;
168 void operator+= (const valarray<value_type>& v) const;
169 void operator-= (const valarray<value_type>& v) const;
170 void operator^= (const valarray<value_type>& v) const;
171 void operator&= (const valarray<value_type>& v) const;
172 void operator|= (const valarray<value_type>& v) const;
173 void operator<<=(const valarray<value_type>& v) const;
174 void operator>>=(const valarray<value_type>& v) const;
175
176 gslice_array(const gslice_array& ga);
177 ~gslice_array();
178 const gslice_array& operator=(const gslice_array& ga) const;
179 void operator=(const value_type& x) const;
180
181 gslice_array() = delete;
182 };
183
184 template <class T>
185 class mask_array
186 {
187 public:
188 typedef T value_type;
189
190 void operator= (const valarray<value_type>& v) const;
191 void operator*= (const valarray<value_type>& v) const;
192 void operator/= (const valarray<value_type>& v) const;
193 void operator%= (const valarray<value_type>& v) const;
194 void operator+= (const valarray<value_type>& v) const;
195 void operator-= (const valarray<value_type>& v) const;
196 void operator^= (const valarray<value_type>& v) const;
197 void operator&= (const valarray<value_type>& v) const;
198 void operator|= (const valarray<value_type>& v) const;
199 void operator<<=(const valarray<value_type>& v) const;
200 void operator>>=(const valarray<value_type>& v) const;
201
202 mask_array(const mask_array& ma);
203 ~mask_array();
204 const mask_array& operator=(const mask_array& ma) const;
205 void operator=(const value_type& x) const;
206
207 mask_array() = delete;
208 };
209
210 template <class T>
211 class indirect_array
212 {
213 public:
214 typedef T value_type;
215
216 void operator= (const valarray<value_type>& v) const;
217 void operator*= (const valarray<value_type>& v) const;
218 void operator/= (const valarray<value_type>& v) const;
219 void operator%= (const valarray<value_type>& v) const;
220 void operator+= (const valarray<value_type>& v) const;
221 void operator-= (const valarray<value_type>& v) const;
222 void operator^= (const valarray<value_type>& v) const;
223 void operator&= (const valarray<value_type>& v) const;
224 void operator|= (const valarray<value_type>& v) const;
225 void operator<<=(const valarray<value_type>& v) const;
226 void operator>>=(const valarray<value_type>& v) const;
227
228 indirect_array(const indirect_array& ia);
229 ~indirect_array();
230 const indirect_array& operator=(const indirect_array& ia) const;
231 void operator=(const value_type& x) const;
232
233 indirect_array() = delete;
234 };
235
236 template<class T> void swap(valarray<T>& x, valarray<T>& y) noexcept;
237
238 template<class T> valarray<T> operator* (const valarray<T>& x, const valarray<T>& y);
239 template<class T> valarray<T> operator* (const valarray<T>& x, const T& y);
240 template<class T> valarray<T> operator* (const T& x, const valarray<T>& y);
241
242 template<class T> valarray<T> operator/ (const valarray<T>& x, const valarray<T>& y);
243 template<class T> valarray<T> operator/ (const valarray<T>& x, const T& y);
244 template<class T> valarray<T> operator/ (const T& x, const valarray<T>& y);
245
246 template<class T> valarray<T> operator% (const valarray<T>& x, const valarray<T>& y);
247 template<class T> valarray<T> operator% (const valarray<T>& x, const T& y);
248 template<class T> valarray<T> operator% (const T& x, const valarray<T>& y);
249
250 template<class T> valarray<T> operator+ (const valarray<T>& x, const valarray<T>& y);
251 template<class T> valarray<T> operator+ (const valarray<T>& x, const T& y);
252 template<class T> valarray<T> operator+ (const T& x, const valarray<T>& y);
253
254 template<class T> valarray<T> operator- (const valarray<T>& x, const valarray<T>& y);
255 template<class T> valarray<T> operator- (const valarray<T>& x, const T& y);
256 template<class T> valarray<T> operator- (const T& x, const valarray<T>& y);
257
258 template<class T> valarray<T> operator^ (const valarray<T>& x, const valarray<T>& y);
259 template<class T> valarray<T> operator^ (const valarray<T>& x, const T& y);
260 template<class T> valarray<T> operator^ (const T& x, const valarray<T>& y);
261
262 template<class T> valarray<T> operator& (const valarray<T>& x, const valarray<T>& y);
263 template<class T> valarray<T> operator& (const valarray<T>& x, const T& y);
264 template<class T> valarray<T> operator& (const T& x, const valarray<T>& y);
265
266 template<class T> valarray<T> operator| (const valarray<T>& x, const valarray<T>& y);
267 template<class T> valarray<T> operator| (const valarray<T>& x, const T& y);
268 template<class T> valarray<T> operator| (const T& x, const valarray<T>& y);
269
270 template<class T> valarray<T> operator<<(const valarray<T>& x, const valarray<T>& y);
271 template<class T> valarray<T> operator<<(const valarray<T>& x, const T& y);
272 template<class T> valarray<T> operator<<(const T& x, const valarray<T>& y);
273
274 template<class T> valarray<T> operator>>(const valarray<T>& x, const valarray<T>& y);
275 template<class T> valarray<T> operator>>(const valarray<T>& x, const T& y);
276 template<class T> valarray<T> operator>>(const T& x, const valarray<T>& y);
277
278 template<class T> valarray<bool> operator&&(const valarray<T>& x, const valarray<T>& y);
279 template<class T> valarray<bool> operator&&(const valarray<T>& x, const T& y);
280 template<class T> valarray<bool> operator&&(const T& x, const valarray<T>& y);
281
282 template<class T> valarray<bool> operator||(const valarray<T>& x, const valarray<T>& y);
283 template<class T> valarray<bool> operator||(const valarray<T>& x, const T& y);
284 template<class T> valarray<bool> operator||(const T& x, const valarray<T>& y);
285
286 template<class T> valarray<bool> operator==(const valarray<T>& x, const valarray<T>& y);
287 template<class T> valarray<bool> operator==(const valarray<T>& x, const T& y);
288 template<class T> valarray<bool> operator==(const T& x, const valarray<T>& y);
289
290 template<class T> valarray<bool> operator!=(const valarray<T>& x, const valarray<T>& y);
291 template<class T> valarray<bool> operator!=(const valarray<T>& x, const T& y);
292 template<class T> valarray<bool> operator!=(const T& x, const valarray<T>& y);
293
294 template<class T> valarray<bool> operator< (const valarray<T>& x, const valarray<T>& y);
295 template<class T> valarray<bool> operator< (const valarray<T>& x, const T& y);
296 template<class T> valarray<bool> operator< (const T& x, const valarray<T>& y);
297
298 template<class T> valarray<bool> operator> (const valarray<T>& x, const valarray<T>& y);
299 template<class T> valarray<bool> operator> (const valarray<T>& x, const T& y);
300 template<class T> valarray<bool> operator> (const T& x, const valarray<T>& y);
301
302 template<class T> valarray<bool> operator<=(const valarray<T>& x, const valarray<T>& y);
303 template<class T> valarray<bool> operator<=(const valarray<T>& x, const T& y);
304 template<class T> valarray<bool> operator<=(const T& x, const valarray<T>& y);
305
306 template<class T> valarray<bool> operator>=(const valarray<T>& x, const valarray<T>& y);
307 template<class T> valarray<bool> operator>=(const valarray<T>& x, const T& y);
308 template<class T> valarray<bool> operator>=(const T& x, const valarray<T>& y);
309
310 template<class T> valarray<T> abs (const valarray<T>& x);
311 template<class T> valarray<T> acos (const valarray<T>& x);
312 template<class T> valarray<T> asin (const valarray<T>& x);
313 template<class T> valarray<T> atan (const valarray<T>& x);
314
315 template<class T> valarray<T> atan2(const valarray<T>& x, const valarray<T>& y);
316 template<class T> valarray<T> atan2(const valarray<T>& x, const T& y);
317 template<class T> valarray<T> atan2(const T& x, const valarray<T>& y);
318
319 template<class T> valarray<T> cos (const valarray<T>& x);
320 template<class T> valarray<T> cosh (const valarray<T>& x);
321 template<class T> valarray<T> exp (const valarray<T>& x);
322 template<class T> valarray<T> log (const valarray<T>& x);
323 template<class T> valarray<T> log10(const valarray<T>& x);
324
325 template<class T> valarray<T> pow(const valarray<T>& x, const valarray<T>& y);
326 template<class T> valarray<T> pow(const valarray<T>& x, const T& y);
327 template<class T> valarray<T> pow(const T& x, const valarray<T>& y);
328
329 template<class T> valarray<T> sin (const valarray<T>& x);
330 template<class T> valarray<T> sinh (const valarray<T>& x);
331 template<class T> valarray<T> sqrt (const valarray<T>& x);
332 template<class T> valarray<T> tan (const valarray<T>& x);
333 template<class T> valarray<T> tanh (const valarray<T>& x);
334
335 template <class T> unspecified1 begin(valarray<T>& v);
336 template <class T> unspecified2 begin(const valarray<T>& v);
337 template <class T> unspecified1 end(valarray<T>& v);
338 template <class T> unspecified2 end(const valarray<T>& v);
339
340 } // std
341
342 */
343
344 #include <__algorithm/copy.h>
345 #include <__algorithm/count.h>
346 #include <__algorithm/fill.h>
347 #include <__algorithm/max_element.h>
348 #include <__algorithm/min.h>
349 #include <__algorithm/min_element.h>
350 #include <__algorithm/unwrap_iter.h>
351 #include <__assert> // all public C++ headers provide the assertion handler
352 #include <__config>
353 #include <__functional/operations.h>
354 #include <__memory/allocator.h>
355 #include <__memory/uninitialized_algorithms.h>
356 #include <__type_traits/remove_reference.h>
357 #include <__utility/move.h>
358 #include <__utility/swap.h>
359 #include <cmath>
360 #include <cstddef>
361 #include <new>
362 #include <version>
363
364 // standard-mandated includes
365
366 // [valarray.syn]
367 #include <initializer_list>
368
369 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
370 # pragma GCC system_header
371 #endif
372
373 _LIBCPP_PUSH_MACROS
374 #include <__undef_macros>
375
376 _LIBCPP_BEGIN_NAMESPACE_STD
377
378 template<class _Tp> class _LIBCPP_TEMPLATE_VIS valarray;
379
380 class _LIBCPP_TEMPLATE_VIS slice
381 {
382 size_t __start_;
383 size_t __size_;
384 size_t __stride_;
385 public:
386 _LIBCPP_INLINE_VISIBILITY
387 slice()
388 : __start_(0),
389 __size_(0),
390 __stride_(0)
391 {}
392
393 _LIBCPP_INLINE_VISIBILITY
394 slice(size_t __start, size_t __size, size_t __stride)
395 : __start_(__start),
396 __size_(__size),
397 __stride_(__stride)
398 {}
399
400 _LIBCPP_INLINE_VISIBILITY size_t start() const {return __start_;}
401 _LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;}
402 _LIBCPP_INLINE_VISIBILITY size_t stride() const {return __stride_;}
403 };
404
405 template <class _Tp> class _LIBCPP_TEMPLATE_VIS slice_array;
406 class _LIBCPP_TYPE_VIS gslice;
407 template <class _Tp> class _LIBCPP_TEMPLATE_VIS gslice_array;
408 template <class _Tp> class _LIBCPP_TEMPLATE_VIS mask_array;
409 template <class _Tp> class _LIBCPP_TEMPLATE_VIS indirect_array;
410
411 template <class _Tp>
412 _LIBCPP_INLINE_VISIBILITY
413 _Tp*
414 begin(valarray<_Tp>& __v);
415
416 template <class _Tp>
417 _LIBCPP_INLINE_VISIBILITY
418 const _Tp*
419 begin(const valarray<_Tp>& __v);
420
421 template <class _Tp>
422 _LIBCPP_INLINE_VISIBILITY
423 _Tp*
424 end(valarray<_Tp>& __v);
425
426 template <class _Tp>
427 _LIBCPP_INLINE_VISIBILITY
428 const _Tp*
429 end(const valarray<_Tp>& __v);
430
431 template <class _Op, class _A0>
432 struct _UnaryOp
433 {
434 typedef typename _Op::__result_type __result_type;
435 typedef typename decay<__result_type>::type value_type;
436
437 _Op __op_;
438 _A0 __a0_;
439
440 _LIBCPP_INLINE_VISIBILITY
441 _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {}
442
443 _LIBCPP_INLINE_VISIBILITY
444 __result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
445
446 _LIBCPP_INLINE_VISIBILITY
447 size_t size() const {return __a0_.size();}
448 };
449
450 template <class _Op, class _A0, class _A1>
451 struct _BinaryOp
452 {
453 typedef typename _Op::__result_type __result_type;
454 typedef typename decay<__result_type>::type value_type;
455
456 _Op __op_;
457 _A0 __a0_;
458 _A1 __a1_;
459
460 _LIBCPP_INLINE_VISIBILITY
461 _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1)
462 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
463
464 _LIBCPP_INLINE_VISIBILITY
465 __result_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
466
467 _LIBCPP_INLINE_VISIBILITY
468 size_t size() const {return __a0_.size();}
469 };
470
471 template <class _Tp>
472 class __scalar_expr
473 {
474 public:
475 typedef _Tp value_type;
476 typedef const _Tp& __result_type;
477 private:
478 const value_type& __t_;
479 size_t __s_;
480 public:
481 _LIBCPP_INLINE_VISIBILITY
482 explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {}
483
484 _LIBCPP_INLINE_VISIBILITY
485 __result_type operator[](size_t) const {return __t_;}
486
487 _LIBCPP_INLINE_VISIBILITY
488 size_t size() const {return __s_;}
489 };
490
491 template <class _Tp>
492 struct __unary_plus
493 {
494 typedef _Tp __result_type;
495 _LIBCPP_INLINE_VISIBILITY
496 _Tp operator()(const _Tp& __x) const
497 {return +__x;}
498 };
499
500 template <class _Tp>
501 struct __bit_not
502 {
503 typedef _Tp __result_type;
504 _LIBCPP_INLINE_VISIBILITY
505 _Tp operator()(const _Tp& __x) const
506 {return ~__x;}
507 };
508
509 template <class _Tp>
510 struct __bit_shift_left
511 {
512 typedef _Tp __result_type;
513 _LIBCPP_INLINE_VISIBILITY
514 _Tp operator()(const _Tp& __x, const _Tp& __y) const
515 {return __x << __y;}
516 };
517
518 template <class _Tp>
519 struct __bit_shift_right
520 {
521 typedef _Tp __result_type;
522 _LIBCPP_INLINE_VISIBILITY
523 _Tp operator()(const _Tp& __x, const _Tp& __y) const
524 {return __x >> __y;}
525 };
526
527 template <class _Tp, class _Fp>
528 struct __apply_expr
529 {
530 private:
531 _Fp __f_;
532 public:
533 typedef _Tp __result_type;
534
535 _LIBCPP_INLINE_VISIBILITY
536 explicit __apply_expr(_Fp __f) : __f_(__f) {}
537
538 _LIBCPP_INLINE_VISIBILITY
539 _Tp operator()(const _Tp& __x) const
540 {return __f_(__x);}
541 };
542
543 template <class _Tp>
544 struct __abs_expr
545 {
546 typedef _Tp __result_type;
547 _LIBCPP_INLINE_VISIBILITY
548 _Tp operator()(const _Tp& __x) const
549 {return std::abs(__x);}
550 };
551
552 template <class _Tp>
553 struct __acos_expr
554 {
555 typedef _Tp __result_type;
556 _LIBCPP_INLINE_VISIBILITY
557 _Tp operator()(const _Tp& __x) const
558 {return std::acos(__x);}
559 };
560
561 template <class _Tp>
562 struct __asin_expr
563 {
564 typedef _Tp __result_type;
565 _LIBCPP_INLINE_VISIBILITY
566 _Tp operator()(const _Tp& __x) const
567 {return std::asin(__x);}
568 };
569
570 template <class _Tp>
571 struct __atan_expr
572 {
573 typedef _Tp __result_type;
574 _LIBCPP_INLINE_VISIBILITY
575 _Tp operator()(const _Tp& __x) const
576 {return std::atan(__x);}
577 };
578
579 template <class _Tp>
580 struct __atan2_expr
581 {
582 typedef _Tp __result_type;
583 _LIBCPP_INLINE_VISIBILITY
584 _Tp operator()(const _Tp& __x, const _Tp& __y) const
585 {return std::atan2(__x, __y);}
586 };
587
588 template <class _Tp>
589 struct __cos_expr
590 {
591 typedef _Tp __result_type;
592 _LIBCPP_INLINE_VISIBILITY
593 _Tp operator()(const _Tp& __x) const
594 {return std::cos(__x);}
595 };
596
597 template <class _Tp>
598 struct __cosh_expr
599 {
600 typedef _Tp __result_type;
601 _LIBCPP_INLINE_VISIBILITY
602 _Tp operator()(const _Tp& __x) const
603 {return std::cosh(__x);}
604 };
605
606 template <class _Tp>
607 struct __exp_expr
608 {
609 typedef _Tp __result_type;
610 _LIBCPP_INLINE_VISIBILITY
611 _Tp operator()(const _Tp& __x) const
612 {return std::exp(__x);}
613 };
614
615 template <class _Tp>
616 struct __log_expr
617 {
618 typedef _Tp __result_type;
619 _LIBCPP_INLINE_VISIBILITY
620 _Tp operator()(const _Tp& __x) const
621 {return std::log(__x);}
622 };
623
624 template <class _Tp>
625 struct __log10_expr
626 {
627 typedef _Tp __result_type;
628 _LIBCPP_INLINE_VISIBILITY
629 _Tp operator()(const _Tp& __x) const
630 {return std::log10(__x);}
631 };
632
633 template <class _Tp>
634 struct __pow_expr
635 {
636 typedef _Tp __result_type;
637 _LIBCPP_INLINE_VISIBILITY
638 _Tp operator()(const _Tp& __x, const _Tp& __y) const
639 {return std::pow(__x, __y);}
640 };
641
642 template <class _Tp>
643 struct __sin_expr
644 {
645 typedef _Tp __result_type;
646 _LIBCPP_INLINE_VISIBILITY
647 _Tp operator()(const _Tp& __x) const
648 {return std::sin(__x);}
649 };
650
651 template <class _Tp>
652 struct __sinh_expr
653 {
654 typedef _Tp __result_type;
655 _LIBCPP_INLINE_VISIBILITY
656 _Tp operator()(const _Tp& __x) const
657 {return std::sinh(__x);}
658 };
659
660 template <class _Tp>
661 struct __sqrt_expr
662 {
663 typedef _Tp __result_type;
664 _LIBCPP_INLINE_VISIBILITY
665 _Tp operator()(const _Tp& __x) const
666 {return std::sqrt(__x);}
667 };
668
669 template <class _Tp>
670 struct __tan_expr
671 {
672 typedef _Tp __result_type;
673 _LIBCPP_INLINE_VISIBILITY
674 _Tp operator()(const _Tp& __x) const
675 {return std::tan(__x);}
676 };
677
678 template <class _Tp>
679 struct __tanh_expr
680 {
681 typedef _Tp __result_type;
682 _LIBCPP_INLINE_VISIBILITY
683 _Tp operator()(const _Tp& __x) const
684 {return std::tanh(__x);}
685 };
686
687 template <class _ValExpr>
688 class __slice_expr
689 {
690 typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
691 public:
692 typedef typename _RmExpr::value_type value_type;
693 typedef value_type __result_type;
694
695 private:
696 _ValExpr __expr_;
697 size_t __start_;
698 size_t __size_;
699 size_t __stride_;
700
701 _LIBCPP_INLINE_VISIBILITY
702 __slice_expr(const slice& __sl, const _RmExpr& __e)
703 : __expr_(__e),
704 __start_(__sl.start()),
705 __size_(__sl.size()),
706 __stride_(__sl.stride())
707 {}
708 public:
709
710 _LIBCPP_INLINE_VISIBILITY
711 __result_type operator[](size_t __i) const
712 {return __expr_[__start_ + __i * __stride_];}
713
714 _LIBCPP_INLINE_VISIBILITY
715 size_t size() const {return __size_;}
716
717 template <class> friend class __val_expr;
718 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
719 };
720
721 template <class _ValExpr>
722 class __mask_expr;
723
724 template <class _ValExpr>
725 class __indirect_expr;
726
727 template <class _ValExpr>
728 class __shift_expr
729 {
730 typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
731 public:
732 typedef typename _RmExpr::value_type value_type;
733 typedef value_type __result_type;
734
735 private:
736 _ValExpr __expr_;
737 size_t __size_;
738 ptrdiff_t __ul_;
739 ptrdiff_t __sn_;
740 ptrdiff_t __n_;
741 static const ptrdiff_t _Np = static_cast<ptrdiff_t>(
742 sizeof(ptrdiff_t) * __CHAR_BIT__ - 1);
743
744 _LIBCPP_INLINE_VISIBILITY
745 __shift_expr(int __n, const _RmExpr& __e)
746 : __expr_(__e),
747 __size_(__e.size()),
748 __n_(__n)
749 {
750 ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _Np);
751 __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _Np);
752 __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n);
753 }
754 public:
755
756 _LIBCPP_INLINE_VISIBILITY
757 __result_type operator[](size_t __j) const
758 {
759 ptrdiff_t __i = static_cast<ptrdiff_t>(__j);
760 ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np;
761 return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
762 }
763
764 _LIBCPP_INLINE_VISIBILITY
765 size_t size() const {return __size_;}
766
767 template <class> friend class __val_expr;
768 };
769
770 template <class _ValExpr>
771 class __cshift_expr
772 {
773 typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
774 public:
775 typedef typename _RmExpr::value_type value_type;
776 typedef value_type __result_type;
777
778 private:
779 _ValExpr __expr_;
780 size_t __size_;
781 size_t __m_;
782 size_t __o1_;
783 size_t __o2_;
784
785 _LIBCPP_INLINE_VISIBILITY
786 __cshift_expr(int __n, const _RmExpr& __e)
787 : __expr_(__e),
788 __size_(__e.size())
789 {
790 __n %= static_cast<int>(__size_);
791 if (__n >= 0)
792 {
793 __m_ = __size_ - __n;
794 __o1_ = __n;
795 __o2_ = __n - __size_;
796 }
797 else
798 {
799 __m_ = -__n;
800 __o1_ = __n + __size_;
801 __o2_ = __n;
802 }
803 }
804 public:
805
806 _LIBCPP_INLINE_VISIBILITY
807 __result_type operator[](size_t __i) const
808 {
809 if (__i < __m_)
810 return __expr_[__i + __o1_];
811 return __expr_[__i + __o2_];
812 }
813
814 _LIBCPP_INLINE_VISIBILITY
815 size_t size() const {return __size_;}
816
817 template <class> friend class __val_expr;
818 };
819
820 template<class _ValExpr>
821 class __val_expr;
822
823 template<class _ValExpr>
824 struct __is_val_expr : false_type {};
825
826 template<class _ValExpr>
827 struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
828
829 template<class _Tp>
830 struct __is_val_expr<valarray<_Tp> > : true_type {};
831
832 template<class _Tp>
833 class _LIBCPP_TEMPLATE_VIS valarray
834 {
835 public:
836 typedef _Tp value_type;
837 typedef _Tp __result_type;
838
839 private:
840 value_type* __begin_;
841 value_type* __end_;
842
843 public:
844 // construct/destroy:
845 _LIBCPP_INLINE_VISIBILITY
846 valarray() : __begin_(nullptr), __end_(nullptr) {}
847 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
848 explicit valarray(size_t __n);
849 _LIBCPP_INLINE_VISIBILITY
850 valarray(const value_type& __x, size_t __n);
851 valarray(const value_type* __p, size_t __n);
852 valarray(const valarray& __v);
853 #ifndef _LIBCPP_CXX03_LANG
854 _LIBCPP_INLINE_VISIBILITY
855 valarray(valarray&& __v) _NOEXCEPT;
856 valarray(initializer_list<value_type> __il);
857 #endif // _LIBCPP_CXX03_LANG
858 valarray(const slice_array<value_type>& __sa);
859 valarray(const gslice_array<value_type>& __ga);
860 valarray(const mask_array<value_type>& __ma);
861 valarray(const indirect_array<value_type>& __ia);
862 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
863 ~valarray();
864
865 // assignment:
866 valarray& operator=(const valarray& __v);
867 #ifndef _LIBCPP_CXX03_LANG
868 _LIBCPP_INLINE_VISIBILITY
869 valarray& operator=(valarray&& __v) _NOEXCEPT;
870 _LIBCPP_INLINE_VISIBILITY
871 valarray& operator=(initializer_list<value_type>);
872 #endif // _LIBCPP_CXX03_LANG
873 _LIBCPP_INLINE_VISIBILITY
874 valarray& operator=(const value_type& __x);
875 _LIBCPP_INLINE_VISIBILITY
876 valarray& operator=(const slice_array<value_type>& __sa);
877 _LIBCPP_INLINE_VISIBILITY
878 valarray& operator=(const gslice_array<value_type>& __ga);
879 _LIBCPP_INLINE_VISIBILITY
880 valarray& operator=(const mask_array<value_type>& __ma);
881 _LIBCPP_INLINE_VISIBILITY
882 valarray& operator=(const indirect_array<value_type>& __ia);
883 template <class _ValExpr>
884 _LIBCPP_INLINE_VISIBILITY
885 valarray& operator=(const __val_expr<_ValExpr>& __v);
886
887 // element access:
888 _LIBCPP_INLINE_VISIBILITY
889 const value_type& operator[](size_t __i) const {return __begin_[__i];}
890
891 _LIBCPP_INLINE_VISIBILITY
892 value_type& operator[](size_t __i) {return __begin_[__i];}
893
894 // subset operations:
895 _LIBCPP_INLINE_VISIBILITY
896 __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const;
897 _LIBCPP_INLINE_VISIBILITY
898 slice_array<value_type> operator[](slice __s);
899 _LIBCPP_INLINE_VISIBILITY
900 __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
901 _LIBCPP_INLINE_VISIBILITY
902 gslice_array<value_type> operator[](const gslice& __gs);
903 #ifndef _LIBCPP_CXX03_LANG
904 _LIBCPP_INLINE_VISIBILITY
905 __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
906 _LIBCPP_INLINE_VISIBILITY
907 gslice_array<value_type> operator[](gslice&& __gs);
908 #endif // _LIBCPP_CXX03_LANG
909 _LIBCPP_INLINE_VISIBILITY
910 __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const;
911 _LIBCPP_INLINE_VISIBILITY
912 mask_array<value_type> operator[](const valarray<bool>& __vb);
913 #ifndef _LIBCPP_CXX03_LANG
914 _LIBCPP_INLINE_VISIBILITY
915 __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const;
916 _LIBCPP_INLINE_VISIBILITY
917 mask_array<value_type> operator[](valarray<bool>&& __vb);
918 #endif // _LIBCPP_CXX03_LANG
919 _LIBCPP_INLINE_VISIBILITY
920 __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
921 _LIBCPP_INLINE_VISIBILITY
922 indirect_array<value_type> operator[](const valarray<size_t>& __vs);
923 #ifndef _LIBCPP_CXX03_LANG
924 _LIBCPP_INLINE_VISIBILITY
925 __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
926 _LIBCPP_INLINE_VISIBILITY
927 indirect_array<value_type> operator[](valarray<size_t>&& __vs);
928 #endif // _LIBCPP_CXX03_LANG
929
930 // unary operators:
931 _LIBCPP_INLINE_VISIBILITY
932 __val_expr<_UnaryOp<__unary_plus<_Tp>, const valarray&> > operator+() const;
933 _LIBCPP_INLINE_VISIBILITY
934 __val_expr<_UnaryOp<negate<_Tp>, const valarray&> > operator-() const;
935 _LIBCPP_INLINE_VISIBILITY
936 __val_expr<_UnaryOp<__bit_not<_Tp>, const valarray&> > operator~() const;
937 _LIBCPP_INLINE_VISIBILITY
938 __val_expr<_UnaryOp<logical_not<_Tp>, const valarray&> > operator!() const;
939
940 // computed assignment:
941 _LIBCPP_INLINE_VISIBILITY
942 valarray& operator*= (const value_type& __x);
943 _LIBCPP_INLINE_VISIBILITY
944 valarray& operator/= (const value_type& __x);
945 _LIBCPP_INLINE_VISIBILITY
946 valarray& operator%= (const value_type& __x);
947 _LIBCPP_INLINE_VISIBILITY
948 valarray& operator+= (const value_type& __x);
949 _LIBCPP_INLINE_VISIBILITY
950 valarray& operator-= (const value_type& __x);
951 _LIBCPP_INLINE_VISIBILITY
952 valarray& operator^= (const value_type& __x);
953 _LIBCPP_INLINE_VISIBILITY
954 valarray& operator&= (const value_type& __x);
955 _LIBCPP_INLINE_VISIBILITY
956 valarray& operator|= (const value_type& __x);
957 _LIBCPP_INLINE_VISIBILITY
958 valarray& operator<<=(const value_type& __x);
959 _LIBCPP_INLINE_VISIBILITY
960 valarray& operator>>=(const value_type& __x);
961
962 template <class _Expr>
963 typename enable_if
964 <
965 __is_val_expr<_Expr>::value,
966 valarray&
967 >::type
968 _LIBCPP_INLINE_VISIBILITY
969 operator*= (const _Expr& __v);
970
971 template <class _Expr>
972 typename enable_if
973 <
974 __is_val_expr<_Expr>::value,
975 valarray&
976 >::type
977 _LIBCPP_INLINE_VISIBILITY
978 operator/= (const _Expr& __v);
979
980 template <class _Expr>
981 typename enable_if
982 <
983 __is_val_expr<_Expr>::value,
984 valarray&
985 >::type
986 _LIBCPP_INLINE_VISIBILITY
987 operator%= (const _Expr& __v);
988
989 template <class _Expr>
990 typename enable_if
991 <
992 __is_val_expr<_Expr>::value,
993 valarray&
994 >::type
995 _LIBCPP_INLINE_VISIBILITY
996 operator+= (const _Expr& __v);
997
998 template <class _Expr>
999 typename enable_if
1000 <
1001 __is_val_expr<_Expr>::value,
1002 valarray&
1003 >::type
1004 _LIBCPP_INLINE_VISIBILITY
1005 operator-= (const _Expr& __v);
1006
1007 template <class _Expr>
1008 typename enable_if
1009 <
1010 __is_val_expr<_Expr>::value,
1011 valarray&
1012 >::type
1013 _LIBCPP_INLINE_VISIBILITY
1014 operator^= (const _Expr& __v);
1015
1016 template <class _Expr>
1017 typename enable_if
1018 <
1019 __is_val_expr<_Expr>::value,
1020 valarray&
1021 >::type
1022 _LIBCPP_INLINE_VISIBILITY
1023 operator|= (const _Expr& __v);
1024
1025 template <class _Expr>
1026 typename enable_if
1027 <
1028 __is_val_expr<_Expr>::value,
1029 valarray&
1030 >::type
1031 _LIBCPP_INLINE_VISIBILITY
1032 operator&= (const _Expr& __v);
1033
1034 template <class _Expr>
1035 typename enable_if
1036 <
1037 __is_val_expr<_Expr>::value,
1038 valarray&
1039 >::type
1040 _LIBCPP_INLINE_VISIBILITY
1041 operator<<= (const _Expr& __v);
1042
1043 template <class _Expr>
1044 typename enable_if
1045 <
1046 __is_val_expr<_Expr>::value,
1047 valarray&
1048 >::type
1049 _LIBCPP_INLINE_VISIBILITY
1050 operator>>= (const _Expr& __v);
1051
1052 // member functions:
1053 _LIBCPP_INLINE_VISIBILITY
1054 void swap(valarray& __v) _NOEXCEPT;
1055
1056 _LIBCPP_INLINE_VISIBILITY
1057 size_t size() const {return static_cast<size_t>(__end_ - __begin_);}
1058
1059 _LIBCPP_INLINE_VISIBILITY
1060 value_type sum() const;
1061 _LIBCPP_INLINE_VISIBILITY
1062 value_type min() const;
1063 _LIBCPP_INLINE_VISIBILITY
1064 value_type max() const;
1065
1066 valarray shift (int __i) const;
1067 valarray cshift(int __i) const;
1068 valarray apply(value_type __f(value_type)) const;
1069 valarray apply(value_type __f(const value_type&)) const;
1070 void resize(size_t __n, value_type __x = value_type());
1071
1072 private:
1073 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
1074 template <class> friend class _LIBCPP_TEMPLATE_VIS slice_array;
1075 template <class> friend class _LIBCPP_TEMPLATE_VIS gslice_array;
1076 template <class> friend class _LIBCPP_TEMPLATE_VIS mask_array;
1077 template <class> friend class __mask_expr;
1078 template <class> friend class _LIBCPP_TEMPLATE_VIS indirect_array;
1079 template <class> friend class __indirect_expr;
1080 template <class> friend class __val_expr;
1081
1082 template <class _Up>
1083 friend
1084 _Up*
1085 begin(valarray<_Up>& __v);
1086
1087 template <class _Up>
1088 friend
1089 const _Up*
1090 begin(const valarray<_Up>& __v);
1091
1092 template <class _Up>
1093 friend
1094 _Up*
1095 end(valarray<_Up>& __v);
1096
1097 template <class _Up>
1098 friend
1099 const _Up*
1100 end(const valarray<_Up>& __v);
1101
1102 _LIBCPP_INLINE_VISIBILITY
1103 void __clear(size_t __capacity);
1104 valarray& __assign_range(const value_type* __f, const value_type* __l);
1105 };
1106
1107 #if _LIBCPP_STD_VER > 14
1108 template<class _Tp, size_t _Size>
1109 valarray(const _Tp(&)[_Size], size_t) -> valarray<_Tp>;
1110 #endif
1111
1112 extern template _LIBCPP_FUNC_VIS void valarray<size_t>::resize(size_t, size_t);
1113
1114 template <class _Op, class _Tp>
1115 struct _UnaryOp<_Op, valarray<_Tp> >
1116 {
1117 typedef typename _Op::__result_type __result_type;
1118 typedef typename decay<__result_type>::type value_type;
1119
1120 _Op __op_;
1121 const valarray<_Tp>& __a0_;
1122
1123 _LIBCPP_INLINE_VISIBILITY
1124 _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
1125
1126 _LIBCPP_INLINE_VISIBILITY
1127 __result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
1128
1129 _LIBCPP_INLINE_VISIBILITY
1130 size_t size() const {return __a0_.size();}
1131 };
1132
1133 template <class _Op, class _Tp, class _A1>
1134 struct _BinaryOp<_Op, valarray<_Tp>, _A1>
1135 {
1136 typedef typename _Op::__result_type __result_type;
1137 typedef typename decay<__result_type>::type value_type;
1138
1139 _Op __op_;
1140 const valarray<_Tp>& __a0_;
1141 _A1 __a1_;
1142
1143 _LIBCPP_INLINE_VISIBILITY
1144 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
1145 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1146
1147 _LIBCPP_INLINE_VISIBILITY
1148 __result_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1149
1150 _LIBCPP_INLINE_VISIBILITY
1151 size_t size() const {return __a0_.size();}
1152 };
1153
1154 template <class _Op, class _A0, class _Tp>
1155 struct _BinaryOp<_Op, _A0, valarray<_Tp> >
1156 {
1157 typedef typename _Op::__result_type __result_type;
1158 typedef typename decay<__result_type>::type value_type;
1159
1160 _Op __op_;
1161 _A0 __a0_;
1162 const valarray<_Tp>& __a1_;
1163
1164 _LIBCPP_INLINE_VISIBILITY
1165 _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
1166 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1167
1168 _LIBCPP_INLINE_VISIBILITY
1169 __result_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1170
1171 _LIBCPP_INLINE_VISIBILITY
1172 size_t size() const {return __a0_.size();}
1173 };
1174
1175 template <class _Op, class _Tp>
1176 struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> >
1177 {
1178 typedef typename _Op::__result_type __result_type;
1179 typedef typename decay<__result_type>::type value_type;
1180
1181 _Op __op_;
1182 const valarray<_Tp>& __a0_;
1183 const valarray<_Tp>& __a1_;
1184
1185 _LIBCPP_INLINE_VISIBILITY
1186 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
1187 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1188
1189 _LIBCPP_INLINE_VISIBILITY
1190 __result_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1191
1192 _LIBCPP_INLINE_VISIBILITY
1193 size_t size() const {return __a0_.size();}
1194 };
1195
1196 // slice_array
1197
1198 template <class _Tp>
1199 class _LIBCPP_TEMPLATE_VIS slice_array
1200 {
1201 public:
1202 typedef _Tp value_type;
1203
1204 private:
1205 value_type* __vp_;
1206 size_t __size_;
1207 size_t __stride_;
1208
1209 public:
1210 template <class _Expr>
1211 typename enable_if
1212 <
1213 __is_val_expr<_Expr>::value,
1214 void
1215 >::type
1216 _LIBCPP_INLINE_VISIBILITY
1217 operator=(const _Expr& __v) const;
1218
1219 template <class _Expr>
1220 typename enable_if
1221 <
1222 __is_val_expr<_Expr>::value,
1223 void
1224 >::type
1225 _LIBCPP_INLINE_VISIBILITY
1226 operator*=(const _Expr& __v) const;
1227
1228 template <class _Expr>
1229 typename enable_if
1230 <
1231 __is_val_expr<_Expr>::value,
1232 void
1233 >::type
1234 _LIBCPP_INLINE_VISIBILITY
1235 operator/=(const _Expr& __v) const;
1236
1237 template <class _Expr>
1238 typename enable_if
1239 <
1240 __is_val_expr<_Expr>::value,
1241 void
1242 >::type
1243 _LIBCPP_INLINE_VISIBILITY
1244 operator%=(const _Expr& __v) const;
1245
1246 template <class _Expr>
1247 typename enable_if
1248 <
1249 __is_val_expr<_Expr>::value,
1250 void
1251 >::type
1252 _LIBCPP_INLINE_VISIBILITY
1253 operator+=(const _Expr& __v) const;
1254
1255 template <class _Expr>
1256 typename enable_if
1257 <
1258 __is_val_expr<_Expr>::value,
1259 void
1260 >::type
1261 _LIBCPP_INLINE_VISIBILITY
1262 operator-=(const _Expr& __v) const;
1263
1264 template <class _Expr>
1265 typename enable_if
1266 <
1267 __is_val_expr<_Expr>::value,
1268 void
1269 >::type
1270 _LIBCPP_INLINE_VISIBILITY
1271 operator^=(const _Expr& __v) const;
1272
1273 template <class _Expr>
1274 typename enable_if
1275 <
1276 __is_val_expr<_Expr>::value,
1277 void
1278 >::type
1279 _LIBCPP_INLINE_VISIBILITY
1280 operator&=(const _Expr& __v) const;
1281
1282 template <class _Expr>
1283 typename enable_if
1284 <
1285 __is_val_expr<_Expr>::value,
1286 void
1287 >::type
1288 _LIBCPP_INLINE_VISIBILITY
1289 operator|=(const _Expr& __v) const;
1290
1291 template <class _Expr>
1292 typename enable_if
1293 <
1294 __is_val_expr<_Expr>::value,
1295 void
1296 >::type
1297 _LIBCPP_INLINE_VISIBILITY
1298 operator<<=(const _Expr& __v) const;
1299
1300 template <class _Expr>
1301 typename enable_if
1302 <
1303 __is_val_expr<_Expr>::value,
1304 void
1305 >::type
1306 _LIBCPP_INLINE_VISIBILITY
1307 operator>>=(const _Expr& __v) const;
1308
1309 slice_array(slice_array const&) = default;
1310
1311 _LIBCPP_INLINE_VISIBILITY
1312 const slice_array& operator=(const slice_array& __sa) const;
1313
1314 _LIBCPP_INLINE_VISIBILITY
1315 void operator=(const value_type& __x) const;
1316
1317 _LIBCPP_INLINE_VISIBILITY
1318 void operator=(const valarray<value_type>& __va) const;
1319
1320 private:
1321 _LIBCPP_INLINE_VISIBILITY
1322 slice_array(const slice& __sl, const valarray<value_type>& __v)
1323 : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())),
1324 __size_(__sl.size()),
1325 __stride_(__sl.stride())
1326 {}
1327
1328 template <class> friend class valarray;
1329 template <class> friend class sliceExpr;
1330 };
1331
1332 template <class _Tp>
1333 inline
1334 const slice_array<_Tp>&
1335 slice_array<_Tp>::operator=(const slice_array& __sa) const
1336 {
1337 value_type* __t = __vp_;
1338 const value_type* __s = __sa.__vp_;
1339 for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
1340 *__t = *__s;
1341 return *this;
1342 }
1343
1344 template <class _Tp>
1345 template <class _Expr>
1346 inline
1347 typename enable_if
1348 <
1349 __is_val_expr<_Expr>::value,
1350 void
1351 >::type
1352 slice_array<_Tp>::operator=(const _Expr& __v) const
1353 {
1354 value_type* __t = __vp_;
1355 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1356 *__t = __v[__i];
1357 }
1358
1359 template <class _Tp>
1360 inline void
1361 slice_array<_Tp>::operator=(const valarray<value_type>& __va) const
1362 {
1363 value_type* __t = __vp_;
1364 for (size_t __i = 0; __i < __va.size(); ++__i, __t += __stride_)
1365 *__t = __va[__i];
1366 }
1367
1368 template <class _Tp>
1369 template <class _Expr>
1370 inline
1371 typename enable_if
1372 <
1373 __is_val_expr<_Expr>::value,
1374 void
1375 >::type
1376 slice_array<_Tp>::operator*=(const _Expr& __v) const
1377 {
1378 value_type* __t = __vp_;
1379 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1380 *__t *= __v[__i];
1381 }
1382
1383 template <class _Tp>
1384 template <class _Expr>
1385 inline
1386 typename enable_if
1387 <
1388 __is_val_expr<_Expr>::value,
1389 void
1390 >::type
1391 slice_array<_Tp>::operator/=(const _Expr& __v) const
1392 {
1393 value_type* __t = __vp_;
1394 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1395 *__t /= __v[__i];
1396 }
1397
1398 template <class _Tp>
1399 template <class _Expr>
1400 inline
1401 typename enable_if
1402 <
1403 __is_val_expr<_Expr>::value,
1404 void
1405 >::type
1406 slice_array<_Tp>::operator%=(const _Expr& __v) const
1407 {
1408 value_type* __t = __vp_;
1409 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1410 *__t %= __v[__i];
1411 }
1412
1413 template <class _Tp>
1414 template <class _Expr>
1415 inline
1416 typename enable_if
1417 <
1418 __is_val_expr<_Expr>::value,
1419 void
1420 >::type
1421 slice_array<_Tp>::operator+=(const _Expr& __v) const
1422 {
1423 value_type* __t = __vp_;
1424 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1425 *__t += __v[__i];
1426 }
1427
1428 template <class _Tp>
1429 template <class _Expr>
1430 inline
1431 typename enable_if
1432 <
1433 __is_val_expr<_Expr>::value,
1434 void
1435 >::type
1436 slice_array<_Tp>::operator-=(const _Expr& __v) const
1437 {
1438 value_type* __t = __vp_;
1439 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1440 *__t -= __v[__i];
1441 }
1442
1443 template <class _Tp>
1444 template <class _Expr>
1445 inline
1446 typename enable_if
1447 <
1448 __is_val_expr<_Expr>::value,
1449 void
1450 >::type
1451 slice_array<_Tp>::operator^=(const _Expr& __v) const
1452 {
1453 value_type* __t = __vp_;
1454 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1455 *__t ^= __v[__i];
1456 }
1457
1458 template <class _Tp>
1459 template <class _Expr>
1460 inline
1461 typename enable_if
1462 <
1463 __is_val_expr<_Expr>::value,
1464 void
1465 >::type
1466 slice_array<_Tp>::operator&=(const _Expr& __v) const
1467 {
1468 value_type* __t = __vp_;
1469 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1470 *__t &= __v[__i];
1471 }
1472
1473 template <class _Tp>
1474 template <class _Expr>
1475 inline
1476 typename enable_if
1477 <
1478 __is_val_expr<_Expr>::value,
1479 void
1480 >::type
1481 slice_array<_Tp>::operator|=(const _Expr& __v) const
1482 {
1483 value_type* __t = __vp_;
1484 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1485 *__t |= __v[__i];
1486 }
1487
1488 template <class _Tp>
1489 template <class _Expr>
1490 inline
1491 typename enable_if
1492 <
1493 __is_val_expr<_Expr>::value,
1494 void
1495 >::type
1496 slice_array<_Tp>::operator<<=(const _Expr& __v) const
1497 {
1498 value_type* __t = __vp_;
1499 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1500 *__t <<= __v[__i];
1501 }
1502
1503 template <class _Tp>
1504 template <class _Expr>
1505 inline
1506 typename enable_if
1507 <
1508 __is_val_expr<_Expr>::value,
1509 void
1510 >::type
1511 slice_array<_Tp>::operator>>=(const _Expr& __v) const
1512 {
1513 value_type* __t = __vp_;
1514 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1515 *__t >>= __v[__i];
1516 }
1517
1518 template <class _Tp>
1519 inline
1520 void
1521 slice_array<_Tp>::operator=(const value_type& __x) const
1522 {
1523 value_type* __t = __vp_;
1524 for (size_t __n = __size_; __n; --__n, __t += __stride_)
1525 *__t = __x;
1526 }
1527
1528 // gslice
1529
1530 class _LIBCPP_TYPE_VIS gslice
1531 {
1532 valarray<size_t> __size_;
1533 valarray<size_t> __stride_;
1534 valarray<size_t> __1d_;
1535
1536 public:
1537 _LIBCPP_INLINE_VISIBILITY
1538 gslice() {}
1539
1540 _LIBCPP_INLINE_VISIBILITY
1541 gslice(size_t __start, const valarray<size_t>& __size,
1542 const valarray<size_t>& __stride)
1543 : __size_(__size),
1544 __stride_(__stride)
1545 {__init(__start);}
1546
1547 #ifndef _LIBCPP_CXX03_LANG
1548
1549 _LIBCPP_INLINE_VISIBILITY
1550 gslice(size_t __start, const valarray<size_t>& __size,
1551 valarray<size_t>&& __stride)
1552 : __size_(__size),
1553 __stride_(std::move(__stride))
1554 {__init(__start);}
1555
1556 _LIBCPP_INLINE_VISIBILITY
1557 gslice(size_t __start, valarray<size_t>&& __size,
1558 const valarray<size_t>& __stride)
1559 : __size_(std::move(__size)),
1560 __stride_(__stride)
1561 {__init(__start);}
1562
1563 _LIBCPP_INLINE_VISIBILITY
1564 gslice(size_t __start, valarray<size_t>&& __size,
1565 valarray<size_t>&& __stride)
1566 : __size_(std::move(__size)),
1567 __stride_(std::move(__stride))
1568 {__init(__start);}
1569
1570 #endif // _LIBCPP_CXX03_LANG
1571
1572 _LIBCPP_INLINE_VISIBILITY
1573 size_t start() const {return __1d_.size() ? __1d_[0] : 0;}
1574
1575 _LIBCPP_INLINE_VISIBILITY
1576 valarray<size_t> size() const {return __size_;}
1577
1578 _LIBCPP_INLINE_VISIBILITY
1579 valarray<size_t> stride() const {return __stride_;}
1580
1581 private:
1582 void __init(size_t __start);
1583
1584 template <class> friend class gslice_array;
1585 template <class> friend class valarray;
1586 template <class> friend class __val_expr;
1587 };
1588
1589 // gslice_array
1590
1591 template <class _Tp>
1592 class _LIBCPP_TEMPLATE_VIS gslice_array
1593 {
1594 public:
1595 typedef _Tp value_type;
1596
1597 private:
1598 value_type* __vp_;
1599 valarray<size_t> __1d_;
1600
1601 public:
1602 template <class _Expr>
1603 typename enable_if
1604 <
1605 __is_val_expr<_Expr>::value,
1606 void
1607 >::type
1608 _LIBCPP_INLINE_VISIBILITY
1609 operator=(const _Expr& __v) const;
1610
1611 template <class _Expr>
1612 typename enable_if
1613 <
1614 __is_val_expr<_Expr>::value,
1615 void
1616 >::type
1617 _LIBCPP_INLINE_VISIBILITY
1618 operator*=(const _Expr& __v) const;
1619
1620 template <class _Expr>
1621 typename enable_if
1622 <
1623 __is_val_expr<_Expr>::value,
1624 void
1625 >::type
1626 _LIBCPP_INLINE_VISIBILITY
1627 operator/=(const _Expr& __v) const;
1628
1629 template <class _Expr>
1630 typename enable_if
1631 <
1632 __is_val_expr<_Expr>::value,
1633 void
1634 >::type
1635 _LIBCPP_INLINE_VISIBILITY
1636 operator%=(const _Expr& __v) const;
1637
1638 template <class _Expr>
1639 typename enable_if
1640 <
1641 __is_val_expr<_Expr>::value,
1642 void
1643 >::type
1644 _LIBCPP_INLINE_VISIBILITY
1645 operator+=(const _Expr& __v) const;
1646
1647 template <class _Expr>
1648 typename enable_if
1649 <
1650 __is_val_expr<_Expr>::value,
1651 void
1652 >::type
1653 _LIBCPP_INLINE_VISIBILITY
1654 operator-=(const _Expr& __v) const;
1655
1656 template <class _Expr>
1657 typename enable_if
1658 <
1659 __is_val_expr<_Expr>::value,
1660 void
1661 >::type
1662 _LIBCPP_INLINE_VISIBILITY
1663 operator^=(const _Expr& __v) const;
1664
1665 template <class _Expr>
1666 typename enable_if
1667 <
1668 __is_val_expr<_Expr>::value,
1669 void
1670 >::type
1671 _LIBCPP_INLINE_VISIBILITY
1672 operator&=(const _Expr& __v) const;
1673
1674 template <class _Expr>
1675 typename enable_if
1676 <
1677 __is_val_expr<_Expr>::value,
1678 void
1679 >::type
1680 _LIBCPP_INLINE_VISIBILITY
1681 operator|=(const _Expr& __v) const;
1682
1683 template <class _Expr>
1684 typename enable_if
1685 <
1686 __is_val_expr<_Expr>::value,
1687 void
1688 >::type
1689 _LIBCPP_INLINE_VISIBILITY
1690 operator<<=(const _Expr& __v) const;
1691
1692 template <class _Expr>
1693 typename enable_if
1694 <
1695 __is_val_expr<_Expr>::value,
1696 void
1697 >::type
1698 _LIBCPP_INLINE_VISIBILITY
1699 operator>>=(const _Expr& __v) const;
1700
1701 _LIBCPP_INLINE_VISIBILITY
1702 const gslice_array& operator=(const gslice_array& __ga) const;
1703
1704 _LIBCPP_INLINE_VISIBILITY
1705 void operator=(const value_type& __x) const;
1706
1707 gslice_array(const gslice_array&) = default;
1708
1709 private:
1710 gslice_array(const gslice& __gs, const valarray<value_type>& __v)
1711 : __vp_(const_cast<value_type*>(__v.__begin_)),
1712 __1d_(__gs.__1d_)
1713 {}
1714
1715 #ifndef _LIBCPP_CXX03_LANG
1716 gslice_array(gslice&& __gs, const valarray<value_type>& __v)
1717 : __vp_(const_cast<value_type*>(__v.__begin_)),
1718 __1d_(std::move(__gs.__1d_))
1719 {}
1720 #endif // _LIBCPP_CXX03_LANG
1721
1722 template <class> friend class valarray;
1723 };
1724
1725 template <class _Tp>
1726 template <class _Expr>
1727 inline
1728 typename enable_if
1729 <
1730 __is_val_expr<_Expr>::value,
1731 void
1732 >::type
1733 gslice_array<_Tp>::operator=(const _Expr& __v) const
1734 {
1735 typedef const size_t* _Ip;
1736 size_t __j = 0;
1737 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1738 __vp_[*__i] = __v[__j];
1739 }
1740
1741 template <class _Tp>
1742 template <class _Expr>
1743 inline
1744 typename enable_if
1745 <
1746 __is_val_expr<_Expr>::value,
1747 void
1748 >::type
1749 gslice_array<_Tp>::operator*=(const _Expr& __v) const
1750 {
1751 typedef const size_t* _Ip;
1752 size_t __j = 0;
1753 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1754 __vp_[*__i] *= __v[__j];
1755 }
1756
1757 template <class _Tp>
1758 template <class _Expr>
1759 inline
1760 typename enable_if
1761 <
1762 __is_val_expr<_Expr>::value,
1763 void
1764 >::type
1765 gslice_array<_Tp>::operator/=(const _Expr& __v) const
1766 {
1767 typedef const size_t* _Ip;
1768 size_t __j = 0;
1769 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1770 __vp_[*__i] /= __v[__j];
1771 }
1772
1773 template <class _Tp>
1774 template <class _Expr>
1775 inline
1776 typename enable_if
1777 <
1778 __is_val_expr<_Expr>::value,
1779 void
1780 >::type
1781 gslice_array<_Tp>::operator%=(const _Expr& __v) const
1782 {
1783 typedef const size_t* _Ip;
1784 size_t __j = 0;
1785 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1786 __vp_[*__i] %= __v[__j];
1787 }
1788
1789 template <class _Tp>
1790 template <class _Expr>
1791 inline
1792 typename enable_if
1793 <
1794 __is_val_expr<_Expr>::value,
1795 void
1796 >::type
1797 gslice_array<_Tp>::operator+=(const _Expr& __v) const
1798 {
1799 typedef const size_t* _Ip;
1800 size_t __j = 0;
1801 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1802 __vp_[*__i] += __v[__j];
1803 }
1804
1805 template <class _Tp>
1806 template <class _Expr>
1807 inline
1808 typename enable_if
1809 <
1810 __is_val_expr<_Expr>::value,
1811 void
1812 >::type
1813 gslice_array<_Tp>::operator-=(const _Expr& __v) const
1814 {
1815 typedef const size_t* _Ip;
1816 size_t __j = 0;
1817 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1818 __vp_[*__i] -= __v[__j];
1819 }
1820
1821 template <class _Tp>
1822 template <class _Expr>
1823 inline
1824 typename enable_if
1825 <
1826 __is_val_expr<_Expr>::value,
1827 void
1828 >::type
1829 gslice_array<_Tp>::operator^=(const _Expr& __v) const
1830 {
1831 typedef const size_t* _Ip;
1832 size_t __j = 0;
1833 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1834 __vp_[*__i] ^= __v[__j];
1835 }
1836
1837 template <class _Tp>
1838 template <class _Expr>
1839 inline
1840 typename enable_if
1841 <
1842 __is_val_expr<_Expr>::value,
1843 void
1844 >::type
1845 gslice_array<_Tp>::operator&=(const _Expr& __v) const
1846 {
1847 typedef const size_t* _Ip;
1848 size_t __j = 0;
1849 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1850 __vp_[*__i] &= __v[__j];
1851 }
1852
1853 template <class _Tp>
1854 template <class _Expr>
1855 inline
1856 typename enable_if
1857 <
1858 __is_val_expr<_Expr>::value,
1859 void
1860 >::type
1861 gslice_array<_Tp>::operator|=(const _Expr& __v) const
1862 {
1863 typedef const size_t* _Ip;
1864 size_t __j = 0;
1865 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1866 __vp_[*__i] |= __v[__j];
1867 }
1868
1869 template <class _Tp>
1870 template <class _Expr>
1871 inline
1872 typename enable_if
1873 <
1874 __is_val_expr<_Expr>::value,
1875 void
1876 >::type
1877 gslice_array<_Tp>::operator<<=(const _Expr& __v) const
1878 {
1879 typedef const size_t* _Ip;
1880 size_t __j = 0;
1881 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1882 __vp_[*__i] <<= __v[__j];
1883 }
1884
1885 template <class _Tp>
1886 template <class _Expr>
1887 inline
1888 typename enable_if
1889 <
1890 __is_val_expr<_Expr>::value,
1891 void
1892 >::type
1893 gslice_array<_Tp>::operator>>=(const _Expr& __v) const
1894 {
1895 typedef const size_t* _Ip;
1896 size_t __j = 0;
1897 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1898 __vp_[*__i] >>= __v[__j];
1899 }
1900
1901 template <class _Tp>
1902 inline
1903 const gslice_array<_Tp>&
1904 gslice_array<_Tp>::operator=(const gslice_array& __ga) const
1905 {
1906 typedef const size_t* _Ip;
1907 const value_type* __s = __ga.__vp_;
1908 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_;
1909 __i != __e; ++__i, ++__j)
1910 __vp_[*__i] = __s[*__j];
1911 return *this;
1912 }
1913
1914 template <class _Tp>
1915 inline
1916 void
1917 gslice_array<_Tp>::operator=(const value_type& __x) const
1918 {
1919 typedef const size_t* _Ip;
1920 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1921 __vp_[*__i] = __x;
1922 }
1923
1924 // mask_array
1925
1926 template <class _Tp>
1927 class _LIBCPP_TEMPLATE_VIS mask_array
1928 {
1929 public:
1930 typedef _Tp value_type;
1931
1932 private:
1933 value_type* __vp_;
1934 valarray<size_t> __1d_;
1935
1936 public:
1937 template <class _Expr>
1938 typename enable_if
1939 <
1940 __is_val_expr<_Expr>::value,
1941 void
1942 >::type
1943 _LIBCPP_INLINE_VISIBILITY
1944 operator=(const _Expr& __v) const;
1945
1946 template <class _Expr>
1947 typename enable_if
1948 <
1949 __is_val_expr<_Expr>::value,
1950 void
1951 >::type
1952 _LIBCPP_INLINE_VISIBILITY
1953 operator*=(const _Expr& __v) const;
1954
1955 template <class _Expr>
1956 typename enable_if
1957 <
1958 __is_val_expr<_Expr>::value,
1959 void
1960 >::type
1961 _LIBCPP_INLINE_VISIBILITY
1962 operator/=(const _Expr& __v) const;
1963
1964 template <class _Expr>
1965 typename enable_if
1966 <
1967 __is_val_expr<_Expr>::value,
1968 void
1969 >::type
1970 _LIBCPP_INLINE_VISIBILITY
1971 operator%=(const _Expr& __v) const;
1972
1973 template <class _Expr>
1974 typename enable_if
1975 <
1976 __is_val_expr<_Expr>::value,
1977 void
1978 >::type
1979 _LIBCPP_INLINE_VISIBILITY
1980 operator+=(const _Expr& __v) const;
1981
1982 template <class _Expr>
1983 typename enable_if
1984 <
1985 __is_val_expr<_Expr>::value,
1986 void
1987 >::type
1988 _LIBCPP_INLINE_VISIBILITY
1989 operator-=(const _Expr& __v) const;
1990
1991 template <class _Expr>
1992 typename enable_if
1993 <
1994 __is_val_expr<_Expr>::value,
1995 void
1996 >::type
1997 _LIBCPP_INLINE_VISIBILITY
1998 operator^=(const _Expr& __v) const;
1999
2000 template <class _Expr>
2001 typename enable_if
2002 <
2003 __is_val_expr<_Expr>::value,
2004 void
2005 >::type
2006 _LIBCPP_INLINE_VISIBILITY
2007 operator&=(const _Expr& __v) const;
2008
2009 template <class _Expr>
2010 typename enable_if
2011 <
2012 __is_val_expr<_Expr>::value,
2013 void
2014 >::type
2015 _LIBCPP_INLINE_VISIBILITY
2016 operator|=(const _Expr& __v) const;
2017
2018 template <class _Expr>
2019 typename enable_if
2020 <
2021 __is_val_expr<_Expr>::value,
2022 void
2023 >::type
2024 _LIBCPP_INLINE_VISIBILITY
2025 operator<<=(const _Expr& __v) const;
2026
2027 template <class _Expr>
2028 typename enable_if
2029 <
2030 __is_val_expr<_Expr>::value,
2031 void
2032 >::type
2033 _LIBCPP_INLINE_VISIBILITY
2034 operator>>=(const _Expr& __v) const;
2035
2036 mask_array(const mask_array&) = default;
2037
2038 _LIBCPP_INLINE_VISIBILITY
2039 const mask_array& operator=(const mask_array& __ma) const;
2040
2041 _LIBCPP_INLINE_VISIBILITY
2042 void operator=(const value_type& __x) const;
2043
2044 private:
2045 _LIBCPP_INLINE_VISIBILITY
2046 mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
2047 : __vp_(const_cast<value_type*>(__v.__begin_)),
2048 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
2049 {
2050 size_t __j = 0;
2051 for (size_t __i = 0; __i < __vb.size(); ++__i)
2052 if (__vb[__i])
2053 __1d_[__j++] = __i;
2054 }
2055
2056 template <class> friend class valarray;
2057 };
2058
2059 template <class _Tp>
2060 template <class _Expr>
2061 inline
2062 typename enable_if
2063 <
2064 __is_val_expr<_Expr>::value,
2065 void
2066 >::type
2067 mask_array<_Tp>::operator=(const _Expr& __v) const
2068 {
2069 size_t __n = __1d_.size();
2070 for (size_t __i = 0; __i < __n; ++__i)
2071 __vp_[__1d_[__i]] = __v[__i];
2072 }
2073
2074 template <class _Tp>
2075 template <class _Expr>
2076 inline
2077 typename enable_if
2078 <
2079 __is_val_expr<_Expr>::value,
2080 void
2081 >::type
2082 mask_array<_Tp>::operator*=(const _Expr& __v) const
2083 {
2084 size_t __n = __1d_.size();
2085 for (size_t __i = 0; __i < __n; ++__i)
2086 __vp_[__1d_[__i]] *= __v[__i];
2087 }
2088
2089 template <class _Tp>
2090 template <class _Expr>
2091 inline
2092 typename enable_if
2093 <
2094 __is_val_expr<_Expr>::value,
2095 void
2096 >::type
2097 mask_array<_Tp>::operator/=(const _Expr& __v) const
2098 {
2099 size_t __n = __1d_.size();
2100 for (size_t __i = 0; __i < __n; ++__i)
2101 __vp_[__1d_[__i]] /= __v[__i];
2102 }
2103
2104 template <class _Tp>
2105 template <class _Expr>
2106 inline
2107 typename enable_if
2108 <
2109 __is_val_expr<_Expr>::value,
2110 void
2111 >::type
2112 mask_array<_Tp>::operator%=(const _Expr& __v) const
2113 {
2114 size_t __n = __1d_.size();
2115 for (size_t __i = 0; __i < __n; ++__i)
2116 __vp_[__1d_[__i]] %= __v[__i];
2117 }
2118
2119 template <class _Tp>
2120 template <class _Expr>
2121 inline
2122 typename enable_if
2123 <
2124 __is_val_expr<_Expr>::value,
2125 void
2126 >::type
2127 mask_array<_Tp>::operator+=(const _Expr& __v) const
2128 {
2129 size_t __n = __1d_.size();
2130 for (size_t __i = 0; __i < __n; ++__i)
2131 __vp_[__1d_[__i]] += __v[__i];
2132 }
2133
2134 template <class _Tp>
2135 template <class _Expr>
2136 inline
2137 typename enable_if
2138 <
2139 __is_val_expr<_Expr>::value,
2140 void
2141 >::type
2142 mask_array<_Tp>::operator-=(const _Expr& __v) const
2143 {
2144 size_t __n = __1d_.size();
2145 for (size_t __i = 0; __i < __n; ++__i)
2146 __vp_[__1d_[__i]] -= __v[__i];
2147 }
2148
2149 template <class _Tp>
2150 template <class _Expr>
2151 inline
2152 typename enable_if
2153 <
2154 __is_val_expr<_Expr>::value,
2155 void
2156 >::type
2157 mask_array<_Tp>::operator^=(const _Expr& __v) const
2158 {
2159 size_t __n = __1d_.size();
2160 for (size_t __i = 0; __i < __n; ++__i)
2161 __vp_[__1d_[__i]] ^= __v[__i];
2162 }
2163
2164 template <class _Tp>
2165 template <class _Expr>
2166 inline
2167 typename enable_if
2168 <
2169 __is_val_expr<_Expr>::value,
2170 void
2171 >::type
2172 mask_array<_Tp>::operator&=(const _Expr& __v) const
2173 {
2174 size_t __n = __1d_.size();
2175 for (size_t __i = 0; __i < __n; ++__i)
2176 __vp_[__1d_[__i]] &= __v[__i];
2177 }
2178
2179 template <class _Tp>
2180 template <class _Expr>
2181 inline
2182 typename enable_if
2183 <
2184 __is_val_expr<_Expr>::value,
2185 void
2186 >::type
2187 mask_array<_Tp>::operator|=(const _Expr& __v) const
2188 {
2189 size_t __n = __1d_.size();
2190 for (size_t __i = 0; __i < __n; ++__i)
2191 __vp_[__1d_[__i]] |= __v[__i];
2192 }
2193
2194 template <class _Tp>
2195 template <class _Expr>
2196 inline
2197 typename enable_if
2198 <
2199 __is_val_expr<_Expr>::value,
2200 void
2201 >::type
2202 mask_array<_Tp>::operator<<=(const _Expr& __v) const
2203 {
2204 size_t __n = __1d_.size();
2205 for (size_t __i = 0; __i < __n; ++__i)
2206 __vp_[__1d_[__i]] <<= __v[__i];
2207 }
2208
2209 template <class _Tp>
2210 template <class _Expr>
2211 inline
2212 typename enable_if
2213 <
2214 __is_val_expr<_Expr>::value,
2215 void
2216 >::type
2217 mask_array<_Tp>::operator>>=(const _Expr& __v) const
2218 {
2219 size_t __n = __1d_.size();
2220 for (size_t __i = 0; __i < __n; ++__i)
2221 __vp_[__1d_[__i]] >>= __v[__i];
2222 }
2223
2224 template <class _Tp>
2225 inline
2226 const mask_array<_Tp>&
2227 mask_array<_Tp>::operator=(const mask_array& __ma) const
2228 {
2229 size_t __n = __1d_.size();
2230 for (size_t __i = 0; __i < __n; ++__i)
2231 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
2232 return *this;
2233 }
2234
2235 template <class _Tp>
2236 inline
2237 void
2238 mask_array<_Tp>::operator=(const value_type& __x) const
2239 {
2240 size_t __n = __1d_.size();
2241 for (size_t __i = 0; __i < __n; ++__i)
2242 __vp_[__1d_[__i]] = __x;
2243 }
2244
2245 template <class _ValExpr>
2246 class __mask_expr
2247 {
2248 typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
2249 public:
2250 typedef typename _RmExpr::value_type value_type;
2251 typedef value_type __result_type;
2252
2253 private:
2254 _ValExpr __expr_;
2255 valarray<size_t> __1d_;
2256
2257 _LIBCPP_INLINE_VISIBILITY
2258 __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
2259 : __expr_(__e),
2260 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
2261 {
2262 size_t __j = 0;
2263 for (size_t __i = 0; __i < __vb.size(); ++__i)
2264 if (__vb[__i])
2265 __1d_[__j++] = __i;
2266 }
2267
2268 public:
2269 _LIBCPP_INLINE_VISIBILITY
2270 __result_type operator[](size_t __i) const
2271 {return __expr_[__1d_[__i]];}
2272
2273 _LIBCPP_INLINE_VISIBILITY
2274 size_t size() const {return __1d_.size();}
2275
2276 template <class> friend class __val_expr;
2277 template <class> friend class valarray;
2278 };
2279
2280 // indirect_array
2281
2282 template <class _Tp>
2283 class _LIBCPP_TEMPLATE_VIS indirect_array
2284 {
2285 public:
2286 typedef _Tp value_type;
2287
2288 private:
2289 value_type* __vp_;
2290 valarray<size_t> __1d_;
2291
2292 public:
2293 template <class _Expr>
2294 typename enable_if
2295 <
2296 __is_val_expr<_Expr>::value,
2297 void
2298 >::type
2299 _LIBCPP_INLINE_VISIBILITY
2300 operator=(const _Expr& __v) const;
2301
2302 template <class _Expr>
2303 typename enable_if
2304 <
2305 __is_val_expr<_Expr>::value,
2306 void
2307 >::type
2308 _LIBCPP_INLINE_VISIBILITY
2309 operator*=(const _Expr& __v) const;
2310
2311 template <class _Expr>
2312 typename enable_if
2313 <
2314 __is_val_expr<_Expr>::value,
2315 void
2316 >::type
2317 _LIBCPP_INLINE_VISIBILITY
2318 operator/=(const _Expr& __v) const;
2319
2320 template <class _Expr>
2321 typename enable_if
2322 <
2323 __is_val_expr<_Expr>::value,
2324 void
2325 >::type
2326 _LIBCPP_INLINE_VISIBILITY
2327 operator%=(const _Expr& __v) const;
2328
2329 template <class _Expr>
2330 typename enable_if
2331 <
2332 __is_val_expr<_Expr>::value,
2333 void
2334 >::type
2335 _LIBCPP_INLINE_VISIBILITY
2336 operator+=(const _Expr& __v) const;
2337
2338 template <class _Expr>
2339 typename enable_if
2340 <
2341 __is_val_expr<_Expr>::value,
2342 void
2343 >::type
2344 _LIBCPP_INLINE_VISIBILITY
2345 operator-=(const _Expr& __v) const;
2346
2347 template <class _Expr>
2348 typename enable_if
2349 <
2350 __is_val_expr<_Expr>::value,
2351 void
2352 >::type
2353 _LIBCPP_INLINE_VISIBILITY
2354 operator^=(const _Expr& __v) const;
2355
2356 template <class _Expr>
2357 typename enable_if
2358 <
2359 __is_val_expr<_Expr>::value,
2360 void
2361 >::type
2362 _LIBCPP_INLINE_VISIBILITY
2363 operator&=(const _Expr& __v) const;
2364
2365 template <class _Expr>
2366 typename enable_if
2367 <
2368 __is_val_expr<_Expr>::value,
2369 void
2370 >::type
2371 _LIBCPP_INLINE_VISIBILITY
2372 operator|=(const _Expr& __v) const;
2373
2374 template <class _Expr>
2375 typename enable_if
2376 <
2377 __is_val_expr<_Expr>::value,
2378 void
2379 >::type
2380 _LIBCPP_INLINE_VISIBILITY
2381 operator<<=(const _Expr& __v) const;
2382
2383 template <class _Expr>
2384 typename enable_if
2385 <
2386 __is_val_expr<_Expr>::value,
2387 void
2388 >::type
2389 _LIBCPP_INLINE_VISIBILITY
2390 operator>>=(const _Expr& __v) const;
2391
2392 indirect_array(const indirect_array&) = default;
2393
2394 _LIBCPP_INLINE_VISIBILITY
2395 const indirect_array& operator=(const indirect_array& __ia) const;
2396
2397 _LIBCPP_INLINE_VISIBILITY
2398 void operator=(const value_type& __x) const;
2399
2400 private:
2401 _LIBCPP_INLINE_VISIBILITY
2402 indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
2403 : __vp_(const_cast<value_type*>(__v.__begin_)),
2404 __1d_(__ia)
2405 {}
2406
2407 #ifndef _LIBCPP_CXX03_LANG
2408
2409 _LIBCPP_INLINE_VISIBILITY
2410 indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
2411 : __vp_(const_cast<value_type*>(__v.__begin_)),
2412 __1d_(std::move(__ia))
2413 {}
2414
2415 #endif // _LIBCPP_CXX03_LANG
2416
2417 template <class> friend class valarray;
2418 };
2419
2420 template <class _Tp>
2421 template <class _Expr>
2422 inline
2423 typename enable_if
2424 <
2425 __is_val_expr<_Expr>::value,
2426 void
2427 >::type
2428 indirect_array<_Tp>::operator=(const _Expr& __v) const
2429 {
2430 size_t __n = __1d_.size();
2431 for (size_t __i = 0; __i < __n; ++__i)
2432 __vp_[__1d_[__i]] = __v[__i];
2433 }
2434
2435 template <class _Tp>
2436 template <class _Expr>
2437 inline
2438 typename enable_if
2439 <
2440 __is_val_expr<_Expr>::value,
2441 void
2442 >::type
2443 indirect_array<_Tp>::operator*=(const _Expr& __v) const
2444 {
2445 size_t __n = __1d_.size();
2446 for (size_t __i = 0; __i < __n; ++__i)
2447 __vp_[__1d_[__i]] *= __v[__i];
2448 }
2449
2450 template <class _Tp>
2451 template <class _Expr>
2452 inline
2453 typename enable_if
2454 <
2455 __is_val_expr<_Expr>::value,
2456 void
2457 >::type
2458 indirect_array<_Tp>::operator/=(const _Expr& __v) const
2459 {
2460 size_t __n = __1d_.size();
2461 for (size_t __i = 0; __i < __n; ++__i)
2462 __vp_[__1d_[__i]] /= __v[__i];
2463 }
2464
2465 template <class _Tp>
2466 template <class _Expr>
2467 inline
2468 typename enable_if
2469 <
2470 __is_val_expr<_Expr>::value,
2471 void
2472 >::type
2473 indirect_array<_Tp>::operator%=(const _Expr& __v) const
2474 {
2475 size_t __n = __1d_.size();
2476 for (size_t __i = 0; __i < __n; ++__i)
2477 __vp_[__1d_[__i]] %= __v[__i];
2478 }
2479
2480 template <class _Tp>
2481 template <class _Expr>
2482 inline
2483 typename enable_if
2484 <
2485 __is_val_expr<_Expr>::value,
2486 void
2487 >::type
2488 indirect_array<_Tp>::operator+=(const _Expr& __v) const
2489 {
2490 size_t __n = __1d_.size();
2491 for (size_t __i = 0; __i < __n; ++__i)
2492 __vp_[__1d_[__i]] += __v[__i];
2493 }
2494
2495 template <class _Tp>
2496 template <class _Expr>
2497 inline
2498 typename enable_if
2499 <
2500 __is_val_expr<_Expr>::value,
2501 void
2502 >::type
2503 indirect_array<_Tp>::operator-=(const _Expr& __v) const
2504 {
2505 size_t __n = __1d_.size();
2506 for (size_t __i = 0; __i < __n; ++__i)
2507 __vp_[__1d_[__i]] -= __v[__i];
2508 }
2509
2510 template <class _Tp>
2511 template <class _Expr>
2512 inline
2513 typename enable_if
2514 <
2515 __is_val_expr<_Expr>::value,
2516 void
2517 >::type
2518 indirect_array<_Tp>::operator^=(const _Expr& __v) const
2519 {
2520 size_t __n = __1d_.size();
2521 for (size_t __i = 0; __i < __n; ++__i)
2522 __vp_[__1d_[__i]] ^= __v[__i];
2523 }
2524
2525 template <class _Tp>
2526 template <class _Expr>
2527 inline
2528 typename enable_if
2529 <
2530 __is_val_expr<_Expr>::value,
2531 void
2532 >::type
2533 indirect_array<_Tp>::operator&=(const _Expr& __v) const
2534 {
2535 size_t __n = __1d_.size();
2536 for (size_t __i = 0; __i < __n; ++__i)
2537 __vp_[__1d_[__i]] &= __v[__i];
2538 }
2539
2540 template <class _Tp>
2541 template <class _Expr>
2542 inline
2543 typename enable_if
2544 <
2545 __is_val_expr<_Expr>::value,
2546 void
2547 >::type
2548 indirect_array<_Tp>::operator|=(const _Expr& __v) const
2549 {
2550 size_t __n = __1d_.size();
2551 for (size_t __i = 0; __i < __n; ++__i)
2552 __vp_[__1d_[__i]] |= __v[__i];
2553 }
2554
2555 template <class _Tp>
2556 template <class _Expr>
2557 inline
2558 typename enable_if
2559 <
2560 __is_val_expr<_Expr>::value,
2561 void
2562 >::type
2563 indirect_array<_Tp>::operator<<=(const _Expr& __v) const
2564 {
2565 size_t __n = __1d_.size();
2566 for (size_t __i = 0; __i < __n; ++__i)
2567 __vp_[__1d_[__i]] <<= __v[__i];
2568 }
2569
2570 template <class _Tp>
2571 template <class _Expr>
2572 inline
2573 typename enable_if
2574 <
2575 __is_val_expr<_Expr>::value,
2576 void
2577 >::type
2578 indirect_array<_Tp>::operator>>=(const _Expr& __v) const
2579 {
2580 size_t __n = __1d_.size();
2581 for (size_t __i = 0; __i < __n; ++__i)
2582 __vp_[__1d_[__i]] >>= __v[__i];
2583 }
2584
2585 template <class _Tp>
2586 inline
2587 const indirect_array<_Tp>&
2588 indirect_array<_Tp>::operator=(const indirect_array& __ia) const
2589 {
2590 typedef const size_t* _Ip;
2591 const value_type* __s = __ia.__vp_;
2592 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_;
2593 __i != __e; ++__i, ++__j)
2594 __vp_[*__i] = __s[*__j];
2595 return *this;
2596 }
2597
2598 template <class _Tp>
2599 inline
2600 void
2601 indirect_array<_Tp>::operator=(const value_type& __x) const
2602 {
2603 typedef const size_t* _Ip;
2604 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
2605 __vp_[*__i] = __x;
2606 }
2607
2608 template <class _ValExpr>
2609 class __indirect_expr
2610 {
2611 typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
2612 public:
2613 typedef typename _RmExpr::value_type value_type;
2614 typedef value_type __result_type;
2615
2616 private:
2617 _ValExpr __expr_;
2618 valarray<size_t> __1d_;
2619
2620 _LIBCPP_INLINE_VISIBILITY
2621 __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e)
2622 : __expr_(__e),
2623 __1d_(__ia)
2624 {}
2625
2626 #ifndef _LIBCPP_CXX03_LANG
2627
2628 _LIBCPP_INLINE_VISIBILITY
2629 __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
2630 : __expr_(__e),
2631 __1d_(std::move(__ia))
2632 {}
2633
2634 #endif // _LIBCPP_CXX03_LANG
2635
2636 public:
2637 _LIBCPP_INLINE_VISIBILITY
2638 __result_type operator[](size_t __i) const
2639 {return __expr_[__1d_[__i]];}
2640
2641 _LIBCPP_INLINE_VISIBILITY
2642 size_t size() const {return __1d_.size();}
2643
2644 template <class> friend class __val_expr;
2645 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
2646 };
2647
2648 template<class _ValExpr>
2649 class __val_expr
2650 {
2651 typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
2652
2653 _ValExpr __expr_;
2654 public:
2655 typedef typename _RmExpr::value_type value_type;
2656 typedef typename _RmExpr::__result_type __result_type;
2657
2658 _LIBCPP_INLINE_VISIBILITY
2659 explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
2660
2661 _LIBCPP_INLINE_VISIBILITY
2662 __result_type operator[](size_t __i) const
2663 {return __expr_[__i];}
2664
2665 _LIBCPP_INLINE_VISIBILITY
2666 __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
2667 {
2668 typedef __slice_expr<_ValExpr> _NewExpr;
2669 return __val_expr< _NewExpr >(_NewExpr(__s, __expr_));
2670 }
2671
2672 _LIBCPP_INLINE_VISIBILITY
2673 __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const
2674 {
2675 typedef __indirect_expr<_ValExpr> _NewExpr;
2676 return __val_expr<_NewExpr >(_NewExpr(__gs.__1d_, __expr_));
2677 }
2678
2679 _LIBCPP_INLINE_VISIBILITY
2680 __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
2681 {
2682 typedef __mask_expr<_ValExpr> _NewExpr;
2683 return __val_expr< _NewExpr >( _NewExpr(__vb, __expr_));
2684 }
2685
2686 _LIBCPP_INLINE_VISIBILITY
2687 __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
2688 {
2689 typedef __indirect_expr<_ValExpr> _NewExpr;
2690 return __val_expr< _NewExpr >(_NewExpr(__vs, __expr_));
2691 }
2692
2693 _LIBCPP_INLINE_VISIBILITY
2694 __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
2695 operator+() const
2696 {
2697 typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
2698 return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
2699 }
2700
2701 _LIBCPP_INLINE_VISIBILITY
2702 __val_expr<_UnaryOp<negate<value_type>, _ValExpr> >
2703 operator-() const
2704 {
2705 typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
2706 return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
2707 }
2708
2709 _LIBCPP_INLINE_VISIBILITY
2710 __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> >
2711 operator~() const
2712 {
2713 typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
2714 return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
2715 }
2716
2717 _LIBCPP_INLINE_VISIBILITY
2718 __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> >
2719 operator!() const
2720 {
2721 typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
2722 return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
2723 }
2724
2725 operator valarray<__result_type>() const;
2726
2727 _LIBCPP_INLINE_VISIBILITY
2728 size_t size() const {return __expr_.size();}
2729
2730 _LIBCPP_INLINE_VISIBILITY
2731 __result_type sum() const
2732 {
2733 size_t __n = __expr_.size();
2734 __result_type __r = __n ? __expr_[0] : __result_type();
2735 for (size_t __i = 1; __i < __n; ++__i)
2736 __r += __expr_[__i];
2737 return __r;
2738 }
2739
2740 _LIBCPP_INLINE_VISIBILITY
2741 __result_type min() const
2742 {
2743 size_t __n = size();
2744 __result_type __r = __n ? (*this)[0] : __result_type();
2745 for (size_t __i = 1; __i < __n; ++__i)
2746 {
2747 __result_type __x = __expr_[__i];
2748 if (__x < __r)
2749 __r = __x;
2750 }
2751 return __r;
2752 }
2753
2754 _LIBCPP_INLINE_VISIBILITY
2755 __result_type max() const
2756 {
2757 size_t __n = size();
2758 __result_type __r = __n ? (*this)[0] : __result_type();
2759 for (size_t __i = 1; __i < __n; ++__i)
2760 {
2761 __result_type __x = __expr_[__i];
2762 if (__r < __x)
2763 __r = __x;
2764 }
2765 return __r;
2766 }
2767
2768 _LIBCPP_INLINE_VISIBILITY
2769 __val_expr<__shift_expr<_ValExpr> > shift (int __i) const
2770 {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));}
2771
2772 _LIBCPP_INLINE_VISIBILITY
2773 __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const
2774 {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));}
2775
2776 _LIBCPP_INLINE_VISIBILITY
2777 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> >
2778 apply(value_type __f(value_type)) const
2779 {
2780 typedef __apply_expr<value_type, value_type(*)(value_type)> _Op;
2781 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2782 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2783 }
2784
2785 _LIBCPP_INLINE_VISIBILITY
2786 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> >
2787 apply(value_type __f(const value_type&)) const
2788 {
2789 typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op;
2790 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2791 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2792 }
2793 };
2794
2795 template<class _ValExpr>
2796 __val_expr<_ValExpr>::operator valarray<__val_expr::__result_type>() const
2797 {
2798 valarray<__result_type> __r;
2799 size_t __n = __expr_.size();
2800 if (__n)
2801 {
2802 __r.__begin_ =
2803 __r.__end_ = allocator<__result_type>().allocate(__n);
2804 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
2805 ::new ((void*)__r.__end_) __result_type(__expr_[__i]);
2806 }
2807 return __r;
2808 }
2809
2810 // valarray
2811
2812 template <class _Tp>
2813 inline
2814 valarray<_Tp>::valarray(size_t __n)
2815 : __begin_(nullptr),
2816 __end_(nullptr)
2817 {
2818 if (__n)
2819 {
2820 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2821 #ifndef _LIBCPP_NO_EXCEPTIONS
2822 try
2823 {
2824 #endif // _LIBCPP_NO_EXCEPTIONS
2825 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
2826 ::new ((void*)__end_) value_type();
2827 #ifndef _LIBCPP_NO_EXCEPTIONS
2828 }
2829 catch (...)
2830 {
2831 __clear(__n);
2832 throw;
2833 }
2834 #endif // _LIBCPP_NO_EXCEPTIONS
2835 }
2836 }
2837
2838 template <class _Tp>
2839 inline
2840 valarray<_Tp>::valarray(const value_type& __x, size_t __n)
2841 : __begin_(nullptr),
2842 __end_(nullptr)
2843 {
2844 resize(__n, __x);
2845 }
2846
2847 template <class _Tp>
2848 valarray<_Tp>::valarray(const value_type* __p, size_t __n)
2849 : __begin_(nullptr),
2850 __end_(nullptr)
2851 {
2852 if (__n)
2853 {
2854 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2855 #ifndef _LIBCPP_NO_EXCEPTIONS
2856 try
2857 {
2858 #endif // _LIBCPP_NO_EXCEPTIONS
2859 for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left)
2860 ::new ((void*)__end_) value_type(*__p);
2861 #ifndef _LIBCPP_NO_EXCEPTIONS
2862 }
2863 catch (...)
2864 {
2865 __clear(__n);
2866 throw;
2867 }
2868 #endif // _LIBCPP_NO_EXCEPTIONS
2869 }
2870 }
2871
2872 template <class _Tp>
2873 valarray<_Tp>::valarray(const valarray& __v)
2874 : __begin_(nullptr),
2875 __end_(nullptr)
2876 {
2877 if (__v.size())
2878 {
2879 __begin_ = __end_ = allocator<value_type>().allocate(__v.size());
2880 #ifndef _LIBCPP_NO_EXCEPTIONS
2881 try
2882 {
2883 #endif // _LIBCPP_NO_EXCEPTIONS
2884 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
2885 ::new ((void*)__end_) value_type(*__p);
2886 #ifndef _LIBCPP_NO_EXCEPTIONS
2887 }
2888 catch (...)
2889 {
2890 __clear(__v.size());
2891 throw;
2892 }
2893 #endif // _LIBCPP_NO_EXCEPTIONS
2894 }
2895 }
2896
2897 #ifndef _LIBCPP_CXX03_LANG
2898
2899 template <class _Tp>
2900 inline
2901 valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT
2902 : __begin_(__v.__begin_),
2903 __end_(__v.__end_)
2904 {
2905 __v.__begin_ = __v.__end_ = nullptr;
2906 }
2907
2908 template <class _Tp>
2909 valarray<_Tp>::valarray(initializer_list<value_type> __il)
2910 : __begin_(nullptr),
2911 __end_(nullptr)
2912 {
2913 const size_t __n = __il.size();
2914 if (__n)
2915 {
2916 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2917 #ifndef _LIBCPP_NO_EXCEPTIONS
2918 try
2919 {
2920 #endif // _LIBCPP_NO_EXCEPTIONS
2921 size_t __n_left = __n;
2922 for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left)
2923 ::new ((void*)__end_) value_type(*__p);
2924 #ifndef _LIBCPP_NO_EXCEPTIONS
2925 }
2926 catch (...)
2927 {
2928 __clear(__n);
2929 throw;
2930 }
2931 #endif // _LIBCPP_NO_EXCEPTIONS
2932 }
2933 }
2934
2935 #endif // _LIBCPP_CXX03_LANG
2936
2937 template <class _Tp>
2938 valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
2939 : __begin_(nullptr),
2940 __end_(nullptr)
2941 {
2942 const size_t __n = __sa.__size_;
2943 if (__n)
2944 {
2945 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2946 #ifndef _LIBCPP_NO_EXCEPTIONS
2947 try
2948 {
2949 #endif // _LIBCPP_NO_EXCEPTIONS
2950 size_t __n_left = __n;
2951 for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left)
2952 ::new ((void*)__end_) value_type(*__p);
2953 #ifndef _LIBCPP_NO_EXCEPTIONS
2954 }
2955 catch (...)
2956 {
2957 __clear(__n);
2958 throw;
2959 }
2960 #endif // _LIBCPP_NO_EXCEPTIONS
2961 }
2962 }
2963
2964 template <class _Tp>
2965 valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
2966 : __begin_(nullptr),
2967 __end_(nullptr)
2968 {
2969 const size_t __n = __ga.__1d_.size();
2970 if (__n)
2971 {
2972 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2973 #ifndef _LIBCPP_NO_EXCEPTIONS
2974 try
2975 {
2976 #endif // _LIBCPP_NO_EXCEPTIONS
2977 typedef const size_t* _Ip;
2978 const value_type* __s = __ga.__vp_;
2979 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2980 __i != __e; ++__i, ++__end_)
2981 ::new ((void*)__end_) value_type(__s[*__i]);
2982 #ifndef _LIBCPP_NO_EXCEPTIONS
2983 }
2984 catch (...)
2985 {
2986 __clear(__n);
2987 throw;
2988 }
2989 #endif // _LIBCPP_NO_EXCEPTIONS
2990 }
2991 }
2992
2993 template <class _Tp>
2994 valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
2995 : __begin_(nullptr),
2996 __end_(nullptr)
2997 {
2998 const size_t __n = __ma.__1d_.size();
2999 if (__n)
3000 {
3001 __begin_ = __end_ = allocator<value_type>().allocate(__n);
3002 #ifndef _LIBCPP_NO_EXCEPTIONS
3003 try
3004 {
3005 #endif // _LIBCPP_NO_EXCEPTIONS
3006 typedef const size_t* _Ip;
3007 const value_type* __s = __ma.__vp_;
3008 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
3009 __i != __e; ++__i, ++__end_)
3010 ::new ((void*)__end_) value_type(__s[*__i]);
3011 #ifndef _LIBCPP_NO_EXCEPTIONS
3012 }
3013 catch (...)
3014 {
3015 __clear(__n);
3016 throw;
3017 }
3018 #endif // _LIBCPP_NO_EXCEPTIONS
3019 }
3020 }
3021
3022 template <class _Tp>
3023 valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
3024 : __begin_(nullptr),
3025 __end_(nullptr)
3026 {
3027 const size_t __n = __ia.__1d_.size();
3028 if (__n)
3029 {
3030 __begin_ = __end_ = allocator<value_type>().allocate(__n);
3031 #ifndef _LIBCPP_NO_EXCEPTIONS
3032 try
3033 {
3034 #endif // _LIBCPP_NO_EXCEPTIONS
3035 typedef const size_t* _Ip;
3036 const value_type* __s = __ia.__vp_;
3037 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
3038 __i != __e; ++__i, ++__end_)
3039 ::new ((void*)__end_) value_type(__s[*__i]);
3040 #ifndef _LIBCPP_NO_EXCEPTIONS
3041 }
3042 catch (...)
3043 {
3044 __clear(__n);
3045 throw;
3046 }
3047 #endif // _LIBCPP_NO_EXCEPTIONS
3048 }
3049 }
3050
3051 template <class _Tp>
3052 inline
3053 valarray<_Tp>::~valarray()
3054 {
3055 __clear(size());
3056 }
3057
3058 template <class _Tp>
3059 valarray<_Tp>&
3060 valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l)
3061 {
3062 size_t __n = __l - __f;
3063 if (size() != __n)
3064 {
3065 __clear(size());
3066 __begin_ = allocator<value_type>().allocate(__n);
3067 __end_ = __begin_ + __n;
3068 _VSTD::uninitialized_copy(__f, __l, __begin_);
3069 } else {
3070 _VSTD::copy(__f, __l, __begin_);
3071 }
3072 return *this;
3073 }
3074
3075 template <class _Tp>
3076 valarray<_Tp>&
3077 valarray<_Tp>::operator=(const valarray& __v)
3078 {
3079 if (this != _VSTD::addressof(__v))
3080 return __assign_range(__v.__begin_, __v.__end_);
3081 return *this;
3082 }
3083
3084 #ifndef _LIBCPP_CXX03_LANG
3085
3086 template <class _Tp>
3087 inline
3088 valarray<_Tp>&
3089 valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
3090 {
3091 __clear(size());
3092 __begin_ = __v.__begin_;
3093 __end_ = __v.__end_;
3094 __v.__begin_ = nullptr;
3095 __v.__end_ = nullptr;
3096 return *this;
3097 }
3098
3099 template <class _Tp>
3100 inline
3101 valarray<_Tp>&
3102 valarray<_Tp>::operator=(initializer_list<value_type> __il)
3103 {
3104 return __assign_range(__il.begin(), __il.end());
3105 }
3106
3107 #endif // _LIBCPP_CXX03_LANG
3108
3109 template <class _Tp>
3110 inline
3111 valarray<_Tp>&
3112 valarray<_Tp>::operator=(const value_type& __x)
3113 {
3114 _VSTD::fill(__begin_, __end_, __x);
3115 return *this;
3116 }
3117
3118 template <class _Tp>
3119 inline
3120 valarray<_Tp>&
3121 valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
3122 {
3123 value_type* __t = __begin_;
3124 const value_type* __s = __sa.__vp_;
3125 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
3126 *__t = *__s;
3127 return *this;
3128 }
3129
3130 template <class _Tp>
3131 inline
3132 valarray<_Tp>&
3133 valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
3134 {
3135 typedef const size_t* _Ip;
3136 value_type* __t = __begin_;
3137 const value_type* __s = __ga.__vp_;
3138 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
3139 __i != __e; ++__i, ++__t)
3140 *__t = __s[*__i];
3141 return *this;
3142 }
3143
3144 template <class _Tp>
3145 inline
3146 valarray<_Tp>&
3147 valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
3148 {
3149 typedef const size_t* _Ip;
3150 value_type* __t = __begin_;
3151 const value_type* __s = __ma.__vp_;
3152 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
3153 __i != __e; ++__i, ++__t)
3154 *__t = __s[*__i];
3155 return *this;
3156 }
3157
3158 template <class _Tp>
3159 inline
3160 valarray<_Tp>&
3161 valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
3162 {
3163 typedef const size_t* _Ip;
3164 value_type* __t = __begin_;
3165 const value_type* __s = __ia.__vp_;
3166 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
3167 __i != __e; ++__i, ++__t)
3168 *__t = __s[*__i];
3169 return *this;
3170 }
3171
3172 template <class _Tp>
3173 template <class _ValExpr>
3174 inline
3175 valarray<_Tp>&
3176 valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
3177 {
3178 size_t __n = __v.size();
3179 if (size() != __n)
3180 resize(__n);
3181 value_type* __t = __begin_;
3182 for (size_t __i = 0; __i != __n; ++__t, ++__i)
3183 *__t = __result_type(__v[__i]);
3184 return *this;
3185 }
3186
3187 template <class _Tp>
3188 inline
3189 __val_expr<__slice_expr<const valarray<_Tp>&> >
3190 valarray<_Tp>::operator[](slice __s) const
3191 {
3192 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
3193 }
3194
3195 template <class _Tp>
3196 inline
3197 slice_array<_Tp>
3198 valarray<_Tp>::operator[](slice __s)
3199 {
3200 return slice_array<value_type>(__s, *this);
3201 }
3202
3203 template <class _Tp>
3204 inline
3205 __val_expr<__indirect_expr<const valarray<_Tp>&> >
3206 valarray<_Tp>::operator[](const gslice& __gs) const
3207 {
3208 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
3209 }
3210
3211 template <class _Tp>
3212 inline
3213 gslice_array<_Tp>
3214 valarray<_Tp>::operator[](const gslice& __gs)
3215 {
3216 return gslice_array<value_type>(__gs, *this);
3217 }
3218
3219 #ifndef _LIBCPP_CXX03_LANG
3220
3221 template <class _Tp>
3222 inline
3223 __val_expr<__indirect_expr<const valarray<_Tp>&> >
3224 valarray<_Tp>::operator[](gslice&& __gs) const
3225 {
3226 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(std::move(__gs.__1d_), *this));
3227 }
3228
3229 template <class _Tp>
3230 inline
3231 gslice_array<_Tp>
3232 valarray<_Tp>::operator[](gslice&& __gs)
3233 {
3234 return gslice_array<value_type>(std::move(__gs), *this);
3235 }
3236
3237 #endif // _LIBCPP_CXX03_LANG
3238
3239 template <class _Tp>
3240 inline
3241 __val_expr<__mask_expr<const valarray<_Tp>&> >
3242 valarray<_Tp>::operator[](const valarray<bool>& __vb) const
3243 {
3244 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
3245 }
3246
3247 template <class _Tp>
3248 inline
3249 mask_array<_Tp>
3250 valarray<_Tp>::operator[](const valarray<bool>& __vb)
3251 {
3252 return mask_array<value_type>(__vb, *this);
3253 }
3254
3255 #ifndef _LIBCPP_CXX03_LANG
3256
3257 template <class _Tp>
3258 inline
3259 __val_expr<__mask_expr<const valarray<_Tp>&> >
3260 valarray<_Tp>::operator[](valarray<bool>&& __vb) const
3261 {
3262 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(std::move(__vb), *this));
3263 }
3264
3265 template <class _Tp>
3266 inline
3267 mask_array<_Tp>
3268 valarray<_Tp>::operator[](valarray<bool>&& __vb)
3269 {
3270 return mask_array<value_type>(std::move(__vb), *this);
3271 }
3272
3273 #endif // _LIBCPP_CXX03_LANG
3274
3275 template <class _Tp>
3276 inline
3277 __val_expr<__indirect_expr<const valarray<_Tp>&> >
3278 valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
3279 {
3280 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
3281 }
3282
3283 template <class _Tp>
3284 inline
3285 indirect_array<_Tp>
3286 valarray<_Tp>::operator[](const valarray<size_t>& __vs)
3287 {
3288 return indirect_array<value_type>(__vs, *this);
3289 }
3290
3291 #ifndef _LIBCPP_CXX03_LANG
3292
3293 template <class _Tp>
3294 inline
3295 __val_expr<__indirect_expr<const valarray<_Tp>&> >
3296 valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
3297 {
3298 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(std::move(__vs), *this));
3299 }
3300
3301 template <class _Tp>
3302 inline
3303 indirect_array<_Tp>
3304 valarray<_Tp>::operator[](valarray<size_t>&& __vs)
3305 {
3306 return indirect_array<value_type>(std::move(__vs), *this);
3307 }
3308
3309 #endif // _LIBCPP_CXX03_LANG
3310
3311 template <class _Tp>
3312 inline
3313 __val_expr<_UnaryOp<__unary_plus<_Tp>, const valarray<_Tp>&> >
3314 valarray<_Tp>::operator+() const
3315 {
3316 using _Op = _UnaryOp<__unary_plus<_Tp>, const valarray<_Tp>&>;
3317 return __val_expr<_Op>(_Op(__unary_plus<_Tp>(), *this));
3318 }
3319
3320 template <class _Tp>
3321 inline
3322 __val_expr<_UnaryOp<negate<_Tp>, const valarray<_Tp>&> >
3323 valarray<_Tp>::operator-() const
3324 {
3325 using _Op = _UnaryOp<negate<_Tp>, const valarray<_Tp>&>;
3326 return __val_expr<_Op>(_Op(negate<_Tp>(), *this));
3327 }
3328
3329 template <class _Tp>
3330 inline
3331 __val_expr<_UnaryOp<__bit_not<_Tp>, const valarray<_Tp>&> >
3332 valarray<_Tp>::operator~() const
3333 {
3334 using _Op = _UnaryOp<__bit_not<_Tp>, const valarray<_Tp>&>;
3335 return __val_expr<_Op>(_Op(__bit_not<_Tp>(), *this));
3336 }
3337
3338 template <class _Tp>
3339 inline
3340 __val_expr<_UnaryOp<logical_not<_Tp>, const valarray<_Tp>&> >
3341 valarray<_Tp>::operator!() const
3342 {
3343 using _Op = _UnaryOp<logical_not<_Tp>, const valarray<_Tp>&>;
3344 return __val_expr<_Op>(_Op(logical_not<_Tp>(), *this));
3345 }
3346
3347 template <class _Tp>
3348 inline
3349 valarray<_Tp>&
3350 valarray<_Tp>::operator*=(const value_type& __x)
3351 {
3352 for (value_type* __p = __begin_; __p != __end_; ++__p)
3353 *__p *= __x;
3354 return *this;
3355 }
3356
3357 template <class _Tp>
3358 inline
3359 valarray<_Tp>&
3360 valarray<_Tp>::operator/=(const value_type& __x)
3361 {
3362 for (value_type* __p = __begin_; __p != __end_; ++__p)
3363 *__p /= __x;
3364 return *this;
3365 }
3366
3367 template <class _Tp>
3368 inline
3369 valarray<_Tp>&
3370 valarray<_Tp>::operator%=(const value_type& __x)
3371 {
3372 for (value_type* __p = __begin_; __p != __end_; ++__p)
3373 *__p %= __x;
3374 return *this;
3375 }
3376
3377 template <class _Tp>
3378 inline
3379 valarray<_Tp>&
3380 valarray<_Tp>::operator+=(const value_type& __x)
3381 {
3382 for (value_type* __p = __begin_; __p != __end_; ++__p)
3383 *__p += __x;
3384 return *this;
3385 }
3386
3387 template <class _Tp>
3388 inline
3389 valarray<_Tp>&
3390 valarray<_Tp>::operator-=(const value_type& __x)
3391 {
3392 for (value_type* __p = __begin_; __p != __end_; ++__p)
3393 *__p -= __x;
3394 return *this;
3395 }
3396
3397 template <class _Tp>
3398 inline
3399 valarray<_Tp>&
3400 valarray<_Tp>::operator^=(const value_type& __x)
3401 {
3402 for (value_type* __p = __begin_; __p != __end_; ++__p)
3403 *__p ^= __x;
3404 return *this;
3405 }
3406
3407 template <class _Tp>
3408 inline
3409 valarray<_Tp>&
3410 valarray<_Tp>::operator&=(const value_type& __x)
3411 {
3412 for (value_type* __p = __begin_; __p != __end_; ++__p)
3413 *__p &= __x;
3414 return *this;
3415 }
3416
3417 template <class _Tp>
3418 inline
3419 valarray<_Tp>&
3420 valarray<_Tp>::operator|=(const value_type& __x)
3421 {
3422 for (value_type* __p = __begin_; __p != __end_; ++__p)
3423 *__p |= __x;
3424 return *this;
3425 }
3426
3427 template <class _Tp>
3428 inline
3429 valarray<_Tp>&
3430 valarray<_Tp>::operator<<=(const value_type& __x)
3431 {
3432 for (value_type* __p = __begin_; __p != __end_; ++__p)
3433 *__p <<= __x;
3434 return *this;
3435 }
3436
3437 template <class _Tp>
3438 inline
3439 valarray<_Tp>&
3440 valarray<_Tp>::operator>>=(const value_type& __x)
3441 {
3442 for (value_type* __p = __begin_; __p != __end_; ++__p)
3443 *__p >>= __x;
3444 return *this;
3445 }
3446
3447 template <class _Tp>
3448 template <class _Expr>
3449 inline
3450 typename enable_if
3451 <
3452 __is_val_expr<_Expr>::value,
3453 valarray<_Tp>&
3454 >::type
3455 valarray<_Tp>::operator*=(const _Expr& __v)
3456 {
3457 size_t __i = 0;
3458 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3459 *__t *= __v[__i];
3460 return *this;
3461 }
3462
3463 template <class _Tp>
3464 template <class _Expr>
3465 inline
3466 typename enable_if
3467 <
3468 __is_val_expr<_Expr>::value,
3469 valarray<_Tp>&
3470 >::type
3471 valarray<_Tp>::operator/=(const _Expr& __v)
3472 {
3473 size_t __i = 0;
3474 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3475 *__t /= __v[__i];
3476 return *this;
3477 }
3478
3479 template <class _Tp>
3480 template <class _Expr>
3481 inline
3482 typename enable_if
3483 <
3484 __is_val_expr<_Expr>::value,
3485 valarray<_Tp>&
3486 >::type
3487 valarray<_Tp>::operator%=(const _Expr& __v)
3488 {
3489 size_t __i = 0;
3490 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3491 *__t %= __v[__i];
3492 return *this;
3493 }
3494
3495 template <class _Tp>
3496 template <class _Expr>
3497 inline
3498 typename enable_if
3499 <
3500 __is_val_expr<_Expr>::value,
3501 valarray<_Tp>&
3502 >::type
3503 valarray<_Tp>::operator+=(const _Expr& __v)
3504 {
3505 size_t __i = 0;
3506 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3507 *__t += __v[__i];
3508 return *this;
3509 }
3510
3511 template <class _Tp>
3512 template <class _Expr>
3513 inline
3514 typename enable_if
3515 <
3516 __is_val_expr<_Expr>::value,
3517 valarray<_Tp>&
3518 >::type
3519 valarray<_Tp>::operator-=(const _Expr& __v)
3520 {
3521 size_t __i = 0;
3522 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3523 *__t -= __v[__i];
3524 return *this;
3525 }
3526
3527 template <class _Tp>
3528 template <class _Expr>
3529 inline
3530 typename enable_if
3531 <
3532 __is_val_expr<_Expr>::value,
3533 valarray<_Tp>&
3534 >::type
3535 valarray<_Tp>::operator^=(const _Expr& __v)
3536 {
3537 size_t __i = 0;
3538 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3539 *__t ^= __v[__i];
3540 return *this;
3541 }
3542
3543 template <class _Tp>
3544 template <class _Expr>
3545 inline
3546 typename enable_if
3547 <
3548 __is_val_expr<_Expr>::value,
3549 valarray<_Tp>&
3550 >::type
3551 valarray<_Tp>::operator|=(const _Expr& __v)
3552 {
3553 size_t __i = 0;
3554 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3555 *__t |= __v[__i];
3556 return *this;
3557 }
3558
3559 template <class _Tp>
3560 template <class _Expr>
3561 inline
3562 typename enable_if
3563 <
3564 __is_val_expr<_Expr>::value,
3565 valarray<_Tp>&
3566 >::type
3567 valarray<_Tp>::operator&=(const _Expr& __v)
3568 {
3569 size_t __i = 0;
3570 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3571 *__t &= __v[__i];
3572 return *this;
3573 }
3574
3575 template <class _Tp>
3576 template <class _Expr>
3577 inline
3578 typename enable_if
3579 <
3580 __is_val_expr<_Expr>::value,
3581 valarray<_Tp>&
3582 >::type
3583 valarray<_Tp>::operator<<=(const _Expr& __v)
3584 {
3585 size_t __i = 0;
3586 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3587 *__t <<= __v[__i];
3588 return *this;
3589 }
3590
3591 template <class _Tp>
3592 template <class _Expr>
3593 inline
3594 typename enable_if
3595 <
3596 __is_val_expr<_Expr>::value,
3597 valarray<_Tp>&
3598 >::type
3599 valarray<_Tp>::operator>>=(const _Expr& __v)
3600 {
3601 size_t __i = 0;
3602 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3603 *__t >>= __v[__i];
3604 return *this;
3605 }
3606
3607 template <class _Tp>
3608 inline
3609 void
3610 valarray<_Tp>::swap(valarray& __v) _NOEXCEPT
3611 {
3612 _VSTD::swap(__begin_, __v.__begin_);
3613 _VSTD::swap(__end_, __v.__end_);
3614 }
3615
3616 template <class _Tp>
3617 inline
3618 _Tp
3619 valarray<_Tp>::sum() const
3620 {
3621 if (__begin_ == __end_)
3622 return value_type();
3623 const value_type* __p = __begin_;
3624 _Tp __r = *__p;
3625 for (++__p; __p != __end_; ++__p)
3626 __r += *__p;
3627 return __r;
3628 }
3629
3630 template <class _Tp>
3631 inline
3632 _Tp
3633 valarray<_Tp>::min() const
3634 {
3635 if (__begin_ == __end_)
3636 return value_type();
3637 return *_VSTD::min_element(__begin_, __end_);
3638 }
3639
3640 template <class _Tp>
3641 inline
3642 _Tp
3643 valarray<_Tp>::max() const
3644 {
3645 if (__begin_ == __end_)
3646 return value_type();
3647 return *_VSTD::max_element(__begin_, __end_);
3648 }
3649
3650 template <class _Tp>
3651 valarray<_Tp>
3652 valarray<_Tp>::shift(int __i) const
3653 {
3654 valarray<value_type> __r;
3655 size_t __n = size();
3656 if (__n)
3657 {
3658 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
3659 const value_type* __sb;
3660 value_type* __tb;
3661 value_type* __te;
3662 if (__i >= 0)
3663 {
3664 __i = _VSTD::min(__i, static_cast<int>(__n));
3665 __sb = __begin_ + __i;
3666 __tb = __r.__begin_;
3667 __te = __r.__begin_ + (__n - __i);
3668 }
3669 else
3670 {
3671 __i = _VSTD::min(-__i, static_cast<int>(__n));
3672 __sb = __begin_;
3673 __tb = __r.__begin_ + __i;
3674 __te = __r.__begin_ + __n;
3675 }
3676 for (; __r.__end_ != __tb; ++__r.__end_)
3677 ::new ((void*)__r.__end_) value_type();
3678 for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
3679 ::new ((void*)__r.__end_) value_type(*__sb);
3680 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
3681 ::new ((void*)__r.__end_) value_type();
3682 }
3683 return __r;
3684 }
3685
3686 template <class _Tp>
3687 valarray<_Tp>
3688 valarray<_Tp>::cshift(int __i) const
3689 {
3690 valarray<value_type> __r;
3691 size_t __n = size();
3692 if (__n)
3693 {
3694 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
3695 __i %= static_cast<int>(__n);
3696 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
3697 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
3698 ::new ((void*)__r.__end_) value_type(*__s);
3699 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
3700 ::new ((void*)__r.__end_) value_type(*__s);
3701 }
3702 return __r;
3703 }
3704
3705 template <class _Tp>
3706 valarray<_Tp>
3707 valarray<_Tp>::apply(value_type __f(value_type)) const
3708 {
3709 valarray<value_type> __r;
3710 size_t __n = size();
3711 if (__n)
3712 {
3713 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
3714 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3715 ::new ((void*)__r.__end_) value_type(__f(*__p));
3716 }
3717 return __r;
3718 }
3719
3720 template <class _Tp>
3721 valarray<_Tp>
3722 valarray<_Tp>::apply(value_type __f(const value_type&)) const
3723 {
3724 valarray<value_type> __r;
3725 size_t __n = size();
3726 if (__n)
3727 {
3728 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
3729 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3730 ::new ((void*)__r.__end_) value_type(__f(*__p));
3731 }
3732 return __r;
3733 }
3734
3735 template <class _Tp>
3736 inline
3737 void valarray<_Tp>::__clear(size_t __capacity)
3738 {
3739 if (__begin_ != nullptr)
3740 {
3741 while (__end_ != __begin_)
3742 (--__end_)->~value_type();
3743 allocator<value_type>().deallocate(__begin_, __capacity);
3744 __begin_ = __end_ = nullptr;
3745 }
3746 }
3747
3748 template <class _Tp>
3749 void
3750 valarray<_Tp>::resize(size_t __n, value_type __x)
3751 {
3752 __clear(size());
3753 if (__n)
3754 {
3755 __begin_ = __end_ = allocator<value_type>().allocate(__n);
3756 #ifndef _LIBCPP_NO_EXCEPTIONS
3757 try
3758 {
3759 #endif // _LIBCPP_NO_EXCEPTIONS
3760 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
3761 ::new ((void*)__end_) value_type(__x);
3762 #ifndef _LIBCPP_NO_EXCEPTIONS
3763 }
3764 catch (...)
3765 {
3766 __clear(__n);
3767 throw;
3768 }
3769 #endif // _LIBCPP_NO_EXCEPTIONS
3770 }
3771 }
3772
3773 template<class _Tp>
3774 inline _LIBCPP_INLINE_VISIBILITY
3775 void
3776 swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT
3777 {
3778 __x.swap(__y);
3779 }
3780
3781 template<class _Expr1, class _Expr2>
3782 inline _LIBCPP_INLINE_VISIBILITY
3783 typename enable_if
3784 <
3785 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3786 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
3787 >::type
3788 operator*(const _Expr1& __x, const _Expr2& __y)
3789 {
3790 typedef typename _Expr1::value_type value_type;
3791 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
3792 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
3793 }
3794
3795 template<class _Expr>
3796 inline _LIBCPP_INLINE_VISIBILITY
3797 typename enable_if
3798 <
3799 __is_val_expr<_Expr>::value,
3800 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3801 _Expr, __scalar_expr<typename _Expr::value_type> > >
3802 >::type
3803 operator*(const _Expr& __x, const typename _Expr::value_type& __y)
3804 {
3805 typedef typename _Expr::value_type value_type;
3806 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3807 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3808 __x, __scalar_expr<value_type>(__y, __x.size())));
3809 }
3810
3811 template<class _Expr>
3812 inline _LIBCPP_INLINE_VISIBILITY
3813 typename enable_if
3814 <
3815 __is_val_expr<_Expr>::value,
3816 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3817 __scalar_expr<typename _Expr::value_type>, _Expr> >
3818 >::type
3819 operator*(const typename _Expr::value_type& __x, const _Expr& __y)
3820 {
3821 typedef typename _Expr::value_type value_type;
3822 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3823 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3824 __scalar_expr<value_type>(__x, __y.size()), __y));
3825 }
3826
3827 template<class _Expr1, class _Expr2>
3828 inline _LIBCPP_INLINE_VISIBILITY
3829 typename enable_if
3830 <
3831 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3832 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
3833 >::type
3834 operator/(const _Expr1& __x, const _Expr2& __y)
3835 {
3836 typedef typename _Expr1::value_type value_type;
3837 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
3838 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
3839 }
3840
3841 template<class _Expr>
3842 inline _LIBCPP_INLINE_VISIBILITY
3843 typename enable_if
3844 <
3845 __is_val_expr<_Expr>::value,
3846 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3847 _Expr, __scalar_expr<typename _Expr::value_type> > >
3848 >::type
3849 operator/(const _Expr& __x, const typename _Expr::value_type& __y)
3850 {
3851 typedef typename _Expr::value_type value_type;
3852 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3853 return __val_expr<_Op>(_Op(divides<value_type>(),
3854 __x, __scalar_expr<value_type>(__y, __x.size())));
3855 }
3856
3857 template<class _Expr>
3858 inline _LIBCPP_INLINE_VISIBILITY
3859 typename enable_if
3860 <
3861 __is_val_expr<_Expr>::value,
3862 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3863 __scalar_expr<typename _Expr::value_type>, _Expr> >
3864 >::type
3865 operator/(const typename _Expr::value_type& __x, const _Expr& __y)
3866 {
3867 typedef typename _Expr::value_type value_type;
3868 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3869 return __val_expr<_Op>(_Op(divides<value_type>(),
3870 __scalar_expr<value_type>(__x, __y.size()), __y));
3871 }
3872
3873 template<class _Expr1, class _Expr2>
3874 inline _LIBCPP_INLINE_VISIBILITY
3875 typename enable_if
3876 <
3877 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3878 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3879 >::type
3880 operator%(const _Expr1& __x, const _Expr2& __y)
3881 {
3882 typedef typename _Expr1::value_type value_type;
3883 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
3884 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
3885 }
3886
3887 template<class _Expr>
3888 inline _LIBCPP_INLINE_VISIBILITY
3889 typename enable_if
3890 <
3891 __is_val_expr<_Expr>::value,
3892 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3893 _Expr, __scalar_expr<typename _Expr::value_type> > >
3894 >::type
3895 operator%(const _Expr& __x, const typename _Expr::value_type& __y)
3896 {
3897 typedef typename _Expr::value_type value_type;
3898 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3899 return __val_expr<_Op>(_Op(modulus<value_type>(),
3900 __x, __scalar_expr<value_type>(__y, __x.size())));
3901 }
3902
3903 template<class _Expr>
3904 inline _LIBCPP_INLINE_VISIBILITY
3905 typename enable_if
3906 <
3907 __is_val_expr<_Expr>::value,
3908 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3909 __scalar_expr<typename _Expr::value_type>, _Expr> >
3910 >::type
3911 operator%(const typename _Expr::value_type& __x, const _Expr& __y)
3912 {
3913 typedef typename _Expr::value_type value_type;
3914 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3915 return __val_expr<_Op>(_Op(modulus<value_type>(),
3916 __scalar_expr<value_type>(__x, __y.size()), __y));
3917 }
3918
3919 template<class _Expr1, class _Expr2>
3920 inline _LIBCPP_INLINE_VISIBILITY
3921 typename enable_if
3922 <
3923 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3924 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3925 >::type
3926 operator+(const _Expr1& __x, const _Expr2& __y)
3927 {
3928 typedef typename _Expr1::value_type value_type;
3929 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
3930 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
3931 }
3932
3933 template<class _Expr>
3934 inline _LIBCPP_INLINE_VISIBILITY
3935 typename enable_if
3936 <
3937 __is_val_expr<_Expr>::value,
3938 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3939 _Expr, __scalar_expr<typename _Expr::value_type> > >
3940 >::type
3941 operator+(const _Expr& __x, const typename _Expr::value_type& __y)
3942 {
3943 typedef typename _Expr::value_type value_type;
3944 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3945 return __val_expr<_Op>(_Op(plus<value_type>(),
3946 __x, __scalar_expr<value_type>(__y, __x.size())));
3947 }
3948
3949 template<class _Expr>
3950 inline _LIBCPP_INLINE_VISIBILITY
3951 typename enable_if
3952 <
3953 __is_val_expr<_Expr>::value,
3954 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3955 __scalar_expr<typename _Expr::value_type>, _Expr> >
3956 >::type
3957 operator+(const typename _Expr::value_type& __x, const _Expr& __y)
3958 {
3959 typedef typename _Expr::value_type value_type;
3960 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3961 return __val_expr<_Op>(_Op(plus<value_type>(),
3962 __scalar_expr<value_type>(__x, __y.size()), __y));
3963 }
3964
3965 template<class _Expr1, class _Expr2>
3966 inline _LIBCPP_INLINE_VISIBILITY
3967 typename enable_if
3968 <
3969 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3970 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3971 >::type
3972 operator-(const _Expr1& __x, const _Expr2& __y)
3973 {
3974 typedef typename _Expr1::value_type value_type;
3975 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
3976 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
3977 }
3978
3979 template<class _Expr>
3980 inline _LIBCPP_INLINE_VISIBILITY
3981 typename enable_if
3982 <
3983 __is_val_expr<_Expr>::value,
3984 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3985 _Expr, __scalar_expr<typename _Expr::value_type> > >
3986 >::type
3987 operator-(const _Expr& __x, const typename _Expr::value_type& __y)
3988 {
3989 typedef typename _Expr::value_type value_type;
3990 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3991 return __val_expr<_Op>(_Op(minus<value_type>(),
3992 __x, __scalar_expr<value_type>(__y, __x.size())));
3993 }
3994
3995 template<class _Expr>
3996 inline _LIBCPP_INLINE_VISIBILITY
3997 typename enable_if
3998 <
3999 __is_val_expr<_Expr>::value,
4000 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
4001 __scalar_expr<typename _Expr::value_type>, _Expr> >
4002 >::type
4003 operator-(const typename _Expr::value_type& __x, const _Expr& __y)
4004 {
4005 typedef typename _Expr::value_type value_type;
4006 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4007 return __val_expr<_Op>(_Op(minus<value_type>(),
4008 __scalar_expr<value_type>(__x, __y.size()), __y));
4009 }
4010
4011 template<class _Expr1, class _Expr2>
4012 inline _LIBCPP_INLINE_VISIBILITY
4013 typename enable_if
4014 <
4015 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4016 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
4017 >::type
4018 operator^(const _Expr1& __x, const _Expr2& __y)
4019 {
4020 typedef typename _Expr1::value_type value_type;
4021 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
4022 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
4023 }
4024
4025 template<class _Expr>
4026 inline _LIBCPP_INLINE_VISIBILITY
4027 typename enable_if
4028 <
4029 __is_val_expr<_Expr>::value,
4030 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
4031 _Expr, __scalar_expr<typename _Expr::value_type> > >
4032 >::type
4033 operator^(const _Expr& __x, const typename _Expr::value_type& __y)
4034 {
4035 typedef typename _Expr::value_type value_type;
4036 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4037 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
4038 __x, __scalar_expr<value_type>(__y, __x.size())));
4039 }
4040
4041 template<class _Expr>
4042 inline _LIBCPP_INLINE_VISIBILITY
4043 typename enable_if
4044 <
4045 __is_val_expr<_Expr>::value,
4046 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
4047 __scalar_expr<typename _Expr::value_type>, _Expr> >
4048 >::type
4049 operator^(const typename _Expr::value_type& __x, const _Expr& __y)
4050 {
4051 typedef typename _Expr::value_type value_type;
4052 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4053 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
4054 __scalar_expr<value_type>(__x, __y.size()), __y));
4055 }
4056
4057 template<class _Expr1, class _Expr2>
4058 inline _LIBCPP_INLINE_VISIBILITY
4059 typename enable_if
4060 <
4061 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4062 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4063 >::type
4064 operator&(const _Expr1& __x, const _Expr2& __y)
4065 {
4066 typedef typename _Expr1::value_type value_type;
4067 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
4068 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
4069 }
4070
4071 template<class _Expr>
4072 inline _LIBCPP_INLINE_VISIBILITY
4073 typename enable_if
4074 <
4075 __is_val_expr<_Expr>::value,
4076 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4077 _Expr, __scalar_expr<typename _Expr::value_type> > >
4078 >::type
4079 operator&(const _Expr& __x, const typename _Expr::value_type& __y)
4080 {
4081 typedef typename _Expr::value_type value_type;
4082 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4083 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4084 __x, __scalar_expr<value_type>(__y, __x.size())));
4085 }
4086
4087 template<class _Expr>
4088 inline _LIBCPP_INLINE_VISIBILITY
4089 typename enable_if
4090 <
4091 __is_val_expr<_Expr>::value,
4092 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4093 __scalar_expr<typename _Expr::value_type>, _Expr> >
4094 >::type
4095 operator&(const typename _Expr::value_type& __x, const _Expr& __y)
4096 {
4097 typedef typename _Expr::value_type value_type;
4098 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4099 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4100 __scalar_expr<value_type>(__x, __y.size()), __y));
4101 }
4102
4103 template<class _Expr1, class _Expr2>
4104 inline _LIBCPP_INLINE_VISIBILITY
4105 typename enable_if
4106 <
4107 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4108 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4109 >::type
4110 operator|(const _Expr1& __x, const _Expr2& __y)
4111 {
4112 typedef typename _Expr1::value_type value_type;
4113 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
4114 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
4115 }
4116
4117 template<class _Expr>
4118 inline _LIBCPP_INLINE_VISIBILITY
4119 typename enable_if
4120 <
4121 __is_val_expr<_Expr>::value,
4122 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4123 _Expr, __scalar_expr<typename _Expr::value_type> > >
4124 >::type
4125 operator|(const _Expr& __x, const typename _Expr::value_type& __y)
4126 {
4127 typedef typename _Expr::value_type value_type;
4128 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4129 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4130 __x, __scalar_expr<value_type>(__y, __x.size())));
4131 }
4132
4133 template<class _Expr>
4134 inline _LIBCPP_INLINE_VISIBILITY
4135 typename enable_if
4136 <
4137 __is_val_expr<_Expr>::value,
4138 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4139 __scalar_expr<typename _Expr::value_type>, _Expr> >
4140 >::type
4141 operator|(const typename _Expr::value_type& __x, const _Expr& __y)
4142 {
4143 typedef typename _Expr::value_type value_type;
4144 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4145 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4146 __scalar_expr<value_type>(__x, __y.size()), __y));
4147 }
4148
4149 template<class _Expr1, class _Expr2>
4150 inline _LIBCPP_INLINE_VISIBILITY
4151 typename enable_if
4152 <
4153 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4154 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
4155 >::type
4156 operator<<(const _Expr1& __x, const _Expr2& __y)
4157 {
4158 typedef typename _Expr1::value_type value_type;
4159 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
4160 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
4161 }
4162
4163 template<class _Expr>
4164 inline _LIBCPP_INLINE_VISIBILITY
4165 typename enable_if
4166 <
4167 __is_val_expr<_Expr>::value,
4168 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4169 _Expr, __scalar_expr<typename _Expr::value_type> > >
4170 >::type
4171 operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
4172 {
4173 typedef typename _Expr::value_type value_type;
4174 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4175 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4176 __x, __scalar_expr<value_type>(__y, __x.size())));
4177 }
4178
4179 template<class _Expr>
4180 inline _LIBCPP_INLINE_VISIBILITY
4181 typename enable_if
4182 <
4183 __is_val_expr<_Expr>::value,
4184 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4185 __scalar_expr<typename _Expr::value_type>, _Expr> >
4186 >::type
4187 operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
4188 {
4189 typedef typename _Expr::value_type value_type;
4190 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4191 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4192 __scalar_expr<value_type>(__x, __y.size()), __y));
4193 }
4194
4195 template<class _Expr1, class _Expr2>
4196 inline _LIBCPP_INLINE_VISIBILITY
4197 typename enable_if
4198 <
4199 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4200 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
4201 >::type
4202 operator>>(const _Expr1& __x, const _Expr2& __y)
4203 {
4204 typedef typename _Expr1::value_type value_type;
4205 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
4206 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
4207 }
4208
4209 template<class _Expr>
4210 inline _LIBCPP_INLINE_VISIBILITY
4211 typename enable_if
4212 <
4213 __is_val_expr<_Expr>::value,
4214 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4215 _Expr, __scalar_expr<typename _Expr::value_type> > >
4216 >::type
4217 operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
4218 {
4219 typedef typename _Expr::value_type value_type;
4220 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4221 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4222 __x, __scalar_expr<value_type>(__y, __x.size())));
4223 }
4224
4225 template<class _Expr>
4226 inline _LIBCPP_INLINE_VISIBILITY
4227 typename enable_if
4228 <
4229 __is_val_expr<_Expr>::value,
4230 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4231 __scalar_expr<typename _Expr::value_type>, _Expr> >
4232 >::type
4233 operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
4234 {
4235 typedef typename _Expr::value_type value_type;
4236 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4237 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4238 __scalar_expr<value_type>(__x, __y.size()), __y));
4239 }
4240
4241 template<class _Expr1, class _Expr2>
4242 inline _LIBCPP_INLINE_VISIBILITY
4243 typename enable_if
4244 <
4245 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4246 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4247 >::type
4248 operator&&(const _Expr1& __x, const _Expr2& __y)
4249 {
4250 typedef typename _Expr1::value_type value_type;
4251 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
4252 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
4253 }
4254
4255 template<class _Expr>
4256 inline _LIBCPP_INLINE_VISIBILITY
4257 typename enable_if
4258 <
4259 __is_val_expr<_Expr>::value,
4260 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4261 _Expr, __scalar_expr<typename _Expr::value_type> > >
4262 >::type
4263 operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
4264 {
4265 typedef typename _Expr::value_type value_type;
4266 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4267 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4268 __x, __scalar_expr<value_type>(__y, __x.size())));
4269 }
4270
4271 template<class _Expr>
4272 inline _LIBCPP_INLINE_VISIBILITY
4273 typename enable_if
4274 <
4275 __is_val_expr<_Expr>::value,
4276 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4277 __scalar_expr<typename _Expr::value_type>, _Expr> >
4278 >::type
4279 operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
4280 {
4281 typedef typename _Expr::value_type value_type;
4282 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4283 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4284 __scalar_expr<value_type>(__x, __y.size()), __y));
4285 }
4286
4287 template<class _Expr1, class _Expr2>
4288 inline _LIBCPP_INLINE_VISIBILITY
4289 typename enable_if
4290 <
4291 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4292 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4293 >::type
4294 operator||(const _Expr1& __x, const _Expr2& __y)
4295 {
4296 typedef typename _Expr1::value_type value_type;
4297 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
4298 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
4299 }
4300
4301 template<class _Expr>
4302 inline _LIBCPP_INLINE_VISIBILITY
4303 typename enable_if
4304 <
4305 __is_val_expr<_Expr>::value,
4306 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4307 _Expr, __scalar_expr<typename _Expr::value_type> > >
4308 >::type
4309 operator||(const _Expr& __x, const typename _Expr::value_type& __y)
4310 {
4311 typedef typename _Expr::value_type value_type;
4312 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4313 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4314 __x, __scalar_expr<value_type>(__y, __x.size())));
4315 }
4316
4317 template<class _Expr>
4318 inline _LIBCPP_INLINE_VISIBILITY
4319 typename enable_if
4320 <
4321 __is_val_expr<_Expr>::value,
4322 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4323 __scalar_expr<typename _Expr::value_type>, _Expr> >
4324 >::type
4325 operator||(const typename _Expr::value_type& __x, const _Expr& __y)
4326 {
4327 typedef typename _Expr::value_type value_type;
4328 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4329 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4330 __scalar_expr<value_type>(__x, __y.size()), __y));
4331 }
4332
4333 template<class _Expr1, class _Expr2>
4334 inline _LIBCPP_INLINE_VISIBILITY
4335 typename enable_if
4336 <
4337 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4338 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4339 >::type
4340 operator==(const _Expr1& __x, const _Expr2& __y)
4341 {
4342 typedef typename _Expr1::value_type value_type;
4343 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
4344 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
4345 }
4346
4347 template<class _Expr>
4348 inline _LIBCPP_INLINE_VISIBILITY
4349 typename enable_if
4350 <
4351 __is_val_expr<_Expr>::value,
4352 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4353 _Expr, __scalar_expr<typename _Expr::value_type> > >
4354 >::type
4355 operator==(const _Expr& __x, const typename _Expr::value_type& __y)
4356 {
4357 typedef typename _Expr::value_type value_type;
4358 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4359 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4360 __x, __scalar_expr<value_type>(__y, __x.size())));
4361 }
4362
4363 template<class _Expr>
4364 inline _LIBCPP_INLINE_VISIBILITY
4365 typename enable_if
4366 <
4367 __is_val_expr<_Expr>::value,
4368 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4369 __scalar_expr<typename _Expr::value_type>, _Expr> >
4370 >::type
4371 operator==(const typename _Expr::value_type& __x, const _Expr& __y)
4372 {
4373 typedef typename _Expr::value_type value_type;
4374 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4375 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4376 __scalar_expr<value_type>(__x, __y.size()), __y));
4377 }
4378
4379 template<class _Expr1, class _Expr2>
4380 inline _LIBCPP_INLINE_VISIBILITY
4381 typename enable_if
4382 <
4383 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4384 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4385 >::type
4386 operator!=(const _Expr1& __x, const _Expr2& __y)
4387 {
4388 typedef typename _Expr1::value_type value_type;
4389 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
4390 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
4391 }
4392
4393 template<class _Expr>
4394 inline _LIBCPP_INLINE_VISIBILITY
4395 typename enable_if
4396 <
4397 __is_val_expr<_Expr>::value,
4398 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4399 _Expr, __scalar_expr<typename _Expr::value_type> > >
4400 >::type
4401 operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
4402 {
4403 typedef typename _Expr::value_type value_type;
4404 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4405 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4406 __x, __scalar_expr<value_type>(__y, __x.size())));
4407 }
4408
4409 template<class _Expr>
4410 inline _LIBCPP_INLINE_VISIBILITY
4411 typename enable_if
4412 <
4413 __is_val_expr<_Expr>::value,
4414 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4415 __scalar_expr<typename _Expr::value_type>, _Expr> >
4416 >::type
4417 operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
4418 {
4419 typedef typename _Expr::value_type value_type;
4420 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4421 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4422 __scalar_expr<value_type>(__x, __y.size()), __y));
4423 }
4424
4425 template<class _Expr1, class _Expr2>
4426 inline _LIBCPP_INLINE_VISIBILITY
4427 typename enable_if
4428 <
4429 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4430 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
4431 >::type
4432 operator<(const _Expr1& __x, const _Expr2& __y)
4433 {
4434 typedef typename _Expr1::value_type value_type;
4435 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
4436 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
4437 }
4438
4439 template<class _Expr>
4440 inline _LIBCPP_INLINE_VISIBILITY
4441 typename enable_if
4442 <
4443 __is_val_expr<_Expr>::value,
4444 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4445 _Expr, __scalar_expr<typename _Expr::value_type> > >
4446 >::type
4447 operator<(const _Expr& __x, const typename _Expr::value_type& __y)
4448 {
4449 typedef typename _Expr::value_type value_type;
4450 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4451 return __val_expr<_Op>(_Op(less<value_type>(),
4452 __x, __scalar_expr<value_type>(__y, __x.size())));
4453 }
4454
4455 template<class _Expr>
4456 inline _LIBCPP_INLINE_VISIBILITY
4457 typename enable_if
4458 <
4459 __is_val_expr<_Expr>::value,
4460 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4461 __scalar_expr<typename _Expr::value_type>, _Expr> >
4462 >::type
4463 operator<(const typename _Expr::value_type& __x, const _Expr& __y)
4464 {
4465 typedef typename _Expr::value_type value_type;
4466 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4467 return __val_expr<_Op>(_Op(less<value_type>(),
4468 __scalar_expr<value_type>(__x, __y.size()), __y));
4469 }
4470
4471 template<class _Expr1, class _Expr2>
4472 inline _LIBCPP_INLINE_VISIBILITY
4473 typename enable_if
4474 <
4475 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4476 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
4477 >::type
4478 operator>(const _Expr1& __x, const _Expr2& __y)
4479 {
4480 typedef typename _Expr1::value_type value_type;
4481 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
4482 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
4483 }
4484
4485 template<class _Expr>
4486 inline _LIBCPP_INLINE_VISIBILITY
4487 typename enable_if
4488 <
4489 __is_val_expr<_Expr>::value,
4490 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4491 _Expr, __scalar_expr<typename _Expr::value_type> > >
4492 >::type
4493 operator>(const _Expr& __x, const typename _Expr::value_type& __y)
4494 {
4495 typedef typename _Expr::value_type value_type;
4496 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4497 return __val_expr<_Op>(_Op(greater<value_type>(),
4498 __x, __scalar_expr<value_type>(__y, __x.size())));
4499 }
4500
4501 template<class _Expr>
4502 inline _LIBCPP_INLINE_VISIBILITY
4503 typename enable_if
4504 <
4505 __is_val_expr<_Expr>::value,
4506 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4507 __scalar_expr<typename _Expr::value_type>, _Expr> >
4508 >::type
4509 operator>(const typename _Expr::value_type& __x, const _Expr& __y)
4510 {
4511 typedef typename _Expr::value_type value_type;
4512 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4513 return __val_expr<_Op>(_Op(greater<value_type>(),
4514 __scalar_expr<value_type>(__x, __y.size()), __y));
4515 }
4516
4517 template<class _Expr1, class _Expr2>
4518 inline _LIBCPP_INLINE_VISIBILITY
4519 typename enable_if
4520 <
4521 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4522 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4523 >::type
4524 operator<=(const _Expr1& __x, const _Expr2& __y)
4525 {
4526 typedef typename _Expr1::value_type value_type;
4527 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
4528 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
4529 }
4530
4531 template<class _Expr>
4532 inline _LIBCPP_INLINE_VISIBILITY
4533 typename enable_if
4534 <
4535 __is_val_expr<_Expr>::value,
4536 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4537 _Expr, __scalar_expr<typename _Expr::value_type> > >
4538 >::type
4539 operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
4540 {
4541 typedef typename _Expr::value_type value_type;
4542 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4543 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4544 __x, __scalar_expr<value_type>(__y, __x.size())));
4545 }
4546
4547 template<class _Expr>
4548 inline _LIBCPP_INLINE_VISIBILITY
4549 typename enable_if
4550 <
4551 __is_val_expr<_Expr>::value,
4552 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4553 __scalar_expr<typename _Expr::value_type>, _Expr> >
4554 >::type
4555 operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
4556 {
4557 typedef typename _Expr::value_type value_type;
4558 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4559 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4560 __scalar_expr<value_type>(__x, __y.size()), __y));
4561 }
4562
4563 template<class _Expr1, class _Expr2>
4564 inline _LIBCPP_INLINE_VISIBILITY
4565 typename enable_if
4566 <
4567 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4568 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4569 >::type
4570 operator>=(const _Expr1& __x, const _Expr2& __y)
4571 {
4572 typedef typename _Expr1::value_type value_type;
4573 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
4574 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
4575 }
4576
4577 template<class _Expr>
4578 inline _LIBCPP_INLINE_VISIBILITY
4579 typename enable_if
4580 <
4581 __is_val_expr<_Expr>::value,
4582 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4583 _Expr, __scalar_expr<typename _Expr::value_type> > >
4584 >::type
4585 operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
4586 {
4587 typedef typename _Expr::value_type value_type;
4588 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4589 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4590 __x, __scalar_expr<value_type>(__y, __x.size())));
4591 }
4592
4593 template<class _Expr>
4594 inline _LIBCPP_INLINE_VISIBILITY
4595 typename enable_if
4596 <
4597 __is_val_expr<_Expr>::value,
4598 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4599 __scalar_expr<typename _Expr::value_type>, _Expr> >
4600 >::type
4601 operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
4602 {
4603 typedef typename _Expr::value_type value_type;
4604 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4605 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4606 __scalar_expr<value_type>(__x, __y.size()), __y));
4607 }
4608
4609 template<class _Expr>
4610 inline _LIBCPP_INLINE_VISIBILITY
4611 typename enable_if
4612 <
4613 __is_val_expr<_Expr>::value,
4614 __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
4615 >::type
4616 abs(const _Expr& __x)
4617 {
4618 typedef typename _Expr::value_type value_type;
4619 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
4620 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
4621 }
4622
4623 template<class _Expr>
4624 inline _LIBCPP_INLINE_VISIBILITY
4625 typename enable_if
4626 <
4627 __is_val_expr<_Expr>::value,
4628 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
4629 >::type
4630 acos(const _Expr& __x)
4631 {
4632 typedef typename _Expr::value_type value_type;
4633 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
4634 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
4635 }
4636
4637 template<class _Expr>
4638 inline _LIBCPP_INLINE_VISIBILITY
4639 typename enable_if
4640 <
4641 __is_val_expr<_Expr>::value,
4642 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
4643 >::type
4644 asin(const _Expr& __x)
4645 {
4646 typedef typename _Expr::value_type value_type;
4647 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
4648 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
4649 }
4650
4651 template<class _Expr>
4652 inline _LIBCPP_INLINE_VISIBILITY
4653 typename enable_if
4654 <
4655 __is_val_expr<_Expr>::value,
4656 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
4657 >::type
4658 atan(const _Expr& __x)
4659 {
4660 typedef typename _Expr::value_type value_type;
4661 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
4662 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
4663 }
4664
4665 template<class _Expr1, class _Expr2>
4666 inline _LIBCPP_INLINE_VISIBILITY
4667 typename enable_if
4668 <
4669 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4670 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4671 >::type
4672 atan2(const _Expr1& __x, const _Expr2& __y)
4673 {
4674 typedef typename _Expr1::value_type value_type;
4675 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
4676 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
4677 }
4678
4679 template<class _Expr>
4680 inline _LIBCPP_INLINE_VISIBILITY
4681 typename enable_if
4682 <
4683 __is_val_expr<_Expr>::value,
4684 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4685 _Expr, __scalar_expr<typename _Expr::value_type> > >
4686 >::type
4687 atan2(const _Expr& __x, const typename _Expr::value_type& __y)
4688 {
4689 typedef typename _Expr::value_type value_type;
4690 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4691 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4692 __x, __scalar_expr<value_type>(__y, __x.size())));
4693 }
4694
4695 template<class _Expr>
4696 inline _LIBCPP_INLINE_VISIBILITY
4697 typename enable_if
4698 <
4699 __is_val_expr<_Expr>::value,
4700 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4701 __scalar_expr<typename _Expr::value_type>, _Expr> >
4702 >::type
4703 atan2(const typename _Expr::value_type& __x, const _Expr& __y)
4704 {
4705 typedef typename _Expr::value_type value_type;
4706 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4707 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4708 __scalar_expr<value_type>(__x, __y.size()), __y));
4709 }
4710
4711 template<class _Expr>
4712 inline _LIBCPP_INLINE_VISIBILITY
4713 typename enable_if
4714 <
4715 __is_val_expr<_Expr>::value,
4716 __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
4717 >::type
4718 cos(const _Expr& __x)
4719 {
4720 typedef typename _Expr::value_type value_type;
4721 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
4722 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
4723 }
4724
4725 template<class _Expr>
4726 inline _LIBCPP_INLINE_VISIBILITY
4727 typename enable_if
4728 <
4729 __is_val_expr<_Expr>::value,
4730 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
4731 >::type
4732 cosh(const _Expr& __x)
4733 {
4734 typedef typename _Expr::value_type value_type;
4735 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
4736 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
4737 }
4738
4739 template<class _Expr>
4740 inline _LIBCPP_INLINE_VISIBILITY
4741 typename enable_if
4742 <
4743 __is_val_expr<_Expr>::value,
4744 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
4745 >::type
4746 exp(const _Expr& __x)
4747 {
4748 typedef typename _Expr::value_type value_type;
4749 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
4750 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
4751 }
4752
4753 template<class _Expr>
4754 inline _LIBCPP_INLINE_VISIBILITY
4755 typename enable_if
4756 <
4757 __is_val_expr<_Expr>::value,
4758 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
4759 >::type
4760 log(const _Expr& __x)
4761 {
4762 typedef typename _Expr::value_type value_type;
4763 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
4764 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
4765 }
4766
4767 template<class _Expr>
4768 inline _LIBCPP_INLINE_VISIBILITY
4769 typename enable_if
4770 <
4771 __is_val_expr<_Expr>::value,
4772 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
4773 >::type
4774 log10(const _Expr& __x)
4775 {
4776 typedef typename _Expr::value_type value_type;
4777 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
4778 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
4779 }
4780
4781 template<class _Expr1, class _Expr2>
4782 inline _LIBCPP_INLINE_VISIBILITY
4783 typename enable_if
4784 <
4785 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4786 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4787 >::type
4788 pow(const _Expr1& __x, const _Expr2& __y)
4789 {
4790 typedef typename _Expr1::value_type value_type;
4791 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
4792 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
4793 }
4794
4795 template<class _Expr>
4796 inline _LIBCPP_INLINE_VISIBILITY
4797 typename enable_if
4798 <
4799 __is_val_expr<_Expr>::value,
4800 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4801 _Expr, __scalar_expr<typename _Expr::value_type> > >
4802 >::type
4803 pow(const _Expr& __x, const typename _Expr::value_type& __y)
4804 {
4805 typedef typename _Expr::value_type value_type;
4806 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4807 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4808 __x, __scalar_expr<value_type>(__y, __x.size())));
4809 }
4810
4811 template<class _Expr>
4812 inline _LIBCPP_INLINE_VISIBILITY
4813 typename enable_if
4814 <
4815 __is_val_expr<_Expr>::value,
4816 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4817 __scalar_expr<typename _Expr::value_type>, _Expr> >
4818 >::type
4819 pow(const typename _Expr::value_type& __x, const _Expr& __y)
4820 {
4821 typedef typename _Expr::value_type value_type;
4822 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4823 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4824 __scalar_expr<value_type>(__x, __y.size()), __y));
4825 }
4826
4827 template<class _Expr>
4828 inline _LIBCPP_INLINE_VISIBILITY
4829 typename enable_if
4830 <
4831 __is_val_expr<_Expr>::value,
4832 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
4833 >::type
4834 sin(const _Expr& __x)
4835 {
4836 typedef typename _Expr::value_type value_type;
4837 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
4838 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
4839 }
4840
4841 template<class _Expr>
4842 inline _LIBCPP_INLINE_VISIBILITY
4843 typename enable_if
4844 <
4845 __is_val_expr<_Expr>::value,
4846 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
4847 >::type
4848 sinh(const _Expr& __x)
4849 {
4850 typedef typename _Expr::value_type value_type;
4851 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
4852 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
4853 }
4854
4855 template<class _Expr>
4856 inline _LIBCPP_INLINE_VISIBILITY
4857 typename enable_if
4858 <
4859 __is_val_expr<_Expr>::value,
4860 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
4861 >::type
4862 sqrt(const _Expr& __x)
4863 {
4864 typedef typename _Expr::value_type value_type;
4865 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
4866 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
4867 }
4868
4869 template<class _Expr>
4870 inline _LIBCPP_INLINE_VISIBILITY
4871 typename enable_if
4872 <
4873 __is_val_expr<_Expr>::value,
4874 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
4875 >::type
4876 tan(const _Expr& __x)
4877 {
4878 typedef typename _Expr::value_type value_type;
4879 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
4880 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
4881 }
4882
4883 template<class _Expr>
4884 inline _LIBCPP_INLINE_VISIBILITY
4885 typename enable_if
4886 <
4887 __is_val_expr<_Expr>::value,
4888 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
4889 >::type
4890 tanh(const _Expr& __x)
4891 {
4892 typedef typename _Expr::value_type value_type;
4893 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
4894 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
4895 }
4896
4897 template <class _Tp>
4898 inline _LIBCPP_INLINE_VISIBILITY
4899 _Tp*
4900 begin(valarray<_Tp>& __v)
4901 {
4902 return __v.__begin_;
4903 }
4904
4905 template <class _Tp>
4906 inline _LIBCPP_INLINE_VISIBILITY
4907 const _Tp*
4908 begin(const valarray<_Tp>& __v)
4909 {
4910 return __v.__begin_;
4911 }
4912
4913 template <class _Tp>
4914 inline _LIBCPP_INLINE_VISIBILITY
4915 _Tp*
4916 end(valarray<_Tp>& __v)
4917 {
4918 return __v.__end_;
4919 }
4920
4921 template <class _Tp>
4922 inline _LIBCPP_INLINE_VISIBILITY
4923 const _Tp*
4924 end(const valarray<_Tp>& __v)
4925 {
4926 return __v.__end_;
4927 }
4928
4929 _LIBCPP_END_NAMESPACE_STD
4930
4931 _LIBCPP_POP_MACROS
4932
4933 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
4934 # include <algorithm>
4935 # include <concepts>
4936 # include <cstring>
4937 # include <functional>
4938 #endif
4939
4940 #endif // _LIBCPP_VALARRAY