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