xref: /freebsd/contrib/llvm-project/libcxx/include/valarray (revision 3ceba58a7509418b47b8fca2d2b6bbf088714e26)
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>
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>
383class _LIBCPP_TEMPLATE_VIS valarray;
384
385class _LIBCPP_TEMPLATE_VIS slice {
386  size_t __start_;
387  size_t __size_;
388  size_t __stride_;
389
390public:
391  _LIBCPP_HIDE_FROM_ABI slice() : __start_(0), __size_(0), __stride_(0) {}
392
393  _LIBCPP_HIDE_FROM_ABI slice(size_t __start, size_t __size, size_t __stride)
394      : __start_(__start), __size_(__size), __stride_(__stride) {}
395
396  _LIBCPP_HIDE_FROM_ABI size_t start() const { return __start_; }
397  _LIBCPP_HIDE_FROM_ABI size_t size() const { return __size_; }
398  _LIBCPP_HIDE_FROM_ABI size_t stride() const { return __stride_; }
399
400#if _LIBCPP_STD_VER >= 20
401
402  _LIBCPP_HIDE_FROM_ABI friend bool operator==(const slice& __x, const slice& __y) {
403    return __x.start() == __y.start() && __x.size() == __y.size() && __x.stride() == __y.stride();
404  }
405
406#endif
407};
408
409template <class _Tp>
410class _LIBCPP_TEMPLATE_VIS slice_array;
411class _LIBCPP_EXPORTED_FROM_ABI gslice;
412template <class _Tp>
413class _LIBCPP_TEMPLATE_VIS gslice_array;
414template <class _Tp>
415class _LIBCPP_TEMPLATE_VIS mask_array;
416template <class _Tp>
417class _LIBCPP_TEMPLATE_VIS indirect_array;
418
419template <class _Tp>
420_LIBCPP_HIDE_FROM_ABI _Tp* begin(valarray<_Tp>& __v);
421
422template <class _Tp>
423_LIBCPP_HIDE_FROM_ABI const _Tp* begin(const valarray<_Tp>& __v);
424
425template <class _Tp>
426_LIBCPP_HIDE_FROM_ABI _Tp* end(valarray<_Tp>& __v);
427
428template <class _Tp>
429_LIBCPP_HIDE_FROM_ABI const _Tp* end(const valarray<_Tp>& __v);
430
431template <class _Op, class _A0>
432struct _UnaryOp {
433  typedef typename _Op::__result_type __result_type;
434  using value_type = __decay_t<__result_type>;
435
436  _Op __op_;
437  _A0 __a0_;
438
439  _LIBCPP_HIDE_FROM_ABI _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {}
440
441  _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i]); }
442
443  _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); }
444};
445
446template <class _Op, class _A0, class _A1>
447struct _BinaryOp {
448  typedef typename _Op::__result_type __result_type;
449  using value_type = __decay_t<__result_type>;
450
451  _Op __op_;
452  _A0 __a0_;
453  _A1 __a1_;
454
455  _LIBCPP_HIDE_FROM_ABI _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1)
456      : __op_(__op), __a0_(__a0), __a1_(__a1) {}
457
458  _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i], __a1_[__i]); }
459
460  _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); }
461};
462
463template <class _Tp>
464class __scalar_expr {
465public:
466  typedef _Tp value_type;
467  typedef const _Tp& __result_type;
468
469private:
470  const value_type& __t_;
471  size_t __s_;
472
473public:
474  _LIBCPP_HIDE_FROM_ABI explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {}
475
476  _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t) const { return __t_; }
477
478  _LIBCPP_HIDE_FROM_ABI size_t size() const { return __s_; }
479};
480
481template <class _Tp>
482struct __unary_plus {
483  typedef _Tp __result_type;
484  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return +__x; }
485};
486
487template <class _Tp>
488struct __bit_not {
489  typedef _Tp __result_type;
490  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return ~__x; }
491};
492
493template <class _Tp>
494struct __bit_shift_left {
495  typedef _Tp __result_type;
496  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x << __y; }
497};
498
499template <class _Tp>
500struct __bit_shift_right {
501  typedef _Tp __result_type;
502  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x >> __y; }
503};
504
505template <class _Tp, class _Fp>
506struct __apply_expr {
507private:
508  _Fp __f_;
509
510public:
511  typedef _Tp __result_type;
512
513  _LIBCPP_HIDE_FROM_ABI explicit __apply_expr(_Fp __f) : __f_(__f) {}
514
515  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return __f_(__x); }
516};
517
518template <class _Tp>
519struct __abs_expr {
520  typedef _Tp __result_type;
521  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::abs(__x); }
522};
523
524template <class _Tp>
525struct __acos_expr {
526  typedef _Tp __result_type;
527  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::acos(__x); }
528};
529
530template <class _Tp>
531struct __asin_expr {
532  typedef _Tp __result_type;
533  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::asin(__x); }
534};
535
536template <class _Tp>
537struct __atan_expr {
538  typedef _Tp __result_type;
539  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::atan(__x); }
540};
541
542template <class _Tp>
543struct __atan2_expr {
544  typedef _Tp __result_type;
545  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return std::atan2(__x, __y); }
546};
547
548template <class _Tp>
549struct __cos_expr {
550  typedef _Tp __result_type;
551  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::cos(__x); }
552};
553
554template <class _Tp>
555struct __cosh_expr {
556  typedef _Tp __result_type;
557  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::cosh(__x); }
558};
559
560template <class _Tp>
561struct __exp_expr {
562  typedef _Tp __result_type;
563  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::exp(__x); }
564};
565
566template <class _Tp>
567struct __log_expr {
568  typedef _Tp __result_type;
569  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::log(__x); }
570};
571
572template <class _Tp>
573struct __log10_expr {
574  typedef _Tp __result_type;
575  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::log10(__x); }
576};
577
578template <class _Tp>
579struct __pow_expr {
580  typedef _Tp __result_type;
581  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return std::pow(__x, __y); }
582};
583
584template <class _Tp>
585struct __sin_expr {
586  typedef _Tp __result_type;
587  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::sin(__x); }
588};
589
590template <class _Tp>
591struct __sinh_expr {
592  typedef _Tp __result_type;
593  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::sinh(__x); }
594};
595
596template <class _Tp>
597struct __sqrt_expr {
598  typedef _Tp __result_type;
599  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::sqrt(__x); }
600};
601
602template <class _Tp>
603struct __tan_expr {
604  typedef _Tp __result_type;
605  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::tan(__x); }
606};
607
608template <class _Tp>
609struct __tanh_expr {
610  typedef _Tp __result_type;
611  _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::tanh(__x); }
612};
613
614template <class _ValExpr>
615class __slice_expr {
616  typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
617
618public:
619  typedef typename _RmExpr::value_type value_type;
620  typedef value_type __result_type;
621
622private:
623  _ValExpr __expr_;
624  size_t __start_;
625  size_t __size_;
626  size_t __stride_;
627
628  _LIBCPP_HIDE_FROM_ABI __slice_expr(const slice& __sl, const _RmExpr& __e)
629      : __expr_(__e), __start_(__sl.start()), __size_(__sl.size()), __stride_(__sl.stride()) {}
630
631public:
632  _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __expr_[__start_ + __i * __stride_]; }
633
634  _LIBCPP_HIDE_FROM_ABI size_t size() const { return __size_; }
635
636  template <class>
637  friend class __val_expr;
638  template <class>
639  friend class _LIBCPP_TEMPLATE_VIS valarray;
640};
641
642template <class _ValExpr>
643class __mask_expr;
644
645template <class _ValExpr>
646class __indirect_expr;
647
648template <class _ValExpr>
649class __shift_expr {
650  typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
651
652public:
653  typedef typename _RmExpr::value_type value_type;
654  typedef value_type __result_type;
655
656private:
657  _ValExpr __expr_;
658  size_t __size_;
659  ptrdiff_t __ul_;
660  ptrdiff_t __sn_;
661  ptrdiff_t __n_;
662  static const ptrdiff_t _Np = static_cast<ptrdiff_t>(sizeof(ptrdiff_t) * __CHAR_BIT__ - 1);
663
664  _LIBCPP_HIDE_FROM_ABI __shift_expr(int __n, const _RmExpr& __e) : __expr_(__e), __size_(__e.size()), __n_(__n) {
665    ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _Np);
666    __sn_             = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _Np);
667    __ul_             = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n);
668  }
669
670public:
671  _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __j) const {
672    ptrdiff_t __i = static_cast<ptrdiff_t>(__j);
673    ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np;
674    return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
675  }
676
677  _LIBCPP_HIDE_FROM_ABI size_t size() const { return __size_; }
678
679  template <class>
680  friend class __val_expr;
681};
682
683template <class _ValExpr>
684class __cshift_expr {
685  typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
686
687public:
688  typedef typename _RmExpr::value_type value_type;
689  typedef value_type __result_type;
690
691private:
692  _ValExpr __expr_;
693  size_t __size_;
694  size_t __m_;
695  size_t __o1_;
696  size_t __o2_;
697
698  _LIBCPP_HIDE_FROM_ABI __cshift_expr(int __n, const _RmExpr& __e) : __expr_(__e), __size_(__e.size()) {
699    __n %= static_cast<int>(__size_);
700    if (__n >= 0) {
701      __m_  = __size_ - __n;
702      __o1_ = __n;
703      __o2_ = __n - __size_;
704    } else {
705      __m_  = -__n;
706      __o1_ = __n + __size_;
707      __o2_ = __n;
708    }
709  }
710
711public:
712  _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const {
713    if (__i < __m_)
714      return __expr_[__i + __o1_];
715    return __expr_[__i + __o2_];
716  }
717
718  _LIBCPP_HIDE_FROM_ABI size_t size() const { return __size_; }
719
720  template <class>
721  friend class __val_expr;
722};
723
724template <class _ValExpr>
725class __val_expr;
726
727template <class _ValExpr>
728struct __is_val_expr : false_type {};
729
730template <class _ValExpr>
731struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
732
733template <class _Tp>
734struct __is_val_expr<valarray<_Tp> > : true_type {};
735
736template <class _Tp>
737struct __is_val_expr<slice_array<_Tp> > : true_type {};
738
739template <class _Tp>
740struct __is_val_expr<gslice_array<_Tp> > : true_type {};
741
742template <class _Tp>
743struct __is_val_expr<mask_array<_Tp> > : true_type {};
744
745template <class _Tp>
746struct __is_val_expr<indirect_array<_Tp> > : true_type {};
747
748// The functions using a __val_expr access the elements by their index.
749// valarray and the libc++ lazy proxies have an operator[]. The
750// Standard proxy array's don't have this operator, instead they have a
751// implementation specific accessor
752//   __get(size_t)
753//
754// The functions use the non-member function
755//   __get(__val_expr, size_t)
756//
757// If the __val_expr is a specialization of __val_expr_use_member_functions it
758// uses the __val_expr's member function
759//   __get(size_t)
760// else it uses the __val_expr's member function
761//   operator[](size_t)
762template <class _ValExpr>
763struct __val_expr_use_member_functions;
764
765template <class>
766struct __val_expr_use_member_functions : false_type {};
767
768template <class _Tp>
769struct __val_expr_use_member_functions<slice_array<_Tp> > : true_type {};
770
771template <class _Tp>
772struct __val_expr_use_member_functions<gslice_array<_Tp> > : true_type {};
773
774template <class _Tp>
775struct __val_expr_use_member_functions<mask_array<_Tp> > : true_type {};
776
777template <class _Tp>
778struct __val_expr_use_member_functions<indirect_array<_Tp> > : true_type {};
779
780template <class _Tp>
781class _LIBCPP_TEMPLATE_VIS valarray {
782public:
783  typedef _Tp value_type;
784  typedef _Tp __result_type;
785
786private:
787  value_type* __begin_;
788  value_type* __end_;
789
790public:
791  // construct/destroy:
792  _LIBCPP_HIDE_FROM_ABI valarray() : __begin_(nullptr), __end_(nullptr) {}
793  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 explicit valarray(size_t __n);
794  _LIBCPP_HIDE_FROM_ABI valarray(const value_type& __x, size_t __n);
795  valarray(const value_type* __p, size_t __n);
796  valarray(const valarray& __v);
797#ifndef _LIBCPP_CXX03_LANG
798  _LIBCPP_HIDE_FROM_ABI valarray(valarray&& __v) _NOEXCEPT;
799  valarray(initializer_list<value_type> __il);
800#endif // _LIBCPP_CXX03_LANG
801  valarray(const slice_array<value_type>& __sa);
802  valarray(const gslice_array<value_type>& __ga);
803  valarray(const mask_array<value_type>& __ma);
804  valarray(const indirect_array<value_type>& __ia);
805  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 ~valarray();
806
807  // assignment:
808  valarray& operator=(const valarray& __v);
809#ifndef _LIBCPP_CXX03_LANG
810  _LIBCPP_HIDE_FROM_ABI valarray& operator=(valarray&& __v) _NOEXCEPT;
811  _LIBCPP_HIDE_FROM_ABI valarray& operator=(initializer_list<value_type>);
812#endif // _LIBCPP_CXX03_LANG
813  _LIBCPP_HIDE_FROM_ABI valarray& operator=(const value_type& __x);
814  _LIBCPP_HIDE_FROM_ABI valarray& operator=(const slice_array<value_type>& __sa);
815  _LIBCPP_HIDE_FROM_ABI valarray& operator=(const gslice_array<value_type>& __ga);
816  _LIBCPP_HIDE_FROM_ABI valarray& operator=(const mask_array<value_type>& __ma);
817  _LIBCPP_HIDE_FROM_ABI valarray& operator=(const indirect_array<value_type>& __ia);
818  template <class _ValExpr>
819  _LIBCPP_HIDE_FROM_ABI valarray& operator=(const __val_expr<_ValExpr>& __v);
820
821  // element access:
822  _LIBCPP_HIDE_FROM_ABI const value_type& operator[](size_t __i) const { return __begin_[__i]; }
823
824  _LIBCPP_HIDE_FROM_ABI value_type& operator[](size_t __i) { return __begin_[__i]; }
825
826  // subset operations:
827  _LIBCPP_HIDE_FROM_ABI __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const;
828  _LIBCPP_HIDE_FROM_ABI slice_array<value_type> operator[](slice __s);
829  _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
830  _LIBCPP_HIDE_FROM_ABI gslice_array<value_type> operator[](const gslice& __gs);
831#ifndef _LIBCPP_CXX03_LANG
832  _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
833  _LIBCPP_HIDE_FROM_ABI gslice_array<value_type> operator[](gslice&& __gs);
834#endif // _LIBCPP_CXX03_LANG
835  _LIBCPP_HIDE_FROM_ABI __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const;
836  _LIBCPP_HIDE_FROM_ABI mask_array<value_type> operator[](const valarray<bool>& __vb);
837#ifndef _LIBCPP_CXX03_LANG
838  _LIBCPP_HIDE_FROM_ABI __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const;
839  _LIBCPP_HIDE_FROM_ABI mask_array<value_type> operator[](valarray<bool>&& __vb);
840#endif // _LIBCPP_CXX03_LANG
841  _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
842  _LIBCPP_HIDE_FROM_ABI indirect_array<value_type> operator[](const valarray<size_t>& __vs);
843#ifndef _LIBCPP_CXX03_LANG
844  _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
845  _LIBCPP_HIDE_FROM_ABI indirect_array<value_type> operator[](valarray<size_t>&& __vs);
846#endif // _LIBCPP_CXX03_LANG
847
848  // unary operators:
849  _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__unary_plus<_Tp>, const valarray&> > operator+() const;
850  _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<negate<_Tp>, const valarray&> > operator-() const;
851  _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__bit_not<_Tp>, const valarray&> > operator~() const;
852  _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<logical_not<_Tp>, const valarray&> > operator!() const;
853
854  // computed assignment:
855  _LIBCPP_HIDE_FROM_ABI valarray& operator*=(const value_type& __x);
856  _LIBCPP_HIDE_FROM_ABI valarray& operator/=(const value_type& __x);
857  _LIBCPP_HIDE_FROM_ABI valarray& operator%=(const value_type& __x);
858  _LIBCPP_HIDE_FROM_ABI valarray& operator+=(const value_type& __x);
859  _LIBCPP_HIDE_FROM_ABI valarray& operator-=(const value_type& __x);
860  _LIBCPP_HIDE_FROM_ABI valarray& operator^=(const value_type& __x);
861  _LIBCPP_HIDE_FROM_ABI valarray& operator&=(const value_type& __x);
862  _LIBCPP_HIDE_FROM_ABI valarray& operator|=(const value_type& __x);
863  _LIBCPP_HIDE_FROM_ABI valarray& operator<<=(const value_type& __x);
864  _LIBCPP_HIDE_FROM_ABI valarray& operator>>=(const value_type& __x);
865
866  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
867  _LIBCPP_HIDE_FROM_ABI valarray& operator*=(const _Expr& __v);
868
869  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
870  _LIBCPP_HIDE_FROM_ABI valarray& operator/=(const _Expr& __v);
871
872  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
873  _LIBCPP_HIDE_FROM_ABI valarray& operator%=(const _Expr& __v);
874
875  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
876  _LIBCPP_HIDE_FROM_ABI valarray& operator+=(const _Expr& __v);
877
878  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
879  _LIBCPP_HIDE_FROM_ABI valarray& operator-=(const _Expr& __v);
880
881  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
882  _LIBCPP_HIDE_FROM_ABI valarray& operator^=(const _Expr& __v);
883
884  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
885  _LIBCPP_HIDE_FROM_ABI valarray& operator|=(const _Expr& __v);
886
887  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
888  _LIBCPP_HIDE_FROM_ABI valarray& operator&=(const _Expr& __v);
889
890  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
891  _LIBCPP_HIDE_FROM_ABI valarray& operator<<=(const _Expr& __v);
892
893  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
894  _LIBCPP_HIDE_FROM_ABI valarray& operator>>=(const _Expr& __v);
895
896  // member functions:
897  _LIBCPP_HIDE_FROM_ABI void swap(valarray& __v) _NOEXCEPT;
898
899  _LIBCPP_HIDE_FROM_ABI size_t size() const { return static_cast<size_t>(__end_ - __begin_); }
900
901  _LIBCPP_HIDE_FROM_ABI value_type sum() const;
902  _LIBCPP_HIDE_FROM_ABI value_type min() const;
903  _LIBCPP_HIDE_FROM_ABI value_type max() const;
904
905  valarray shift(int __i) const;
906  valarray cshift(int __i) const;
907  valarray apply(value_type __f(value_type)) const;
908  valarray apply(value_type __f(const value_type&)) const;
909  void resize(size_t __n, value_type __x = value_type());
910
911private:
912  template <class>
913  friend class _LIBCPP_TEMPLATE_VIS valarray;
914  template <class>
915  friend class _LIBCPP_TEMPLATE_VIS slice_array;
916  template <class>
917  friend class _LIBCPP_TEMPLATE_VIS gslice_array;
918  template <class>
919  friend class _LIBCPP_TEMPLATE_VIS mask_array;
920  template <class>
921  friend class __mask_expr;
922  template <class>
923  friend class _LIBCPP_TEMPLATE_VIS indirect_array;
924  template <class>
925  friend class __indirect_expr;
926  template <class>
927  friend class __val_expr;
928
929  template <class _Up>
930  friend _Up* begin(valarray<_Up>& __v);
931
932  template <class _Up>
933  friend const _Up* begin(const valarray<_Up>& __v);
934
935  template <class _Up>
936  friend _Up* end(valarray<_Up>& __v);
937
938  template <class _Up>
939  friend const _Up* end(const valarray<_Up>& __v);
940
941  _LIBCPP_HIDE_FROM_ABI void __clear(size_t __capacity);
942  valarray& __assign_range(const value_type* __f, const value_type* __l);
943};
944
945#if _LIBCPP_STD_VER >= 17
946template <class _Tp, size_t _Size>
947valarray(const _Tp (&)[_Size], size_t) -> valarray<_Tp>;
948#endif
949
950template <class _Expr,
951          __enable_if_t<__is_val_expr<_Expr>::value && __val_expr_use_member_functions<_Expr>::value, int> = 0>
952_LIBCPP_HIDE_FROM_ABI typename _Expr::value_type __get(const _Expr& __v, size_t __i) {
953  return __v.__get(__i);
954}
955
956template <class _Expr,
957          __enable_if_t<__is_val_expr<_Expr>::value && !__val_expr_use_member_functions<_Expr>::value, int> = 0>
958_LIBCPP_HIDE_FROM_ABI typename _Expr::value_type __get(const _Expr& __v, size_t __i) {
959  return __v[__i];
960}
961
962extern template _LIBCPP_EXPORTED_FROM_ABI void valarray<size_t>::resize(size_t, size_t);
963
964template <class _Op, class _Tp>
965struct _UnaryOp<_Op, valarray<_Tp> > {
966  typedef typename _Op::__result_type __result_type;
967  using value_type = __decay_t<__result_type>;
968
969  _Op __op_;
970  const valarray<_Tp>& __a0_;
971
972  _LIBCPP_HIDE_FROM_ABI _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
973
974  _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i]); }
975
976  _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); }
977};
978
979template <class _Op, class _Tp, class _A1>
980struct _BinaryOp<_Op, valarray<_Tp>, _A1> {
981  typedef typename _Op::__result_type __result_type;
982  using value_type = __decay_t<__result_type>;
983
984  _Op __op_;
985  const valarray<_Tp>& __a0_;
986  _A1 __a1_;
987
988  _LIBCPP_HIDE_FROM_ABI _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
989      : __op_(__op), __a0_(__a0), __a1_(__a1) {}
990
991  _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i], __a1_[__i]); }
992
993  _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); }
994};
995
996template <class _Op, class _A0, class _Tp>
997struct _BinaryOp<_Op, _A0, valarray<_Tp> > {
998  typedef typename _Op::__result_type __result_type;
999  using value_type = __decay_t<__result_type>;
1000
1001  _Op __op_;
1002  _A0 __a0_;
1003  const valarray<_Tp>& __a1_;
1004
1005  _LIBCPP_HIDE_FROM_ABI _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
1006      : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1007
1008  _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i], __a1_[__i]); }
1009
1010  _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); }
1011};
1012
1013template <class _Op, class _Tp>
1014struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> > {
1015  typedef typename _Op::__result_type __result_type;
1016  using value_type = __decay_t<__result_type>;
1017
1018  _Op __op_;
1019  const valarray<_Tp>& __a0_;
1020  const valarray<_Tp>& __a1_;
1021
1022  _LIBCPP_HIDE_FROM_ABI _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
1023      : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1024
1025  _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i], __a1_[__i]); }
1026
1027  _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); }
1028};
1029
1030// slice_array
1031
1032template <class _Tp>
1033class _LIBCPP_TEMPLATE_VIS slice_array {
1034public:
1035  typedef _Tp value_type;
1036
1037private:
1038  value_type* __vp_;
1039  size_t __size_;
1040  size_t __stride_;
1041
1042public:
1043  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1044  void _LIBCPP_HIDE_FROM_ABI operator=(const _Expr& __v) const;
1045
1046  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1047  void _LIBCPP_HIDE_FROM_ABI operator*=(const _Expr& __v) const;
1048
1049  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1050  void _LIBCPP_HIDE_FROM_ABI operator/=(const _Expr& __v) const;
1051
1052  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1053  void _LIBCPP_HIDE_FROM_ABI operator%=(const _Expr& __v) const;
1054
1055  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1056  void _LIBCPP_HIDE_FROM_ABI operator+=(const _Expr& __v) const;
1057
1058  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1059  void _LIBCPP_HIDE_FROM_ABI operator-=(const _Expr& __v) const;
1060
1061  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1062  void _LIBCPP_HIDE_FROM_ABI operator^=(const _Expr& __v) const;
1063
1064  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1065  void _LIBCPP_HIDE_FROM_ABI operator&=(const _Expr& __v) const;
1066
1067  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1068  void _LIBCPP_HIDE_FROM_ABI operator|=(const _Expr& __v) const;
1069
1070  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1071  void _LIBCPP_HIDE_FROM_ABI operator<<=(const _Expr& __v) const;
1072
1073  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1074  void _LIBCPP_HIDE_FROM_ABI operator>>=(const _Expr& __v) const;
1075
1076  slice_array(slice_array const&) = default;
1077
1078  _LIBCPP_HIDE_FROM_ABI const slice_array& operator=(const slice_array& __sa) const;
1079
1080  _LIBCPP_HIDE_FROM_ABI void operator=(const value_type& __x) const;
1081
1082  _LIBCPP_HIDE_FROM_ABI void operator=(const valarray<value_type>& __va) const;
1083
1084  // Behaves like __val_expr::operator[], which returns by value.
1085  _LIBCPP_HIDE_FROM_ABI value_type __get(size_t __i) const {
1086    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __size_, "slice_array.__get() index out of bounds");
1087    return __vp_[__i * __stride_];
1088  }
1089
1090private:
1091  _LIBCPP_HIDE_FROM_ABI slice_array(const slice& __sl, const valarray<value_type>& __v)
1092      : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())), __size_(__sl.size()), __stride_(__sl.stride()) {}
1093
1094  template <class>
1095  friend class valarray;
1096};
1097
1098template <class _Tp>
1099inline const slice_array<_Tp>& slice_array<_Tp>::operator=(const slice_array& __sa) const {
1100  value_type* __t       = __vp_;
1101  const value_type* __s = __sa.__vp_;
1102  for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
1103    *__t = *__s;
1104  return *this;
1105}
1106
1107template <class _Tp>
1108template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1109inline void slice_array<_Tp>::operator=(const _Expr& __v) const {
1110  value_type* __t = __vp_;
1111  for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1112    *__t = __v[__i];
1113}
1114
1115template <class _Tp>
1116inline void slice_array<_Tp>::operator=(const valarray<value_type>& __va) const {
1117  value_type* __t = __vp_;
1118  for (size_t __i = 0; __i < __va.size(); ++__i, __t += __stride_)
1119    *__t = __va[__i];
1120}
1121
1122template <class _Tp>
1123template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1124inline void slice_array<_Tp>::operator*=(const _Expr& __v) const {
1125  value_type* __t = __vp_;
1126  for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1127    *__t *= __v[__i];
1128}
1129
1130template <class _Tp>
1131template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1132inline void slice_array<_Tp>::operator/=(const _Expr& __v) const {
1133  value_type* __t = __vp_;
1134  for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1135    *__t /= __v[__i];
1136}
1137
1138template <class _Tp>
1139template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1140inline void slice_array<_Tp>::operator%=(const _Expr& __v) const {
1141  value_type* __t = __vp_;
1142  for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1143    *__t %= __v[__i];
1144}
1145
1146template <class _Tp>
1147template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1148inline void slice_array<_Tp>::operator+=(const _Expr& __v) const {
1149  value_type* __t = __vp_;
1150  for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1151    *__t += __v[__i];
1152}
1153
1154template <class _Tp>
1155template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1156inline void slice_array<_Tp>::operator-=(const _Expr& __v) const {
1157  value_type* __t = __vp_;
1158  for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1159    *__t -= __v[__i];
1160}
1161
1162template <class _Tp>
1163template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1164inline void slice_array<_Tp>::operator^=(const _Expr& __v) const {
1165  value_type* __t = __vp_;
1166  for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1167    *__t ^= __v[__i];
1168}
1169
1170template <class _Tp>
1171template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1172inline void slice_array<_Tp>::operator&=(const _Expr& __v) const {
1173  value_type* __t = __vp_;
1174  for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1175    *__t &= __v[__i];
1176}
1177
1178template <class _Tp>
1179template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1180inline void slice_array<_Tp>::operator|=(const _Expr& __v) const {
1181  value_type* __t = __vp_;
1182  for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1183    *__t |= __v[__i];
1184}
1185
1186template <class _Tp>
1187template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1188inline void slice_array<_Tp>::operator<<=(const _Expr& __v) const {
1189  value_type* __t = __vp_;
1190  for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1191    *__t <<= __v[__i];
1192}
1193
1194template <class _Tp>
1195template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1196inline void slice_array<_Tp>::operator>>=(const _Expr& __v) const {
1197  value_type* __t = __vp_;
1198  for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1199    *__t >>= __v[__i];
1200}
1201
1202template <class _Tp>
1203inline void slice_array<_Tp>::operator=(const value_type& __x) const {
1204  value_type* __t = __vp_;
1205  for (size_t __n = __size_; __n; --__n, __t += __stride_)
1206    *__t = __x;
1207}
1208
1209// gslice
1210
1211class _LIBCPP_EXPORTED_FROM_ABI gslice {
1212  valarray<size_t> __size_;
1213  valarray<size_t> __stride_;
1214  valarray<size_t> __1d_;
1215
1216public:
1217  _LIBCPP_HIDE_FROM_ABI gslice() {}
1218
1219  _LIBCPP_HIDE_FROM_ABI gslice(size_t __start, const valarray<size_t>& __size, const valarray<size_t>& __stride)
1220      : __size_(__size), __stride_(__stride) {
1221    __init(__start);
1222  }
1223
1224#ifndef _LIBCPP_CXX03_LANG
1225
1226  _LIBCPP_HIDE_FROM_ABI gslice(size_t __start, const valarray<size_t>& __size, valarray<size_t>&& __stride)
1227      : __size_(__size), __stride_(std::move(__stride)) {
1228    __init(__start);
1229  }
1230
1231  _LIBCPP_HIDE_FROM_ABI gslice(size_t __start, valarray<size_t>&& __size, const valarray<size_t>& __stride)
1232      : __size_(std::move(__size)), __stride_(__stride) {
1233    __init(__start);
1234  }
1235
1236  _LIBCPP_HIDE_FROM_ABI gslice(size_t __start, valarray<size_t>&& __size, valarray<size_t>&& __stride)
1237      : __size_(std::move(__size)), __stride_(std::move(__stride)) {
1238    __init(__start);
1239  }
1240
1241#endif // _LIBCPP_CXX03_LANG
1242
1243  _LIBCPP_HIDE_FROM_ABI size_t start() const { return __1d_.size() ? __1d_[0] : 0; }
1244
1245  _LIBCPP_HIDE_FROM_ABI valarray<size_t> size() const { return __size_; }
1246
1247  _LIBCPP_HIDE_FROM_ABI valarray<size_t> stride() const { return __stride_; }
1248
1249private:
1250  void __init(size_t __start);
1251
1252  template <class>
1253  friend class gslice_array;
1254  template <class>
1255  friend class valarray;
1256  template <class>
1257  friend class __val_expr;
1258};
1259
1260// gslice_array
1261
1262template <class _Tp>
1263class _LIBCPP_TEMPLATE_VIS gslice_array {
1264public:
1265  typedef _Tp value_type;
1266
1267private:
1268  value_type* __vp_;
1269  valarray<size_t> __1d_;
1270
1271public:
1272  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1273  void _LIBCPP_HIDE_FROM_ABI operator=(const _Expr& __v) const;
1274
1275  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1276  void _LIBCPP_HIDE_FROM_ABI operator*=(const _Expr& __v) const;
1277
1278  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1279  void _LIBCPP_HIDE_FROM_ABI operator/=(const _Expr& __v) const;
1280
1281  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1282  void _LIBCPP_HIDE_FROM_ABI operator%=(const _Expr& __v) const;
1283
1284  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1285  void _LIBCPP_HIDE_FROM_ABI operator+=(const _Expr& __v) const;
1286
1287  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1288  void _LIBCPP_HIDE_FROM_ABI operator-=(const _Expr& __v) const;
1289
1290  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1291  void _LIBCPP_HIDE_FROM_ABI operator^=(const _Expr& __v) const;
1292
1293  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1294  void _LIBCPP_HIDE_FROM_ABI operator&=(const _Expr& __v) const;
1295
1296  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1297  void _LIBCPP_HIDE_FROM_ABI operator|=(const _Expr& __v) const;
1298
1299  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1300  void _LIBCPP_HIDE_FROM_ABI operator<<=(const _Expr& __v) const;
1301
1302  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1303  void _LIBCPP_HIDE_FROM_ABI operator>>=(const _Expr& __v) const;
1304
1305  _LIBCPP_HIDE_FROM_ABI const gslice_array& operator=(const gslice_array& __ga) const;
1306
1307  _LIBCPP_HIDE_FROM_ABI void operator=(const value_type& __x) const;
1308
1309  gslice_array(const gslice_array&) = default;
1310
1311  // Behaves like __val_expr::operator[], which returns by value.
1312  _LIBCPP_HIDE_FROM_ABI value_type __get(size_t __i) const {
1313    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __1d_.size(), "gslice_array.__get() index out of bounds");
1314    return __vp_[__1d_[__i]];
1315  }
1316
1317private:
1318  gslice_array(const gslice& __gs, const valarray<value_type>& __v)
1319      : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(__gs.__1d_) {}
1320
1321#ifndef _LIBCPP_CXX03_LANG
1322  gslice_array(gslice&& __gs, const valarray<value_type>& __v)
1323      : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(std::move(__gs.__1d_)) {}
1324#endif // _LIBCPP_CXX03_LANG
1325
1326  template <class>
1327  friend class valarray;
1328};
1329
1330template <class _Tp>
1331template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1332inline void gslice_array<_Tp>::operator=(const _Expr& __v) const {
1333  typedef const size_t* _Ip;
1334  size_t __j = 0;
1335  for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1336    __vp_[*__i] = __v[__j];
1337}
1338
1339template <class _Tp>
1340template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1341inline void gslice_array<_Tp>::operator*=(const _Expr& __v) const {
1342  typedef const size_t* _Ip;
1343  size_t __j = 0;
1344  for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1345    __vp_[*__i] *= __v[__j];
1346}
1347
1348template <class _Tp>
1349template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1350inline void gslice_array<_Tp>::operator/=(const _Expr& __v) const {
1351  typedef const size_t* _Ip;
1352  size_t __j = 0;
1353  for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1354    __vp_[*__i] /= __v[__j];
1355}
1356
1357template <class _Tp>
1358template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1359inline void gslice_array<_Tp>::operator%=(const _Expr& __v) const {
1360  typedef const size_t* _Ip;
1361  size_t __j = 0;
1362  for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1363    __vp_[*__i] %= __v[__j];
1364}
1365
1366template <class _Tp>
1367template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1368inline void gslice_array<_Tp>::operator+=(const _Expr& __v) const {
1369  typedef const size_t* _Ip;
1370  size_t __j = 0;
1371  for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1372    __vp_[*__i] += __v[__j];
1373}
1374
1375template <class _Tp>
1376template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1377inline void gslice_array<_Tp>::operator-=(const _Expr& __v) const {
1378  typedef const size_t* _Ip;
1379  size_t __j = 0;
1380  for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1381    __vp_[*__i] -= __v[__j];
1382}
1383
1384template <class _Tp>
1385template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1386inline void gslice_array<_Tp>::operator^=(const _Expr& __v) const {
1387  typedef const size_t* _Ip;
1388  size_t __j = 0;
1389  for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1390    __vp_[*__i] ^= __v[__j];
1391}
1392
1393template <class _Tp>
1394template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1395inline void gslice_array<_Tp>::operator&=(const _Expr& __v) const {
1396  typedef const size_t* _Ip;
1397  size_t __j = 0;
1398  for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1399    __vp_[*__i] &= __v[__j];
1400}
1401
1402template <class _Tp>
1403template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1404inline void gslice_array<_Tp>::operator|=(const _Expr& __v) const {
1405  typedef const size_t* _Ip;
1406  size_t __j = 0;
1407  for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1408    __vp_[*__i] |= __v[__j];
1409}
1410
1411template <class _Tp>
1412template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1413inline void gslice_array<_Tp>::operator<<=(const _Expr& __v) const {
1414  typedef const size_t* _Ip;
1415  size_t __j = 0;
1416  for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1417    __vp_[*__i] <<= __v[__j];
1418}
1419
1420template <class _Tp>
1421template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1422inline void gslice_array<_Tp>::operator>>=(const _Expr& __v) const {
1423  typedef const size_t* _Ip;
1424  size_t __j = 0;
1425  for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1426    __vp_[*__i] >>= __v[__j];
1427}
1428
1429template <class _Tp>
1430inline const gslice_array<_Tp>& gslice_array<_Tp>::operator=(const gslice_array& __ga) const {
1431  typedef const size_t* _Ip;
1432  const value_type* __s = __ga.__vp_;
1433  for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_; __i != __e; ++__i, ++__j)
1434    __vp_[*__i] = __s[*__j];
1435  return *this;
1436}
1437
1438template <class _Tp>
1439inline void gslice_array<_Tp>::operator=(const value_type& __x) const {
1440  typedef const size_t* _Ip;
1441  for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1442    __vp_[*__i] = __x;
1443}
1444
1445// mask_array
1446
1447template <class _Tp>
1448class _LIBCPP_TEMPLATE_VIS mask_array {
1449public:
1450  typedef _Tp value_type;
1451
1452private:
1453  value_type* __vp_;
1454  valarray<size_t> __1d_;
1455
1456public:
1457  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1458  void _LIBCPP_HIDE_FROM_ABI operator=(const _Expr& __v) const;
1459
1460  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1461  void _LIBCPP_HIDE_FROM_ABI operator*=(const _Expr& __v) const;
1462
1463  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1464  void _LIBCPP_HIDE_FROM_ABI operator/=(const _Expr& __v) const;
1465
1466  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1467  void _LIBCPP_HIDE_FROM_ABI operator%=(const _Expr& __v) const;
1468
1469  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1470  void _LIBCPP_HIDE_FROM_ABI operator+=(const _Expr& __v) const;
1471
1472  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1473  void _LIBCPP_HIDE_FROM_ABI operator-=(const _Expr& __v) const;
1474
1475  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1476  void _LIBCPP_HIDE_FROM_ABI operator^=(const _Expr& __v) const;
1477
1478  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1479  void _LIBCPP_HIDE_FROM_ABI operator&=(const _Expr& __v) const;
1480
1481  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1482  void _LIBCPP_HIDE_FROM_ABI operator|=(const _Expr& __v) const;
1483
1484  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1485  void _LIBCPP_HIDE_FROM_ABI operator<<=(const _Expr& __v) const;
1486
1487  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1488  void _LIBCPP_HIDE_FROM_ABI operator>>=(const _Expr& __v) const;
1489
1490  mask_array(const mask_array&) = default;
1491
1492  _LIBCPP_HIDE_FROM_ABI const mask_array& operator=(const mask_array& __ma) const;
1493
1494  _LIBCPP_HIDE_FROM_ABI void operator=(const value_type& __x) const;
1495
1496  // Behaves like __val_expr::operator[], which returns by value.
1497  _LIBCPP_HIDE_FROM_ABI value_type __get(size_t __i) const {
1498    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __1d_.size(), "mask_array.__get() index out of bounds");
1499    return __vp_[__1d_[__i]];
1500  }
1501
1502private:
1503  _LIBCPP_HIDE_FROM_ABI mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
1504      : __vp_(const_cast<value_type*>(__v.__begin_)),
1505        __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true))) {
1506    size_t __j = 0;
1507    for (size_t __i = 0; __i < __vb.size(); ++__i)
1508      if (__vb[__i])
1509        __1d_[__j++] = __i;
1510  }
1511
1512  template <class>
1513  friend class valarray;
1514};
1515
1516template <class _Tp>
1517template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1518inline void mask_array<_Tp>::operator=(const _Expr& __v) const {
1519  size_t __n = __1d_.size();
1520  for (size_t __i = 0; __i < __n; ++__i)
1521    __vp_[__1d_[__i]] = __v[__i];
1522}
1523
1524template <class _Tp>
1525template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1526inline void mask_array<_Tp>::operator*=(const _Expr& __v) const {
1527  size_t __n = __1d_.size();
1528  for (size_t __i = 0; __i < __n; ++__i)
1529    __vp_[__1d_[__i]] *= __v[__i];
1530}
1531
1532template <class _Tp>
1533template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1534inline void mask_array<_Tp>::operator/=(const _Expr& __v) const {
1535  size_t __n = __1d_.size();
1536  for (size_t __i = 0; __i < __n; ++__i)
1537    __vp_[__1d_[__i]] /= __v[__i];
1538}
1539
1540template <class _Tp>
1541template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1542inline void mask_array<_Tp>::operator%=(const _Expr& __v) const {
1543  size_t __n = __1d_.size();
1544  for (size_t __i = 0; __i < __n; ++__i)
1545    __vp_[__1d_[__i]] %= __v[__i];
1546}
1547
1548template <class _Tp>
1549template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1550inline void mask_array<_Tp>::operator+=(const _Expr& __v) const {
1551  size_t __n = __1d_.size();
1552  for (size_t __i = 0; __i < __n; ++__i)
1553    __vp_[__1d_[__i]] += __v[__i];
1554}
1555
1556template <class _Tp>
1557template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1558inline void mask_array<_Tp>::operator-=(const _Expr& __v) const {
1559  size_t __n = __1d_.size();
1560  for (size_t __i = 0; __i < __n; ++__i)
1561    __vp_[__1d_[__i]] -= __v[__i];
1562}
1563
1564template <class _Tp>
1565template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1566inline void mask_array<_Tp>::operator^=(const _Expr& __v) const {
1567  size_t __n = __1d_.size();
1568  for (size_t __i = 0; __i < __n; ++__i)
1569    __vp_[__1d_[__i]] ^= __v[__i];
1570}
1571
1572template <class _Tp>
1573template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1574inline void mask_array<_Tp>::operator&=(const _Expr& __v) const {
1575  size_t __n = __1d_.size();
1576  for (size_t __i = 0; __i < __n; ++__i)
1577    __vp_[__1d_[__i]] &= __v[__i];
1578}
1579
1580template <class _Tp>
1581template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1582inline void mask_array<_Tp>::operator|=(const _Expr& __v) const {
1583  size_t __n = __1d_.size();
1584  for (size_t __i = 0; __i < __n; ++__i)
1585    __vp_[__1d_[__i]] |= __v[__i];
1586}
1587
1588template <class _Tp>
1589template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1590inline void mask_array<_Tp>::operator<<=(const _Expr& __v) const {
1591  size_t __n = __1d_.size();
1592  for (size_t __i = 0; __i < __n; ++__i)
1593    __vp_[__1d_[__i]] <<= __v[__i];
1594}
1595
1596template <class _Tp>
1597template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1598inline void mask_array<_Tp>::operator>>=(const _Expr& __v) const {
1599  size_t __n = __1d_.size();
1600  for (size_t __i = 0; __i < __n; ++__i)
1601    __vp_[__1d_[__i]] >>= __v[__i];
1602}
1603
1604template <class _Tp>
1605inline const mask_array<_Tp>& mask_array<_Tp>::operator=(const mask_array& __ma) const {
1606  size_t __n = __1d_.size();
1607  for (size_t __i = 0; __i < __n; ++__i)
1608    __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
1609  return *this;
1610}
1611
1612template <class _Tp>
1613inline void mask_array<_Tp>::operator=(const value_type& __x) const {
1614  size_t __n = __1d_.size();
1615  for (size_t __i = 0; __i < __n; ++__i)
1616    __vp_[__1d_[__i]] = __x;
1617}
1618
1619template <class _ValExpr>
1620class __mask_expr {
1621  typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
1622
1623public:
1624  typedef typename _RmExpr::value_type value_type;
1625  typedef value_type __result_type;
1626
1627private:
1628  _ValExpr __expr_;
1629  valarray<size_t> __1d_;
1630
1631  _LIBCPP_HIDE_FROM_ABI __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
1632      : __expr_(__e), __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true))) {
1633    size_t __j = 0;
1634    for (size_t __i = 0; __i < __vb.size(); ++__i)
1635      if (__vb[__i])
1636        __1d_[__j++] = __i;
1637  }
1638
1639public:
1640  _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __expr_[__1d_[__i]]; }
1641
1642  _LIBCPP_HIDE_FROM_ABI size_t size() const { return __1d_.size(); }
1643
1644  template <class>
1645  friend class __val_expr;
1646  template <class>
1647  friend class valarray;
1648};
1649
1650// indirect_array
1651
1652template <class _Tp>
1653class _LIBCPP_TEMPLATE_VIS indirect_array {
1654public:
1655  typedef _Tp value_type;
1656
1657private:
1658  value_type* __vp_;
1659  valarray<size_t> __1d_;
1660
1661public:
1662  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1663  void _LIBCPP_HIDE_FROM_ABI operator=(const _Expr& __v) const;
1664
1665  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1666  void _LIBCPP_HIDE_FROM_ABI operator*=(const _Expr& __v) const;
1667
1668  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1669  void _LIBCPP_HIDE_FROM_ABI operator/=(const _Expr& __v) const;
1670
1671  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1672  void _LIBCPP_HIDE_FROM_ABI operator%=(const _Expr& __v) const;
1673
1674  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1675  void _LIBCPP_HIDE_FROM_ABI operator+=(const _Expr& __v) const;
1676
1677  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1678  void _LIBCPP_HIDE_FROM_ABI operator-=(const _Expr& __v) const;
1679
1680  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1681  void _LIBCPP_HIDE_FROM_ABI operator^=(const _Expr& __v) const;
1682
1683  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1684  void _LIBCPP_HIDE_FROM_ABI operator&=(const _Expr& __v) const;
1685
1686  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1687  void _LIBCPP_HIDE_FROM_ABI operator|=(const _Expr& __v) const;
1688
1689  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1690  void _LIBCPP_HIDE_FROM_ABI operator<<=(const _Expr& __v) const;
1691
1692  template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
1693  void _LIBCPP_HIDE_FROM_ABI operator>>=(const _Expr& __v) const;
1694
1695  indirect_array(const indirect_array&) = default;
1696
1697  _LIBCPP_HIDE_FROM_ABI const indirect_array& operator=(const indirect_array& __ia) const;
1698
1699  _LIBCPP_HIDE_FROM_ABI void operator=(const value_type& __x) const;
1700
1701  // Behaves like __val_expr::operator[], which returns by value.
1702  _LIBCPP_HIDE_FROM_ABI value_type __get(size_t __i) const {
1703    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __1d_.size(), "indirect_array.__get() index out of bounds");
1704    return __vp_[__1d_[__i]];
1705  }
1706
1707private:
1708  _LIBCPP_HIDE_FROM_ABI indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
1709      : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(__ia) {}
1710
1711#ifndef _LIBCPP_CXX03_LANG
1712
1713  _LIBCPP_HIDE_FROM_ABI indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
1714      : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(std::move(__ia)) {}
1715
1716#endif // _LIBCPP_CXX03_LANG
1717
1718  template <class>
1719  friend class valarray;
1720};
1721
1722template <class _Tp>
1723template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1724inline void indirect_array<_Tp>::operator=(const _Expr& __v) const {
1725  size_t __n = __1d_.size();
1726  for (size_t __i = 0; __i < __n; ++__i)
1727    __vp_[__1d_[__i]] = __v[__i];
1728}
1729
1730template <class _Tp>
1731template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1732inline void indirect_array<_Tp>::operator*=(const _Expr& __v) const {
1733  size_t __n = __1d_.size();
1734  for (size_t __i = 0; __i < __n; ++__i)
1735    __vp_[__1d_[__i]] *= __v[__i];
1736}
1737
1738template <class _Tp>
1739template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1740inline void indirect_array<_Tp>::operator/=(const _Expr& __v) const {
1741  size_t __n = __1d_.size();
1742  for (size_t __i = 0; __i < __n; ++__i)
1743    __vp_[__1d_[__i]] /= __v[__i];
1744}
1745
1746template <class _Tp>
1747template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1748inline void indirect_array<_Tp>::operator%=(const _Expr& __v) const {
1749  size_t __n = __1d_.size();
1750  for (size_t __i = 0; __i < __n; ++__i)
1751    __vp_[__1d_[__i]] %= __v[__i];
1752}
1753
1754template <class _Tp>
1755template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1756inline void indirect_array<_Tp>::operator+=(const _Expr& __v) const {
1757  size_t __n = __1d_.size();
1758  for (size_t __i = 0; __i < __n; ++__i)
1759    __vp_[__1d_[__i]] += __v[__i];
1760}
1761
1762template <class _Tp>
1763template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1764inline void indirect_array<_Tp>::operator-=(const _Expr& __v) const {
1765  size_t __n = __1d_.size();
1766  for (size_t __i = 0; __i < __n; ++__i)
1767    __vp_[__1d_[__i]] -= __v[__i];
1768}
1769
1770template <class _Tp>
1771template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1772inline void indirect_array<_Tp>::operator^=(const _Expr& __v) const {
1773  size_t __n = __1d_.size();
1774  for (size_t __i = 0; __i < __n; ++__i)
1775    __vp_[__1d_[__i]] ^= __v[__i];
1776}
1777
1778template <class _Tp>
1779template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1780inline void indirect_array<_Tp>::operator&=(const _Expr& __v) const {
1781  size_t __n = __1d_.size();
1782  for (size_t __i = 0; __i < __n; ++__i)
1783    __vp_[__1d_[__i]] &= __v[__i];
1784}
1785
1786template <class _Tp>
1787template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1788inline void indirect_array<_Tp>::operator|=(const _Expr& __v) const {
1789  size_t __n = __1d_.size();
1790  for (size_t __i = 0; __i < __n; ++__i)
1791    __vp_[__1d_[__i]] |= __v[__i];
1792}
1793
1794template <class _Tp>
1795template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1796inline void indirect_array<_Tp>::operator<<=(const _Expr& __v) const {
1797  size_t __n = __1d_.size();
1798  for (size_t __i = 0; __i < __n; ++__i)
1799    __vp_[__1d_[__i]] <<= __v[__i];
1800}
1801
1802template <class _Tp>
1803template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
1804inline void indirect_array<_Tp>::operator>>=(const _Expr& __v) const {
1805  size_t __n = __1d_.size();
1806  for (size_t __i = 0; __i < __n; ++__i)
1807    __vp_[__1d_[__i]] >>= __v[__i];
1808}
1809
1810template <class _Tp>
1811inline const indirect_array<_Tp>& indirect_array<_Tp>::operator=(const indirect_array& __ia) const {
1812  typedef const size_t* _Ip;
1813  const value_type* __s = __ia.__vp_;
1814  for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_; __i != __e; ++__i, ++__j)
1815    __vp_[*__i] = __s[*__j];
1816  return *this;
1817}
1818
1819template <class _Tp>
1820inline void indirect_array<_Tp>::operator=(const value_type& __x) const {
1821  typedef const size_t* _Ip;
1822  for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1823    __vp_[*__i] = __x;
1824}
1825
1826template <class _ValExpr>
1827class __indirect_expr {
1828  typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
1829
1830public:
1831  typedef typename _RmExpr::value_type value_type;
1832  typedef value_type __result_type;
1833
1834private:
1835  _ValExpr __expr_;
1836  valarray<size_t> __1d_;
1837
1838  _LIBCPP_HIDE_FROM_ABI __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e) : __expr_(__e), __1d_(__ia) {}
1839
1840#ifndef _LIBCPP_CXX03_LANG
1841
1842  _LIBCPP_HIDE_FROM_ABI __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
1843      : __expr_(__e), __1d_(std::move(__ia)) {}
1844
1845#endif // _LIBCPP_CXX03_LANG
1846
1847public:
1848  _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __expr_[__1d_[__i]]; }
1849
1850  _LIBCPP_HIDE_FROM_ABI size_t size() const { return __1d_.size(); }
1851
1852  template <class>
1853  friend class __val_expr;
1854  template <class>
1855  friend class _LIBCPP_TEMPLATE_VIS valarray;
1856};
1857
1858template <class _ValExpr>
1859class __val_expr {
1860  typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
1861
1862  _ValExpr __expr_;
1863
1864public:
1865  typedef typename _RmExpr::value_type value_type;
1866  typedef typename _RmExpr::__result_type __result_type;
1867
1868  _LIBCPP_HIDE_FROM_ABI explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
1869
1870  _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __expr_[__i]; }
1871
1872  _LIBCPP_HIDE_FROM_ABI __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const {
1873    typedef __slice_expr<_ValExpr> _NewExpr;
1874    return __val_expr< _NewExpr >(_NewExpr(__s, __expr_));
1875  }
1876
1877  _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const {
1878    typedef __indirect_expr<_ValExpr> _NewExpr;
1879    return __val_expr<_NewExpr >(_NewExpr(__gs.__1d_, __expr_));
1880  }
1881
1882  _LIBCPP_HIDE_FROM_ABI __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const {
1883    typedef __mask_expr<_ValExpr> _NewExpr;
1884    return __val_expr< _NewExpr >(_NewExpr(__vb, __expr_));
1885  }
1886
1887  _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const {
1888    typedef __indirect_expr<_ValExpr> _NewExpr;
1889    return __val_expr< _NewExpr >(_NewExpr(__vs, __expr_));
1890  }
1891
1892  _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> > operator+() const {
1893    typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
1894    return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
1895  }
1896
1897  _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<negate<value_type>, _ValExpr> > operator-() const {
1898    typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
1899    return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
1900  }
1901
1902  _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> > operator~() const {
1903    typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
1904    return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
1905  }
1906
1907  _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> > operator!() const {
1908    typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
1909    return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
1910  }
1911
1912  operator valarray<__result_type>() const;
1913
1914  _LIBCPP_HIDE_FROM_ABI size_t size() const { return __expr_.size(); }
1915
1916  _LIBCPP_HIDE_FROM_ABI __result_type sum() const {
1917    size_t __n        = __expr_.size();
1918    __result_type __r = __n ? __expr_[0] : __result_type();
1919    for (size_t __i = 1; __i < __n; ++__i)
1920      __r += __expr_[__i];
1921    return __r;
1922  }
1923
1924  _LIBCPP_HIDE_FROM_ABI __result_type min() const {
1925    size_t __n        = size();
1926    __result_type __r = __n ? (*this)[0] : __result_type();
1927    for (size_t __i = 1; __i < __n; ++__i) {
1928      __result_type __x = __expr_[__i];
1929      if (__x < __r)
1930        __r = __x;
1931    }
1932    return __r;
1933  }
1934
1935  _LIBCPP_HIDE_FROM_ABI __result_type max() const {
1936    size_t __n        = size();
1937    __result_type __r = __n ? (*this)[0] : __result_type();
1938    for (size_t __i = 1; __i < __n; ++__i) {
1939      __result_type __x = __expr_[__i];
1940      if (__r < __x)
1941        __r = __x;
1942    }
1943    return __r;
1944  }
1945
1946  _LIBCPP_HIDE_FROM_ABI __val_expr<__shift_expr<_ValExpr> > shift(int __i) const {
1947    return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));
1948  }
1949
1950  _LIBCPP_HIDE_FROM_ABI __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const {
1951    return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));
1952  }
1953
1954  _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__apply_expr<value_type, value_type (*)(value_type)>, _ValExpr> >
1955  apply(value_type __f(value_type)) const {
1956    typedef __apply_expr<value_type, value_type (*)(value_type)> _Op;
1957    typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
1958    return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
1959  }
1960
1961  _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__apply_expr<value_type, value_type (*)(const value_type&)>, _ValExpr> >
1962  apply(value_type __f(const value_type&)) const {
1963    typedef __apply_expr<value_type, value_type (*)(const value_type&)> _Op;
1964    typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
1965    return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
1966  }
1967};
1968
1969template <class _ValExpr>
1970__val_expr<_ValExpr>::operator valarray<__val_expr::__result_type>() const {
1971  valarray<__result_type> __r;
1972  size_t __n = __expr_.size();
1973  if (__n) {
1974    __r.__begin_ = __r.__end_ = allocator<__result_type>().allocate(__n);
1975    for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
1976      ::new ((void*)__r.__end_) __result_type(__expr_[__i]);
1977  }
1978  return __r;
1979}
1980
1981// valarray
1982
1983template <class _Tp>
1984inline valarray<_Tp>::valarray(size_t __n) : __begin_(nullptr), __end_(nullptr) {
1985  if (__n) {
1986    __begin_ = __end_ = allocator<value_type>().allocate(__n);
1987#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1988    try {
1989#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1990      for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
1991        ::new ((void*)__end_) value_type();
1992#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1993    } catch (...) {
1994      __clear(__n);
1995      throw;
1996    }
1997#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1998  }
1999}
2000
2001template <class _Tp>
2002inline valarray<_Tp>::valarray(const value_type& __x, size_t __n) : __begin_(nullptr), __end_(nullptr) {
2003  resize(__n, __x);
2004}
2005
2006template <class _Tp>
2007valarray<_Tp>::valarray(const value_type* __p, size_t __n) : __begin_(nullptr), __end_(nullptr) {
2008  if (__n) {
2009    __begin_ = __end_ = allocator<value_type>().allocate(__n);
2010#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2011    try {
2012#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2013      for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left)
2014        ::new ((void*)__end_) value_type(*__p);
2015#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2016    } catch (...) {
2017      __clear(__n);
2018      throw;
2019    }
2020#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2021  }
2022}
2023
2024template <class _Tp>
2025valarray<_Tp>::valarray(const valarray& __v) : __begin_(nullptr), __end_(nullptr) {
2026  if (__v.size()) {
2027    __begin_ = __end_ = allocator<value_type>().allocate(__v.size());
2028#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2029    try {
2030#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2031      for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
2032        ::new ((void*)__end_) value_type(*__p);
2033#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2034    } catch (...) {
2035      __clear(__v.size());
2036      throw;
2037    }
2038#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2039  }
2040}
2041
2042#ifndef _LIBCPP_CXX03_LANG
2043
2044template <class _Tp>
2045inline valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT : __begin_(__v.__begin_), __end_(__v.__end_) {
2046  __v.__begin_ = __v.__end_ = nullptr;
2047}
2048
2049template <class _Tp>
2050valarray<_Tp>::valarray(initializer_list<value_type> __il) : __begin_(nullptr), __end_(nullptr) {
2051  const size_t __n = __il.size();
2052  if (__n) {
2053    __begin_ = __end_ = allocator<value_type>().allocate(__n);
2054#  ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2055    try {
2056#  endif // _LIBCPP_HAS_NO_EXCEPTIONS
2057      size_t __n_left = __n;
2058      for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left)
2059        ::new ((void*)__end_) value_type(*__p);
2060#  ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2061    } catch (...) {
2062      __clear(__n);
2063      throw;
2064    }
2065#  endif // _LIBCPP_HAS_NO_EXCEPTIONS
2066  }
2067}
2068
2069#endif // _LIBCPP_CXX03_LANG
2070
2071template <class _Tp>
2072valarray<_Tp>::valarray(const slice_array<value_type>& __sa) : __begin_(nullptr), __end_(nullptr) {
2073  const size_t __n = __sa.__size_;
2074  if (__n) {
2075    __begin_ = __end_ = allocator<value_type>().allocate(__n);
2076#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2077    try {
2078#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2079      size_t __n_left = __n;
2080      for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left)
2081        ::new ((void*)__end_) value_type(*__p);
2082#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2083    } catch (...) {
2084      __clear(__n);
2085      throw;
2086    }
2087#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2088  }
2089}
2090
2091template <class _Tp>
2092valarray<_Tp>::valarray(const gslice_array<value_type>& __ga) : __begin_(nullptr), __end_(nullptr) {
2093  const size_t __n = __ga.__1d_.size();
2094  if (__n) {
2095    __begin_ = __end_ = allocator<value_type>().allocate(__n);
2096#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2097    try {
2098#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2099      typedef const size_t* _Ip;
2100      const value_type* __s = __ga.__vp_;
2101      for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; __i != __e; ++__i, ++__end_)
2102        ::new ((void*)__end_) value_type(__s[*__i]);
2103#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2104    } catch (...) {
2105      __clear(__n);
2106      throw;
2107    }
2108#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2109  }
2110}
2111
2112template <class _Tp>
2113valarray<_Tp>::valarray(const mask_array<value_type>& __ma) : __begin_(nullptr), __end_(nullptr) {
2114  const size_t __n = __ma.__1d_.size();
2115  if (__n) {
2116    __begin_ = __end_ = allocator<value_type>().allocate(__n);
2117#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2118    try {
2119#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2120      typedef const size_t* _Ip;
2121      const value_type* __s = __ma.__vp_;
2122      for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; __i != __e; ++__i, ++__end_)
2123        ::new ((void*)__end_) value_type(__s[*__i]);
2124#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2125    } catch (...) {
2126      __clear(__n);
2127      throw;
2128    }
2129#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2130  }
2131}
2132
2133template <class _Tp>
2134valarray<_Tp>::valarray(const indirect_array<value_type>& __ia) : __begin_(nullptr), __end_(nullptr) {
2135  const size_t __n = __ia.__1d_.size();
2136  if (__n) {
2137    __begin_ = __end_ = allocator<value_type>().allocate(__n);
2138#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2139    try {
2140#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2141      typedef const size_t* _Ip;
2142      const value_type* __s = __ia.__vp_;
2143      for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; __i != __e; ++__i, ++__end_)
2144        ::new ((void*)__end_) value_type(__s[*__i]);
2145#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2146    } catch (...) {
2147      __clear(__n);
2148      throw;
2149    }
2150#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2151  }
2152}
2153
2154template <class _Tp>
2155inline valarray<_Tp>::~valarray() {
2156  __clear(size());
2157}
2158
2159template <class _Tp>
2160valarray<_Tp>& valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l) {
2161  size_t __n = __l - __f;
2162  if (size() != __n) {
2163    __clear(size());
2164    __begin_ = allocator<value_type>().allocate(__n);
2165    __end_   = __begin_ + __n;
2166    std::uninitialized_copy(__f, __l, __begin_);
2167  } else {
2168    std::copy(__f, __l, __begin_);
2169  }
2170  return *this;
2171}
2172
2173template <class _Tp>
2174valarray<_Tp>& valarray<_Tp>::operator=(const valarray& __v) {
2175  if (this != std::addressof(__v))
2176    return __assign_range(__v.__begin_, __v.__end_);
2177  return *this;
2178}
2179
2180#ifndef _LIBCPP_CXX03_LANG
2181
2182template <class _Tp>
2183inline valarray<_Tp>& valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT {
2184  __clear(size());
2185  __begin_     = __v.__begin_;
2186  __end_       = __v.__end_;
2187  __v.__begin_ = nullptr;
2188  __v.__end_   = nullptr;
2189  return *this;
2190}
2191
2192template <class _Tp>
2193inline valarray<_Tp>& valarray<_Tp>::operator=(initializer_list<value_type> __il) {
2194  return __assign_range(__il.begin(), __il.end());
2195}
2196
2197#endif // _LIBCPP_CXX03_LANG
2198
2199template <class _Tp>
2200inline valarray<_Tp>& valarray<_Tp>::operator=(const value_type& __x) {
2201  std::fill(__begin_, __end_, __x);
2202  return *this;
2203}
2204
2205template <class _Tp>
2206inline valarray<_Tp>& valarray<_Tp>::operator=(const slice_array<value_type>& __sa) {
2207  value_type* __t       = __begin_;
2208  const value_type* __s = __sa.__vp_;
2209  for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
2210    *__t = *__s;
2211  return *this;
2212}
2213
2214template <class _Tp>
2215inline valarray<_Tp>& valarray<_Tp>::operator=(const gslice_array<value_type>& __ga) {
2216  typedef const size_t* _Ip;
2217  value_type* __t       = __begin_;
2218  const value_type* __s = __ga.__vp_;
2219  for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; __i != __e; ++__i, ++__t)
2220    *__t = __s[*__i];
2221  return *this;
2222}
2223
2224template <class _Tp>
2225inline valarray<_Tp>& valarray<_Tp>::operator=(const mask_array<value_type>& __ma) {
2226  typedef const size_t* _Ip;
2227  value_type* __t       = __begin_;
2228  const value_type* __s = __ma.__vp_;
2229  for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; __i != __e; ++__i, ++__t)
2230    *__t = __s[*__i];
2231  return *this;
2232}
2233
2234template <class _Tp>
2235inline valarray<_Tp>& valarray<_Tp>::operator=(const indirect_array<value_type>& __ia) {
2236  typedef const size_t* _Ip;
2237  value_type* __t       = __begin_;
2238  const value_type* __s = __ia.__vp_;
2239  for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; __i != __e; ++__i, ++__t)
2240    *__t = __s[*__i];
2241  return *this;
2242}
2243
2244template <class _Tp>
2245template <class _ValExpr>
2246inline valarray<_Tp>& valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v) {
2247  size_t __n = __v.size();
2248  if (size() != __n)
2249    resize(__n);
2250  value_type* __t = __begin_;
2251  for (size_t __i = 0; __i != __n; ++__t, ++__i)
2252    *__t = __result_type(__v[__i]);
2253  return *this;
2254}
2255
2256template <class _Tp>
2257inline __val_expr<__slice_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](slice __s) const {
2258  return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
2259}
2260
2261template <class _Tp>
2262inline slice_array<_Tp> valarray<_Tp>::operator[](slice __s) {
2263  return slice_array<value_type>(__s, *this);
2264}
2265
2266template <class _Tp>
2267inline __val_expr<__indirect_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](const gslice& __gs) const {
2268  return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
2269}
2270
2271template <class _Tp>
2272inline gslice_array<_Tp> valarray<_Tp>::operator[](const gslice& __gs) {
2273  return gslice_array<value_type>(__gs, *this);
2274}
2275
2276#ifndef _LIBCPP_CXX03_LANG
2277
2278template <class _Tp>
2279inline __val_expr<__indirect_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](gslice&& __gs) const {
2280  return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(std::move(__gs.__1d_), *this));
2281}
2282
2283template <class _Tp>
2284inline gslice_array<_Tp> valarray<_Tp>::operator[](gslice&& __gs) {
2285  return gslice_array<value_type>(std::move(__gs), *this);
2286}
2287
2288#endif // _LIBCPP_CXX03_LANG
2289
2290template <class _Tp>
2291inline __val_expr<__mask_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](const valarray<bool>& __vb) const {
2292  return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
2293}
2294
2295template <class _Tp>
2296inline mask_array<_Tp> valarray<_Tp>::operator[](const valarray<bool>& __vb) {
2297  return mask_array<value_type>(__vb, *this);
2298}
2299
2300#ifndef _LIBCPP_CXX03_LANG
2301
2302template <class _Tp>
2303inline __val_expr<__mask_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](valarray<bool>&& __vb) const {
2304  return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(std::move(__vb), *this));
2305}
2306
2307template <class _Tp>
2308inline mask_array<_Tp> valarray<_Tp>::operator[](valarray<bool>&& __vb) {
2309  return mask_array<value_type>(std::move(__vb), *this);
2310}
2311
2312#endif // _LIBCPP_CXX03_LANG
2313
2314template <class _Tp>
2315inline __val_expr<__indirect_expr<const valarray<_Tp>&> >
2316valarray<_Tp>::operator[](const valarray<size_t>& __vs) const {
2317  return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
2318}
2319
2320template <class _Tp>
2321inline indirect_array<_Tp> valarray<_Tp>::operator[](const valarray<size_t>& __vs) {
2322  return indirect_array<value_type>(__vs, *this);
2323}
2324
2325#ifndef _LIBCPP_CXX03_LANG
2326
2327template <class _Tp>
2328inline __val_expr<__indirect_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](valarray<size_t>&& __vs) const {
2329  return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(std::move(__vs), *this));
2330}
2331
2332template <class _Tp>
2333inline indirect_array<_Tp> valarray<_Tp>::operator[](valarray<size_t>&& __vs) {
2334  return indirect_array<value_type>(std::move(__vs), *this);
2335}
2336
2337#endif // _LIBCPP_CXX03_LANG
2338
2339template <class _Tp>
2340inline __val_expr<_UnaryOp<__unary_plus<_Tp>, const valarray<_Tp>&> > valarray<_Tp>::operator+() const {
2341  using _Op = _UnaryOp<__unary_plus<_Tp>, const valarray<_Tp>&>;
2342  return __val_expr<_Op>(_Op(__unary_plus<_Tp>(), *this));
2343}
2344
2345template <class _Tp>
2346inline __val_expr<_UnaryOp<negate<_Tp>, const valarray<_Tp>&> > valarray<_Tp>::operator-() const {
2347  using _Op = _UnaryOp<negate<_Tp>, const valarray<_Tp>&>;
2348  return __val_expr<_Op>(_Op(negate<_Tp>(), *this));
2349}
2350
2351template <class _Tp>
2352inline __val_expr<_UnaryOp<__bit_not<_Tp>, const valarray<_Tp>&> > valarray<_Tp>::operator~() const {
2353  using _Op = _UnaryOp<__bit_not<_Tp>, const valarray<_Tp>&>;
2354  return __val_expr<_Op>(_Op(__bit_not<_Tp>(), *this));
2355}
2356
2357template <class _Tp>
2358inline __val_expr<_UnaryOp<logical_not<_Tp>, const valarray<_Tp>&> > valarray<_Tp>::operator!() const {
2359  using _Op = _UnaryOp<logical_not<_Tp>, const valarray<_Tp>&>;
2360  return __val_expr<_Op>(_Op(logical_not<_Tp>(), *this));
2361}
2362
2363template <class _Tp>
2364inline valarray<_Tp>& valarray<_Tp>::operator*=(const value_type& __x) {
2365  for (value_type* __p = __begin_; __p != __end_; ++__p)
2366    *__p *= __x;
2367  return *this;
2368}
2369
2370template <class _Tp>
2371inline valarray<_Tp>& valarray<_Tp>::operator/=(const value_type& __x) {
2372  for (value_type* __p = __begin_; __p != __end_; ++__p)
2373    *__p /= __x;
2374  return *this;
2375}
2376
2377template <class _Tp>
2378inline valarray<_Tp>& valarray<_Tp>::operator%=(const value_type& __x) {
2379  for (value_type* __p = __begin_; __p != __end_; ++__p)
2380    *__p %= __x;
2381  return *this;
2382}
2383
2384template <class _Tp>
2385inline valarray<_Tp>& valarray<_Tp>::operator+=(const value_type& __x) {
2386  for (value_type* __p = __begin_; __p != __end_; ++__p)
2387    *__p += __x;
2388  return *this;
2389}
2390
2391template <class _Tp>
2392inline valarray<_Tp>& valarray<_Tp>::operator-=(const value_type& __x) {
2393  for (value_type* __p = __begin_; __p != __end_; ++__p)
2394    *__p -= __x;
2395  return *this;
2396}
2397
2398template <class _Tp>
2399inline valarray<_Tp>& valarray<_Tp>::operator^=(const value_type& __x) {
2400  for (value_type* __p = __begin_; __p != __end_; ++__p)
2401    *__p ^= __x;
2402  return *this;
2403}
2404
2405template <class _Tp>
2406inline valarray<_Tp>& valarray<_Tp>::operator&=(const value_type& __x) {
2407  for (value_type* __p = __begin_; __p != __end_; ++__p)
2408    *__p &= __x;
2409  return *this;
2410}
2411
2412template <class _Tp>
2413inline valarray<_Tp>& valarray<_Tp>::operator|=(const value_type& __x) {
2414  for (value_type* __p = __begin_; __p != __end_; ++__p)
2415    *__p |= __x;
2416  return *this;
2417}
2418
2419template <class _Tp>
2420inline valarray<_Tp>& valarray<_Tp>::operator<<=(const value_type& __x) {
2421  for (value_type* __p = __begin_; __p != __end_; ++__p)
2422    *__p <<= __x;
2423  return *this;
2424}
2425
2426template <class _Tp>
2427inline valarray<_Tp>& valarray<_Tp>::operator>>=(const value_type& __x) {
2428  for (value_type* __p = __begin_; __p != __end_; ++__p)
2429    *__p >>= __x;
2430  return *this;
2431}
2432
2433template <class _Tp>
2434template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2435inline valarray<_Tp>& valarray<_Tp>::operator*=(const _Expr& __v) {
2436  size_t __i = 0;
2437  for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2438    *__t *= std::__get(__v, __i);
2439  return *this;
2440}
2441
2442template <class _Tp>
2443template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2444inline valarray<_Tp>& valarray<_Tp>::operator/=(const _Expr& __v) {
2445  size_t __i = 0;
2446  for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2447    *__t /= std::__get(__v, __i);
2448  return *this;
2449}
2450
2451template <class _Tp>
2452template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2453inline valarray<_Tp>& valarray<_Tp>::operator%=(const _Expr& __v) {
2454  size_t __i = 0;
2455  for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2456    *__t %= std::__get(__v, __i);
2457  return *this;
2458}
2459
2460template <class _Tp>
2461template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2462inline valarray<_Tp>& valarray<_Tp>::operator+=(const _Expr& __v) {
2463  size_t __i = 0;
2464  for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2465    *__t += std::__get(__v, __i);
2466  return *this;
2467}
2468
2469template <class _Tp>
2470template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2471inline valarray<_Tp>& valarray<_Tp>::operator-=(const _Expr& __v) {
2472  size_t __i = 0;
2473  for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2474    *__t -= std::__get(__v, __i);
2475  return *this;
2476}
2477
2478template <class _Tp>
2479template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2480inline valarray<_Tp>& valarray<_Tp>::operator^=(const _Expr& __v) {
2481  size_t __i = 0;
2482  for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2483    *__t ^= std::__get(__v, __i);
2484  return *this;
2485}
2486
2487template <class _Tp>
2488template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2489inline valarray<_Tp>& valarray<_Tp>::operator|=(const _Expr& __v) {
2490  size_t __i = 0;
2491  for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2492    *__t |= std::__get(__v, __i);
2493  return *this;
2494}
2495
2496template <class _Tp>
2497template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2498inline valarray<_Tp>& valarray<_Tp>::operator&=(const _Expr& __v) {
2499  size_t __i = 0;
2500  for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2501    *__t &= std::__get(__v, __i);
2502  return *this;
2503}
2504
2505template <class _Tp>
2506template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2507inline valarray<_Tp>& valarray<_Tp>::operator<<=(const _Expr& __v) {
2508  size_t __i = 0;
2509  for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2510    *__t <<= std::__get(__v, __i);
2511  return *this;
2512}
2513
2514template <class _Tp>
2515template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
2516inline valarray<_Tp>& valarray<_Tp>::operator>>=(const _Expr& __v) {
2517  size_t __i = 0;
2518  for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
2519    *__t >>= std::__get(__v, __i);
2520  return *this;
2521}
2522
2523template <class _Tp>
2524inline void valarray<_Tp>::swap(valarray& __v) _NOEXCEPT {
2525  std::swap(__begin_, __v.__begin_);
2526  std::swap(__end_, __v.__end_);
2527}
2528
2529template <class _Tp>
2530inline _Tp valarray<_Tp>::sum() const {
2531  if (__begin_ == __end_)
2532    return value_type();
2533  const value_type* __p = __begin_;
2534  _Tp __r               = *__p;
2535  for (++__p; __p != __end_; ++__p)
2536    __r += *__p;
2537  return __r;
2538}
2539
2540template <class _Tp>
2541inline _Tp valarray<_Tp>::min() const {
2542  if (__begin_ == __end_)
2543    return value_type();
2544  return *std::min_element(__begin_, __end_);
2545}
2546
2547template <class _Tp>
2548inline _Tp valarray<_Tp>::max() const {
2549  if (__begin_ == __end_)
2550    return value_type();
2551  return *std::max_element(__begin_, __end_);
2552}
2553
2554template <class _Tp>
2555valarray<_Tp> valarray<_Tp>::shift(int __i) const {
2556  valarray<value_type> __r;
2557  size_t __n = size();
2558  if (__n) {
2559    __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
2560    const value_type* __sb;
2561    value_type* __tb;
2562    value_type* __te;
2563    if (__i >= 0) {
2564      __i  = std::min(__i, static_cast<int>(__n));
2565      __sb = __begin_ + __i;
2566      __tb = __r.__begin_;
2567      __te = __r.__begin_ + (__n - __i);
2568    } else {
2569      __i  = std::min(-__i, static_cast<int>(__n));
2570      __sb = __begin_;
2571      __tb = __r.__begin_ + __i;
2572      __te = __r.__begin_ + __n;
2573    }
2574    for (; __r.__end_ != __tb; ++__r.__end_)
2575      ::new ((void*)__r.__end_) value_type();
2576    for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
2577      ::new ((void*)__r.__end_) value_type(*__sb);
2578    for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
2579      ::new ((void*)__r.__end_) value_type();
2580  }
2581  return __r;
2582}
2583
2584template <class _Tp>
2585valarray<_Tp> valarray<_Tp>::cshift(int __i) const {
2586  valarray<value_type> __r;
2587  size_t __n = size();
2588  if (__n) {
2589    __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
2590    __i %= static_cast<int>(__n);
2591    const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
2592    for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
2593      ::new ((void*)__r.__end_) value_type(*__s);
2594    for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
2595      ::new ((void*)__r.__end_) value_type(*__s);
2596  }
2597  return __r;
2598}
2599
2600template <class _Tp>
2601valarray<_Tp> valarray<_Tp>::apply(value_type __f(value_type)) const {
2602  valarray<value_type> __r;
2603  size_t __n = size();
2604  if (__n) {
2605    __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
2606    for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
2607      ::new ((void*)__r.__end_) value_type(__f(*__p));
2608  }
2609  return __r;
2610}
2611
2612template <class _Tp>
2613valarray<_Tp> valarray<_Tp>::apply(value_type __f(const value_type&)) const {
2614  valarray<value_type> __r;
2615  size_t __n = size();
2616  if (__n) {
2617    __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
2618    for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
2619      ::new ((void*)__r.__end_) value_type(__f(*__p));
2620  }
2621  return __r;
2622}
2623
2624template <class _Tp>
2625inline void valarray<_Tp>::__clear(size_t __capacity) {
2626  if (__begin_ != nullptr) {
2627    while (__end_ != __begin_)
2628      (--__end_)->~value_type();
2629    allocator<value_type>().deallocate(__begin_, __capacity);
2630    __begin_ = __end_ = nullptr;
2631  }
2632}
2633
2634template <class _Tp>
2635void valarray<_Tp>::resize(size_t __n, value_type __x) {
2636  __clear(size());
2637  if (__n) {
2638    __begin_ = __end_ = allocator<value_type>().allocate(__n);
2639#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2640    try {
2641#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2642      for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
2643        ::new ((void*)__end_) value_type(__x);
2644#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2645    } catch (...) {
2646      __clear(__n);
2647      throw;
2648    }
2649#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2650  }
2651}
2652
2653template <class _Tp>
2654inline _LIBCPP_HIDE_FROM_ABI void swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT {
2655  __x.swap(__y);
2656}
2657
2658template <class _Expr1,
2659          class _Expr2,
2660          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2661inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
2662operator*(const _Expr1& __x, const _Expr2& __y) {
2663  typedef typename _Expr1::value_type value_type;
2664  typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
2665  return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
2666}
2667
2668template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2669inline _LIBCPP_HIDE_FROM_ABI
2670__val_expr<_BinaryOp<multiplies<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2671operator*(const _Expr& __x, const typename _Expr::value_type& __y) {
2672  typedef typename _Expr::value_type value_type;
2673  typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2674  return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2675}
2676
2677template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2678inline _LIBCPP_HIDE_FROM_ABI
2679__val_expr<_BinaryOp<multiplies<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2680operator*(const typename _Expr::value_type& __x, const _Expr& __y) {
2681  typedef typename _Expr::value_type value_type;
2682  typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2683  return __val_expr<_Op>(_Op(multiplies<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2684}
2685
2686template <class _Expr1,
2687          class _Expr2,
2688          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2689inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
2690operator/(const _Expr1& __x, const _Expr2& __y) {
2691  typedef typename _Expr1::value_type value_type;
2692  typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
2693  return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
2694}
2695
2696template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2697inline _LIBCPP_HIDE_FROM_ABI
2698__val_expr<_BinaryOp<divides<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2699operator/(const _Expr& __x, const typename _Expr::value_type& __y) {
2700  typedef typename _Expr::value_type value_type;
2701  typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2702  return __val_expr<_Op>(_Op(divides<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2703}
2704
2705template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2706inline _LIBCPP_HIDE_FROM_ABI
2707__val_expr<_BinaryOp<divides<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2708operator/(const typename _Expr::value_type& __x, const _Expr& __y) {
2709  typedef typename _Expr::value_type value_type;
2710  typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2711  return __val_expr<_Op>(_Op(divides<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2712}
2713
2714template <class _Expr1,
2715          class _Expr2,
2716          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2717inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
2718operator%(const _Expr1& __x, const _Expr2& __y) {
2719  typedef typename _Expr1::value_type value_type;
2720  typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
2721  return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
2722}
2723
2724template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2725inline _LIBCPP_HIDE_FROM_ABI
2726__val_expr<_BinaryOp<modulus<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2727operator%(const _Expr& __x, const typename _Expr::value_type& __y) {
2728  typedef typename _Expr::value_type value_type;
2729  typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2730  return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2731}
2732
2733template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2734inline _LIBCPP_HIDE_FROM_ABI
2735__val_expr<_BinaryOp<modulus<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2736operator%(const typename _Expr::value_type& __x, const _Expr& __y) {
2737  typedef typename _Expr::value_type value_type;
2738  typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2739  return __val_expr<_Op>(_Op(modulus<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2740}
2741
2742template <class _Expr1,
2743          class _Expr2,
2744          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2745inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
2746operator+(const _Expr1& __x, const _Expr2& __y) {
2747  typedef typename _Expr1::value_type value_type;
2748  typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
2749  return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
2750}
2751
2752template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2753inline _LIBCPP_HIDE_FROM_ABI
2754__val_expr<_BinaryOp<plus<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2755operator+(const _Expr& __x, const typename _Expr::value_type& __y) {
2756  typedef typename _Expr::value_type value_type;
2757  typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2758  return __val_expr<_Op>(_Op(plus<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2759}
2760
2761template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2762inline _LIBCPP_HIDE_FROM_ABI
2763__val_expr<_BinaryOp<plus<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2764operator+(const typename _Expr::value_type& __x, const _Expr& __y) {
2765  typedef typename _Expr::value_type value_type;
2766  typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2767  return __val_expr<_Op>(_Op(plus<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2768}
2769
2770template <class _Expr1,
2771          class _Expr2,
2772          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2773inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
2774operator-(const _Expr1& __x, const _Expr2& __y) {
2775  typedef typename _Expr1::value_type value_type;
2776  typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
2777  return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
2778}
2779
2780template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2781inline _LIBCPP_HIDE_FROM_ABI
2782__val_expr<_BinaryOp<minus<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2783operator-(const _Expr& __x, const typename _Expr::value_type& __y) {
2784  typedef typename _Expr::value_type value_type;
2785  typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2786  return __val_expr<_Op>(_Op(minus<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2787}
2788
2789template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2790inline _LIBCPP_HIDE_FROM_ABI
2791__val_expr<_BinaryOp<minus<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2792operator-(const typename _Expr::value_type& __x, const _Expr& __y) {
2793  typedef typename _Expr::value_type value_type;
2794  typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2795  return __val_expr<_Op>(_Op(minus<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2796}
2797
2798template <class _Expr1,
2799          class _Expr2,
2800          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2801inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
2802operator^(const _Expr1& __x, const _Expr2& __y) {
2803  typedef typename _Expr1::value_type value_type;
2804  typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
2805  return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
2806}
2807
2808template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2809inline _LIBCPP_HIDE_FROM_ABI
2810__val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2811operator^(const _Expr& __x, const typename _Expr::value_type& __y) {
2812  typedef typename _Expr::value_type value_type;
2813  typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2814  return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2815}
2816
2817template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2818inline _LIBCPP_HIDE_FROM_ABI
2819__val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2820operator^(const typename _Expr::value_type& __x, const _Expr& __y) {
2821  typedef typename _Expr::value_type value_type;
2822  typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2823  return __val_expr<_Op>(_Op(bit_xor<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2824}
2825
2826template <class _Expr1,
2827          class _Expr2,
2828          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2829inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
2830operator&(const _Expr1& __x, const _Expr2& __y) {
2831  typedef typename _Expr1::value_type value_type;
2832  typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
2833  return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
2834}
2835
2836template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2837inline _LIBCPP_HIDE_FROM_ABI
2838__val_expr<_BinaryOp<bit_and<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2839operator&(const _Expr& __x, const typename _Expr::value_type& __y) {
2840  typedef typename _Expr::value_type value_type;
2841  typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2842  return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2843}
2844
2845template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2846inline _LIBCPP_HIDE_FROM_ABI
2847__val_expr<_BinaryOp<bit_and<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2848operator&(const typename _Expr::value_type& __x, const _Expr& __y) {
2849  typedef typename _Expr::value_type value_type;
2850  typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2851  return __val_expr<_Op>(_Op(bit_and<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2852}
2853
2854template <class _Expr1,
2855          class _Expr2,
2856          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2857inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
2858operator|(const _Expr1& __x, const _Expr2& __y) {
2859  typedef typename _Expr1::value_type value_type;
2860  typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
2861  return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
2862}
2863
2864template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2865inline _LIBCPP_HIDE_FROM_ABI
2866__val_expr<_BinaryOp<bit_or<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2867operator|(const _Expr& __x, const typename _Expr::value_type& __y) {
2868  typedef typename _Expr::value_type value_type;
2869  typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2870  return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2871}
2872
2873template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2874inline _LIBCPP_HIDE_FROM_ABI
2875__val_expr<_BinaryOp<bit_or<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2876operator|(const typename _Expr::value_type& __x, const _Expr& __y) {
2877  typedef typename _Expr::value_type value_type;
2878  typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2879  return __val_expr<_Op>(_Op(bit_or<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2880}
2881
2882template <class _Expr1,
2883          class _Expr2,
2884          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2885inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
2886operator<<(const _Expr1& __x, const _Expr2& __y) {
2887  typedef typename _Expr1::value_type value_type;
2888  typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
2889  return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
2890}
2891
2892template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2893inline _LIBCPP_HIDE_FROM_ABI
2894__val_expr< _BinaryOp<__bit_shift_left<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2895operator<<(const _Expr& __x, const typename _Expr::value_type& __y) {
2896  typedef typename _Expr::value_type value_type;
2897  typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2898  return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2899}
2900
2901template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2902inline _LIBCPP_HIDE_FROM_ABI
2903__val_expr< _BinaryOp<__bit_shift_left<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2904operator<<(const typename _Expr::value_type& __x, const _Expr& __y) {
2905  typedef typename _Expr::value_type value_type;
2906  typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2907  return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2908}
2909
2910template <class _Expr1,
2911          class _Expr2,
2912          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2913inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
2914operator>>(const _Expr1& __x, const _Expr2& __y) {
2915  typedef typename _Expr1::value_type value_type;
2916  typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
2917  return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
2918}
2919
2920template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2921inline _LIBCPP_HIDE_FROM_ABI __val_expr<
2922    _BinaryOp<__bit_shift_right<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2923operator>>(const _Expr& __x, const typename _Expr::value_type& __y) {
2924  typedef typename _Expr::value_type value_type;
2925  typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2926  return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2927}
2928
2929template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2930inline _LIBCPP_HIDE_FROM_ABI
2931__val_expr< _BinaryOp<__bit_shift_right<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2932operator>>(const typename _Expr::value_type& __x, const _Expr& __y) {
2933  typedef typename _Expr::value_type value_type;
2934  typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2935  return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2936}
2937
2938template <class _Expr1,
2939          class _Expr2,
2940          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2941inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
2942operator&&(const _Expr1& __x, const _Expr2& __y) {
2943  typedef typename _Expr1::value_type value_type;
2944  typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
2945  return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
2946}
2947
2948template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2949inline _LIBCPP_HIDE_FROM_ABI
2950__val_expr<_BinaryOp<logical_and<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2951operator&&(const _Expr& __x, const typename _Expr::value_type& __y) {
2952  typedef typename _Expr::value_type value_type;
2953  typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2954  return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2955}
2956
2957template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2958inline _LIBCPP_HIDE_FROM_ABI
2959__val_expr<_BinaryOp<logical_and<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2960operator&&(const typename _Expr::value_type& __x, const _Expr& __y) {
2961  typedef typename _Expr::value_type value_type;
2962  typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2963  return __val_expr<_Op>(_Op(logical_and<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2964}
2965
2966template <class _Expr1,
2967          class _Expr2,
2968          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2969inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
2970operator||(const _Expr1& __x, const _Expr2& __y) {
2971  typedef typename _Expr1::value_type value_type;
2972  typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
2973  return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
2974}
2975
2976template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2977inline _LIBCPP_HIDE_FROM_ABI
2978__val_expr<_BinaryOp<logical_or<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
2979operator||(const _Expr& __x, const typename _Expr::value_type& __y) {
2980  typedef typename _Expr::value_type value_type;
2981  typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
2982  return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
2983}
2984
2985template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
2986inline _LIBCPP_HIDE_FROM_ABI
2987__val_expr<_BinaryOp<logical_or<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
2988operator||(const typename _Expr::value_type& __x, const _Expr& __y) {
2989  typedef typename _Expr::value_type value_type;
2990  typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
2991  return __val_expr<_Op>(_Op(logical_or<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
2992}
2993
2994template <class _Expr1,
2995          class _Expr2,
2996          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
2997inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
2998operator==(const _Expr1& __x, const _Expr2& __y) {
2999  typedef typename _Expr1::value_type value_type;
3000  typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
3001  return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
3002}
3003
3004template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3005inline _LIBCPP_HIDE_FROM_ABI
3006__val_expr<_BinaryOp<equal_to<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
3007operator==(const _Expr& __x, const typename _Expr::value_type& __y) {
3008  typedef typename _Expr::value_type value_type;
3009  typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3010  return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
3011}
3012
3013template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3014inline _LIBCPP_HIDE_FROM_ABI
3015__val_expr<_BinaryOp<equal_to<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
3016operator==(const typename _Expr::value_type& __x, const _Expr& __y) {
3017  typedef typename _Expr::value_type value_type;
3018  typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3019  return __val_expr<_Op>(_Op(equal_to<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
3020}
3021
3022template <class _Expr1,
3023          class _Expr2,
3024          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
3025inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
3026operator!=(const _Expr1& __x, const _Expr2& __y) {
3027  typedef typename _Expr1::value_type value_type;
3028  typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
3029  return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
3030}
3031
3032template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3033inline _LIBCPP_HIDE_FROM_ABI
3034__val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
3035operator!=(const _Expr& __x, const typename _Expr::value_type& __y) {
3036  typedef typename _Expr::value_type value_type;
3037  typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3038  return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
3039}
3040
3041template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3042inline _LIBCPP_HIDE_FROM_ABI
3043__val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
3044operator!=(const typename _Expr::value_type& __x, const _Expr& __y) {
3045  typedef typename _Expr::value_type value_type;
3046  typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3047  return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
3048}
3049
3050template <class _Expr1,
3051          class _Expr2,
3052          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
3053inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
3054operator<(const _Expr1& __x, const _Expr2& __y) {
3055  typedef typename _Expr1::value_type value_type;
3056  typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
3057  return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
3058}
3059
3060template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3061inline _LIBCPP_HIDE_FROM_ABI
3062__val_expr<_BinaryOp<less<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
3063operator<(const _Expr& __x, const typename _Expr::value_type& __y) {
3064  typedef typename _Expr::value_type value_type;
3065  typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3066  return __val_expr<_Op>(_Op(less<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
3067}
3068
3069template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3070inline _LIBCPP_HIDE_FROM_ABI
3071__val_expr<_BinaryOp<less<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
3072operator<(const typename _Expr::value_type& __x, const _Expr& __y) {
3073  typedef typename _Expr::value_type value_type;
3074  typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3075  return __val_expr<_Op>(_Op(less<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
3076}
3077
3078template <class _Expr1,
3079          class _Expr2,
3080          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
3081inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
3082operator>(const _Expr1& __x, const _Expr2& __y) {
3083  typedef typename _Expr1::value_type value_type;
3084  typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
3085  return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
3086}
3087
3088template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3089inline _LIBCPP_HIDE_FROM_ABI
3090__val_expr<_BinaryOp<greater<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
3091operator>(const _Expr& __x, const typename _Expr::value_type& __y) {
3092  typedef typename _Expr::value_type value_type;
3093  typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3094  return __val_expr<_Op>(_Op(greater<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
3095}
3096
3097template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3098inline _LIBCPP_HIDE_FROM_ABI
3099__val_expr<_BinaryOp<greater<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
3100operator>(const typename _Expr::value_type& __x, const _Expr& __y) {
3101  typedef typename _Expr::value_type value_type;
3102  typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3103  return __val_expr<_Op>(_Op(greater<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
3104}
3105
3106template <class _Expr1,
3107          class _Expr2,
3108          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
3109inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
3110operator<=(const _Expr1& __x, const _Expr2& __y) {
3111  typedef typename _Expr1::value_type value_type;
3112  typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
3113  return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
3114}
3115
3116template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3117inline _LIBCPP_HIDE_FROM_ABI
3118__val_expr<_BinaryOp<less_equal<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
3119operator<=(const _Expr& __x, const typename _Expr::value_type& __y) {
3120  typedef typename _Expr::value_type value_type;
3121  typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3122  return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
3123}
3124
3125template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3126inline _LIBCPP_HIDE_FROM_ABI
3127__val_expr<_BinaryOp<less_equal<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
3128operator<=(const typename _Expr::value_type& __x, const _Expr& __y) {
3129  typedef typename _Expr::value_type value_type;
3130  typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3131  return __val_expr<_Op>(_Op(less_equal<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
3132}
3133
3134template <class _Expr1,
3135          class _Expr2,
3136          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
3137inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
3138operator>=(const _Expr1& __x, const _Expr2& __y) {
3139  typedef typename _Expr1::value_type value_type;
3140  typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
3141  return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
3142}
3143
3144template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3145inline _LIBCPP_HIDE_FROM_ABI
3146__val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
3147operator>=(const _Expr& __x, const typename _Expr::value_type& __y) {
3148  typedef typename _Expr::value_type value_type;
3149  typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3150  return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
3151}
3152
3153template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3154inline _LIBCPP_HIDE_FROM_ABI
3155__val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
3156operator>=(const typename _Expr::value_type& __x, const _Expr& __y) {
3157  typedef typename _Expr::value_type value_type;
3158  typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3159  return __val_expr<_Op>(_Op(greater_equal<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
3160}
3161
3162template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3163inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
3164abs(const _Expr& __x) {
3165  typedef typename _Expr::value_type value_type;
3166  typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
3167  return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
3168}
3169
3170template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3171inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
3172acos(const _Expr& __x) {
3173  typedef typename _Expr::value_type value_type;
3174  typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
3175  return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
3176}
3177
3178template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3179inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
3180asin(const _Expr& __x) {
3181  typedef typename _Expr::value_type value_type;
3182  typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
3183  return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
3184}
3185
3186template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3187inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
3188atan(const _Expr& __x) {
3189  typedef typename _Expr::value_type value_type;
3190  typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
3191  return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
3192}
3193
3194template <class _Expr1,
3195          class _Expr2,
3196          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
3197inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
3198atan2(const _Expr1& __x, const _Expr2& __y) {
3199  typedef typename _Expr1::value_type value_type;
3200  typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
3201  return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
3202}
3203
3204template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3205inline _LIBCPP_HIDE_FROM_ABI
3206__val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
3207atan2(const _Expr& __x, const typename _Expr::value_type& __y) {
3208  typedef typename _Expr::value_type value_type;
3209  typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3210  return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
3211}
3212
3213template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3214inline _LIBCPP_HIDE_FROM_ABI
3215__val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
3216atan2(const typename _Expr::value_type& __x, const _Expr& __y) {
3217  typedef typename _Expr::value_type value_type;
3218  typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3219  return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
3220}
3221
3222template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3223inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
3224cos(const _Expr& __x) {
3225  typedef typename _Expr::value_type value_type;
3226  typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
3227  return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
3228}
3229
3230template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3231inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
3232cosh(const _Expr& __x) {
3233  typedef typename _Expr::value_type value_type;
3234  typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
3235  return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
3236}
3237
3238template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3239inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
3240exp(const _Expr& __x) {
3241  typedef typename _Expr::value_type value_type;
3242  typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
3243  return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
3244}
3245
3246template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3247inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
3248log(const _Expr& __x) {
3249  typedef typename _Expr::value_type value_type;
3250  typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
3251  return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
3252}
3253
3254template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3255inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
3256log10(const _Expr& __x) {
3257  typedef typename _Expr::value_type value_type;
3258  typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
3259  return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
3260}
3261
3262template <class _Expr1,
3263          class _Expr2,
3264          __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
3265inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
3266pow(const _Expr1& __x, const _Expr2& __y) {
3267  typedef typename _Expr1::value_type value_type;
3268  typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
3269  return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
3270}
3271
3272template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3273inline _LIBCPP_HIDE_FROM_ABI
3274__val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
3275pow(const _Expr& __x, const typename _Expr::value_type& __y) {
3276  typedef typename _Expr::value_type value_type;
3277  typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3278  return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
3279}
3280
3281template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3282inline _LIBCPP_HIDE_FROM_ABI
3283__val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
3284pow(const typename _Expr::value_type& __x, const _Expr& __y) {
3285  typedef typename _Expr::value_type value_type;
3286  typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3287  return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
3288}
3289
3290template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3291inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
3292sin(const _Expr& __x) {
3293  typedef typename _Expr::value_type value_type;
3294  typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
3295  return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
3296}
3297
3298template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3299inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
3300sinh(const _Expr& __x) {
3301  typedef typename _Expr::value_type value_type;
3302  typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
3303  return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
3304}
3305
3306template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3307inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
3308sqrt(const _Expr& __x) {
3309  typedef typename _Expr::value_type value_type;
3310  typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
3311  return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
3312}
3313
3314template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3315inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
3316tan(const _Expr& __x) {
3317  typedef typename _Expr::value_type value_type;
3318  typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
3319  return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
3320}
3321
3322template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
3323inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
3324tanh(const _Expr& __x) {
3325  typedef typename _Expr::value_type value_type;
3326  typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
3327  return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
3328}
3329
3330template <class _Tp>
3331inline _LIBCPP_HIDE_FROM_ABI _Tp* begin(valarray<_Tp>& __v) {
3332  return __v.__begin_;
3333}
3334
3335template <class _Tp>
3336inline _LIBCPP_HIDE_FROM_ABI const _Tp* begin(const valarray<_Tp>& __v) {
3337  return __v.__begin_;
3338}
3339
3340template <class _Tp>
3341inline _LIBCPP_HIDE_FROM_ABI _Tp* end(valarray<_Tp>& __v) {
3342  return __v.__end_;
3343}
3344
3345template <class _Tp>
3346inline _LIBCPP_HIDE_FROM_ABI const _Tp* end(const valarray<_Tp>& __v) {
3347  return __v.__end_;
3348}
3349
3350_LIBCPP_END_NAMESPACE_STD
3351
3352_LIBCPP_POP_MACROS
3353
3354#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
3355#  include <algorithm>
3356#  include <concepts>
3357#  include <cstdlib>
3358#  include <cstring>
3359#  include <functional>
3360#  include <stdexcept>
3361#  include <type_traits>
3362#endif
3363
3364#endif // _LIBCPP_VALARRAY
3365