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