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