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);
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);
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);
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);
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
349#pragma GCC system_header
350
351_LIBCPP_BEGIN_NAMESPACE_STD
352
353template<class _Tp> class valarray;
354
355class _LIBCPP_VISIBLE slice
356{
357    size_t __start_;
358    size_t __size_;
359    size_t __stride_;
360public:
361    _LIBCPP_INLINE_VISIBILITY
362    slice()
363        : __start_(0),
364          __size_(0),
365          __stride_(0)
366          {}
367
368    _LIBCPP_INLINE_VISIBILITY
369    slice(size_t __start, size_t __size, size_t __stride)
370        : __start_(__start),
371          __size_(__size),
372          __stride_(__stride)
373          {}
374
375    _LIBCPP_INLINE_VISIBILITY size_t start()  const {return __start_;}
376    _LIBCPP_INLINE_VISIBILITY size_t size()   const {return __size_;}
377    _LIBCPP_INLINE_VISIBILITY size_t stride() const {return __stride_;}
378};
379
380template <class _Tp> class slice_array;
381class gslice;
382template <class _Tp> class gslice_array;
383template <class _Tp> class mask_array;
384template <class _Tp> class indirect_array;
385
386template <class _Tp>
387_Tp*
388begin(valarray<_Tp>& __v);
389
390template <class _Tp>
391const _Tp*
392begin(const valarray<_Tp>& __v);
393
394template <class _Tp>
395_Tp*
396end(valarray<_Tp>& __v);
397
398template <class _Tp>
399const _Tp*
400end(const valarray<_Tp>& __v);
401
402template <class _Op, class _A0>
403struct _UnaryOp
404{
405    typedef typename _Op::result_type result_type;
406    typedef typename _A0::value_type value_type;
407
408    _Op __op_;
409    _A0 __a0_;
410
411    _LIBCPP_INLINE_VISIBILITY
412    _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {}
413
414    _LIBCPP_INLINE_VISIBILITY
415    result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
416
417    _LIBCPP_INLINE_VISIBILITY
418    size_t size() const {return __a0_.size();}
419};
420
421template <class _Op, class _A0, class _A1>
422struct _BinaryOp
423{
424    typedef typename _Op::result_type result_type;
425    typedef typename _A0::value_type value_type;
426
427    _Op __op_;
428    _A0 __a0_;
429    _A1 __a1_;
430
431    _LIBCPP_INLINE_VISIBILITY
432    _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1)
433        : __op_(__op), __a0_(__a0), __a1_(__a1) {}
434
435    _LIBCPP_INLINE_VISIBILITY
436    value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
437
438    _LIBCPP_INLINE_VISIBILITY
439    size_t size() const {return __a0_.size();}
440};
441
442template <class _Tp>
443class __scalar_expr
444{
445public:
446    typedef _Tp        value_type;
447    typedef const _Tp& result_type;
448private:
449    const value_type& __t_;
450    size_t __s_;
451public:
452    _LIBCPP_INLINE_VISIBILITY
453    explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {}
454
455    _LIBCPP_INLINE_VISIBILITY
456    result_type operator[](size_t) const {return __t_;}
457
458    _LIBCPP_INLINE_VISIBILITY
459    size_t size() const {return __s_;}
460};
461
462template <class _Tp>
463struct __unary_plus : unary_function<_Tp, _Tp>
464{
465    _LIBCPP_INLINE_VISIBILITY
466    _Tp operator()(const _Tp& __x) const
467        {return +__x;}
468};
469
470template <class _Tp>
471struct __bit_not  : unary_function<_Tp, _Tp>
472{
473    _LIBCPP_INLINE_VISIBILITY
474    _Tp operator()(const _Tp& __x) const
475        {return ~__x;}
476};
477
478template <class _Tp>
479struct __bit_shift_left : binary_function<_Tp, _Tp, _Tp>
480{
481    _LIBCPP_INLINE_VISIBILITY
482    _Tp operator()(const _Tp& __x, const _Tp& __y) const
483        {return __x << __y;}
484};
485
486template <class _Tp>
487struct __bit_shift_right : binary_function<_Tp, _Tp, _Tp>
488{
489    _LIBCPP_INLINE_VISIBILITY
490    _Tp operator()(const _Tp& __x, const _Tp& __y) const
491        {return __x >> __y;}
492};
493
494template <class _Tp, class _F>
495struct __apply_expr   : unary_function<_Tp, _Tp>
496{
497private:
498    _F __f_;
499public:
500    _LIBCPP_INLINE_VISIBILITY
501    explicit __apply_expr(_F __f) : __f_(__f) {}
502
503    _LIBCPP_INLINE_VISIBILITY
504    _Tp operator()(const _Tp& __x) const
505        {return __f_(__x);}
506};
507
508template <class _Tp>
509struct __abs_expr : unary_function<_Tp, _Tp>
510{
511    _LIBCPP_INLINE_VISIBILITY
512    _Tp operator()(const _Tp& __x) const
513        {return abs(__x);}
514};
515
516template <class _Tp>
517struct __acos_expr : unary_function<_Tp, _Tp>
518{
519    _LIBCPP_INLINE_VISIBILITY
520    _Tp operator()(const _Tp& __x) const
521        {return acos(__x);}
522};
523
524template <class _Tp>
525struct __asin_expr : unary_function<_Tp, _Tp>
526{
527    _LIBCPP_INLINE_VISIBILITY
528    _Tp operator()(const _Tp& __x) const
529        {return asin(__x);}
530};
531
532template <class _Tp>
533struct __atan_expr : unary_function<_Tp, _Tp>
534{
535    _LIBCPP_INLINE_VISIBILITY
536    _Tp operator()(const _Tp& __x) const
537        {return atan(__x);}
538};
539
540template <class _Tp>
541struct __atan2_expr : binary_function<_Tp, _Tp, _Tp>
542{
543    _LIBCPP_INLINE_VISIBILITY
544    _Tp operator()(const _Tp& __x, const _Tp& __y) const
545        {return atan2(__x, __y);}
546};
547
548template <class _Tp>
549struct __cos_expr : unary_function<_Tp, _Tp>
550{
551    _LIBCPP_INLINE_VISIBILITY
552    _Tp operator()(const _Tp& __x) const
553        {return cos(__x);}
554};
555
556template <class _Tp>
557struct __cosh_expr : unary_function<_Tp, _Tp>
558{
559    _LIBCPP_INLINE_VISIBILITY
560    _Tp operator()(const _Tp& __x) const
561        {return cosh(__x);}
562};
563
564template <class _Tp>
565struct __exp_expr : unary_function<_Tp, _Tp>
566{
567    _LIBCPP_INLINE_VISIBILITY
568    _Tp operator()(const _Tp& __x) const
569        {return exp(__x);}
570};
571
572template <class _Tp>
573struct __log_expr : unary_function<_Tp, _Tp>
574{
575    _LIBCPP_INLINE_VISIBILITY
576    _Tp operator()(const _Tp& __x) const
577        {return log(__x);}
578};
579
580template <class _Tp>
581struct __log10_expr : unary_function<_Tp, _Tp>
582{
583    _LIBCPP_INLINE_VISIBILITY
584    _Tp operator()(const _Tp& __x) const
585        {return log10(__x);}
586};
587
588template <class _Tp>
589struct __pow_expr : binary_function<_Tp, _Tp, _Tp>
590{
591    _LIBCPP_INLINE_VISIBILITY
592    _Tp operator()(const _Tp& __x, const _Tp& __y) const
593        {return pow(__x, __y);}
594};
595
596template <class _Tp>
597struct __sin_expr : unary_function<_Tp, _Tp>
598{
599    _LIBCPP_INLINE_VISIBILITY
600    _Tp operator()(const _Tp& __x) const
601        {return sin(__x);}
602};
603
604template <class _Tp>
605struct __sinh_expr : unary_function<_Tp, _Tp>
606{
607    _LIBCPP_INLINE_VISIBILITY
608    _Tp operator()(const _Tp& __x) const
609        {return sinh(__x);}
610};
611
612template <class _Tp>
613struct __sqrt_expr : unary_function<_Tp, _Tp>
614{
615    _LIBCPP_INLINE_VISIBILITY
616    _Tp operator()(const _Tp& __x) const
617        {return sqrt(__x);}
618};
619
620template <class _Tp>
621struct __tan_expr : unary_function<_Tp, _Tp>
622{
623    _LIBCPP_INLINE_VISIBILITY
624    _Tp operator()(const _Tp& __x) const
625        {return tan(__x);}
626};
627
628template <class _Tp>
629struct __tanh_expr : unary_function<_Tp, _Tp>
630{
631    _LIBCPP_INLINE_VISIBILITY
632    _Tp operator()(const _Tp& __x) const
633        {return tanh(__x);}
634};
635
636template <class _ValExpr>
637class __slice_expr
638{
639    typedef typename remove_reference<_ValExpr>::type  _RmExpr;
640public:
641    typedef typename _RmExpr::value_type value_type;
642    typedef value_type result_type;
643
644private:
645    _ValExpr __expr_;
646    size_t __start_;
647    size_t __size_;
648    size_t __stride_;
649
650    _LIBCPP_INLINE_VISIBILITY
651    __slice_expr(const slice& __sl, const _RmExpr& __e)
652        : __expr_(__e),
653          __start_(__sl.start()),
654          __size_(__sl.size()),
655          __stride_(__sl.stride())
656        {}
657public:
658
659    _LIBCPP_INLINE_VISIBILITY
660    result_type operator[](size_t __i) const
661        {return __expr_[__start_ + __i * __stride_];}
662
663    _LIBCPP_INLINE_VISIBILITY
664    size_t size() const {return __size_;}
665
666    template <class> friend class _LIBCPP_VISIBLE valarray;
667};
668
669template <class _ValExpr>
670class __mask_expr;
671
672template <class _ValExpr>
673class __indirect_expr;
674
675template <class _ValExpr>
676class __shift_expr
677{
678    typedef typename remove_reference<_ValExpr>::type  _RmExpr;
679public:
680    typedef typename _RmExpr::value_type value_type;
681    typedef value_type result_type;
682
683private:
684    _ValExpr __expr_;
685    size_t __size_;
686    ptrdiff_t __ul_;
687    ptrdiff_t __sn_;
688    ptrdiff_t __n_;
689    static const ptrdiff_t _N = static_cast<ptrdiff_t>(
690                                    sizeof(ptrdiff_t) * __CHAR_BIT__ - 1);
691
692    _LIBCPP_INLINE_VISIBILITY
693    __shift_expr(int __n, const _RmExpr& __e)
694        : __expr_(__e),
695          __size_(__e.size()),
696          __n_(__n)
697        {
698            ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _N);
699            __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _N);
700            __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n);
701        }
702public:
703
704    _LIBCPP_INLINE_VISIBILITY
705    result_type operator[](size_t __j) const
706        {
707            ptrdiff_t __i = static_cast<size_t>(__j);
708            ptrdiff_t __m = (__sn_ * __i - __ul_) >> _N;
709            return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
710        }
711
712    _LIBCPP_INLINE_VISIBILITY
713    size_t size() const {return __size_;}
714
715    template <class> friend class __val_expr;
716};
717
718template <class _ValExpr>
719class __cshift_expr
720{
721    typedef typename remove_reference<_ValExpr>::type  _RmExpr;
722public:
723    typedef typename _RmExpr::value_type value_type;
724    typedef value_type result_type;
725
726private:
727    _ValExpr __expr_;
728    size_t __size_;
729    size_t __m_;
730    size_t __o1_;
731    size_t __o2_;
732
733    _LIBCPP_INLINE_VISIBILITY
734    __cshift_expr(int __n, const _RmExpr& __e)
735        : __expr_(__e),
736          __size_(__e.size())
737        {
738            __n %= static_cast<int>(__size_);
739            if (__n >= 0)
740            {
741                __m_ = __size_ - __n;
742                __o1_ = __n;
743                __o2_ = __n - __size_;
744            }
745            else
746            {
747                __m_ = -__n;
748                __o1_ = __n + __size_;
749                __o2_ = __n;
750            }
751        }
752public:
753
754    _LIBCPP_INLINE_VISIBILITY
755    result_type operator[](size_t __i) const
756        {
757            if (__i < __m_)
758                return __expr_[__i + __o1_];
759            return __expr_[__i + __o2_];
760        }
761
762    _LIBCPP_INLINE_VISIBILITY
763    size_t size() const {return __size_;}
764
765    template <class> friend class __val_expr;
766};
767
768template<class _ValExpr>
769class __val_expr;
770
771template<class _ValExpr>
772struct __is_val_expr : false_type {};
773
774template<class _ValExpr>
775struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
776
777template<class _Tp>
778struct __is_val_expr<valarray<_Tp> > : true_type {};
779
780template<class _Tp>
781class _LIBCPP_VISIBLE valarray
782{
783public:
784    typedef _Tp value_type;
785    typedef _Tp result_type;
786
787private:
788    value_type* __begin_;
789    value_type* __end_;
790
791public:
792    // construct/destroy:
793    _LIBCPP_INLINE_VISIBILITY
794    valarray() : __begin_(0), __end_(0) {}
795    explicit valarray(size_t __n);
796    valarray(const value_type& __x, size_t __n);
797    valarray(const value_type* __p, size_t __n);
798    valarray(const valarray& __v);
799#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
800    valarray(valarray&& __v);
801#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
802#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
803    valarray(initializer_list<value_type> __il);
804#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
805    valarray(const slice_array<value_type>& __sa);
806    valarray(const gslice_array<value_type>& __ga);
807    valarray(const mask_array<value_type>& __ma);
808    valarray(const indirect_array<value_type>& __ia);
809    ~valarray();
810
811    // assignment:
812    valarray& operator=(const valarray& __v);
813#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
814    valarray& operator=(valarray&& __v);
815#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
816#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
817    valarray& operator=(initializer_list<value_type>);
818#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
819    valarray& operator=(const value_type& __x);
820    valarray& operator=(const slice_array<value_type>& __sa);
821    valarray& operator=(const gslice_array<value_type>& __ga);
822    valarray& operator=(const mask_array<value_type>& __ma);
823    valarray& operator=(const indirect_array<value_type>& __ia);
824    template <class _ValExpr>
825        valarray& operator=(const __val_expr<_ValExpr>& __v);
826
827    // element access:
828    _LIBCPP_INLINE_VISIBILITY
829    const value_type& operator[](size_t __i) const {return __begin_[__i];}
830
831    _LIBCPP_INLINE_VISIBILITY
832    value_type&       operator[](size_t __i)       {return __begin_[__i];}
833
834    // subset operations:
835    __val_expr<__slice_expr<const valarray&> >    operator[](slice __s) const;
836    slice_array<value_type>                       operator[](slice __s);
837    __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
838    gslice_array<value_type>   operator[](const gslice& __gs);
839#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
840    __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
841    gslice_array<value_type>                      operator[](gslice&& __gs);
842#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
843    __val_expr<__mask_expr<const valarray&> >     operator[](const valarray<bool>& __vb) const;
844    mask_array<value_type>                        operator[](const valarray<bool>& __vb);
845#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
846    __val_expr<__mask_expr<const valarray&> >     operator[](valarray<bool>&& __vb) const;
847    mask_array<value_type>                        operator[](valarray<bool>&& __vb);
848#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
849    __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
850    indirect_array<value_type>                    operator[](const valarray<size_t>& __vs);
851#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
852    __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
853    indirect_array<value_type>                    operator[](valarray<size_t>&& __vs);
854#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
855
856    // unary operators:
857    valarray       operator+() const;
858    valarray       operator-() const;
859    valarray       operator~() const;
860    valarray<bool> operator!() const;
861
862    // computed assignment:
863    valarray& operator*= (const value_type& __x);
864    valarray& operator/= (const value_type& __x);
865    valarray& operator%= (const value_type& __x);
866    valarray& operator+= (const value_type& __x);
867    valarray& operator-= (const value_type& __x);
868    valarray& operator^= (const value_type& __x);
869    valarray& operator&= (const value_type& __x);
870    valarray& operator|= (const value_type& __x);
871    valarray& operator<<=(const value_type& __x);
872    valarray& operator>>=(const value_type& __x);
873
874    template <class _Expr>
875    typename enable_if
876    <
877        __is_val_expr<_Expr>::value,
878        valarray&
879    >::type
880    operator*= (const _Expr& __v);
881
882    template <class _Expr>
883    typename enable_if
884    <
885        __is_val_expr<_Expr>::value,
886        valarray&
887    >::type
888    operator/= (const _Expr& __v);
889
890    template <class _Expr>
891    typename enable_if
892    <
893        __is_val_expr<_Expr>::value,
894        valarray&
895    >::type
896    operator%= (const _Expr& __v);
897
898    template <class _Expr>
899    typename enable_if
900    <
901        __is_val_expr<_Expr>::value,
902        valarray&
903    >::type
904    operator+= (const _Expr& __v);
905
906    template <class _Expr>
907    typename enable_if
908    <
909        __is_val_expr<_Expr>::value,
910        valarray&
911    >::type
912    operator-= (const _Expr& __v);
913
914    template <class _Expr>
915    typename enable_if
916    <
917        __is_val_expr<_Expr>::value,
918        valarray&
919    >::type
920    operator^= (const _Expr& __v);
921
922    template <class _Expr>
923    typename enable_if
924    <
925        __is_val_expr<_Expr>::value,
926        valarray&
927    >::type
928    operator|= (const _Expr& __v);
929
930    template <class _Expr>
931    typename enable_if
932    <
933        __is_val_expr<_Expr>::value,
934        valarray&
935    >::type
936    operator&= (const _Expr& __v);
937
938    template <class _Expr>
939    typename enable_if
940    <
941        __is_val_expr<_Expr>::value,
942        valarray&
943    >::type
944    operator<<= (const _Expr& __v);
945
946    template <class _Expr>
947    typename enable_if
948    <
949        __is_val_expr<_Expr>::value,
950        valarray&
951    >::type
952    operator>>= (const _Expr& __v);
953
954    // member functions:
955    void swap(valarray& __v);
956
957    _LIBCPP_INLINE_VISIBILITY
958    size_t size() const {return __end_ - __begin_;}
959
960    value_type sum() const;
961    value_type min() const;
962    value_type max() const;
963
964    valarray shift (int __i) const;
965    valarray cshift(int __i) const;
966    valarray apply(value_type __f(value_type)) const;
967    valarray apply(value_type __f(const value_type&)) const;
968    void     resize(size_t __n, value_type __x = value_type());
969
970private:
971    template <class> friend class _LIBCPP_VISIBLE valarray;
972    template <class> friend class _LIBCPP_VISIBLE slice_array;
973    template <class> friend class _LIBCPP_VISIBLE gslice_array;
974    template <class> friend class _LIBCPP_VISIBLE mask_array;
975    template <class> friend class __mask_expr;
976    template <class> friend class _LIBCPP_VISIBLE indirect_array;
977    template <class> friend class __indirect_expr;
978    template <class> friend class __val_expr;
979
980    template <class _Up>
981    friend
982    _Up*
983    begin(valarray<_Up>& __v);
984
985    template <class _Up>
986    friend
987    const _Up*
988    begin(const valarray<_Up>& __v);
989
990    template <class _Up>
991    friend
992    _Up*
993    end(valarray<_Up>& __v);
994
995    template <class _Up>
996    friend
997    const _Up*
998    end(const valarray<_Up>& __v);
999};
1000
1001template <class _Op, class _Tp>
1002struct _UnaryOp<_Op, valarray<_Tp> >
1003{
1004    typedef typename _Op::result_type result_type;
1005    typedef _Tp value_type;
1006
1007    _Op __op_;
1008    const valarray<_Tp>& __a0_;
1009
1010    _LIBCPP_INLINE_VISIBILITY
1011    _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
1012
1013    _LIBCPP_INLINE_VISIBILITY
1014    result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
1015
1016    _LIBCPP_INLINE_VISIBILITY
1017    size_t size() const {return __a0_.size();}
1018};
1019
1020template <class _Op, class _Tp, class _A1>
1021struct _BinaryOp<_Op, valarray<_Tp>, _A1>
1022{
1023    typedef typename _Op::result_type result_type;
1024    typedef _Tp value_type;
1025
1026    _Op __op_;
1027    const valarray<_Tp>& __a0_;
1028    _A1 __a1_;
1029
1030    _LIBCPP_INLINE_VISIBILITY
1031    _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
1032        : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1033
1034    _LIBCPP_INLINE_VISIBILITY
1035    value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1036
1037    _LIBCPP_INLINE_VISIBILITY
1038    size_t size() const {return __a0_.size();}
1039};
1040
1041template <class _Op, class _A0, class _Tp>
1042struct _BinaryOp<_Op, _A0, valarray<_Tp> >
1043{
1044    typedef typename _Op::result_type result_type;
1045    typedef _Tp value_type;
1046
1047    _Op __op_;
1048    _A0 __a0_;
1049    const valarray<_Tp>& __a1_;
1050
1051    _LIBCPP_INLINE_VISIBILITY
1052    _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
1053        : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1054
1055    _LIBCPP_INLINE_VISIBILITY
1056    value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1057
1058    _LIBCPP_INLINE_VISIBILITY
1059    size_t size() const {return __a0_.size();}
1060};
1061
1062template <class _Op, class _Tp>
1063struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> >
1064{
1065    typedef typename _Op::result_type result_type;
1066    typedef _Tp value_type;
1067
1068    _Op __op_;
1069    const valarray<_Tp>& __a0_;
1070    const valarray<_Tp>& __a1_;
1071
1072    _LIBCPP_INLINE_VISIBILITY
1073    _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
1074        : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1075
1076    _LIBCPP_INLINE_VISIBILITY
1077    value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1078
1079    _LIBCPP_INLINE_VISIBILITY
1080    size_t size() const {return __a0_.size();}
1081};
1082
1083// slice_array
1084
1085template <class _Tp>
1086class _LIBCPP_VISIBLE slice_array
1087{
1088public:
1089    typedef _Tp value_type;
1090
1091private:
1092    value_type* __vp_;
1093    size_t __size_;
1094    size_t __stride_;
1095
1096public:
1097    template <class _Expr>
1098    typename enable_if
1099    <
1100        __is_val_expr<_Expr>::value,
1101        void
1102    >::type
1103    operator=(const _Expr& __v) const;
1104
1105    template <class _Expr>
1106    typename enable_if
1107    <
1108        __is_val_expr<_Expr>::value,
1109        void
1110    >::type
1111    operator*=(const _Expr& __v) const;
1112
1113    template <class _Expr>
1114    typename enable_if
1115    <
1116        __is_val_expr<_Expr>::value,
1117        void
1118    >::type
1119    operator/=(const _Expr& __v) const;
1120
1121    template <class _Expr>
1122    typename enable_if
1123    <
1124        __is_val_expr<_Expr>::value,
1125        void
1126    >::type
1127    operator%=(const _Expr& __v) const;
1128
1129    template <class _Expr>
1130    typename enable_if
1131    <
1132        __is_val_expr<_Expr>::value,
1133        void
1134    >::type
1135    operator+=(const _Expr& __v) const;
1136
1137    template <class _Expr>
1138    typename enable_if
1139    <
1140        __is_val_expr<_Expr>::value,
1141        void
1142    >::type
1143    operator-=(const _Expr& __v) const;
1144
1145    template <class _Expr>
1146    typename enable_if
1147    <
1148        __is_val_expr<_Expr>::value,
1149        void
1150    >::type
1151    operator^=(const _Expr& __v) const;
1152
1153    template <class _Expr>
1154    typename enable_if
1155    <
1156        __is_val_expr<_Expr>::value,
1157        void
1158    >::type
1159    operator&=(const _Expr& __v) const;
1160
1161    template <class _Expr>
1162    typename enable_if
1163    <
1164        __is_val_expr<_Expr>::value,
1165        void
1166    >::type
1167    operator|=(const _Expr& __v) const;
1168
1169    template <class _Expr>
1170    typename enable_if
1171    <
1172        __is_val_expr<_Expr>::value,
1173        void
1174    >::type
1175    operator<<=(const _Expr& __v) const;
1176
1177    template <class _Expr>
1178    typename enable_if
1179    <
1180        __is_val_expr<_Expr>::value,
1181        void
1182    >::type
1183    operator>>=(const _Expr& __v) const;
1184
1185    const slice_array& operator=(const slice_array& __sa) const;
1186
1187    void operator=(const value_type& __x) const;
1188
1189private:
1190    _LIBCPP_INLINE_VISIBILITY
1191    slice_array(const slice& __sl, const valarray<value_type>& __v)
1192        : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())),
1193          __size_(__sl.size()),
1194          __stride_(__sl.stride())
1195        {}
1196
1197    template <class> friend class valarray;
1198    template <class> friend class sliceExpr;
1199};
1200
1201template <class _Tp>
1202inline _LIBCPP_INLINE_VISIBILITY
1203const slice_array<_Tp>&
1204slice_array<_Tp>::operator=(const slice_array& __sa) const
1205{
1206    value_type* __t = __vp_;
1207    const value_type* __s = __sa.__vp_;
1208    for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
1209        *__t = *__s;
1210}
1211
1212template <class _Tp>
1213template <class _Expr>
1214inline _LIBCPP_INLINE_VISIBILITY
1215typename enable_if
1216<
1217    __is_val_expr<_Expr>::value,
1218    void
1219>::type
1220slice_array<_Tp>::operator=(const _Expr& __v) const
1221{
1222    value_type* __t = __vp_;
1223    for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1224        *__t = __v[__i];
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>
1378inline _LIBCPP_INLINE_VISIBILITY
1379void
1380slice_array<_Tp>::operator=(const value_type& __x) const
1381{
1382    value_type* __t = __vp_;
1383    for (size_t __n = __size_; __n; --__n, __t += __stride_)
1384        *__t = __x;
1385}
1386
1387// gslice
1388
1389class _LIBCPP_VISIBLE gslice
1390{
1391    valarray<size_t> __size_;
1392    valarray<size_t> __stride_;
1393    valarray<size_t> __1d_;
1394
1395public:
1396    _LIBCPP_INLINE_VISIBILITY
1397    gslice() {}
1398
1399    _LIBCPP_INLINE_VISIBILITY
1400    gslice(size_t __start, const valarray<size_t>& __size,
1401                           const valarray<size_t>& __stride)
1402        : __size_(__size),
1403          __stride_(__stride)
1404        {__init(__start);}
1405
1406#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1407
1408    _LIBCPP_INLINE_VISIBILITY
1409    gslice(size_t __start, const valarray<size_t>&  __size,
1410                                 valarray<size_t>&& __stride)
1411        : __size_(__size),
1412          __stride_(move(__stride))
1413        {__init(__start);}
1414
1415    _LIBCPP_INLINE_VISIBILITY
1416    gslice(size_t __start,       valarray<size_t>&& __size,
1417                           const valarray<size_t>&  __stride)
1418        : __size_(move(__size)),
1419          __stride_(__stride)
1420        {__init(__start);}
1421
1422    _LIBCPP_INLINE_VISIBILITY
1423    gslice(size_t __start,       valarray<size_t>&& __size,
1424                                 valarray<size_t>&& __stride)
1425        : __size_(move(__size)),
1426          __stride_(move(__stride))
1427        {__init(__start);}
1428
1429#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1430
1431//  gslice(const gslice&)            = default;
1432//  gslice(gslice&&)                 = default;
1433//  gslice& operator=(const gslice&) = default;
1434//  gslice& operator=(gslice&&)      = default;
1435
1436    _LIBCPP_INLINE_VISIBILITY
1437    size_t           start()  const {return __1d_.size() ? __1d_[0] : 0;}
1438
1439    _LIBCPP_INLINE_VISIBILITY
1440    valarray<size_t> size()   const {return __size_;}
1441
1442    _LIBCPP_INLINE_VISIBILITY
1443    valarray<size_t> stride() const {return __stride_;}
1444
1445private:
1446    void __init(size_t __start);
1447
1448    template <class> friend class gslice_array;
1449    template <class> friend class valarray;
1450    template <class> friend class __val_expr;
1451};
1452
1453// gslice_array
1454
1455template <class _Tp>
1456class _LIBCPP_VISIBLE gslice_array
1457{
1458public:
1459    typedef _Tp value_type;
1460
1461private:
1462    value_type*      __vp_;
1463    valarray<size_t> __1d_;
1464
1465public:
1466    template <class _Expr>
1467    typename enable_if
1468    <
1469        __is_val_expr<_Expr>::value,
1470        void
1471    >::type
1472    operator=(const _Expr& __v) const;
1473
1474    template <class _Expr>
1475    typename enable_if
1476    <
1477        __is_val_expr<_Expr>::value,
1478        void
1479    >::type
1480    operator*=(const _Expr& __v) const;
1481
1482    template <class _Expr>
1483    typename enable_if
1484    <
1485        __is_val_expr<_Expr>::value,
1486        void
1487    >::type
1488    operator/=(const _Expr& __v) const;
1489
1490    template <class _Expr>
1491    typename enable_if
1492    <
1493        __is_val_expr<_Expr>::value,
1494        void
1495    >::type
1496    operator%=(const _Expr& __v) const;
1497
1498    template <class _Expr>
1499    typename enable_if
1500    <
1501        __is_val_expr<_Expr>::value,
1502        void
1503    >::type
1504    operator+=(const _Expr& __v) const;
1505
1506    template <class _Expr>
1507    typename enable_if
1508    <
1509        __is_val_expr<_Expr>::value,
1510        void
1511    >::type
1512    operator-=(const _Expr& __v) const;
1513
1514    template <class _Expr>
1515    typename enable_if
1516    <
1517        __is_val_expr<_Expr>::value,
1518        void
1519    >::type
1520    operator^=(const _Expr& __v) const;
1521
1522    template <class _Expr>
1523    typename enable_if
1524    <
1525        __is_val_expr<_Expr>::value,
1526        void
1527    >::type
1528    operator&=(const _Expr& __v) const;
1529
1530    template <class _Expr>
1531    typename enable_if
1532    <
1533        __is_val_expr<_Expr>::value,
1534        void
1535    >::type
1536    operator|=(const _Expr& __v) const;
1537
1538    template <class _Expr>
1539    typename enable_if
1540    <
1541        __is_val_expr<_Expr>::value,
1542        void
1543    >::type
1544    operator<<=(const _Expr& __v) const;
1545
1546    template <class _Expr>
1547    typename enable_if
1548    <
1549        __is_val_expr<_Expr>::value,
1550        void
1551    >::type
1552    operator>>=(const _Expr& __v) const;
1553
1554    const gslice_array& operator=(const gslice_array& __ga) const;
1555
1556    void operator=(const value_type& __x) const;
1557
1558//  gslice_array(const gslice_array&)            = default;
1559//  gslice_array(gslice_array&&)                 = default;
1560//  gslice_array& operator=(const gslice_array&) = default;
1561//  gslice_array& operator=(gslice_array&&)      = default;
1562
1563private:
1564    _LIBCPP_INLINE_VISIBILITY
1565    gslice_array(const gslice& __gs, const valarray<value_type>& __v)
1566        : __vp_(const_cast<value_type*>(__v.__begin_)),
1567          __1d_(__gs.__1d_)
1568        {}
1569
1570#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1571
1572    _LIBCPP_INLINE_VISIBILITY
1573    gslice_array(gslice&& __gs, const valarray<value_type>& __v)
1574        : __vp_(const_cast<value_type*>(__v.__begin_)),
1575          __1d_(move(__gs.__1d_))
1576        {}
1577
1578#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1579
1580    template <class> friend class valarray;
1581};
1582
1583template <class _Tp>
1584template <class _Expr>
1585inline _LIBCPP_INLINE_VISIBILITY
1586typename enable_if
1587<
1588    __is_val_expr<_Expr>::value,
1589    void
1590>::type
1591gslice_array<_Tp>::operator=(const _Expr& __v) const
1592{
1593    typedef const size_t* _Ip;
1594    size_t __j = 0;
1595    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1596        __vp_[*__i] = __v[__j];
1597}
1598
1599template <class _Tp>
1600template <class _Expr>
1601inline _LIBCPP_INLINE_VISIBILITY
1602typename enable_if
1603<
1604    __is_val_expr<_Expr>::value,
1605    void
1606>::type
1607gslice_array<_Tp>::operator*=(const _Expr& __v) const
1608{
1609    typedef const size_t* _Ip;
1610    size_t __j = 0;
1611    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1612        __vp_[*__i] *= __v[__j];
1613}
1614
1615template <class _Tp>
1616template <class _Expr>
1617inline _LIBCPP_INLINE_VISIBILITY
1618typename enable_if
1619<
1620    __is_val_expr<_Expr>::value,
1621    void
1622>::type
1623gslice_array<_Tp>::operator/=(const _Expr& __v) const
1624{
1625    typedef const size_t* _Ip;
1626    size_t __j = 0;
1627    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1628        __vp_[*__i] /= __v[__j];
1629}
1630
1631template <class _Tp>
1632template <class _Expr>
1633inline _LIBCPP_INLINE_VISIBILITY
1634typename enable_if
1635<
1636    __is_val_expr<_Expr>::value,
1637    void
1638>::type
1639gslice_array<_Tp>::operator%=(const _Expr& __v) const
1640{
1641    typedef const size_t* _Ip;
1642    size_t __j = 0;
1643    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1644        __vp_[*__i] %= __v[__j];
1645}
1646
1647template <class _Tp>
1648template <class _Expr>
1649inline _LIBCPP_INLINE_VISIBILITY
1650typename enable_if
1651<
1652    __is_val_expr<_Expr>::value,
1653    void
1654>::type
1655gslice_array<_Tp>::operator+=(const _Expr& __v) const
1656{
1657    typedef const size_t* _Ip;
1658    size_t __j = 0;
1659    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1660        __vp_[*__i] += __v[__j];
1661}
1662
1663template <class _Tp>
1664template <class _Expr>
1665inline _LIBCPP_INLINE_VISIBILITY
1666typename enable_if
1667<
1668    __is_val_expr<_Expr>::value,
1669    void
1670>::type
1671gslice_array<_Tp>::operator-=(const _Expr& __v) const
1672{
1673    typedef const size_t* _Ip;
1674    size_t __j = 0;
1675    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1676        __vp_[*__i] -= __v[__j];
1677}
1678
1679template <class _Tp>
1680template <class _Expr>
1681inline _LIBCPP_INLINE_VISIBILITY
1682typename enable_if
1683<
1684    __is_val_expr<_Expr>::value,
1685    void
1686>::type
1687gslice_array<_Tp>::operator^=(const _Expr& __v) const
1688{
1689    typedef const size_t* _Ip;
1690    size_t __j = 0;
1691    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1692        __vp_[*__i] ^= __v[__j];
1693}
1694
1695template <class _Tp>
1696template <class _Expr>
1697inline _LIBCPP_INLINE_VISIBILITY
1698typename enable_if
1699<
1700    __is_val_expr<_Expr>::value,
1701    void
1702>::type
1703gslice_array<_Tp>::operator&=(const _Expr& __v) const
1704{
1705    typedef const size_t* _Ip;
1706    size_t __j = 0;
1707    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1708        __vp_[*__i] &= __v[__j];
1709}
1710
1711template <class _Tp>
1712template <class _Expr>
1713inline _LIBCPP_INLINE_VISIBILITY
1714typename enable_if
1715<
1716    __is_val_expr<_Expr>::value,
1717    void
1718>::type
1719gslice_array<_Tp>::operator|=(const _Expr& __v) const
1720{
1721    typedef const size_t* _Ip;
1722    size_t __j = 0;
1723    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1724        __vp_[*__i] |= __v[__j];
1725}
1726
1727template <class _Tp>
1728template <class _Expr>
1729inline _LIBCPP_INLINE_VISIBILITY
1730typename enable_if
1731<
1732    __is_val_expr<_Expr>::value,
1733    void
1734>::type
1735gslice_array<_Tp>::operator<<=(const _Expr& __v) const
1736{
1737    typedef const size_t* _Ip;
1738    size_t __j = 0;
1739    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1740        __vp_[*__i] <<= __v[__j];
1741}
1742
1743template <class _Tp>
1744template <class _Expr>
1745inline _LIBCPP_INLINE_VISIBILITY
1746typename enable_if
1747<
1748    __is_val_expr<_Expr>::value,
1749    void
1750>::type
1751gslice_array<_Tp>::operator>>=(const _Expr& __v) const
1752{
1753    typedef const size_t* _Ip;
1754    size_t __j = 0;
1755    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1756        __vp_[*__i] >>= __v[__j];
1757}
1758
1759template <class _Tp>
1760inline _LIBCPP_INLINE_VISIBILITY
1761const gslice_array<_Tp>&
1762gslice_array<_Tp>::operator=(const gslice_array& __ga) const
1763{
1764    typedef const size_t* _Ip;
1765    const value_type* __s = __ga.__vp_;
1766    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_;
1767            __i != __e; ++__i, ++__j)
1768        __vp_[*__i] = __s[*__j];
1769    return *this;
1770}
1771
1772template <class _Tp>
1773inline _LIBCPP_INLINE_VISIBILITY
1774void
1775gslice_array<_Tp>::operator=(const value_type& __x) const
1776{
1777    typedef const size_t* _Ip;
1778    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1779        __vp_[*__i] = __x;
1780}
1781
1782// mask_array
1783
1784template <class _Tp>
1785class _LIBCPP_VISIBLE mask_array
1786{
1787public:
1788    typedef _Tp value_type;
1789
1790private:
1791    value_type*      __vp_;
1792    valarray<size_t> __1d_;
1793
1794public:
1795    template <class _Expr>
1796    typename enable_if
1797    <
1798        __is_val_expr<_Expr>::value,
1799        void
1800    >::type
1801    operator=(const _Expr& __v) const;
1802
1803    template <class _Expr>
1804    typename enable_if
1805    <
1806        __is_val_expr<_Expr>::value,
1807        void
1808    >::type
1809    operator*=(const _Expr& __v) const;
1810
1811    template <class _Expr>
1812    typename enable_if
1813    <
1814        __is_val_expr<_Expr>::value,
1815        void
1816    >::type
1817    operator/=(const _Expr& __v) const;
1818
1819    template <class _Expr>
1820    typename enable_if
1821    <
1822        __is_val_expr<_Expr>::value,
1823        void
1824    >::type
1825    operator%=(const _Expr& __v) const;
1826
1827    template <class _Expr>
1828    typename enable_if
1829    <
1830        __is_val_expr<_Expr>::value,
1831        void
1832    >::type
1833    operator+=(const _Expr& __v) const;
1834
1835    template <class _Expr>
1836    typename enable_if
1837    <
1838        __is_val_expr<_Expr>::value,
1839        void
1840    >::type
1841    operator-=(const _Expr& __v) const;
1842
1843    template <class _Expr>
1844    typename enable_if
1845    <
1846        __is_val_expr<_Expr>::value,
1847        void
1848    >::type
1849    operator^=(const _Expr& __v) const;
1850
1851    template <class _Expr>
1852    typename enable_if
1853    <
1854        __is_val_expr<_Expr>::value,
1855        void
1856    >::type
1857    operator&=(const _Expr& __v) const;
1858
1859    template <class _Expr>
1860    typename enable_if
1861    <
1862        __is_val_expr<_Expr>::value,
1863        void
1864    >::type
1865    operator|=(const _Expr& __v) const;
1866
1867    template <class _Expr>
1868    typename enable_if
1869    <
1870        __is_val_expr<_Expr>::value,
1871        void
1872    >::type
1873    operator<<=(const _Expr& __v) const;
1874
1875    template <class _Expr>
1876    typename enable_if
1877    <
1878        __is_val_expr<_Expr>::value,
1879        void
1880    >::type
1881    operator>>=(const _Expr& __v) const;
1882
1883    const mask_array& operator=(const mask_array& __ma) const;
1884
1885    void operator=(const value_type& __x) const;
1886
1887//  mask_array(const mask_array&)            = default;
1888//  mask_array(mask_array&&)                 = default;
1889//  mask_array& operator=(const mask_array&) = default;
1890//  mask_array& operator=(mask_array&&)      = default;
1891
1892private:
1893    _LIBCPP_INLINE_VISIBILITY
1894    mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
1895        : __vp_(const_cast<value_type*>(__v.__begin_)),
1896          __1d_(count(__vb.__begin_, __vb.__end_, true))
1897          {
1898              size_t __j = 0;
1899              for (size_t __i = 0; __i < __vb.size(); ++__i)
1900                  if (__vb[__i])
1901                      __1d_[__j++] = __i;
1902          }
1903
1904    template <class> friend class valarray;
1905};
1906
1907template <class _Tp>
1908template <class _Expr>
1909inline _LIBCPP_INLINE_VISIBILITY
1910typename enable_if
1911<
1912    __is_val_expr<_Expr>::value,
1913    void
1914>::type
1915mask_array<_Tp>::operator=(const _Expr& __v) const
1916{
1917    size_t __n = __1d_.size();
1918    for (size_t __i = 0; __i < __n; ++__i)
1919        __vp_[__1d_[__i]] = __v[__i];
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>
2073inline _LIBCPP_INLINE_VISIBILITY
2074const mask_array<_Tp>&
2075mask_array<_Tp>::operator=(const mask_array& __ma) const
2076{
2077    size_t __n = __1d_.size();
2078    for (size_t __i = 0; __i < __n; ++__i)
2079        __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
2080}
2081
2082template <class _Tp>
2083inline _LIBCPP_INLINE_VISIBILITY
2084void
2085mask_array<_Tp>::operator=(const value_type& __x) const
2086{
2087    size_t __n = __1d_.size();
2088    for (size_t __i = 0; __i < __n; ++__i)
2089        __vp_[__1d_[__i]] = __x;
2090}
2091
2092template <class _ValExpr>
2093class __mask_expr
2094{
2095    typedef typename remove_reference<_ValExpr>::type  _RmExpr;
2096public:
2097    typedef typename _RmExpr::value_type value_type;
2098    typedef value_type result_type;
2099
2100private:
2101    _ValExpr __expr_;
2102    valarray<size_t> __1d_;
2103
2104    _LIBCPP_INLINE_VISIBILITY
2105    __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
2106        : __expr_(__e),
2107          __1d_(count(__vb.__begin_, __vb.__end_, true))
2108          {
2109              size_t __j = 0;
2110              for (size_t __i = 0; __i < __vb.size(); ++__i)
2111                  if (__vb[__i])
2112                      __1d_[__j++] = __i;
2113          }
2114
2115public:
2116    _LIBCPP_INLINE_VISIBILITY
2117    result_type operator[](size_t __i) const
2118        {return __expr_[__1d_[__i]];}
2119
2120    _LIBCPP_INLINE_VISIBILITY
2121    size_t size() const {return __1d_.size();}
2122
2123    template <class> friend class valarray;
2124};
2125
2126// indirect_array
2127
2128template <class _Tp>
2129class _LIBCPP_VISIBLE indirect_array
2130{
2131public:
2132    typedef _Tp value_type;
2133
2134private:
2135    value_type*      __vp_;
2136    valarray<size_t> __1d_;
2137
2138public:
2139    template <class _Expr>
2140    typename enable_if
2141    <
2142        __is_val_expr<_Expr>::value,
2143        void
2144    >::type
2145    operator=(const _Expr& __v) const;
2146
2147    template <class _Expr>
2148    typename enable_if
2149    <
2150        __is_val_expr<_Expr>::value,
2151        void
2152    >::type
2153    operator*=(const _Expr& __v) const;
2154
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    const indirect_array& operator=(const indirect_array& __ia) const;
2228
2229    void operator=(const value_type& __x) const;
2230
2231//  indirect_array(const indirect_array&)            = default;
2232//  indirect_array(indirect_array&&)                 = default;
2233//  indirect_array& operator=(const indirect_array&) = default;
2234//  indirect_array& operator=(indirect_array&&)      = default;
2235
2236private:
2237     _LIBCPP_INLINE_VISIBILITY
2238   indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
2239        : __vp_(const_cast<value_type*>(__v.__begin_)),
2240          __1d_(__ia)
2241        {}
2242
2243#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2244
2245    _LIBCPP_INLINE_VISIBILITY
2246    indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
2247        : __vp_(const_cast<value_type*>(__v.__begin_)),
2248          __1d_(move(__ia))
2249        {}
2250
2251#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2252
2253    template <class> friend class valarray;
2254};
2255
2256template <class _Tp>
2257template <class _Expr>
2258inline _LIBCPP_INLINE_VISIBILITY
2259typename enable_if
2260<
2261    __is_val_expr<_Expr>::value,
2262    void
2263>::type
2264indirect_array<_Tp>::operator=(const _Expr& __v) const
2265{
2266    size_t __n = __1d_.size();
2267    for (size_t __i = 0; __i < __n; ++__i)
2268        __vp_[__1d_[__i]] = __v[__i];
2269}
2270
2271template <class _Tp>
2272template <class _Expr>
2273inline _LIBCPP_INLINE_VISIBILITY
2274typename enable_if
2275<
2276    __is_val_expr<_Expr>::value,
2277    void
2278>::type
2279indirect_array<_Tp>::operator*=(const _Expr& __v) const
2280{
2281    size_t __n = __1d_.size();
2282    for (size_t __i = 0; __i < __n; ++__i)
2283        __vp_[__1d_[__i]] *= __v[__i];
2284}
2285
2286template <class _Tp>
2287template <class _Expr>
2288inline _LIBCPP_INLINE_VISIBILITY
2289typename enable_if
2290<
2291    __is_val_expr<_Expr>::value,
2292    void
2293>::type
2294indirect_array<_Tp>::operator/=(const _Expr& __v) const
2295{
2296    size_t __n = __1d_.size();
2297    for (size_t __i = 0; __i < __n; ++__i)
2298        __vp_[__1d_[__i]] /= __v[__i];
2299}
2300
2301template <class _Tp>
2302template <class _Expr>
2303inline _LIBCPP_INLINE_VISIBILITY
2304typename enable_if
2305<
2306    __is_val_expr<_Expr>::value,
2307    void
2308>::type
2309indirect_array<_Tp>::operator%=(const _Expr& __v) const
2310{
2311    size_t __n = __1d_.size();
2312    for (size_t __i = 0; __i < __n; ++__i)
2313        __vp_[__1d_[__i]] %= __v[__i];
2314}
2315
2316template <class _Tp>
2317template <class _Expr>
2318inline _LIBCPP_INLINE_VISIBILITY
2319typename enable_if
2320<
2321    __is_val_expr<_Expr>::value,
2322    void
2323>::type
2324indirect_array<_Tp>::operator+=(const _Expr& __v) const
2325{
2326    size_t __n = __1d_.size();
2327    for (size_t __i = 0; __i < __n; ++__i)
2328        __vp_[__1d_[__i]] += __v[__i];
2329}
2330
2331template <class _Tp>
2332template <class _Expr>
2333inline _LIBCPP_INLINE_VISIBILITY
2334typename enable_if
2335<
2336    __is_val_expr<_Expr>::value,
2337    void
2338>::type
2339indirect_array<_Tp>::operator-=(const _Expr& __v) const
2340{
2341    size_t __n = __1d_.size();
2342    for (size_t __i = 0; __i < __n; ++__i)
2343        __vp_[__1d_[__i]] -= __v[__i];
2344}
2345
2346template <class _Tp>
2347template <class _Expr>
2348inline _LIBCPP_INLINE_VISIBILITY
2349typename enable_if
2350<
2351    __is_val_expr<_Expr>::value,
2352    void
2353>::type
2354indirect_array<_Tp>::operator^=(const _Expr& __v) const
2355{
2356    size_t __n = __1d_.size();
2357    for (size_t __i = 0; __i < __n; ++__i)
2358        __vp_[__1d_[__i]] ^= __v[__i];
2359}
2360
2361template <class _Tp>
2362template <class _Expr>
2363inline _LIBCPP_INLINE_VISIBILITY
2364typename enable_if
2365<
2366    __is_val_expr<_Expr>::value,
2367    void
2368>::type
2369indirect_array<_Tp>::operator&=(const _Expr& __v) const
2370{
2371    size_t __n = __1d_.size();
2372    for (size_t __i = 0; __i < __n; ++__i)
2373        __vp_[__1d_[__i]] &= __v[__i];
2374}
2375
2376template <class _Tp>
2377template <class _Expr>
2378inline _LIBCPP_INLINE_VISIBILITY
2379typename enable_if
2380<
2381    __is_val_expr<_Expr>::value,
2382    void
2383>::type
2384indirect_array<_Tp>::operator|=(const _Expr& __v) const
2385{
2386    size_t __n = __1d_.size();
2387    for (size_t __i = 0; __i < __n; ++__i)
2388        __vp_[__1d_[__i]] |= __v[__i];
2389}
2390
2391template <class _Tp>
2392template <class _Expr>
2393inline _LIBCPP_INLINE_VISIBILITY
2394typename enable_if
2395<
2396    __is_val_expr<_Expr>::value,
2397    void
2398>::type
2399indirect_array<_Tp>::operator<<=(const _Expr& __v) const
2400{
2401    size_t __n = __1d_.size();
2402    for (size_t __i = 0; __i < __n; ++__i)
2403        __vp_[__1d_[__i]] <<= __v[__i];
2404}
2405
2406template <class _Tp>
2407template <class _Expr>
2408inline _LIBCPP_INLINE_VISIBILITY
2409typename enable_if
2410<
2411    __is_val_expr<_Expr>::value,
2412    void
2413>::type
2414indirect_array<_Tp>::operator>>=(const _Expr& __v) const
2415{
2416    size_t __n = __1d_.size();
2417    for (size_t __i = 0; __i < __n; ++__i)
2418        __vp_[__1d_[__i]] >>= __v[__i];
2419}
2420
2421template <class _Tp>
2422inline _LIBCPP_INLINE_VISIBILITY
2423const indirect_array<_Tp>&
2424indirect_array<_Tp>::operator=(const indirect_array& __ia) const
2425{
2426    typedef const size_t* _Ip;
2427    const value_type* __s = __ia.__vp_;
2428    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_;
2429            __i != __e; ++__i, ++__j)
2430        __vp_[*__i] = __s[*__j];
2431    return *this;
2432}
2433
2434template <class _Tp>
2435inline _LIBCPP_INLINE_VISIBILITY
2436void
2437indirect_array<_Tp>::operator=(const value_type& __x) const
2438{
2439    typedef const size_t* _Ip;
2440    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
2441        __vp_[*__i] = __x;
2442}
2443
2444template <class _ValExpr>
2445class __indirect_expr
2446{
2447    typedef typename remove_reference<_ValExpr>::type  _RmExpr;
2448public:
2449    typedef typename _RmExpr::value_type value_type;
2450    typedef value_type result_type;
2451
2452private:
2453    _ValExpr __expr_;
2454    valarray<size_t> __1d_;
2455
2456    _LIBCPP_INLINE_VISIBILITY
2457    __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e)
2458        : __expr_(__e),
2459          __1d_(__ia)
2460          {}
2461
2462#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2463
2464    _LIBCPP_INLINE_VISIBILITY
2465    __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
2466        : __expr_(__e),
2467          __1d_(move(__ia))
2468          {}
2469
2470#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2471
2472public:
2473    _LIBCPP_INLINE_VISIBILITY
2474    result_type operator[](size_t __i) const
2475        {return __expr_[__1d_[__i]];}
2476
2477    _LIBCPP_INLINE_VISIBILITY
2478    size_t size() const {return __1d_.size();}
2479
2480    template <class> friend class _LIBCPP_VISIBLE valarray;
2481};
2482
2483template<class _ValExpr>
2484class __val_expr
2485{
2486    typedef typename remove_reference<_ValExpr>::type  _RmExpr;
2487
2488    _ValExpr __expr_;
2489public:
2490    typedef typename _RmExpr::value_type value_type;
2491    typedef typename _RmExpr::result_type result_type;
2492
2493    _LIBCPP_INLINE_VISIBILITY
2494    explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
2495
2496    _LIBCPP_INLINE_VISIBILITY
2497    result_type operator[](size_t __i) const
2498        {return __expr_[__i];}
2499
2500    _LIBCPP_INLINE_VISIBILITY
2501    __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
2502        {return __val_expr<__slice_expr<_ValExpr> >(__expr_, __s);}
2503
2504    _LIBCPP_INLINE_VISIBILITY
2505    __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const
2506        {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __gs.__1d_);}
2507
2508    _LIBCPP_INLINE_VISIBILITY
2509    __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
2510        {return __val_expr<__mask_expr<_ValExpr> >(__expr_, __vb);}
2511
2512    _LIBCPP_INLINE_VISIBILITY
2513    __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
2514        {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __vs);}
2515
2516    _LIBCPP_INLINE_VISIBILITY
2517    __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
2518    operator+() const
2519    {
2520        typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
2521        return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
2522    }
2523
2524    _LIBCPP_INLINE_VISIBILITY
2525    __val_expr<_UnaryOp<negate<value_type>, _ValExpr> >
2526    operator-() const
2527    {
2528        typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
2529        return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
2530    }
2531
2532    _LIBCPP_INLINE_VISIBILITY
2533    __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> >
2534    operator~() const
2535    {
2536        typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
2537        return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
2538    }
2539
2540    _LIBCPP_INLINE_VISIBILITY
2541    __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> >
2542    operator!() const
2543    {
2544        typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
2545        return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
2546    }
2547
2548    operator valarray<result_type>() const;
2549
2550    _LIBCPP_INLINE_VISIBILITY
2551    size_t size() const {return __expr_.size();}
2552
2553    _LIBCPP_INLINE_VISIBILITY
2554    result_type sum() const
2555    {
2556        size_t __n = __expr_.size();
2557        result_type __r = __n ? __expr_[0] : result_type();
2558        for (size_t __i = 1; __i < __n; ++__i)
2559            __r += __expr_[__i];
2560        return __r;
2561    }
2562
2563    _LIBCPP_INLINE_VISIBILITY
2564    result_type min() const
2565    {
2566        size_t __n = size();
2567        result_type __r = __n ? (*this)[0] : result_type();
2568        for (size_t __i = 1; __i < __n; ++__i)
2569        {
2570            result_type __x = __expr_[__i];
2571            if (__x < __r)
2572                __r = __x;
2573        }
2574        return __r;
2575    }
2576
2577    _LIBCPP_INLINE_VISIBILITY
2578    result_type max() const
2579    {
2580        size_t __n = size();
2581        result_type __r = __n ? (*this)[0] : result_type();
2582        for (size_t __i = 1; __i < __n; ++__i)
2583        {
2584            result_type __x = __expr_[__i];
2585            if (__r < __x)
2586                __r = __x;
2587        }
2588        return __r;
2589    }
2590
2591    _LIBCPP_INLINE_VISIBILITY
2592    __val_expr<__shift_expr<_ValExpr> > shift (int __i) const
2593        {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));}
2594
2595    _LIBCPP_INLINE_VISIBILITY
2596    __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const
2597        {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));}
2598
2599    _LIBCPP_INLINE_VISIBILITY
2600    __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> >
2601    apply(value_type __f(value_type)) const
2602    {
2603        typedef __apply_expr<value_type, value_type(*)(value_type)> _Op;
2604        typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2605        return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2606    }
2607
2608    _LIBCPP_INLINE_VISIBILITY
2609    __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> >
2610    apply(value_type __f(const value_type&)) const
2611    {
2612        typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op;
2613        typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2614        return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2615    }
2616};
2617
2618template<class _ValExpr>
2619__val_expr<_ValExpr>::operator valarray<result_type>() const
2620{
2621    valarray<result_type> __r;
2622    size_t __n = __expr_.size();
2623    if (__n)
2624    {
2625        __r.__begin_ =
2626            __r.__end_ =
2627                static_cast<result_type*>(::operator new(__n * sizeof(result_type)));
2628        for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
2629            ::new (__r.__end_) result_type(__expr_[__i]);
2630    }
2631    return __r;
2632}
2633
2634// valarray
2635
2636template <class _Tp>
2637inline _LIBCPP_INLINE_VISIBILITY
2638valarray<_Tp>::valarray(size_t __n)
2639    : __begin_(0),
2640      __end_(0)
2641{
2642    resize(__n);
2643}
2644
2645template <class _Tp>
2646inline _LIBCPP_INLINE_VISIBILITY
2647valarray<_Tp>::valarray(const value_type& __x, size_t __n)
2648    : __begin_(0),
2649      __end_(0)
2650{
2651    resize(__n, __x);
2652}
2653
2654template <class _Tp>
2655valarray<_Tp>::valarray(const value_type* __p, size_t __n)
2656    : __begin_(0),
2657      __end_(0)
2658{
2659    if (__n)
2660    {
2661        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2662#ifndef _LIBCPP_NO_EXCEPTIONS
2663        try
2664        {
2665#endif  // _LIBCPP_NO_EXCEPTIONS
2666            for (; __n; ++__end_, ++__p, --__n)
2667                ::new (__end_) value_type(*__p);
2668#ifndef _LIBCPP_NO_EXCEPTIONS
2669        }
2670        catch (...)
2671        {
2672            resize(0);
2673            throw;
2674        }
2675#endif  // _LIBCPP_NO_EXCEPTIONS
2676    }
2677}
2678
2679template <class _Tp>
2680valarray<_Tp>::valarray(const valarray& __v)
2681    : __begin_(0),
2682      __end_(0)
2683{
2684    if (__v.size())
2685    {
2686        __begin_ = __end_ = static_cast<value_type*>(::operator new(__v.size() * sizeof(value_type)));
2687#ifndef _LIBCPP_NO_EXCEPTIONS
2688        try
2689        {
2690#endif  // _LIBCPP_NO_EXCEPTIONS
2691            for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
2692                ::new (__end_) value_type(*__p);
2693#ifndef _LIBCPP_NO_EXCEPTIONS
2694        }
2695        catch (...)
2696        {
2697            resize(0);
2698            throw;
2699        }
2700#endif  // _LIBCPP_NO_EXCEPTIONS
2701    }
2702}
2703
2704#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2705
2706template <class _Tp>
2707inline _LIBCPP_INLINE_VISIBILITY
2708valarray<_Tp>::valarray(valarray&& __v)
2709    : __begin_(__v.__begin_),
2710      __end_(__v.__end_)
2711{
2712    __v.__begin_ = __v.__end_ = nullptr;
2713}
2714
2715#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2716
2717#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2718
2719template <class _Tp>
2720valarray<_Tp>::valarray(initializer_list<value_type> __il)
2721    : __begin_(0),
2722      __end_(0)
2723{
2724    size_t __n = __il.size();
2725    if (__n)
2726    {
2727        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2728#ifndef _LIBCPP_NO_EXCEPTIONS
2729        try
2730        {
2731#endif  // _LIBCPP_NO_EXCEPTIONS
2732            for (const value_type* __p = __il.begin(); __n; ++__end_, ++__p, --__n)
2733                ::new (__end_) value_type(*__p);
2734#ifndef _LIBCPP_NO_EXCEPTIONS
2735        }
2736        catch (...)
2737        {
2738            resize(0);
2739            throw;
2740        }
2741#endif  // _LIBCPP_NO_EXCEPTIONS
2742    }
2743}
2744
2745#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2746
2747template <class _Tp>
2748valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
2749    : __begin_(0),
2750      __end_(0)
2751{
2752    size_t __n = __sa.__size_;
2753    if (__n)
2754    {
2755        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2756#ifndef _LIBCPP_NO_EXCEPTIONS
2757        try
2758        {
2759#endif  // _LIBCPP_NO_EXCEPTIONS
2760            for (const value_type* __p = __sa.__vp_; __n; ++__end_, __p += __sa.__stride_, --__n)
2761                ::new (__end_) value_type(*__p);
2762#ifndef _LIBCPP_NO_EXCEPTIONS
2763        }
2764        catch (...)
2765        {
2766            resize(0);
2767            throw;
2768        }
2769#endif  // _LIBCPP_NO_EXCEPTIONS
2770    }
2771}
2772
2773template <class _Tp>
2774valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
2775    : __begin_(0),
2776      __end_(0)
2777{
2778    size_t __n = __ga.__1d_.size();
2779    if (__n)
2780    {
2781        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2782#ifndef _LIBCPP_NO_EXCEPTIONS
2783        try
2784        {
2785#endif  // _LIBCPP_NO_EXCEPTIONS
2786            typedef const size_t* _Ip;
2787            const value_type* __s = __ga.__vp_;
2788            for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2789                    __i != __e; ++__i, ++__end_)
2790                ::new (__end_) value_type(__s[*__i]);
2791#ifndef _LIBCPP_NO_EXCEPTIONS
2792        }
2793        catch (...)
2794        {
2795            resize(0);
2796            throw;
2797        }
2798#endif  // _LIBCPP_NO_EXCEPTIONS
2799    }
2800}
2801
2802template <class _Tp>
2803valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
2804    : __begin_(0),
2805      __end_(0)
2806{
2807    size_t __n = __ma.__1d_.size();
2808    if (__n)
2809    {
2810        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2811#ifndef _LIBCPP_NO_EXCEPTIONS
2812        try
2813        {
2814#endif  // _LIBCPP_NO_EXCEPTIONS
2815            typedef const size_t* _Ip;
2816            const value_type* __s = __ma.__vp_;
2817            for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2818                    __i != __e; ++__i, ++__end_)
2819                ::new (__end_) value_type(__s[*__i]);
2820#ifndef _LIBCPP_NO_EXCEPTIONS
2821        }
2822        catch (...)
2823        {
2824            resize(0);
2825            throw;
2826        }
2827#endif  // _LIBCPP_NO_EXCEPTIONS
2828    }
2829}
2830
2831template <class _Tp>
2832valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
2833    : __begin_(0),
2834      __end_(0)
2835{
2836    size_t __n = __ia.__1d_.size();
2837    if (__n)
2838    {
2839        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2840#ifndef _LIBCPP_NO_EXCEPTIONS
2841        try
2842        {
2843#endif  // _LIBCPP_NO_EXCEPTIONS
2844            typedef const size_t* _Ip;
2845            const value_type* __s = __ia.__vp_;
2846            for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2847                    __i != __e; ++__i, ++__end_)
2848                ::new (__end_) value_type(__s[*__i]);
2849#ifndef _LIBCPP_NO_EXCEPTIONS
2850        }
2851        catch (...)
2852        {
2853            resize(0);
2854            throw;
2855        }
2856#endif  // _LIBCPP_NO_EXCEPTIONS
2857    }
2858}
2859
2860template <class _Tp>
2861inline _LIBCPP_INLINE_VISIBILITY
2862valarray<_Tp>::~valarray()
2863{
2864    resize(0);
2865}
2866
2867template <class _Tp>
2868valarray<_Tp>&
2869valarray<_Tp>::operator=(const valarray& __v)
2870{
2871    if (this != &__v)
2872    {
2873        if (size() != __v.size())
2874            resize(__v.size());
2875        _VSTD::copy(__v.__begin_, __v.__end_, __begin_);
2876    }
2877    return *this;
2878}
2879
2880#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2881
2882template <class _Tp>
2883inline _LIBCPP_INLINE_VISIBILITY
2884valarray<_Tp>&
2885valarray<_Tp>::operator=(valarray&& __v)
2886{
2887    resize(0);
2888    __begin_ = __v.__begin_;
2889    __end_ = __v.__end_;
2890    __v.__begin_ = nullptr;
2891    __v.__end_ = nullptr;
2892    return *this;
2893}
2894
2895#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2896
2897#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2898
2899template <class _Tp>
2900inline _LIBCPP_INLINE_VISIBILITY
2901valarray<_Tp>&
2902valarray<_Tp>::operator=(initializer_list<value_type> __il)
2903{
2904    if (size() != __il.size())
2905        resize(__il.size());
2906    _VSTD::copy(__il.begin(), __il.end(), __begin_);
2907    return *this;
2908}
2909
2910#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2911
2912template <class _Tp>
2913inline _LIBCPP_INLINE_VISIBILITY
2914valarray<_Tp>&
2915valarray<_Tp>::operator=(const value_type& __x)
2916{
2917    _VSTD::fill(__begin_, __end_, __x);
2918    return *this;
2919}
2920
2921template <class _Tp>
2922inline _LIBCPP_INLINE_VISIBILITY
2923valarray<_Tp>&
2924valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
2925{
2926    value_type* __t = __begin_;
2927    const value_type* __s = __sa.__vp_;
2928    for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
2929        *__t = *__s;
2930    return *this;
2931}
2932
2933template <class _Tp>
2934inline _LIBCPP_INLINE_VISIBILITY
2935valarray<_Tp>&
2936valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
2937{
2938    typedef const size_t* _Ip;
2939    value_type* __t = __begin_;
2940    const value_type* __s = __ga.__vp_;
2941    for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2942                    __i != __e; ++__i, ++__t)
2943        *__t = __s[*__i];
2944    return *this;
2945}
2946
2947template <class _Tp>
2948inline _LIBCPP_INLINE_VISIBILITY
2949valarray<_Tp>&
2950valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
2951{
2952    typedef const size_t* _Ip;
2953    value_type* __t = __begin_;
2954    const value_type* __s = __ma.__vp_;
2955    for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2956                    __i != __e; ++__i, ++__t)
2957        *__t = __s[*__i];
2958    return *this;
2959}
2960
2961template <class _Tp>
2962inline _LIBCPP_INLINE_VISIBILITY
2963valarray<_Tp>&
2964valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
2965{
2966    typedef const size_t* _Ip;
2967    value_type* __t = __begin_;
2968    const value_type* __s = __ia.__vp_;
2969    for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2970                    __i != __e; ++__i, ++__t)
2971        *__t = __s[*__i];
2972    return *this;
2973}
2974
2975template <class _Tp>
2976template <class _ValExpr>
2977inline _LIBCPP_INLINE_VISIBILITY
2978valarray<_Tp>&
2979valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
2980{
2981    size_t __n = __v.size();
2982    if (size() != __n)
2983        resize(__n);
2984    value_type* __t = __begin_;
2985    for (size_t __i = 0; __i != __n; ++__t, ++__i)
2986        *__t = result_type(__v[__i]);
2987    return *this;
2988}
2989
2990template <class _Tp>
2991inline _LIBCPP_INLINE_VISIBILITY
2992__val_expr<__slice_expr<const valarray<_Tp>&> >
2993valarray<_Tp>::operator[](slice __s) const
2994{
2995    return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
2996}
2997
2998template <class _Tp>
2999inline _LIBCPP_INLINE_VISIBILITY
3000slice_array<_Tp>
3001valarray<_Tp>::operator[](slice __s)
3002{
3003    return slice_array<value_type>(__s, *this);
3004}
3005
3006template <class _Tp>
3007inline _LIBCPP_INLINE_VISIBILITY
3008__val_expr<__indirect_expr<const valarray<_Tp>&> >
3009valarray<_Tp>::operator[](const gslice& __gs) const
3010{
3011    return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
3012}
3013
3014template <class _Tp>
3015inline _LIBCPP_INLINE_VISIBILITY
3016gslice_array<_Tp>
3017valarray<_Tp>::operator[](const gslice& __gs)
3018{
3019    return gslice_array<value_type>(__gs, *this);
3020}
3021
3022#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3023
3024template <class _Tp>
3025inline _LIBCPP_INLINE_VISIBILITY
3026__val_expr<__indirect_expr<const valarray<_Tp>&> >
3027valarray<_Tp>::operator[](gslice&& __gs) const
3028{
3029    return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
3030}
3031
3032template <class _Tp>
3033inline _LIBCPP_INLINE_VISIBILITY
3034gslice_array<_Tp>
3035valarray<_Tp>::operator[](gslice&& __gs)
3036{
3037    return gslice_array<value_type>(move(__gs), *this);
3038}
3039
3040#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3041
3042template <class _Tp>
3043inline _LIBCPP_INLINE_VISIBILITY
3044__val_expr<__mask_expr<const valarray<_Tp>&> >
3045valarray<_Tp>::operator[](const valarray<bool>& __vb) const
3046{
3047    return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
3048}
3049
3050template <class _Tp>
3051inline _LIBCPP_INLINE_VISIBILITY
3052mask_array<_Tp>
3053valarray<_Tp>::operator[](const valarray<bool>& __vb)
3054{
3055    return mask_array<value_type>(__vb, *this);
3056}
3057
3058#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3059
3060template <class _Tp>
3061inline _LIBCPP_INLINE_VISIBILITY
3062__val_expr<__mask_expr<const valarray<_Tp>&> >
3063valarray<_Tp>::operator[](valarray<bool>&& __vb) const
3064{
3065    return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
3066}
3067
3068template <class _Tp>
3069inline _LIBCPP_INLINE_VISIBILITY
3070mask_array<_Tp>
3071valarray<_Tp>::operator[](valarray<bool>&& __vb)
3072{
3073    return mask_array<value_type>(move(__vb), *this);
3074}
3075
3076#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3077
3078template <class _Tp>
3079inline _LIBCPP_INLINE_VISIBILITY
3080__val_expr<__indirect_expr<const valarray<_Tp>&> >
3081valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
3082{
3083    return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
3084}
3085
3086template <class _Tp>
3087inline _LIBCPP_INLINE_VISIBILITY
3088indirect_array<_Tp>
3089valarray<_Tp>::operator[](const valarray<size_t>& __vs)
3090{
3091    return indirect_array<value_type>(__vs, *this);
3092}
3093
3094#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3095
3096template <class _Tp>
3097inline _LIBCPP_INLINE_VISIBILITY
3098__val_expr<__indirect_expr<const valarray<_Tp>&> >
3099valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
3100{
3101    return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
3102}
3103
3104template <class _Tp>
3105inline _LIBCPP_INLINE_VISIBILITY
3106indirect_array<_Tp>
3107valarray<_Tp>::operator[](valarray<size_t>&& __vs)
3108{
3109    return indirect_array<value_type>(move(__vs), *this);
3110}
3111
3112#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3113
3114template <class _Tp>
3115valarray<_Tp>
3116valarray<_Tp>::operator+() const
3117{
3118    valarray<value_type> __r;
3119    size_t __n = size();
3120    if (__n)
3121    {
3122        __r.__begin_ =
3123            __r.__end_ =
3124                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3125        for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3126            ::new (__r.__end_) value_type(+*__p);
3127    }
3128    return __r;
3129}
3130
3131template <class _Tp>
3132valarray<_Tp>
3133valarray<_Tp>::operator-() const
3134{
3135    valarray<value_type> __r;
3136    size_t __n = size();
3137    if (__n)
3138    {
3139        __r.__begin_ =
3140            __r.__end_ =
3141                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3142        for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3143            ::new (__r.__end_) value_type(-*__p);
3144    }
3145    return __r;
3146}
3147
3148template <class _Tp>
3149valarray<_Tp>
3150valarray<_Tp>::operator~() const
3151{
3152    valarray<value_type> __r;
3153    size_t __n = size();
3154    if (__n)
3155    {
3156        __r.__begin_ =
3157            __r.__end_ =
3158                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3159        for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3160            ::new (__r.__end_) value_type(~*__p);
3161    }
3162    return __r;
3163}
3164
3165template <class _Tp>
3166valarray<bool>
3167valarray<_Tp>::operator!() const
3168{
3169    valarray<bool> __r;
3170    size_t __n = size();
3171    if (__n)
3172    {
3173        __r.__begin_ =
3174            __r.__end_ =
3175                static_cast<bool*>(::operator new(__n * sizeof(bool)));
3176        for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3177            ::new (__r.__end_) bool(!*__p);
3178    }
3179    return __r;
3180}
3181
3182template <class _Tp>
3183inline _LIBCPP_INLINE_VISIBILITY
3184valarray<_Tp>&
3185valarray<_Tp>::operator*=(const value_type& __x)
3186{
3187    for (value_type* __p = __begin_; __p != __end_; ++__p)
3188        *__p *= __x;
3189    return *this;
3190}
3191
3192template <class _Tp>
3193inline _LIBCPP_INLINE_VISIBILITY
3194valarray<_Tp>&
3195valarray<_Tp>::operator/=(const value_type& __x)
3196{
3197    for (value_type* __p = __begin_; __p != __end_; ++__p)
3198        *__p /= __x;
3199    return *this;
3200}
3201
3202template <class _Tp>
3203inline _LIBCPP_INLINE_VISIBILITY
3204valarray<_Tp>&
3205valarray<_Tp>::operator%=(const value_type& __x)
3206{
3207    for (value_type* __p = __begin_; __p != __end_; ++__p)
3208        *__p %= __x;
3209    return *this;
3210}
3211
3212template <class _Tp>
3213inline _LIBCPP_INLINE_VISIBILITY
3214valarray<_Tp>&
3215valarray<_Tp>::operator+=(const value_type& __x)
3216{
3217    for (value_type* __p = __begin_; __p != __end_; ++__p)
3218        *__p += __x;
3219    return *this;
3220}
3221
3222template <class _Tp>
3223inline _LIBCPP_INLINE_VISIBILITY
3224valarray<_Tp>&
3225valarray<_Tp>::operator-=(const value_type& __x)
3226{
3227    for (value_type* __p = __begin_; __p != __end_; ++__p)
3228        *__p -= __x;
3229    return *this;
3230}
3231
3232template <class _Tp>
3233inline _LIBCPP_INLINE_VISIBILITY
3234valarray<_Tp>&
3235valarray<_Tp>::operator^=(const value_type& __x)
3236{
3237    for (value_type* __p = __begin_; __p != __end_; ++__p)
3238        *__p ^= __x;
3239    return *this;
3240}
3241
3242template <class _Tp>
3243inline _LIBCPP_INLINE_VISIBILITY
3244valarray<_Tp>&
3245valarray<_Tp>::operator&=(const value_type& __x)
3246{
3247    for (value_type* __p = __begin_; __p != __end_; ++__p)
3248        *__p &= __x;
3249    return *this;
3250}
3251
3252template <class _Tp>
3253inline _LIBCPP_INLINE_VISIBILITY
3254valarray<_Tp>&
3255valarray<_Tp>::operator|=(const value_type& __x)
3256{
3257    for (value_type* __p = __begin_; __p != __end_; ++__p)
3258        *__p |= __x;
3259    return *this;
3260}
3261
3262template <class _Tp>
3263inline _LIBCPP_INLINE_VISIBILITY
3264valarray<_Tp>&
3265valarray<_Tp>::operator<<=(const value_type& __x)
3266{
3267    for (value_type* __p = __begin_; __p != __end_; ++__p)
3268        *__p <<= __x;
3269    return *this;
3270}
3271
3272template <class _Tp>
3273inline _LIBCPP_INLINE_VISIBILITY
3274valarray<_Tp>&
3275valarray<_Tp>::operator>>=(const value_type& __x)
3276{
3277    for (value_type* __p = __begin_; __p != __end_; ++__p)
3278        *__p >>= __x;
3279    return *this;
3280}
3281
3282template <class _Tp>
3283template <class _Expr>
3284inline _LIBCPP_INLINE_VISIBILITY
3285typename enable_if
3286<
3287    __is_val_expr<_Expr>::value,
3288    valarray<_Tp>&
3289>::type
3290valarray<_Tp>::operator*=(const _Expr& __v)
3291{
3292    size_t __i = 0;
3293    for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3294        *__t *= __v[__i];
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>
3443inline _LIBCPP_INLINE_VISIBILITY
3444void
3445valarray<_Tp>::swap(valarray& __v)
3446{
3447    _VSTD::swap(__begin_, __v.__begin_);
3448    _VSTD::swap(__end_, __v.__end_);
3449}
3450
3451template <class _Tp>
3452inline _LIBCPP_INLINE_VISIBILITY
3453_Tp
3454valarray<_Tp>::sum() const
3455{
3456    if (__begin_ == __end_)
3457        return value_type();
3458    const value_type* __p = __begin_;
3459    _Tp __r = *__p;
3460    for (++__p; __p != __end_; ++__p)
3461        __r += *__p;
3462    return __r;
3463}
3464
3465template <class _Tp>
3466inline _LIBCPP_INLINE_VISIBILITY
3467_Tp
3468valarray<_Tp>::min() const
3469{
3470    if (__begin_ == __end_)
3471        return value_type();
3472    return *_VSTD::min_element(__begin_, __end_);
3473}
3474
3475template <class _Tp>
3476inline _LIBCPP_INLINE_VISIBILITY
3477_Tp
3478valarray<_Tp>::max() const
3479{
3480    if (__begin_ == __end_)
3481        return value_type();
3482    return *_VSTD::max_element(__begin_, __end_);
3483}
3484
3485template <class _Tp>
3486valarray<_Tp>
3487valarray<_Tp>::shift(int __i) const
3488{
3489    valarray<value_type> __r;
3490    size_t __n = size();
3491    if (__n)
3492    {
3493        __r.__begin_ =
3494            __r.__end_ =
3495                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3496        const value_type* __sb;
3497        value_type* __tb;
3498        value_type* __te;
3499        if (__i >= 0)
3500        {
3501            __i = _VSTD::min(__i, static_cast<int>(__n));
3502            __sb = __begin_ + __i;
3503            __tb = __r.__begin_;
3504            __te = __r.__begin_ + (__n - __i);
3505        }
3506        else
3507        {
3508            __i = _VSTD::min(-__i, static_cast<int>(__n));
3509            __sb = __begin_;
3510            __tb = __r.__begin_ + __i;
3511            __te = __r.__begin_ + __n;
3512        }
3513        for (; __r.__end_ != __tb; ++__r.__end_)
3514            ::new (__r.__end_) value_type();
3515        for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
3516            ::new (__r.__end_) value_type(*__sb);
3517        for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
3518            ::new (__r.__end_) value_type();
3519    }
3520    return __r;
3521}
3522
3523template <class _Tp>
3524valarray<_Tp>
3525valarray<_Tp>::cshift(int __i) const
3526{
3527    valarray<value_type> __r;
3528    size_t __n = size();
3529    if (__n)
3530    {
3531        __r.__begin_ =
3532            __r.__end_ =
3533                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3534        __i %= static_cast<int>(__n);
3535        const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
3536        for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
3537            ::new (__r.__end_) value_type(*__s);
3538        for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
3539            ::new (__r.__end_) value_type(*__s);
3540    }
3541    return __r;
3542}
3543
3544template <class _Tp>
3545valarray<_Tp>
3546valarray<_Tp>::apply(value_type __f(value_type)) const
3547{
3548    valarray<value_type> __r;
3549    size_t __n = size();
3550    if (__n)
3551    {
3552        __r.__begin_ =
3553            __r.__end_ =
3554                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3555        for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3556            ::new (__r.__end_) value_type(__f(*__p));
3557    }
3558    return __r;
3559}
3560
3561template <class _Tp>
3562valarray<_Tp>
3563valarray<_Tp>::apply(value_type __f(const value_type&)) const
3564{
3565    valarray<value_type> __r;
3566    size_t __n = size();
3567    if (__n)
3568    {
3569        __r.__begin_ =
3570            __r.__end_ =
3571                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3572        for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3573            ::new (__r.__end_) value_type(__f(*__p));
3574    }
3575    return __r;
3576}
3577
3578template <class _Tp>
3579void
3580valarray<_Tp>::resize(size_t __n, value_type __x)
3581{
3582    if (__begin_ != nullptr)
3583    {
3584        while (__end_ != __begin_)
3585            (--__end_)->~value_type();
3586        ::operator delete(__begin_);
3587        __begin_ = __end_ = nullptr;
3588    }
3589    if (__n)
3590    {
3591        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3592#ifndef _LIBCPP_NO_EXCEPTIONS
3593        try
3594        {
3595#endif  // _LIBCPP_NO_EXCEPTIONS
3596            for (; __n; --__n, ++__end_)
3597                ::new (__end_) value_type(__x);
3598#ifndef _LIBCPP_NO_EXCEPTIONS
3599        }
3600        catch (...)
3601        {
3602            resize(0);
3603            throw;
3604        }
3605#endif  // _LIBCPP_NO_EXCEPTIONS
3606    }
3607}
3608
3609template<class _Tp>
3610inline _LIBCPP_INLINE_VISIBILITY
3611void
3612swap(valarray<_Tp>& __x, valarray<_Tp>& __y)
3613{
3614    __x.swap(__y);
3615}
3616
3617template<class _Expr1, class _Expr2>
3618inline _LIBCPP_INLINE_VISIBILITY
3619typename enable_if
3620<
3621    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3622    __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
3623>::type
3624operator*(const _Expr1& __x, const _Expr2& __y)
3625{
3626    typedef typename _Expr1::value_type value_type;
3627    typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
3628    return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
3629}
3630
3631template<class _Expr>
3632inline _LIBCPP_INLINE_VISIBILITY
3633typename enable_if
3634<
3635    __is_val_expr<_Expr>::value,
3636    __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3637               _Expr, __scalar_expr<typename _Expr::value_type> > >
3638>::type
3639operator*(const _Expr& __x, const typename _Expr::value_type& __y)
3640{
3641    typedef typename _Expr::value_type value_type;
3642    typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3643    return __val_expr<_Op>(_Op(multiplies<value_type>(),
3644                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
3654>::type
3655operator*(const typename _Expr::value_type& __x, const _Expr& __y)
3656{
3657    typedef typename _Expr::value_type value_type;
3658    typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3659    return __val_expr<_Op>(_Op(multiplies<value_type>(),
3660                           __scalar_expr<value_type>(__x, __y.size()), __y));
3661}
3662
3663template<class _Expr1, class _Expr2>
3664inline _LIBCPP_INLINE_VISIBILITY
3665typename enable_if
3666<
3667    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3668    __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
3669>::type
3670operator/(const _Expr1& __x, const _Expr2& __y)
3671{
3672    typedef typename _Expr1::value_type value_type;
3673    typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
3674    return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
3675}
3676
3677template<class _Expr>
3678inline _LIBCPP_INLINE_VISIBILITY
3679typename enable_if
3680<
3681    __is_val_expr<_Expr>::value,
3682    __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3683               _Expr, __scalar_expr<typename _Expr::value_type> > >
3684>::type
3685operator/(const _Expr& __x, const typename _Expr::value_type& __y)
3686{
3687    typedef typename _Expr::value_type value_type;
3688    typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3689    return __val_expr<_Op>(_Op(divides<value_type>(),
3690                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
3700>::type
3701operator/(const typename _Expr::value_type& __x, const _Expr& __y)
3702{
3703    typedef typename _Expr::value_type value_type;
3704    typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3705    return __val_expr<_Op>(_Op(divides<value_type>(),
3706                           __scalar_expr<value_type>(__x, __y.size()), __y));
3707}
3708
3709template<class _Expr1, class _Expr2>
3710inline _LIBCPP_INLINE_VISIBILITY
3711typename enable_if
3712<
3713    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3714    __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3715>::type
3716operator%(const _Expr1& __x, const _Expr2& __y)
3717{
3718    typedef typename _Expr1::value_type value_type;
3719    typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
3720    return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
3721}
3722
3723template<class _Expr>
3724inline _LIBCPP_INLINE_VISIBILITY
3725typename enable_if
3726<
3727    __is_val_expr<_Expr>::value,
3728    __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3729               _Expr, __scalar_expr<typename _Expr::value_type> > >
3730>::type
3731operator%(const _Expr& __x, const typename _Expr::value_type& __y)
3732{
3733    typedef typename _Expr::value_type value_type;
3734    typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3735    return __val_expr<_Op>(_Op(modulus<value_type>(),
3736                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
3746>::type
3747operator%(const typename _Expr::value_type& __x, const _Expr& __y)
3748{
3749    typedef typename _Expr::value_type value_type;
3750    typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3751    return __val_expr<_Op>(_Op(modulus<value_type>(),
3752                           __scalar_expr<value_type>(__x, __y.size()), __y));
3753}
3754
3755template<class _Expr1, class _Expr2>
3756inline _LIBCPP_INLINE_VISIBILITY
3757typename enable_if
3758<
3759    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3760    __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3761>::type
3762operator+(const _Expr1& __x, const _Expr2& __y)
3763{
3764    typedef typename _Expr1::value_type value_type;
3765    typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
3766    return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
3767}
3768
3769template<class _Expr>
3770inline _LIBCPP_INLINE_VISIBILITY
3771typename enable_if
3772<
3773    __is_val_expr<_Expr>::value,
3774    __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3775               _Expr, __scalar_expr<typename _Expr::value_type> > >
3776>::type
3777operator+(const _Expr& __x, const typename _Expr::value_type& __y)
3778{
3779    typedef typename _Expr::value_type value_type;
3780    typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3781    return __val_expr<_Op>(_Op(plus<value_type>(),
3782                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
3792>::type
3793operator+(const typename _Expr::value_type& __x, const _Expr& __y)
3794{
3795    typedef typename _Expr::value_type value_type;
3796    typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3797    return __val_expr<_Op>(_Op(plus<value_type>(),
3798                           __scalar_expr<value_type>(__x, __y.size()), __y));
3799}
3800
3801template<class _Expr1, class _Expr2>
3802inline _LIBCPP_INLINE_VISIBILITY
3803typename enable_if
3804<
3805    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3806    __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3807>::type
3808operator-(const _Expr1& __x, const _Expr2& __y)
3809{
3810    typedef typename _Expr1::value_type value_type;
3811    typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
3812    return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
3813}
3814
3815template<class _Expr>
3816inline _LIBCPP_INLINE_VISIBILITY
3817typename enable_if
3818<
3819    __is_val_expr<_Expr>::value,
3820    __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3821               _Expr, __scalar_expr<typename _Expr::value_type> > >
3822>::type
3823operator-(const _Expr& __x, const typename _Expr::value_type& __y)
3824{
3825    typedef typename _Expr::value_type value_type;
3826    typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3827    return __val_expr<_Op>(_Op(minus<value_type>(),
3828                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
3838>::type
3839operator-(const typename _Expr::value_type& __x, const _Expr& __y)
3840{
3841    typedef typename _Expr::value_type value_type;
3842    typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3843    return __val_expr<_Op>(_Op(minus<value_type>(),
3844                           __scalar_expr<value_type>(__x, __y.size()), __y));
3845}
3846
3847template<class _Expr1, class _Expr2>
3848inline _LIBCPP_INLINE_VISIBILITY
3849typename enable_if
3850<
3851    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3852    __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
3853>::type
3854operator^(const _Expr1& __x, const _Expr2& __y)
3855{
3856    typedef typename _Expr1::value_type value_type;
3857    typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
3858    return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
3859}
3860
3861template<class _Expr>
3862inline _LIBCPP_INLINE_VISIBILITY
3863typename enable_if
3864<
3865    __is_val_expr<_Expr>::value,
3866    __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
3867               _Expr, __scalar_expr<typename _Expr::value_type> > >
3868>::type
3869operator^(const _Expr& __x, const typename _Expr::value_type& __y)
3870{
3871    typedef typename _Expr::value_type value_type;
3872    typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3873    return __val_expr<_Op>(_Op(bit_xor<value_type>(),
3874                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
3884>::type
3885operator^(const typename _Expr::value_type& __x, const _Expr& __y)
3886{
3887    typedef typename _Expr::value_type value_type;
3888    typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3889    return __val_expr<_Op>(_Op(bit_xor<value_type>(),
3890                           __scalar_expr<value_type>(__x, __y.size()), __y));
3891}
3892
3893template<class _Expr1, class _Expr2>
3894inline _LIBCPP_INLINE_VISIBILITY
3895typename enable_if
3896<
3897    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3898    __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
3899>::type
3900operator&(const _Expr1& __x, const _Expr2& __y)
3901{
3902    typedef typename _Expr1::value_type value_type;
3903    typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
3904    return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
3905}
3906
3907template<class _Expr>
3908inline _LIBCPP_INLINE_VISIBILITY
3909typename enable_if
3910<
3911    __is_val_expr<_Expr>::value,
3912    __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
3913               _Expr, __scalar_expr<typename _Expr::value_type> > >
3914>::type
3915operator&(const _Expr& __x, const typename _Expr::value_type& __y)
3916{
3917    typedef typename _Expr::value_type value_type;
3918    typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3919    return __val_expr<_Op>(_Op(bit_and<value_type>(),
3920                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
3930>::type
3931operator&(const typename _Expr::value_type& __x, const _Expr& __y)
3932{
3933    typedef typename _Expr::value_type value_type;
3934    typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3935    return __val_expr<_Op>(_Op(bit_and<value_type>(),
3936                           __scalar_expr<value_type>(__x, __y.size()), __y));
3937}
3938
3939template<class _Expr1, class _Expr2>
3940inline _LIBCPP_INLINE_VISIBILITY
3941typename enable_if
3942<
3943    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3944    __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
3945>::type
3946operator|(const _Expr1& __x, const _Expr2& __y)
3947{
3948    typedef typename _Expr1::value_type value_type;
3949    typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
3950    return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
3951}
3952
3953template<class _Expr>
3954inline _LIBCPP_INLINE_VISIBILITY
3955typename enable_if
3956<
3957    __is_val_expr<_Expr>::value,
3958    __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
3959               _Expr, __scalar_expr<typename _Expr::value_type> > >
3960>::type
3961operator|(const _Expr& __x, const typename _Expr::value_type& __y)
3962{
3963    typedef typename _Expr::value_type value_type;
3964    typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3965    return __val_expr<_Op>(_Op(bit_or<value_type>(),
3966                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
3976>::type
3977operator|(const typename _Expr::value_type& __x, const _Expr& __y)
3978{
3979    typedef typename _Expr::value_type value_type;
3980    typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3981    return __val_expr<_Op>(_Op(bit_or<value_type>(),
3982                           __scalar_expr<value_type>(__x, __y.size()), __y));
3983}
3984
3985template<class _Expr1, class _Expr2>
3986inline _LIBCPP_INLINE_VISIBILITY
3987typename enable_if
3988<
3989    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3990    __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
3991>::type
3992operator<<(const _Expr1& __x, const _Expr2& __y)
3993{
3994    typedef typename _Expr1::value_type value_type;
3995    typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
3996    return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
3997}
3998
3999template<class _Expr>
4000inline _LIBCPP_INLINE_VISIBILITY
4001typename enable_if
4002<
4003    __is_val_expr<_Expr>::value,
4004    __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4005               _Expr, __scalar_expr<typename _Expr::value_type> > >
4006>::type
4007operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
4008{
4009    typedef typename _Expr::value_type value_type;
4010    typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4011    return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4012                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
4022>::type
4023operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
4024{
4025    typedef typename _Expr::value_type value_type;
4026    typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4027    return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4028                           __scalar_expr<value_type>(__x, __y.size()), __y));
4029}
4030
4031template<class _Expr1, class _Expr2>
4032inline _LIBCPP_INLINE_VISIBILITY
4033typename enable_if
4034<
4035    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4036    __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
4037>::type
4038operator>>(const _Expr1& __x, const _Expr2& __y)
4039{
4040    typedef typename _Expr1::value_type value_type;
4041    typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
4042    return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
4043}
4044
4045template<class _Expr>
4046inline _LIBCPP_INLINE_VISIBILITY
4047typename enable_if
4048<
4049    __is_val_expr<_Expr>::value,
4050    __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4051               _Expr, __scalar_expr<typename _Expr::value_type> > >
4052>::type
4053operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
4054{
4055    typedef typename _Expr::value_type value_type;
4056    typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4057    return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4058                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
4068>::type
4069operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
4070{
4071    typedef typename _Expr::value_type value_type;
4072    typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4073    return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4074                           __scalar_expr<value_type>(__x, __y.size()), __y));
4075}
4076
4077template<class _Expr1, class _Expr2>
4078inline _LIBCPP_INLINE_VISIBILITY
4079typename enable_if
4080<
4081    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4082    __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4083>::type
4084operator&&(const _Expr1& __x, const _Expr2& __y)
4085{
4086    typedef typename _Expr1::value_type value_type;
4087    typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
4088    return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
4089}
4090
4091template<class _Expr>
4092inline _LIBCPP_INLINE_VISIBILITY
4093typename enable_if
4094<
4095    __is_val_expr<_Expr>::value,
4096    __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4097               _Expr, __scalar_expr<typename _Expr::value_type> > >
4098>::type
4099operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
4100{
4101    typedef typename _Expr::value_type value_type;
4102    typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4103    return __val_expr<_Op>(_Op(logical_and<value_type>(),
4104                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
4114>::type
4115operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
4116{
4117    typedef typename _Expr::value_type value_type;
4118    typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4119    return __val_expr<_Op>(_Op(logical_and<value_type>(),
4120                           __scalar_expr<value_type>(__x, __y.size()), __y));
4121}
4122
4123template<class _Expr1, class _Expr2>
4124inline _LIBCPP_INLINE_VISIBILITY
4125typename enable_if
4126<
4127    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4128    __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4129>::type
4130operator||(const _Expr1& __x, const _Expr2& __y)
4131{
4132    typedef typename _Expr1::value_type value_type;
4133    typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
4134    return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
4135}
4136
4137template<class _Expr>
4138inline _LIBCPP_INLINE_VISIBILITY
4139typename enable_if
4140<
4141    __is_val_expr<_Expr>::value,
4142    __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4143               _Expr, __scalar_expr<typename _Expr::value_type> > >
4144>::type
4145operator||(const _Expr& __x, const typename _Expr::value_type& __y)
4146{
4147    typedef typename _Expr::value_type value_type;
4148    typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4149    return __val_expr<_Op>(_Op(logical_or<value_type>(),
4150                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
4160>::type
4161operator||(const typename _Expr::value_type& __x, const _Expr& __y)
4162{
4163    typedef typename _Expr::value_type value_type;
4164    typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4165    return __val_expr<_Op>(_Op(logical_or<value_type>(),
4166                           __scalar_expr<value_type>(__x, __y.size()), __y));
4167}
4168
4169template<class _Expr1, class _Expr2>
4170inline _LIBCPP_INLINE_VISIBILITY
4171typename enable_if
4172<
4173    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4174    __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4175>::type
4176operator==(const _Expr1& __x, const _Expr2& __y)
4177{
4178    typedef typename _Expr1::value_type value_type;
4179    typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
4180    return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
4181}
4182
4183template<class _Expr>
4184inline _LIBCPP_INLINE_VISIBILITY
4185typename enable_if
4186<
4187    __is_val_expr<_Expr>::value,
4188    __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4189               _Expr, __scalar_expr<typename _Expr::value_type> > >
4190>::type
4191operator==(const _Expr& __x, const typename _Expr::value_type& __y)
4192{
4193    typedef typename _Expr::value_type value_type;
4194    typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4195    return __val_expr<_Op>(_Op(equal_to<value_type>(),
4196                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
4206>::type
4207operator==(const typename _Expr::value_type& __x, const _Expr& __y)
4208{
4209    typedef typename _Expr::value_type value_type;
4210    typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4211    return __val_expr<_Op>(_Op(equal_to<value_type>(),
4212                           __scalar_expr<value_type>(__x, __y.size()), __y));
4213}
4214
4215template<class _Expr1, class _Expr2>
4216inline _LIBCPP_INLINE_VISIBILITY
4217typename enable_if
4218<
4219    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4220    __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4221>::type
4222operator!=(const _Expr1& __x, const _Expr2& __y)
4223{
4224    typedef typename _Expr1::value_type value_type;
4225    typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
4226    return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
4227}
4228
4229template<class _Expr>
4230inline _LIBCPP_INLINE_VISIBILITY
4231typename enable_if
4232<
4233    __is_val_expr<_Expr>::value,
4234    __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4235               _Expr, __scalar_expr<typename _Expr::value_type> > >
4236>::type
4237operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
4238{
4239    typedef typename _Expr::value_type value_type;
4240    typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4241    return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4242                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
4252>::type
4253operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
4254{
4255    typedef typename _Expr::value_type value_type;
4256    typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4257    return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4258                           __scalar_expr<value_type>(__x, __y.size()), __y));
4259}
4260
4261template<class _Expr1, class _Expr2>
4262inline _LIBCPP_INLINE_VISIBILITY
4263typename enable_if
4264<
4265    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4266    __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
4267>::type
4268operator<(const _Expr1& __x, const _Expr2& __y)
4269{
4270    typedef typename _Expr1::value_type value_type;
4271    typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
4272    return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
4273}
4274
4275template<class _Expr>
4276inline _LIBCPP_INLINE_VISIBILITY
4277typename enable_if
4278<
4279    __is_val_expr<_Expr>::value,
4280    __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4281               _Expr, __scalar_expr<typename _Expr::value_type> > >
4282>::type
4283operator<(const _Expr& __x, const typename _Expr::value_type& __y)
4284{
4285    typedef typename _Expr::value_type value_type;
4286    typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4287    return __val_expr<_Op>(_Op(less<value_type>(),
4288                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
4298>::type
4299operator<(const typename _Expr::value_type& __x, const _Expr& __y)
4300{
4301    typedef typename _Expr::value_type value_type;
4302    typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4303    return __val_expr<_Op>(_Op(less<value_type>(),
4304                           __scalar_expr<value_type>(__x, __y.size()), __y));
4305}
4306
4307template<class _Expr1, class _Expr2>
4308inline _LIBCPP_INLINE_VISIBILITY
4309typename enable_if
4310<
4311    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4312    __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
4313>::type
4314operator>(const _Expr1& __x, const _Expr2& __y)
4315{
4316    typedef typename _Expr1::value_type value_type;
4317    typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
4318    return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
4319}
4320
4321template<class _Expr>
4322inline _LIBCPP_INLINE_VISIBILITY
4323typename enable_if
4324<
4325    __is_val_expr<_Expr>::value,
4326    __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4327               _Expr, __scalar_expr<typename _Expr::value_type> > >
4328>::type
4329operator>(const _Expr& __x, const typename _Expr::value_type& __y)
4330{
4331    typedef typename _Expr::value_type value_type;
4332    typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4333    return __val_expr<_Op>(_Op(greater<value_type>(),
4334                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
4344>::type
4345operator>(const typename _Expr::value_type& __x, const _Expr& __y)
4346{
4347    typedef typename _Expr::value_type value_type;
4348    typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4349    return __val_expr<_Op>(_Op(greater<value_type>(),
4350                           __scalar_expr<value_type>(__x, __y.size()), __y));
4351}
4352
4353template<class _Expr1, class _Expr2>
4354inline _LIBCPP_INLINE_VISIBILITY
4355typename enable_if
4356<
4357    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4358    __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4359>::type
4360operator<=(const _Expr1& __x, const _Expr2& __y)
4361{
4362    typedef typename _Expr1::value_type value_type;
4363    typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
4364    return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
4365}
4366
4367template<class _Expr>
4368inline _LIBCPP_INLINE_VISIBILITY
4369typename enable_if
4370<
4371    __is_val_expr<_Expr>::value,
4372    __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4373               _Expr, __scalar_expr<typename _Expr::value_type> > >
4374>::type
4375operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
4376{
4377    typedef typename _Expr::value_type value_type;
4378    typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4379    return __val_expr<_Op>(_Op(less_equal<value_type>(),
4380                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
4390>::type
4391operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
4392{
4393    typedef typename _Expr::value_type value_type;
4394    typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4395    return __val_expr<_Op>(_Op(less_equal<value_type>(),
4396                           __scalar_expr<value_type>(__x, __y.size()), __y));
4397}
4398
4399template<class _Expr1, class _Expr2>
4400inline _LIBCPP_INLINE_VISIBILITY
4401typename enable_if
4402<
4403    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4404    __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4405>::type
4406operator>=(const _Expr1& __x, const _Expr2& __y)
4407{
4408    typedef typename _Expr1::value_type value_type;
4409    typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
4410    return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
4411}
4412
4413template<class _Expr>
4414inline _LIBCPP_INLINE_VISIBILITY
4415typename enable_if
4416<
4417    __is_val_expr<_Expr>::value,
4418    __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4419               _Expr, __scalar_expr<typename _Expr::value_type> > >
4420>::type
4421operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
4422{
4423    typedef typename _Expr::value_type value_type;
4424    typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4425    return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4426                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
4436>::type
4437operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
4438{
4439    typedef typename _Expr::value_type value_type;
4440    typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4441    return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4442                           __scalar_expr<value_type>(__x, __y.size()), __y));
4443}
4444
4445template<class _Expr>
4446inline _LIBCPP_INLINE_VISIBILITY
4447typename enable_if
4448<
4449    __is_val_expr<_Expr>::value,
4450    __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
4451>::type
4452abs(const _Expr& __x)
4453{
4454    typedef typename _Expr::value_type value_type;
4455    typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
4456    return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
4457}
4458
4459template<class _Expr>
4460inline _LIBCPP_INLINE_VISIBILITY
4461typename enable_if
4462<
4463    __is_val_expr<_Expr>::value,
4464    __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
4465>::type
4466acos(const _Expr& __x)
4467{
4468    typedef typename _Expr::value_type value_type;
4469    typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
4470    return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
4471}
4472
4473template<class _Expr>
4474inline _LIBCPP_INLINE_VISIBILITY
4475typename enable_if
4476<
4477    __is_val_expr<_Expr>::value,
4478    __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
4479>::type
4480asin(const _Expr& __x)
4481{
4482    typedef typename _Expr::value_type value_type;
4483    typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
4484    return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
4485}
4486
4487template<class _Expr>
4488inline _LIBCPP_INLINE_VISIBILITY
4489typename enable_if
4490<
4491    __is_val_expr<_Expr>::value,
4492    __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
4493>::type
4494atan(const _Expr& __x)
4495{
4496    typedef typename _Expr::value_type value_type;
4497    typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
4498    return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
4499}
4500
4501template<class _Expr1, class _Expr2>
4502inline _LIBCPP_INLINE_VISIBILITY
4503typename enable_if
4504<
4505    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4506    __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4507>::type
4508atan2(const _Expr1& __x, const _Expr2& __y)
4509{
4510    typedef typename _Expr1::value_type value_type;
4511    typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
4512    return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
4513}
4514
4515template<class _Expr>
4516inline _LIBCPP_INLINE_VISIBILITY
4517typename enable_if
4518<
4519    __is_val_expr<_Expr>::value,
4520    __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4521               _Expr, __scalar_expr<typename _Expr::value_type> > >
4522>::type
4523atan2(const _Expr& __x, const typename _Expr::value_type& __y)
4524{
4525    typedef typename _Expr::value_type value_type;
4526    typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4527    return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4528                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
4538>::type
4539atan2(const typename _Expr::value_type& __x, const _Expr& __y)
4540{
4541    typedef typename _Expr::value_type value_type;
4542    typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4543    return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4544                           __scalar_expr<value_type>(__x, __y.size()), __y));
4545}
4546
4547template<class _Expr>
4548inline _LIBCPP_INLINE_VISIBILITY
4549typename enable_if
4550<
4551    __is_val_expr<_Expr>::value,
4552    __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
4553>::type
4554cos(const _Expr& __x)
4555{
4556    typedef typename _Expr::value_type value_type;
4557    typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
4558    return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
4559}
4560
4561template<class _Expr>
4562inline _LIBCPP_INLINE_VISIBILITY
4563typename enable_if
4564<
4565    __is_val_expr<_Expr>::value,
4566    __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
4567>::type
4568cosh(const _Expr& __x)
4569{
4570    typedef typename _Expr::value_type value_type;
4571    typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
4572    return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
4573}
4574
4575template<class _Expr>
4576inline _LIBCPP_INLINE_VISIBILITY
4577typename enable_if
4578<
4579    __is_val_expr<_Expr>::value,
4580    __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
4581>::type
4582exp(const _Expr& __x)
4583{
4584    typedef typename _Expr::value_type value_type;
4585    typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
4586    return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
4587}
4588
4589template<class _Expr>
4590inline _LIBCPP_INLINE_VISIBILITY
4591typename enable_if
4592<
4593    __is_val_expr<_Expr>::value,
4594    __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
4595>::type
4596log(const _Expr& __x)
4597{
4598    typedef typename _Expr::value_type value_type;
4599    typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
4600    return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
4601}
4602
4603template<class _Expr>
4604inline _LIBCPP_INLINE_VISIBILITY
4605typename enable_if
4606<
4607    __is_val_expr<_Expr>::value,
4608    __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
4609>::type
4610log10(const _Expr& __x)
4611{
4612    typedef typename _Expr::value_type value_type;
4613    typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
4614    return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
4615}
4616
4617template<class _Expr1, class _Expr2>
4618inline _LIBCPP_INLINE_VISIBILITY
4619typename enable_if
4620<
4621    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4622    __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4623>::type
4624pow(const _Expr1& __x, const _Expr2& __y)
4625{
4626    typedef typename _Expr1::value_type value_type;
4627    typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
4628    return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
4629}
4630
4631template<class _Expr>
4632inline _LIBCPP_INLINE_VISIBILITY
4633typename enable_if
4634<
4635    __is_val_expr<_Expr>::value,
4636    __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4637               _Expr, __scalar_expr<typename _Expr::value_type> > >
4638>::type
4639pow(const _Expr& __x, const typename _Expr::value_type& __y)
4640{
4641    typedef typename _Expr::value_type value_type;
4642    typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4643    return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4644                           __x, __scalar_expr<value_type>(__y, __x.size())));
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               __scalar_expr<typename _Expr::value_type>, _Expr> >
4654>::type
4655pow(const typename _Expr::value_type& __x, const _Expr& __y)
4656{
4657    typedef typename _Expr::value_type value_type;
4658    typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4659    return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4660                           __scalar_expr<value_type>(__x, __y.size()), __y));
4661}
4662
4663template<class _Expr>
4664inline _LIBCPP_INLINE_VISIBILITY
4665typename enable_if
4666<
4667    __is_val_expr<_Expr>::value,
4668    __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
4669>::type
4670sin(const _Expr& __x)
4671{
4672    typedef typename _Expr::value_type value_type;
4673    typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
4674    return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
4675}
4676
4677template<class _Expr>
4678inline _LIBCPP_INLINE_VISIBILITY
4679typename enable_if
4680<
4681    __is_val_expr<_Expr>::value,
4682    __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
4683>::type
4684sinh(const _Expr& __x)
4685{
4686    typedef typename _Expr::value_type value_type;
4687    typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
4688    return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
4689}
4690
4691template<class _Expr>
4692inline _LIBCPP_INLINE_VISIBILITY
4693typename enable_if
4694<
4695    __is_val_expr<_Expr>::value,
4696    __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
4697>::type
4698sqrt(const _Expr& __x)
4699{
4700    typedef typename _Expr::value_type value_type;
4701    typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
4702    return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
4703}
4704
4705template<class _Expr>
4706inline _LIBCPP_INLINE_VISIBILITY
4707typename enable_if
4708<
4709    __is_val_expr<_Expr>::value,
4710    __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
4711>::type
4712tan(const _Expr& __x)
4713{
4714    typedef typename _Expr::value_type value_type;
4715    typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
4716    return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
4717}
4718
4719template<class _Expr>
4720inline _LIBCPP_INLINE_VISIBILITY
4721typename enable_if
4722<
4723    __is_val_expr<_Expr>::value,
4724    __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
4725>::type
4726tanh(const _Expr& __x)
4727{
4728    typedef typename _Expr::value_type value_type;
4729    typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
4730    return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
4731}
4732
4733template <class _Tp>
4734inline _LIBCPP_INLINE_VISIBILITY
4735_Tp*
4736begin(valarray<_Tp>& __v)
4737{
4738    return __v.__begin_;
4739}
4740
4741template <class _Tp>
4742inline _LIBCPP_INLINE_VISIBILITY
4743const _Tp*
4744begin(const valarray<_Tp>& __v)
4745{
4746    return __v.__begin_;
4747}
4748
4749template <class _Tp>
4750inline _LIBCPP_INLINE_VISIBILITY
4751_Tp*
4752end(valarray<_Tp>& __v)
4753{
4754    return __v.__end_;
4755}
4756
4757template <class _Tp>
4758inline _LIBCPP_INLINE_VISIBILITY
4759const _Tp*
4760end(const valarray<_Tp>& __v)
4761{
4762    return __v.__end_;
4763}
4764
4765extern template valarray<size_t>::valarray(size_t);
4766extern template valarray<size_t>::~valarray();
4767extern template void valarray<size_t>::resize(size_t, size_t);
4768
4769_LIBCPP_END_NAMESPACE_STD
4770
4771#endif  // _LIBCPP_VALARRAY
4772