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