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