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