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