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