xref: /freebsd/contrib/llvm-project/libcxx/include/valarray (revision 9f23cbd6cae82fd77edfad7173432fa8dccd0a95)
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_VALARRAY
11#define _LIBCPP_VALARRAY
12
13/*
14    valarray synopsis
15
16namespace std
17{
18
19template<class T>
20class valarray
21{
22public:
23    typedef T value_type;
24
25    // construct/destroy:
26    valarray();
27    explicit valarray(size_t n);
28    valarray(const value_type& x, size_t n);
29    valarray(const value_type* px, size_t n);
30    valarray(const valarray& v);
31    valarray(valarray&& v) noexcept;
32    valarray(const slice_array<value_type>& sa);
33    valarray(const gslice_array<value_type>& ga);
34    valarray(const mask_array<value_type>& ma);
35    valarray(const indirect_array<value_type>& ia);
36    valarray(initializer_list<value_type> il);
37    ~valarray();
38
39    // assignment:
40    valarray& operator=(const valarray& v);
41    valarray& operator=(valarray&& v) noexcept;
42    valarray& operator=(initializer_list<value_type> il);
43    valarray& operator=(const value_type& x);
44    valarray& operator=(const slice_array<value_type>& sa);
45    valarray& operator=(const gslice_array<value_type>& ga);
46    valarray& operator=(const mask_array<value_type>& ma);
47    valarray& operator=(const indirect_array<value_type>& ia);
48
49    // element access:
50    const value_type& operator[](size_t i) const;
51    value_type&       operator[](size_t i);
52
53    // subset operations:
54    valarray                   operator[](slice s) const;
55    slice_array<value_type>    operator[](slice s);
56    valarray                   operator[](const gslice& gs) const;
57    gslice_array<value_type>   operator[](const gslice& gs);
58    valarray                   operator[](const valarray<bool>& vb) const;
59    mask_array<value_type>     operator[](const valarray<bool>& vb);
60    valarray                   operator[](const valarray<size_t>& vs) const;
61    indirect_array<value_type> operator[](const valarray<size_t>& vs);
62
63    // unary operators:
64    valarray       operator+() const;
65    valarray       operator-() const;
66    valarray       operator~() const;
67    valarray<bool> operator!() const;
68
69    // computed assignment:
70    valarray& operator*= (const value_type& x);
71    valarray& operator/= (const value_type& x);
72    valarray& operator%= (const value_type& x);
73    valarray& operator+= (const value_type& x);
74    valarray& operator-= (const value_type& x);
75    valarray& operator^= (const value_type& x);
76    valarray& operator&= (const value_type& x);
77    valarray& operator|= (const value_type& x);
78    valarray& operator<<=(const value_type& x);
79    valarray& operator>>=(const value_type& x);
80
81    valarray& operator*= (const valarray& v);
82    valarray& operator/= (const valarray& v);
83    valarray& operator%= (const valarray& v);
84    valarray& operator+= (const valarray& v);
85    valarray& operator-= (const valarray& v);
86    valarray& operator^= (const valarray& v);
87    valarray& operator|= (const valarray& v);
88    valarray& operator&= (const valarray& v);
89    valarray& operator<<=(const valarray& v);
90    valarray& operator>>=(const valarray& v);
91
92    // member functions:
93    void swap(valarray& v) noexcept;
94
95    size_t size() const;
96
97    value_type sum() const;
98    value_type min() const;
99    value_type max() const;
100
101    valarray shift (int i) const;
102    valarray cshift(int i) const;
103    valarray apply(value_type f(value_type)) const;
104    valarray apply(value_type f(const value_type&)) const;
105    void resize(size_t n, value_type x = value_type());
106};
107
108template<class T, size_t cnt> valarray(const T(&)[cnt], size_t) -> valarray<T>;
109
110class slice
111{
112public:
113    slice();
114    slice(size_t start, size_t size, size_t stride);
115
116    size_t start()  const;
117    size_t size()   const;
118    size_t stride() const;
119};
120
121template <class T>
122class slice_array
123{
124public:
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
146class gslice
147{
148public:
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
158template <class T>
159class gslice_array
160{
161public:
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
184template <class T>
185class mask_array
186{
187public:
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
210template <class T>
211class indirect_array
212{
213public:
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
236template<class T> void swap(valarray<T>& x, valarray<T>& y) noexcept;
237
238template<class T> valarray<T> operator* (const valarray<T>& x, const valarray<T>& y);
239template<class T> valarray<T> operator* (const valarray<T>& x, const T& y);
240template<class T> valarray<T> operator* (const T& x, const valarray<T>& y);
241
242template<class T> valarray<T> operator/ (const valarray<T>& x, const valarray<T>& y);
243template<class T> valarray<T> operator/ (const valarray<T>& x, const T& y);
244template<class T> valarray<T> operator/ (const T& x, const valarray<T>& y);
245
246template<class T> valarray<T> operator% (const valarray<T>& x, const valarray<T>& y);
247template<class T> valarray<T> operator% (const valarray<T>& x, const T& y);
248template<class T> valarray<T> operator% (const T& x, const valarray<T>& y);
249
250template<class T> valarray<T> operator+ (const valarray<T>& x, const valarray<T>& y);
251template<class T> valarray<T> operator+ (const valarray<T>& x, const T& y);
252template<class T> valarray<T> operator+ (const T& x, const valarray<T>& y);
253
254template<class T> valarray<T> operator- (const valarray<T>& x, const valarray<T>& y);
255template<class T> valarray<T> operator- (const valarray<T>& x, const T& y);
256template<class T> valarray<T> operator- (const T& x, const valarray<T>& y);
257
258template<class T> valarray<T> operator^ (const valarray<T>& x, const valarray<T>& y);
259template<class T> valarray<T> operator^ (const valarray<T>& x, const T& y);
260template<class T> valarray<T> operator^ (const T& x, const valarray<T>& y);
261
262template<class T> valarray<T> operator& (const valarray<T>& x, const valarray<T>& y);
263template<class T> valarray<T> operator& (const valarray<T>& x, const T& y);
264template<class T> valarray<T> operator& (const T& x, const valarray<T>& y);
265
266template<class T> valarray<T> operator| (const valarray<T>& x, const valarray<T>& y);
267template<class T> valarray<T> operator| (const valarray<T>& x, const T& y);
268template<class T> valarray<T> operator| (const T& x, const valarray<T>& y);
269
270template<class T> valarray<T> operator<<(const valarray<T>& x, const valarray<T>& y);
271template<class T> valarray<T> operator<<(const valarray<T>& x, const T& y);
272template<class T> valarray<T> operator<<(const T& x, const valarray<T>& y);
273
274template<class T> valarray<T> operator>>(const valarray<T>& x, const valarray<T>& y);
275template<class T> valarray<T> operator>>(const valarray<T>& x, const T& y);
276template<class T> valarray<T> operator>>(const T& x, const valarray<T>& y);
277
278template<class T> valarray<bool> operator&&(const valarray<T>& x, const valarray<T>& y);
279template<class T> valarray<bool> operator&&(const valarray<T>& x, const T& y);
280template<class T> valarray<bool> operator&&(const T& x, const valarray<T>& y);
281
282template<class T> valarray<bool> operator||(const valarray<T>& x, const valarray<T>& y);
283template<class T> valarray<bool> operator||(const valarray<T>& x, const T& y);
284template<class T> valarray<bool> operator||(const T& x, const valarray<T>& y);
285
286template<class T> valarray<bool> operator==(const valarray<T>& x, const valarray<T>& y);
287template<class T> valarray<bool> operator==(const valarray<T>& x, const T& y);
288template<class T> valarray<bool> operator==(const T& x, const valarray<T>& y);
289
290template<class T> valarray<bool> operator!=(const valarray<T>& x, const valarray<T>& y);
291template<class T> valarray<bool> operator!=(const valarray<T>& x, const T& y);
292template<class T> valarray<bool> operator!=(const T& x, const valarray<T>& y);
293
294template<class T> valarray<bool> operator< (const valarray<T>& x, const valarray<T>& y);
295template<class T> valarray<bool> operator< (const valarray<T>& x, const T& y);
296template<class T> valarray<bool> operator< (const T& x, const valarray<T>& y);
297
298template<class T> valarray<bool> operator> (const valarray<T>& x, const valarray<T>& y);
299template<class T> valarray<bool> operator> (const valarray<T>& x, const T& y);
300template<class T> valarray<bool> operator> (const T& x, const valarray<T>& y);
301
302template<class T> valarray<bool> operator<=(const valarray<T>& x, const valarray<T>& y);
303template<class T> valarray<bool> operator<=(const valarray<T>& x, const T& y);
304template<class T> valarray<bool> operator<=(const T& x, const valarray<T>& y);
305
306template<class T> valarray<bool> operator>=(const valarray<T>& x, const valarray<T>& y);
307template<class T> valarray<bool> operator>=(const valarray<T>& x, const T& y);
308template<class T> valarray<bool> operator>=(const T& x, const valarray<T>& y);
309
310template<class T> valarray<T> abs (const valarray<T>& x);
311template<class T> valarray<T> acos (const valarray<T>& x);
312template<class T> valarray<T> asin (const valarray<T>& x);
313template<class T> valarray<T> atan (const valarray<T>& x);
314
315template<class T> valarray<T> atan2(const valarray<T>& x, const valarray<T>& y);
316template<class T> valarray<T> atan2(const valarray<T>& x, const T& y);
317template<class T> valarray<T> atan2(const T& x, const valarray<T>& y);
318
319template<class T> valarray<T> cos (const valarray<T>& x);
320template<class T> valarray<T> cosh (const valarray<T>& x);
321template<class T> valarray<T> exp (const valarray<T>& x);
322template<class T> valarray<T> log (const valarray<T>& x);
323template<class T> valarray<T> log10(const valarray<T>& x);
324
325template<class T> valarray<T> pow(const valarray<T>& x, const valarray<T>& y);
326template<class T> valarray<T> pow(const valarray<T>& x, const T& y);
327template<class T> valarray<T> pow(const T& x, const valarray<T>& y);
328
329template<class T> valarray<T> sin (const valarray<T>& x);
330template<class T> valarray<T> sinh (const valarray<T>& x);
331template<class T> valarray<T> sqrt (const valarray<T>& x);
332template<class T> valarray<T> tan (const valarray<T>& x);
333template<class T> valarray<T> tanh (const valarray<T>& x);
334
335template <class T> unspecified1 begin(valarray<T>& v);
336template <class T> unspecified2 begin(const valarray<T>& v);
337template <class T> unspecified1 end(valarray<T>& v);
338template <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
378template<class _Tp> class _LIBCPP_TEMPLATE_VIS valarray;
379
380class _LIBCPP_TEMPLATE_VIS slice
381{
382    size_t __start_;
383    size_t __size_;
384    size_t __stride_;
385public:
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
405template <class _Tp> class _LIBCPP_TEMPLATE_VIS slice_array;
406class _LIBCPP_TYPE_VIS gslice;
407template <class _Tp> class _LIBCPP_TEMPLATE_VIS gslice_array;
408template <class _Tp> class _LIBCPP_TEMPLATE_VIS mask_array;
409template <class _Tp> class _LIBCPP_TEMPLATE_VIS indirect_array;
410
411template <class _Tp>
412_LIBCPP_INLINE_VISIBILITY
413_Tp*
414begin(valarray<_Tp>& __v);
415
416template <class _Tp>
417_LIBCPP_INLINE_VISIBILITY
418const _Tp*
419begin(const valarray<_Tp>& __v);
420
421template <class _Tp>
422_LIBCPP_INLINE_VISIBILITY
423_Tp*
424end(valarray<_Tp>& __v);
425
426template <class _Tp>
427_LIBCPP_INLINE_VISIBILITY
428const _Tp*
429end(const valarray<_Tp>& __v);
430
431template <class _Op, class _A0>
432struct _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
450template <class _Op, class _A0, class _A1>
451struct _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
471template <class _Tp>
472class __scalar_expr
473{
474public:
475    typedef _Tp        value_type;
476    typedef const _Tp& __result_type;
477private:
478    const value_type& __t_;
479    size_t __s_;
480public:
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
491template <class _Tp>
492struct __unary_plus
493{
494    typedef _Tp __result_type;
495    _LIBCPP_INLINE_VISIBILITY
496    _Tp operator()(const _Tp& __x) const
497        {return +__x;}
498};
499
500template <class _Tp>
501struct __bit_not
502{
503    typedef _Tp __result_type;
504    _LIBCPP_INLINE_VISIBILITY
505    _Tp operator()(const _Tp& __x) const
506        {return ~__x;}
507};
508
509template <class _Tp>
510struct __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
518template <class _Tp>
519struct __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
527template <class _Tp, class _Fp>
528struct __apply_expr
529{
530private:
531    _Fp __f_;
532public:
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
543template <class _Tp>
544struct __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
552template <class _Tp>
553struct __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
561template <class _Tp>
562struct __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
570template <class _Tp>
571struct __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
579template <class _Tp>
580struct __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
588template <class _Tp>
589struct __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
597template <class _Tp>
598struct __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
606template <class _Tp>
607struct __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
615template <class _Tp>
616struct __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
624template <class _Tp>
625struct __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
633template <class _Tp>
634struct __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
642template <class _Tp>
643struct __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
651template <class _Tp>
652struct __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
660template <class _Tp>
661struct __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
669template <class _Tp>
670struct __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
678template <class _Tp>
679struct __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
687template <class _ValExpr>
688class __slice_expr
689{
690    typedef __libcpp_remove_reference_t<_ValExpr>  _RmExpr;
691public:
692    typedef typename _RmExpr::value_type value_type;
693    typedef value_type __result_type;
694
695private:
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        {}
708public:
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
721template <class _ValExpr>
722class __mask_expr;
723
724template <class _ValExpr>
725class __indirect_expr;
726
727template <class _ValExpr>
728class __shift_expr
729{
730    typedef __libcpp_remove_reference_t<_ValExpr>  _RmExpr;
731public:
732    typedef typename _RmExpr::value_type value_type;
733    typedef value_type __result_type;
734
735private:
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        }
754public:
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
770template <class _ValExpr>
771class __cshift_expr
772{
773    typedef __libcpp_remove_reference_t<_ValExpr>  _RmExpr;
774public:
775    typedef typename _RmExpr::value_type value_type;
776    typedef value_type __result_type;
777
778private:
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        }
804public:
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
820template<class _ValExpr>
821class __val_expr;
822
823template<class _ValExpr>
824struct __is_val_expr : false_type {};
825
826template<class _ValExpr>
827struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
828
829template<class _Tp>
830struct __is_val_expr<valarray<_Tp> > : true_type {};
831
832template<class _Tp>
833class _LIBCPP_TEMPLATE_VIS valarray
834{
835public:
836    typedef _Tp value_type;
837    typedef _Tp __result_type;
838
839private:
840    value_type* __begin_;
841    value_type* __end_;
842
843public:
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
1072private:
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
1108template<class _Tp, size_t _Size>
1109valarray(const _Tp(&)[_Size], size_t) -> valarray<_Tp>;
1110#endif
1111
1112extern template _LIBCPP_FUNC_VIS void valarray<size_t>::resize(size_t, size_t);
1113
1114template <class _Op, class _Tp>
1115struct _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
1133template <class _Op, class _Tp, class _A1>
1134struct _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
1154template <class _Op, class _A0, class _Tp>
1155struct _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
1175template <class _Op, class _Tp>
1176struct _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
1198template <class _Tp>
1199class _LIBCPP_TEMPLATE_VIS slice_array
1200{
1201public:
1202    typedef _Tp value_type;
1203
1204private:
1205    value_type* __vp_;
1206    size_t __size_;
1207    size_t __stride_;
1208
1209public:
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
1320private:
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
1332template <class _Tp>
1333inline
1334const slice_array<_Tp>&
1335slice_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
1344template <class _Tp>
1345template <class _Expr>
1346inline
1347typename enable_if
1348<
1349    __is_val_expr<_Expr>::value,
1350    void
1351>::type
1352slice_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
1359template <class _Tp>
1360inline void
1361slice_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
1368template <class _Tp>
1369template <class _Expr>
1370inline
1371typename enable_if
1372<
1373    __is_val_expr<_Expr>::value,
1374    void
1375>::type
1376slice_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
1383template <class _Tp>
1384template <class _Expr>
1385inline
1386typename enable_if
1387<
1388    __is_val_expr<_Expr>::value,
1389    void
1390>::type
1391slice_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
1398template <class _Tp>
1399template <class _Expr>
1400inline
1401typename enable_if
1402<
1403    __is_val_expr<_Expr>::value,
1404    void
1405>::type
1406slice_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
1413template <class _Tp>
1414template <class _Expr>
1415inline
1416typename enable_if
1417<
1418    __is_val_expr<_Expr>::value,
1419    void
1420>::type
1421slice_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
1428template <class _Tp>
1429template <class _Expr>
1430inline
1431typename enable_if
1432<
1433    __is_val_expr<_Expr>::value,
1434    void
1435>::type
1436slice_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
1443template <class _Tp>
1444template <class _Expr>
1445inline
1446typename enable_if
1447<
1448    __is_val_expr<_Expr>::value,
1449    void
1450>::type
1451slice_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
1458template <class _Tp>
1459template <class _Expr>
1460inline
1461typename enable_if
1462<
1463    __is_val_expr<_Expr>::value,
1464    void
1465>::type
1466slice_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
1473template <class _Tp>
1474template <class _Expr>
1475inline
1476typename enable_if
1477<
1478    __is_val_expr<_Expr>::value,
1479    void
1480>::type
1481slice_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
1488template <class _Tp>
1489template <class _Expr>
1490inline
1491typename enable_if
1492<
1493    __is_val_expr<_Expr>::value,
1494    void
1495>::type
1496slice_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
1503template <class _Tp>
1504template <class _Expr>
1505inline
1506typename enable_if
1507<
1508    __is_val_expr<_Expr>::value,
1509    void
1510>::type
1511slice_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
1518template <class _Tp>
1519inline
1520void
1521slice_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
1530class _LIBCPP_TYPE_VIS gslice
1531{
1532    valarray<size_t> __size_;
1533    valarray<size_t> __stride_;
1534    valarray<size_t> __1d_;
1535
1536public:
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
1581private:
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
1591template <class _Tp>
1592class _LIBCPP_TEMPLATE_VIS gslice_array
1593{
1594public:
1595    typedef _Tp value_type;
1596
1597private:
1598    value_type*      __vp_;
1599    valarray<size_t> __1d_;
1600
1601public:
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
1709private:
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
1725template <class _Tp>
1726template <class _Expr>
1727inline
1728typename enable_if
1729<
1730    __is_val_expr<_Expr>::value,
1731    void
1732>::type
1733gslice_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
1741template <class _Tp>
1742template <class _Expr>
1743inline
1744typename enable_if
1745<
1746    __is_val_expr<_Expr>::value,
1747    void
1748>::type
1749gslice_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
1757template <class _Tp>
1758template <class _Expr>
1759inline
1760typename enable_if
1761<
1762    __is_val_expr<_Expr>::value,
1763    void
1764>::type
1765gslice_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
1773template <class _Tp>
1774template <class _Expr>
1775inline
1776typename enable_if
1777<
1778    __is_val_expr<_Expr>::value,
1779    void
1780>::type
1781gslice_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
1789template <class _Tp>
1790template <class _Expr>
1791inline
1792typename enable_if
1793<
1794    __is_val_expr<_Expr>::value,
1795    void
1796>::type
1797gslice_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
1805template <class _Tp>
1806template <class _Expr>
1807inline
1808typename enable_if
1809<
1810    __is_val_expr<_Expr>::value,
1811    void
1812>::type
1813gslice_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
1821template <class _Tp>
1822template <class _Expr>
1823inline
1824typename enable_if
1825<
1826    __is_val_expr<_Expr>::value,
1827    void
1828>::type
1829gslice_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
1837template <class _Tp>
1838template <class _Expr>
1839inline
1840typename enable_if
1841<
1842    __is_val_expr<_Expr>::value,
1843    void
1844>::type
1845gslice_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
1853template <class _Tp>
1854template <class _Expr>
1855inline
1856typename enable_if
1857<
1858    __is_val_expr<_Expr>::value,
1859    void
1860>::type
1861gslice_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
1869template <class _Tp>
1870template <class _Expr>
1871inline
1872typename enable_if
1873<
1874    __is_val_expr<_Expr>::value,
1875    void
1876>::type
1877gslice_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
1885template <class _Tp>
1886template <class _Expr>
1887inline
1888typename enable_if
1889<
1890    __is_val_expr<_Expr>::value,
1891    void
1892>::type
1893gslice_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
1901template <class _Tp>
1902inline
1903const gslice_array<_Tp>&
1904gslice_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
1914template <class _Tp>
1915inline
1916void
1917gslice_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
1926template <class _Tp>
1927class _LIBCPP_TEMPLATE_VIS mask_array
1928{
1929public:
1930    typedef _Tp value_type;
1931
1932private:
1933    value_type*      __vp_;
1934    valarray<size_t> __1d_;
1935
1936public:
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
2044private:
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
2059template <class _Tp>
2060template <class _Expr>
2061inline
2062typename enable_if
2063<
2064    __is_val_expr<_Expr>::value,
2065    void
2066>::type
2067mask_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
2074template <class _Tp>
2075template <class _Expr>
2076inline
2077typename enable_if
2078<
2079    __is_val_expr<_Expr>::value,
2080    void
2081>::type
2082mask_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
2089template <class _Tp>
2090template <class _Expr>
2091inline
2092typename enable_if
2093<
2094    __is_val_expr<_Expr>::value,
2095    void
2096>::type
2097mask_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
2104template <class _Tp>
2105template <class _Expr>
2106inline
2107typename enable_if
2108<
2109    __is_val_expr<_Expr>::value,
2110    void
2111>::type
2112mask_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
2119template <class _Tp>
2120template <class _Expr>
2121inline
2122typename enable_if
2123<
2124    __is_val_expr<_Expr>::value,
2125    void
2126>::type
2127mask_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
2134template <class _Tp>
2135template <class _Expr>
2136inline
2137typename enable_if
2138<
2139    __is_val_expr<_Expr>::value,
2140    void
2141>::type
2142mask_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
2149template <class _Tp>
2150template <class _Expr>
2151inline
2152typename enable_if
2153<
2154    __is_val_expr<_Expr>::value,
2155    void
2156>::type
2157mask_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
2164template <class _Tp>
2165template <class _Expr>
2166inline
2167typename enable_if
2168<
2169    __is_val_expr<_Expr>::value,
2170    void
2171>::type
2172mask_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
2179template <class _Tp>
2180template <class _Expr>
2181inline
2182typename enable_if
2183<
2184    __is_val_expr<_Expr>::value,
2185    void
2186>::type
2187mask_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
2194template <class _Tp>
2195template <class _Expr>
2196inline
2197typename enable_if
2198<
2199    __is_val_expr<_Expr>::value,
2200    void
2201>::type
2202mask_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
2209template <class _Tp>
2210template <class _Expr>
2211inline
2212typename enable_if
2213<
2214    __is_val_expr<_Expr>::value,
2215    void
2216>::type
2217mask_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
2224template <class _Tp>
2225inline
2226const mask_array<_Tp>&
2227mask_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
2235template <class _Tp>
2236inline
2237void
2238mask_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
2245template <class _ValExpr>
2246class __mask_expr
2247{
2248    typedef __libcpp_remove_reference_t<_ValExpr>  _RmExpr;
2249public:
2250    typedef typename _RmExpr::value_type value_type;
2251    typedef value_type __result_type;
2252
2253private:
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
2268public:
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
2282template <class _Tp>
2283class _LIBCPP_TEMPLATE_VIS indirect_array
2284{
2285public:
2286    typedef _Tp value_type;
2287
2288private:
2289    value_type*      __vp_;
2290    valarray<size_t> __1d_;
2291
2292public:
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
2400private:
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
2420template <class _Tp>
2421template <class _Expr>
2422inline
2423typename enable_if
2424<
2425    __is_val_expr<_Expr>::value,
2426    void
2427>::type
2428indirect_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
2435template <class _Tp>
2436template <class _Expr>
2437inline
2438typename enable_if
2439<
2440    __is_val_expr<_Expr>::value,
2441    void
2442>::type
2443indirect_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
2450template <class _Tp>
2451template <class _Expr>
2452inline
2453typename enable_if
2454<
2455    __is_val_expr<_Expr>::value,
2456    void
2457>::type
2458indirect_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
2465template <class _Tp>
2466template <class _Expr>
2467inline
2468typename enable_if
2469<
2470    __is_val_expr<_Expr>::value,
2471    void
2472>::type
2473indirect_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
2480template <class _Tp>
2481template <class _Expr>
2482inline
2483typename enable_if
2484<
2485    __is_val_expr<_Expr>::value,
2486    void
2487>::type
2488indirect_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
2495template <class _Tp>
2496template <class _Expr>
2497inline
2498typename enable_if
2499<
2500    __is_val_expr<_Expr>::value,
2501    void
2502>::type
2503indirect_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
2510template <class _Tp>
2511template <class _Expr>
2512inline
2513typename enable_if
2514<
2515    __is_val_expr<_Expr>::value,
2516    void
2517>::type
2518indirect_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
2525template <class _Tp>
2526template <class _Expr>
2527inline
2528typename enable_if
2529<
2530    __is_val_expr<_Expr>::value,
2531    void
2532>::type
2533indirect_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
2540template <class _Tp>
2541template <class _Expr>
2542inline
2543typename enable_if
2544<
2545    __is_val_expr<_Expr>::value,
2546    void
2547>::type
2548indirect_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
2555template <class _Tp>
2556template <class _Expr>
2557inline
2558typename enable_if
2559<
2560    __is_val_expr<_Expr>::value,
2561    void
2562>::type
2563indirect_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
2570template <class _Tp>
2571template <class _Expr>
2572inline
2573typename enable_if
2574<
2575    __is_val_expr<_Expr>::value,
2576    void
2577>::type
2578indirect_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
2585template <class _Tp>
2586inline
2587const indirect_array<_Tp>&
2588indirect_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
2598template <class _Tp>
2599inline
2600void
2601indirect_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
2608template <class _ValExpr>
2609class __indirect_expr
2610{
2611    typedef __libcpp_remove_reference_t<_ValExpr>  _RmExpr;
2612public:
2613    typedef typename _RmExpr::value_type value_type;
2614    typedef value_type __result_type;
2615
2616private:
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
2636public:
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
2648template<class _ValExpr>
2649class __val_expr
2650{
2651    typedef __libcpp_remove_reference_t<_ValExpr>  _RmExpr;
2652
2653    _ValExpr __expr_;
2654public:
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
2795template<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
2812template <class _Tp>
2813inline
2814valarray<_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
2838template <class _Tp>
2839inline
2840valarray<_Tp>::valarray(const value_type& __x, size_t __n)
2841    : __begin_(nullptr),
2842      __end_(nullptr)
2843{
2844    resize(__n, __x);
2845}
2846
2847template <class _Tp>
2848valarray<_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
2872template <class _Tp>
2873valarray<_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
2899template <class _Tp>
2900inline
2901valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT
2902    : __begin_(__v.__begin_),
2903      __end_(__v.__end_)
2904{
2905    __v.__begin_ = __v.__end_ = nullptr;
2906}
2907
2908template <class _Tp>
2909valarray<_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
2937template <class _Tp>
2938valarray<_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
2964template <class _Tp>
2965valarray<_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
2993template <class _Tp>
2994valarray<_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
3022template <class _Tp>
3023valarray<_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
3051template <class _Tp>
3052inline
3053valarray<_Tp>::~valarray()
3054{
3055    __clear(size());
3056}
3057
3058template <class _Tp>
3059valarray<_Tp>&
3060valarray<_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
3075template <class _Tp>
3076valarray<_Tp>&
3077valarray<_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
3086template <class _Tp>
3087inline
3088valarray<_Tp>&
3089valarray<_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
3099template <class _Tp>
3100inline
3101valarray<_Tp>&
3102valarray<_Tp>::operator=(initializer_list<value_type> __il)
3103{
3104    return __assign_range(__il.begin(), __il.end());
3105}
3106
3107#endif // _LIBCPP_CXX03_LANG
3108
3109template <class _Tp>
3110inline
3111valarray<_Tp>&
3112valarray<_Tp>::operator=(const value_type& __x)
3113{
3114    _VSTD::fill(__begin_, __end_, __x);
3115    return *this;
3116}
3117
3118template <class _Tp>
3119inline
3120valarray<_Tp>&
3121valarray<_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
3130template <class _Tp>
3131inline
3132valarray<_Tp>&
3133valarray<_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
3144template <class _Tp>
3145inline
3146valarray<_Tp>&
3147valarray<_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
3158template <class _Tp>
3159inline
3160valarray<_Tp>&
3161valarray<_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
3172template <class _Tp>
3173template <class _ValExpr>
3174inline
3175valarray<_Tp>&
3176valarray<_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
3187template <class _Tp>
3188inline
3189__val_expr<__slice_expr<const valarray<_Tp>&> >
3190valarray<_Tp>::operator[](slice __s) const
3191{
3192    return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
3193}
3194
3195template <class _Tp>
3196inline
3197slice_array<_Tp>
3198valarray<_Tp>::operator[](slice __s)
3199{
3200    return slice_array<value_type>(__s, *this);
3201}
3202
3203template <class _Tp>
3204inline
3205__val_expr<__indirect_expr<const valarray<_Tp>&> >
3206valarray<_Tp>::operator[](const gslice& __gs) const
3207{
3208    return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
3209}
3210
3211template <class _Tp>
3212inline
3213gslice_array<_Tp>
3214valarray<_Tp>::operator[](const gslice& __gs)
3215{
3216    return gslice_array<value_type>(__gs, *this);
3217}
3218
3219#ifndef _LIBCPP_CXX03_LANG
3220
3221template <class _Tp>
3222inline
3223__val_expr<__indirect_expr<const valarray<_Tp>&> >
3224valarray<_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
3229template <class _Tp>
3230inline
3231gslice_array<_Tp>
3232valarray<_Tp>::operator[](gslice&& __gs)
3233{
3234    return gslice_array<value_type>(std::move(__gs), *this);
3235}
3236
3237#endif // _LIBCPP_CXX03_LANG
3238
3239template <class _Tp>
3240inline
3241__val_expr<__mask_expr<const valarray<_Tp>&> >
3242valarray<_Tp>::operator[](const valarray<bool>& __vb) const
3243{
3244    return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
3245}
3246
3247template <class _Tp>
3248inline
3249mask_array<_Tp>
3250valarray<_Tp>::operator[](const valarray<bool>& __vb)
3251{
3252    return mask_array<value_type>(__vb, *this);
3253}
3254
3255#ifndef _LIBCPP_CXX03_LANG
3256
3257template <class _Tp>
3258inline
3259__val_expr<__mask_expr<const valarray<_Tp>&> >
3260valarray<_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
3265template <class _Tp>
3266inline
3267mask_array<_Tp>
3268valarray<_Tp>::operator[](valarray<bool>&& __vb)
3269{
3270    return mask_array<value_type>(std::move(__vb), *this);
3271}
3272
3273#endif // _LIBCPP_CXX03_LANG
3274
3275template <class _Tp>
3276inline
3277__val_expr<__indirect_expr<const valarray<_Tp>&> >
3278valarray<_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
3283template <class _Tp>
3284inline
3285indirect_array<_Tp>
3286valarray<_Tp>::operator[](const valarray<size_t>& __vs)
3287{
3288    return indirect_array<value_type>(__vs, *this);
3289}
3290
3291#ifndef _LIBCPP_CXX03_LANG
3292
3293template <class _Tp>
3294inline
3295__val_expr<__indirect_expr<const valarray<_Tp>&> >
3296valarray<_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
3301template <class _Tp>
3302inline
3303indirect_array<_Tp>
3304valarray<_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
3311template <class _Tp>
3312inline
3313__val_expr<_UnaryOp<__unary_plus<_Tp>, const valarray<_Tp>&> >
3314valarray<_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
3320template <class _Tp>
3321inline
3322__val_expr<_UnaryOp<negate<_Tp>, const valarray<_Tp>&> >
3323valarray<_Tp>::operator-() const
3324{
3325    using _Op = _UnaryOp<negate<_Tp>, const valarray<_Tp>&>;
3326    return __val_expr<_Op>(_Op(negate<_Tp>(), *this));
3327}
3328
3329template <class _Tp>
3330inline
3331__val_expr<_UnaryOp<__bit_not<_Tp>, const valarray<_Tp>&> >
3332valarray<_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
3338template <class _Tp>
3339inline
3340__val_expr<_UnaryOp<logical_not<_Tp>, const valarray<_Tp>&> >
3341valarray<_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
3347template <class _Tp>
3348inline
3349valarray<_Tp>&
3350valarray<_Tp>::operator*=(const value_type& __x)
3351{
3352    for (value_type* __p = __begin_; __p != __end_; ++__p)
3353        *__p *= __x;
3354    return *this;
3355}
3356
3357template <class _Tp>
3358inline
3359valarray<_Tp>&
3360valarray<_Tp>::operator/=(const value_type& __x)
3361{
3362    for (value_type* __p = __begin_; __p != __end_; ++__p)
3363        *__p /= __x;
3364    return *this;
3365}
3366
3367template <class _Tp>
3368inline
3369valarray<_Tp>&
3370valarray<_Tp>::operator%=(const value_type& __x)
3371{
3372    for (value_type* __p = __begin_; __p != __end_; ++__p)
3373        *__p %= __x;
3374    return *this;
3375}
3376
3377template <class _Tp>
3378inline
3379valarray<_Tp>&
3380valarray<_Tp>::operator+=(const value_type& __x)
3381{
3382    for (value_type* __p = __begin_; __p != __end_; ++__p)
3383        *__p += __x;
3384    return *this;
3385}
3386
3387template <class _Tp>
3388inline
3389valarray<_Tp>&
3390valarray<_Tp>::operator-=(const value_type& __x)
3391{
3392    for (value_type* __p = __begin_; __p != __end_; ++__p)
3393        *__p -= __x;
3394    return *this;
3395}
3396
3397template <class _Tp>
3398inline
3399valarray<_Tp>&
3400valarray<_Tp>::operator^=(const value_type& __x)
3401{
3402    for (value_type* __p = __begin_; __p != __end_; ++__p)
3403        *__p ^= __x;
3404    return *this;
3405}
3406
3407template <class _Tp>
3408inline
3409valarray<_Tp>&
3410valarray<_Tp>::operator&=(const value_type& __x)
3411{
3412    for (value_type* __p = __begin_; __p != __end_; ++__p)
3413        *__p &= __x;
3414    return *this;
3415}
3416
3417template <class _Tp>
3418inline
3419valarray<_Tp>&
3420valarray<_Tp>::operator|=(const value_type& __x)
3421{
3422    for (value_type* __p = __begin_; __p != __end_; ++__p)
3423        *__p |= __x;
3424    return *this;
3425}
3426
3427template <class _Tp>
3428inline
3429valarray<_Tp>&
3430valarray<_Tp>::operator<<=(const value_type& __x)
3431{
3432    for (value_type* __p = __begin_; __p != __end_; ++__p)
3433        *__p <<= __x;
3434    return *this;
3435}
3436
3437template <class _Tp>
3438inline
3439valarray<_Tp>&
3440valarray<_Tp>::operator>>=(const value_type& __x)
3441{
3442    for (value_type* __p = __begin_; __p != __end_; ++__p)
3443        *__p >>= __x;
3444    return *this;
3445}
3446
3447template <class _Tp>
3448template <class _Expr>
3449inline
3450typename enable_if
3451<
3452    __is_val_expr<_Expr>::value,
3453    valarray<_Tp>&
3454>::type
3455valarray<_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
3463template <class _Tp>
3464template <class _Expr>
3465inline
3466typename enable_if
3467<
3468    __is_val_expr<_Expr>::value,
3469    valarray<_Tp>&
3470>::type
3471valarray<_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
3479template <class _Tp>
3480template <class _Expr>
3481inline
3482typename enable_if
3483<
3484    __is_val_expr<_Expr>::value,
3485    valarray<_Tp>&
3486>::type
3487valarray<_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
3495template <class _Tp>
3496template <class _Expr>
3497inline
3498typename enable_if
3499<
3500    __is_val_expr<_Expr>::value,
3501    valarray<_Tp>&
3502>::type
3503valarray<_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
3511template <class _Tp>
3512template <class _Expr>
3513inline
3514typename enable_if
3515<
3516    __is_val_expr<_Expr>::value,
3517    valarray<_Tp>&
3518>::type
3519valarray<_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
3527template <class _Tp>
3528template <class _Expr>
3529inline
3530typename enable_if
3531<
3532    __is_val_expr<_Expr>::value,
3533    valarray<_Tp>&
3534>::type
3535valarray<_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
3543template <class _Tp>
3544template <class _Expr>
3545inline
3546typename enable_if
3547<
3548    __is_val_expr<_Expr>::value,
3549    valarray<_Tp>&
3550>::type
3551valarray<_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
3559template <class _Tp>
3560template <class _Expr>
3561inline
3562typename enable_if
3563<
3564    __is_val_expr<_Expr>::value,
3565    valarray<_Tp>&
3566>::type
3567valarray<_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
3575template <class _Tp>
3576template <class _Expr>
3577inline
3578typename enable_if
3579<
3580    __is_val_expr<_Expr>::value,
3581    valarray<_Tp>&
3582>::type
3583valarray<_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
3591template <class _Tp>
3592template <class _Expr>
3593inline
3594typename enable_if
3595<
3596    __is_val_expr<_Expr>::value,
3597    valarray<_Tp>&
3598>::type
3599valarray<_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
3607template <class _Tp>
3608inline
3609void
3610valarray<_Tp>::swap(valarray& __v) _NOEXCEPT
3611{
3612    _VSTD::swap(__begin_, __v.__begin_);
3613    _VSTD::swap(__end_, __v.__end_);
3614}
3615
3616template <class _Tp>
3617inline
3618_Tp
3619valarray<_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
3630template <class _Tp>
3631inline
3632_Tp
3633valarray<_Tp>::min() const
3634{
3635    if (__begin_ == __end_)
3636        return value_type();
3637    return *_VSTD::min_element(__begin_, __end_);
3638}
3639
3640template <class _Tp>
3641inline
3642_Tp
3643valarray<_Tp>::max() const
3644{
3645    if (__begin_ == __end_)
3646        return value_type();
3647    return *_VSTD::max_element(__begin_, __end_);
3648}
3649
3650template <class _Tp>
3651valarray<_Tp>
3652valarray<_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
3686template <class _Tp>
3687valarray<_Tp>
3688valarray<_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
3705template <class _Tp>
3706valarray<_Tp>
3707valarray<_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
3720template <class _Tp>
3721valarray<_Tp>
3722valarray<_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
3735template <class _Tp>
3736inline
3737void 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
3748template <class _Tp>
3749void
3750valarray<_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
3773template<class _Tp>
3774inline _LIBCPP_INLINE_VISIBILITY
3775void
3776swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT
3777{
3778    __x.swap(__y);
3779}
3780
3781template<class _Expr1, class _Expr2>
3782inline _LIBCPP_INLINE_VISIBILITY
3783typename 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
3788operator*(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
3795template<class _Expr>
3796inline _LIBCPP_INLINE_VISIBILITY
3797typename 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
3803operator*(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
3811template<class _Expr>
3812inline _LIBCPP_INLINE_VISIBILITY
3813typename 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
3819operator*(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
3827template<class _Expr1, class _Expr2>
3828inline _LIBCPP_INLINE_VISIBILITY
3829typename 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
3834operator/(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
3841template<class _Expr>
3842inline _LIBCPP_INLINE_VISIBILITY
3843typename 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
3849operator/(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
3857template<class _Expr>
3858inline _LIBCPP_INLINE_VISIBILITY
3859typename 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
3865operator/(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
3873template<class _Expr1, class _Expr2>
3874inline _LIBCPP_INLINE_VISIBILITY
3875typename 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
3880operator%(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
3887template<class _Expr>
3888inline _LIBCPP_INLINE_VISIBILITY
3889typename 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
3895operator%(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
3903template<class _Expr>
3904inline _LIBCPP_INLINE_VISIBILITY
3905typename 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
3911operator%(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
3919template<class _Expr1, class _Expr2>
3920inline _LIBCPP_INLINE_VISIBILITY
3921typename 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
3926operator+(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
3933template<class _Expr>
3934inline _LIBCPP_INLINE_VISIBILITY
3935typename 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
3941operator+(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
3949template<class _Expr>
3950inline _LIBCPP_INLINE_VISIBILITY
3951typename 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
3957operator+(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
3965template<class _Expr1, class _Expr2>
3966inline _LIBCPP_INLINE_VISIBILITY
3967typename 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
3972operator-(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
3979template<class _Expr>
3980inline _LIBCPP_INLINE_VISIBILITY
3981typename 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
3987operator-(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
3995template<class _Expr>
3996inline _LIBCPP_INLINE_VISIBILITY
3997typename 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
4003operator-(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
4011template<class _Expr1, class _Expr2>
4012inline _LIBCPP_INLINE_VISIBILITY
4013typename 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
4018operator^(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
4025template<class _Expr>
4026inline _LIBCPP_INLINE_VISIBILITY
4027typename 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
4033operator^(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
4041template<class _Expr>
4042inline _LIBCPP_INLINE_VISIBILITY
4043typename 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
4049operator^(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
4057template<class _Expr1, class _Expr2>
4058inline _LIBCPP_INLINE_VISIBILITY
4059typename 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
4064operator&(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
4071template<class _Expr>
4072inline _LIBCPP_INLINE_VISIBILITY
4073typename 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
4079operator&(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
4087template<class _Expr>
4088inline _LIBCPP_INLINE_VISIBILITY
4089typename 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
4095operator&(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
4103template<class _Expr1, class _Expr2>
4104inline _LIBCPP_INLINE_VISIBILITY
4105typename 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
4110operator|(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
4117template<class _Expr>
4118inline _LIBCPP_INLINE_VISIBILITY
4119typename 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
4125operator|(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
4133template<class _Expr>
4134inline _LIBCPP_INLINE_VISIBILITY
4135typename 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
4141operator|(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
4149template<class _Expr1, class _Expr2>
4150inline _LIBCPP_INLINE_VISIBILITY
4151typename 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
4156operator<<(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
4163template<class _Expr>
4164inline _LIBCPP_INLINE_VISIBILITY
4165typename 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
4171operator<<(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
4179template<class _Expr>
4180inline _LIBCPP_INLINE_VISIBILITY
4181typename 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
4187operator<<(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
4195template<class _Expr1, class _Expr2>
4196inline _LIBCPP_INLINE_VISIBILITY
4197typename 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
4202operator>>(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
4209template<class _Expr>
4210inline _LIBCPP_INLINE_VISIBILITY
4211typename 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
4217operator>>(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
4225template<class _Expr>
4226inline _LIBCPP_INLINE_VISIBILITY
4227typename 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
4233operator>>(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
4241template<class _Expr1, class _Expr2>
4242inline _LIBCPP_INLINE_VISIBILITY
4243typename 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
4248operator&&(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
4255template<class _Expr>
4256inline _LIBCPP_INLINE_VISIBILITY
4257typename 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
4263operator&&(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
4271template<class _Expr>
4272inline _LIBCPP_INLINE_VISIBILITY
4273typename 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
4279operator&&(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
4287template<class _Expr1, class _Expr2>
4288inline _LIBCPP_INLINE_VISIBILITY
4289typename 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
4294operator||(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
4301template<class _Expr>
4302inline _LIBCPP_INLINE_VISIBILITY
4303typename 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
4309operator||(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
4317template<class _Expr>
4318inline _LIBCPP_INLINE_VISIBILITY
4319typename 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
4325operator||(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
4333template<class _Expr1, class _Expr2>
4334inline _LIBCPP_INLINE_VISIBILITY
4335typename 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
4340operator==(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
4347template<class _Expr>
4348inline _LIBCPP_INLINE_VISIBILITY
4349typename 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
4355operator==(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
4363template<class _Expr>
4364inline _LIBCPP_INLINE_VISIBILITY
4365typename 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
4371operator==(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
4379template<class _Expr1, class _Expr2>
4380inline _LIBCPP_INLINE_VISIBILITY
4381typename 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
4386operator!=(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
4393template<class _Expr>
4394inline _LIBCPP_INLINE_VISIBILITY
4395typename 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
4401operator!=(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
4409template<class _Expr>
4410inline _LIBCPP_INLINE_VISIBILITY
4411typename 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
4417operator!=(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
4425template<class _Expr1, class _Expr2>
4426inline _LIBCPP_INLINE_VISIBILITY
4427typename 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
4432operator<(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
4439template<class _Expr>
4440inline _LIBCPP_INLINE_VISIBILITY
4441typename 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
4447operator<(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
4455template<class _Expr>
4456inline _LIBCPP_INLINE_VISIBILITY
4457typename 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
4463operator<(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
4471template<class _Expr1, class _Expr2>
4472inline _LIBCPP_INLINE_VISIBILITY
4473typename 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
4478operator>(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
4485template<class _Expr>
4486inline _LIBCPP_INLINE_VISIBILITY
4487typename 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
4493operator>(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
4501template<class _Expr>
4502inline _LIBCPP_INLINE_VISIBILITY
4503typename 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
4509operator>(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
4517template<class _Expr1, class _Expr2>
4518inline _LIBCPP_INLINE_VISIBILITY
4519typename 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
4524operator<=(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
4531template<class _Expr>
4532inline _LIBCPP_INLINE_VISIBILITY
4533typename 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
4539operator<=(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
4547template<class _Expr>
4548inline _LIBCPP_INLINE_VISIBILITY
4549typename 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
4555operator<=(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
4563template<class _Expr1, class _Expr2>
4564inline _LIBCPP_INLINE_VISIBILITY
4565typename 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
4570operator>=(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
4577template<class _Expr>
4578inline _LIBCPP_INLINE_VISIBILITY
4579typename 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
4585operator>=(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
4593template<class _Expr>
4594inline _LIBCPP_INLINE_VISIBILITY
4595typename 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
4601operator>=(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
4609template<class _Expr>
4610inline _LIBCPP_INLINE_VISIBILITY
4611typename enable_if
4612<
4613    __is_val_expr<_Expr>::value,
4614    __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
4615>::type
4616abs(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
4623template<class _Expr>
4624inline _LIBCPP_INLINE_VISIBILITY
4625typename enable_if
4626<
4627    __is_val_expr<_Expr>::value,
4628    __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
4629>::type
4630acos(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
4637template<class _Expr>
4638inline _LIBCPP_INLINE_VISIBILITY
4639typename enable_if
4640<
4641    __is_val_expr<_Expr>::value,
4642    __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
4643>::type
4644asin(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
4651template<class _Expr>
4652inline _LIBCPP_INLINE_VISIBILITY
4653typename enable_if
4654<
4655    __is_val_expr<_Expr>::value,
4656    __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
4657>::type
4658atan(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
4665template<class _Expr1, class _Expr2>
4666inline _LIBCPP_INLINE_VISIBILITY
4667typename 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
4672atan2(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
4679template<class _Expr>
4680inline _LIBCPP_INLINE_VISIBILITY
4681typename 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
4687atan2(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
4695template<class _Expr>
4696inline _LIBCPP_INLINE_VISIBILITY
4697typename 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
4703atan2(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
4711template<class _Expr>
4712inline _LIBCPP_INLINE_VISIBILITY
4713typename enable_if
4714<
4715    __is_val_expr<_Expr>::value,
4716    __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
4717>::type
4718cos(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
4725template<class _Expr>
4726inline _LIBCPP_INLINE_VISIBILITY
4727typename enable_if
4728<
4729    __is_val_expr<_Expr>::value,
4730    __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
4731>::type
4732cosh(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
4739template<class _Expr>
4740inline _LIBCPP_INLINE_VISIBILITY
4741typename enable_if
4742<
4743    __is_val_expr<_Expr>::value,
4744    __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
4745>::type
4746exp(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
4753template<class _Expr>
4754inline _LIBCPP_INLINE_VISIBILITY
4755typename enable_if
4756<
4757    __is_val_expr<_Expr>::value,
4758    __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
4759>::type
4760log(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
4767template<class _Expr>
4768inline _LIBCPP_INLINE_VISIBILITY
4769typename enable_if
4770<
4771    __is_val_expr<_Expr>::value,
4772    __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
4773>::type
4774log10(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
4781template<class _Expr1, class _Expr2>
4782inline _LIBCPP_INLINE_VISIBILITY
4783typename 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
4788pow(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
4795template<class _Expr>
4796inline _LIBCPP_INLINE_VISIBILITY
4797typename 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
4803pow(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
4811template<class _Expr>
4812inline _LIBCPP_INLINE_VISIBILITY
4813typename 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
4819pow(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
4827template<class _Expr>
4828inline _LIBCPP_INLINE_VISIBILITY
4829typename enable_if
4830<
4831    __is_val_expr<_Expr>::value,
4832    __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
4833>::type
4834sin(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
4841template<class _Expr>
4842inline _LIBCPP_INLINE_VISIBILITY
4843typename enable_if
4844<
4845    __is_val_expr<_Expr>::value,
4846    __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
4847>::type
4848sinh(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
4855template<class _Expr>
4856inline _LIBCPP_INLINE_VISIBILITY
4857typename enable_if
4858<
4859    __is_val_expr<_Expr>::value,
4860    __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
4861>::type
4862sqrt(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
4869template<class _Expr>
4870inline _LIBCPP_INLINE_VISIBILITY
4871typename enable_if
4872<
4873    __is_val_expr<_Expr>::value,
4874    __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
4875>::type
4876tan(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
4883template<class _Expr>
4884inline _LIBCPP_INLINE_VISIBILITY
4885typename enable_if
4886<
4887    __is_val_expr<_Expr>::value,
4888    __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
4889>::type
4890tanh(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
4897template <class _Tp>
4898inline _LIBCPP_INLINE_VISIBILITY
4899_Tp*
4900begin(valarray<_Tp>& __v)
4901{
4902    return __v.__begin_;
4903}
4904
4905template <class _Tp>
4906inline _LIBCPP_INLINE_VISIBILITY
4907const _Tp*
4908begin(const valarray<_Tp>& __v)
4909{
4910    return __v.__begin_;
4911}
4912
4913template <class _Tp>
4914inline _LIBCPP_INLINE_VISIBILITY
4915_Tp*
4916end(valarray<_Tp>& __v)
4917{
4918    return __v.__end_;
4919}
4920
4921template <class _Tp>
4922inline _LIBCPP_INLINE_VISIBILITY
4923const _Tp*
4924end(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
4941