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