blob: 9654cd5aa998f8a3150d89730adcf62a8a7cbea0 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- valarray ----------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// 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
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
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);
Howard Hinnant298aed92012-07-21 00:51:28 +000031 valarray(valarray&& v) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000032 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);
Howard Hinnant298aed92012-07-21 00:51:28 +000041 valarray& operator=(valarray&& v) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000042 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:
Howard Hinnant298aed92012-07-21 00:51:28 +000093 void swap(valarray& v) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000094
95 size_t size() const;
96
97 value_type sum() const;
98 value_type min() const;
99 value_type max() const;
100
101 valarray shift (int i) const;
102 valarray cshift(int i) const;
103 valarray apply(value_type f(value_type)) const;
104 valarray apply(value_type f(const value_type&)) const;
105 void resize(size_t n, value_type x = value_type());
106};
107
108class slice
109{
110public:
111 slice();
112 slice(size_t start, size_t size, size_t stride);
113
114 size_t start() const;
115 size_t size() const;
116 size_t stride() const;
117};
118
119template <class T>
120class slice_array
121{
122public:
123 typedef T value_type;
124
125 const slice_array& operator=(const slice_array& sa) const;
126 void operator= (const valarray<value_type>& v) const;
127 void operator*= (const valarray<value_type>& v) const;
128 void operator/= (const valarray<value_type>& v) const;
129 void operator%= (const valarray<value_type>& v) const;
130 void operator+= (const valarray<value_type>& v) const;
131 void operator-= (const valarray<value_type>& v) const;
132 void operator^= (const valarray<value_type>& v) const;
133 void operator&= (const valarray<value_type>& v) const;
134 void operator|= (const valarray<value_type>& v) const;
135 void operator<<=(const valarray<value_type>& v) const;
136 void operator>>=(const valarray<value_type>& v) const;
137
138 void operator=(const value_type& x) const;
zoecarver79fa7502020-12-02 10:49:20 -0800139 void operator=(const valarray<T>& val_arr) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000140
141 slice_array() = delete;
142};
143
144class gslice
145{
146public:
147 gslice();
148 gslice(size_t start, const valarray<size_t>& size,
149 const valarray<size_t>& stride);
150
151 size_t start() const;
152 valarray<size_t> size() const;
153 valarray<size_t> stride() const;
154};
155
156template <class T>
157class gslice_array
158{
159public:
160 typedef T value_type;
161
162 void operator= (const valarray<value_type>& v) const;
163 void operator*= (const valarray<value_type>& v) const;
164 void operator/= (const valarray<value_type>& v) const;
165 void operator%= (const valarray<value_type>& v) const;
166 void operator+= (const valarray<value_type>& v) const;
167 void operator-= (const valarray<value_type>& v) const;
168 void operator^= (const valarray<value_type>& v) const;
169 void operator&= (const valarray<value_type>& v) const;
170 void operator|= (const valarray<value_type>& v) const;
171 void operator<<=(const valarray<value_type>& v) const;
172 void operator>>=(const valarray<value_type>& v) const;
173
174 gslice_array(const gslice_array& ga);
175 ~gslice_array();
176 const gslice_array& operator=(const gslice_array& ga) const;
177 void operator=(const value_type& x) const;
178
179 gslice_array() = delete;
180};
181
182template <class T>
183class mask_array
184{
185public:
186 typedef T value_type;
187
188 void operator= (const valarray<value_type>& v) const;
189 void operator*= (const valarray<value_type>& v) const;
190 void operator/= (const valarray<value_type>& v) const;
191 void operator%= (const valarray<value_type>& v) const;
192 void operator+= (const valarray<value_type>& v) const;
193 void operator-= (const valarray<value_type>& v) const;
194 void operator^= (const valarray<value_type>& v) const;
195 void operator&= (const valarray<value_type>& v) const;
196 void operator|= (const valarray<value_type>& v) const;
197 void operator<<=(const valarray<value_type>& v) const;
198 void operator>>=(const valarray<value_type>& v) const;
199
200 mask_array(const mask_array& ma);
201 ~mask_array();
202 const mask_array& operator=(const mask_array& ma) const;
203 void operator=(const value_type& x) const;
204
205 mask_array() = delete;
206};
207
208template <class T>
209class indirect_array
210{
211public:
212 typedef T value_type;
213
214 void operator= (const valarray<value_type>& v) const;
215 void operator*= (const valarray<value_type>& v) const;
216 void operator/= (const valarray<value_type>& v) const;
217 void operator%= (const valarray<value_type>& v) const;
218 void operator+= (const valarray<value_type>& v) const;
219 void operator-= (const valarray<value_type>& v) const;
220 void operator^= (const valarray<value_type>& v) const;
221 void operator&= (const valarray<value_type>& v) const;
222 void operator|= (const valarray<value_type>& v) const;
223 void operator<<=(const valarray<value_type>& v) const;
224 void operator>>=(const valarray<value_type>& v) const;
225
226 indirect_array(const indirect_array& ia);
227 ~indirect_array();
228 const indirect_array& operator=(const indirect_array& ia) const;
229 void operator=(const value_type& x) const;
230
231 indirect_array() = delete;
232};
233
Howard Hinnant298aed92012-07-21 00:51:28 +0000234template<class T> void swap(valarray<T>& x, valarray<T>& y) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000235
236template<class T> valarray<T> operator* (const valarray<T>& x, const valarray<T>& y);
237template<class T> valarray<T> operator* (const valarray<T>& x, const T& y);
238template<class T> valarray<T> operator* (const T& x, const valarray<T>& y);
239
240template<class T> valarray<T> operator/ (const valarray<T>& x, const valarray<T>& y);
241template<class T> valarray<T> operator/ (const valarray<T>& x, const T& y);
242template<class T> valarray<T> operator/ (const T& x, const valarray<T>& y);
243
244template<class T> valarray<T> operator% (const valarray<T>& x, const valarray<T>& y);
245template<class T> valarray<T> operator% (const valarray<T>& x, const T& y);
246template<class T> valarray<T> operator% (const T& x, const valarray<T>& y);
247
248template<class T> valarray<T> operator+ (const valarray<T>& x, const valarray<T>& y);
249template<class T> valarray<T> operator+ (const valarray<T>& x, const T& y);
250template<class T> valarray<T> operator+ (const T& x, const valarray<T>& y);
251
252template<class T> valarray<T> operator- (const valarray<T>& x, const valarray<T>& y);
253template<class T> valarray<T> operator- (const valarray<T>& x, const T& y);
254template<class T> valarray<T> operator- (const T& x, const valarray<T>& y);
255
256template<class T> valarray<T> operator^ (const valarray<T>& x, const valarray<T>& y);
257template<class T> valarray<T> operator^ (const valarray<T>& x, const T& y);
258template<class T> valarray<T> operator^ (const T& x, const valarray<T>& y);
259
260template<class T> valarray<T> operator& (const valarray<T>& x, const valarray<T>& y);
261template<class T> valarray<T> operator& (const valarray<T>& x, const T& y);
262template<class T> valarray<T> operator& (const T& x, const valarray<T>& y);
263
264template<class T> valarray<T> operator| (const valarray<T>& x, const valarray<T>& y);
265template<class T> valarray<T> operator| (const valarray<T>& x, const T& y);
266template<class T> valarray<T> operator| (const T& x, const valarray<T>& y);
267
268template<class T> valarray<T> operator<<(const valarray<T>& x, const valarray<T>& y);
269template<class T> valarray<T> operator<<(const valarray<T>& x, const T& y);
270template<class T> valarray<T> operator<<(const T& x, const valarray<T>& y);
271
272template<class T> valarray<T> operator>>(const valarray<T>& x, const valarray<T>& y);
273template<class T> valarray<T> operator>>(const valarray<T>& x, const T& y);
274template<class T> valarray<T> operator>>(const T& x, const valarray<T>& y);
275
276template<class T> valarray<bool> operator&&(const valarray<T>& x, const valarray<T>& y);
277template<class T> valarray<bool> operator&&(const valarray<T>& x, const T& y);
278template<class T> valarray<bool> operator&&(const T& x, const valarray<T>& y);
279
280template<class T> valarray<bool> operator||(const valarray<T>& x, const valarray<T>& y);
281template<class T> valarray<bool> operator||(const valarray<T>& x, const T& y);
282template<class T> valarray<bool> operator||(const T& x, const valarray<T>& y);
283
284template<class T> valarray<bool> operator==(const valarray<T>& x, const valarray<T>& y);
285template<class T> valarray<bool> operator==(const valarray<T>& x, const T& y);
286template<class T> valarray<bool> operator==(const T& x, const valarray<T>& y);
287
288template<class T> valarray<bool> operator!=(const valarray<T>& x, const valarray<T>& y);
289template<class T> valarray<bool> operator!=(const valarray<T>& x, const T& y);
290template<class T> valarray<bool> operator!=(const T& x, const valarray<T>& y);
291
292template<class T> valarray<bool> operator< (const valarray<T>& x, const valarray<T>& y);
293template<class T> valarray<bool> operator< (const valarray<T>& x, const T& y);
294template<class T> valarray<bool> operator< (const T& x, const valarray<T>& y);
295
296template<class T> valarray<bool> operator> (const valarray<T>& x, const valarray<T>& y);
297template<class T> valarray<bool> operator> (const valarray<T>& x, const T& y);
298template<class T> valarray<bool> operator> (const T& x, const valarray<T>& y);
299
300template<class T> valarray<bool> operator<=(const valarray<T>& x, const valarray<T>& y);
301template<class T> valarray<bool> operator<=(const valarray<T>& x, const T& y);
302template<class T> valarray<bool> operator<=(const T& x, const valarray<T>& y);
303
304template<class T> valarray<bool> operator>=(const valarray<T>& x, const valarray<T>& y);
305template<class T> valarray<bool> operator>=(const valarray<T>& x, const T& y);
306template<class T> valarray<bool> operator>=(const T& x, const valarray<T>& y);
307
308template<class T> valarray<T> abs (const valarray<T>& x);
309template<class T> valarray<T> acos (const valarray<T>& x);
310template<class T> valarray<T> asin (const valarray<T>& x);
311template<class T> valarray<T> atan (const valarray<T>& x);
312
313template<class T> valarray<T> atan2(const valarray<T>& x, const valarray<T>& y);
314template<class T> valarray<T> atan2(const valarray<T>& x, const T& y);
315template<class T> valarray<T> atan2(const T& x, const valarray<T>& y);
316
317template<class T> valarray<T> cos (const valarray<T>& x);
318template<class T> valarray<T> cosh (const valarray<T>& x);
319template<class T> valarray<T> exp (const valarray<T>& x);
320template<class T> valarray<T> log (const valarray<T>& x);
321template<class T> valarray<T> log10(const valarray<T>& x);
322
323template<class T> valarray<T> pow(const valarray<T>& x, const valarray<T>& y);
324template<class T> valarray<T> pow(const valarray<T>& x, const T& y);
325template<class T> valarray<T> pow(const T& x, const valarray<T>& y);
326
327template<class T> valarray<T> sin (const valarray<T>& x);
328template<class T> valarray<T> sinh (const valarray<T>& x);
329template<class T> valarray<T> sqrt (const valarray<T>& x);
330template<class T> valarray<T> tan (const valarray<T>& x);
331template<class T> valarray<T> tanh (const valarray<T>& x);
332
333template <class T> unspecified1 begin(valarray<T>& v);
334template <class T> unspecified2 begin(const valarray<T>& v);
335template <class T> unspecified1 end(valarray<T>& v);
336template <class T> unspecified2 end(const valarray<T>& v);
337
338} // std
339
340*/
341
342#include <__config>
343#include <cstddef>
344#include <cmath>
345#include <initializer_list>
346#include <algorithm>
347#include <functional>
Richard Smith1f1c1472014-06-04 19:54:15 +0000348#include <new>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000349
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000350#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000351#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000352#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000353
Eric Fiselierf4433a32017-05-31 22:07:49 +0000354_LIBCPP_PUSH_MACROS
355#include <__undef_macros>
356
357
Howard Hinnantc51e1022010-05-11 19:42:16 +0000358_LIBCPP_BEGIN_NAMESPACE_STD
359
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000360template<class _Tp> class _LIBCPP_TEMPLATE_VIS valarray;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000361
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000362class _LIBCPP_TEMPLATE_VIS slice
Howard Hinnantc51e1022010-05-11 19:42:16 +0000363{
364 size_t __start_;
365 size_t __size_;
366 size_t __stride_;
367public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000368 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000369 slice()
370 : __start_(0),
371 __size_(0),
372 __stride_(0)
373 {}
374
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000375 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000376 slice(size_t __start, size_t __size, size_t __stride)
377 : __start_(__start),
378 __size_(__size),
379 __stride_(__stride)
380 {}
381
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000382 _LIBCPP_INLINE_VISIBILITY size_t start() const {return __start_;}
383 _LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;}
384 _LIBCPP_INLINE_VISIBILITY size_t stride() const {return __stride_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000385};
386
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000387template <class _Tp> class _LIBCPP_TEMPLATE_VIS slice_array;
Howard Hinnant8331b762013-03-06 23:30:19 +0000388class _LIBCPP_TYPE_VIS gslice;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000389template <class _Tp> class _LIBCPP_TEMPLATE_VIS gslice_array;
390template <class _Tp> class _LIBCPP_TEMPLATE_VIS mask_array;
391template <class _Tp> class _LIBCPP_TEMPLATE_VIS indirect_array;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392
393template <class _Tp>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000394_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000395_Tp*
396begin(valarray<_Tp>& __v);
397
398template <class _Tp>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000399_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000400const _Tp*
401begin(const valarray<_Tp>& __v);
402
403template <class _Tp>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000404_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000405_Tp*
406end(valarray<_Tp>& __v);
407
408template <class _Tp>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000409_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000410const _Tp*
411end(const valarray<_Tp>& __v);
412
413template <class _Op, class _A0>
414struct _UnaryOp
415{
416 typedef typename _Op::result_type result_type;
417 typedef typename _A0::value_type value_type;
418
419 _Op __op_;
420 _A0 __a0_;
421
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423 _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {}
424
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000425 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000426 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
427
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000429 size_t size() const {return __a0_.size();}
430};
431
432template <class _Op, class _A0, class _A1>
433struct _BinaryOp
434{
435 typedef typename _Op::result_type result_type;
436 typedef typename _A0::value_type value_type;
437
438 _Op __op_;
439 _A0 __a0_;
440 _A1 __a1_;
441
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000442 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000443 _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1)
444 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
445
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000446 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000447 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
448
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000450 size_t size() const {return __a0_.size();}
451};
452
453template <class _Tp>
454class __scalar_expr
455{
456public:
457 typedef _Tp value_type;
458 typedef const _Tp& result_type;
459private:
460 const value_type& __t_;
461 size_t __s_;
462public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000464 explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {}
465
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000467 result_type operator[](size_t) const {return __t_;}
468
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000470 size_t size() const {return __s_;}
471};
472
473template <class _Tp>
474struct __unary_plus : unary_function<_Tp, _Tp>
475{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000477 _Tp operator()(const _Tp& __x) const
478 {return +__x;}
479};
480
481template <class _Tp>
482struct __bit_not : unary_function<_Tp, _Tp>
483{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000485 _Tp operator()(const _Tp& __x) const
486 {return ~__x;}
487};
488
489template <class _Tp>
490struct __bit_shift_left : binary_function<_Tp, _Tp, _Tp>
491{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000493 _Tp operator()(const _Tp& __x, const _Tp& __y) const
494 {return __x << __y;}
495};
496
497template <class _Tp>
498struct __bit_shift_right : binary_function<_Tp, _Tp, _Tp>
499{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501 _Tp operator()(const _Tp& __x, const _Tp& __y) const
502 {return __x >> __y;}
503};
504
Howard Hinnantc834c512011-11-29 18:15:50 +0000505template <class _Tp, class _Fp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000506struct __apply_expr : unary_function<_Tp, _Tp>
507{
508private:
Howard Hinnantc834c512011-11-29 18:15:50 +0000509 _Fp __f_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000510public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +0000512 explicit __apply_expr(_Fp __f) : __f_(__f) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000515 _Tp operator()(const _Tp& __x) const
516 {return __f_(__x);}
517};
518
519template <class _Tp>
520struct __abs_expr : unary_function<_Tp, _Tp>
521{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000523 _Tp operator()(const _Tp& __x) const
524 {return abs(__x);}
525};
526
527template <class _Tp>
528struct __acos_expr : unary_function<_Tp, _Tp>
529{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000530 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000531 _Tp operator()(const _Tp& __x) const
532 {return acos(__x);}
533};
534
535template <class _Tp>
536struct __asin_expr : unary_function<_Tp, _Tp>
537{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000539 _Tp operator()(const _Tp& __x) const
540 {return asin(__x);}
541};
542
543template <class _Tp>
544struct __atan_expr : unary_function<_Tp, _Tp>
545{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000546 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000547 _Tp operator()(const _Tp& __x) const
548 {return atan(__x);}
549};
550
551template <class _Tp>
552struct __atan2_expr : binary_function<_Tp, _Tp, _Tp>
553{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000555 _Tp operator()(const _Tp& __x, const _Tp& __y) const
556 {return atan2(__x, __y);}
557};
558
559template <class _Tp>
560struct __cos_expr : unary_function<_Tp, _Tp>
561{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000563 _Tp operator()(const _Tp& __x) const
564 {return cos(__x);}
565};
566
567template <class _Tp>
568struct __cosh_expr : unary_function<_Tp, _Tp>
569{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000571 _Tp operator()(const _Tp& __x) const
572 {return cosh(__x);}
573};
574
575template <class _Tp>
576struct __exp_expr : unary_function<_Tp, _Tp>
577{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000579 _Tp operator()(const _Tp& __x) const
580 {return exp(__x);}
581};
582
583template <class _Tp>
584struct __log_expr : unary_function<_Tp, _Tp>
585{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000587 _Tp operator()(const _Tp& __x) const
588 {return log(__x);}
589};
590
591template <class _Tp>
592struct __log10_expr : unary_function<_Tp, _Tp>
593{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000595 _Tp operator()(const _Tp& __x) const
596 {return log10(__x);}
597};
598
599template <class _Tp>
600struct __pow_expr : binary_function<_Tp, _Tp, _Tp>
601{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000603 _Tp operator()(const _Tp& __x, const _Tp& __y) const
604 {return pow(__x, __y);}
605};
606
607template <class _Tp>
608struct __sin_expr : unary_function<_Tp, _Tp>
609{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000611 _Tp operator()(const _Tp& __x) const
612 {return sin(__x);}
613};
614
615template <class _Tp>
616struct __sinh_expr : unary_function<_Tp, _Tp>
617{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000619 _Tp operator()(const _Tp& __x) const
620 {return sinh(__x);}
621};
622
623template <class _Tp>
624struct __sqrt_expr : unary_function<_Tp, _Tp>
625{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000627 _Tp operator()(const _Tp& __x) const
628 {return sqrt(__x);}
629};
630
631template <class _Tp>
632struct __tan_expr : unary_function<_Tp, _Tp>
633{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000635 _Tp operator()(const _Tp& __x) const
636 {return tan(__x);}
637};
638
639template <class _Tp>
640struct __tanh_expr : unary_function<_Tp, _Tp>
641{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000643 _Tp operator()(const _Tp& __x) const
644 {return tanh(__x);}
645};
646
647template <class _ValExpr>
648class __slice_expr
649{
650 typedef typename remove_reference<_ValExpr>::type _RmExpr;
651public:
652 typedef typename _RmExpr::value_type value_type;
653 typedef value_type result_type;
654
655private:
656 _ValExpr __expr_;
657 size_t __start_;
658 size_t __size_;
659 size_t __stride_;
660
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000662 __slice_expr(const slice& __sl, const _RmExpr& __e)
663 : __expr_(__e),
664 __start_(__sl.start()),
665 __size_(__sl.size()),
666 __stride_(__sl.stride())
667 {}
668public:
669
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000670 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671 result_type operator[](size_t __i) const
672 {return __expr_[__start_ + __i * __stride_];}
673
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000675 size_t size() const {return __size_;}
676
Eric Fiselier7b31ed02019-04-02 08:05:23 +0000677 template <class> friend class __val_expr;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000678 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000679};
680
681template <class _ValExpr>
682class __mask_expr;
683
684template <class _ValExpr>
685class __indirect_expr;
686
687template <class _ValExpr>
688class __shift_expr
689{
690 typedef typename remove_reference<_ValExpr>::type _RmExpr;
691public:
692 typedef typename _RmExpr::value_type value_type;
693 typedef value_type result_type;
694
695private:
696 _ValExpr __expr_;
697 size_t __size_;
698 ptrdiff_t __ul_;
699 ptrdiff_t __sn_;
700 ptrdiff_t __n_;
Howard Hinnantc834c512011-11-29 18:15:50 +0000701 static const ptrdiff_t _Np = static_cast<ptrdiff_t>(
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702 sizeof(ptrdiff_t) * __CHAR_BIT__ - 1);
703
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000704 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000705 __shift_expr(int __n, const _RmExpr& __e)
706 : __expr_(__e),
707 __size_(__e.size()),
708 __n_(__n)
709 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000710 ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _Np);
711 __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _Np);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000712 __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n);
713 }
714public:
715
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000717 result_type operator[](size_t __j) const
718 {
Howard Hinnant28b24882011-12-01 20:21:04 +0000719 ptrdiff_t __i = static_cast<ptrdiff_t>(__j);
Howard Hinnantc834c512011-11-29 18:15:50 +0000720 ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000721 return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
722 }
723
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000725 size_t size() const {return __size_;}
726
727 template <class> friend class __val_expr;
728};
729
730template <class _ValExpr>
731class __cshift_expr
732{
733 typedef typename remove_reference<_ValExpr>::type _RmExpr;
734public:
735 typedef typename _RmExpr::value_type value_type;
736 typedef value_type result_type;
737
738private:
739 _ValExpr __expr_;
740 size_t __size_;
741 size_t __m_;
742 size_t __o1_;
743 size_t __o2_;
744
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000745 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000746 __cshift_expr(int __n, const _RmExpr& __e)
747 : __expr_(__e),
748 __size_(__e.size())
749 {
750 __n %= static_cast<int>(__size_);
751 if (__n >= 0)
752 {
753 __m_ = __size_ - __n;
754 __o1_ = __n;
755 __o2_ = __n - __size_;
756 }
757 else
758 {
759 __m_ = -__n;
760 __o1_ = __n + __size_;
761 __o2_ = __n;
762 }
763 }
764public:
765
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000766 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000767 result_type operator[](size_t __i) const
768 {
769 if (__i < __m_)
770 return __expr_[__i + __o1_];
771 return __expr_[__i + __o2_];
772 }
773
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000774 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000775 size_t size() const {return __size_;}
776
777 template <class> friend class __val_expr;
778};
779
780template<class _ValExpr>
781class __val_expr;
782
783template<class _ValExpr>
784struct __is_val_expr : false_type {};
785
786template<class _ValExpr>
787struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
788
789template<class _Tp>
790struct __is_val_expr<valarray<_Tp> > : true_type {};
791
792template<class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000793class _LIBCPP_TEMPLATE_VIS valarray
Howard Hinnantc51e1022010-05-11 19:42:16 +0000794{
795public:
796 typedef _Tp value_type;
797 typedef _Tp result_type;
798
799private:
800 value_type* __begin_;
801 value_type* __end_;
802
803public:
804 // construct/destroy:
Douglas Gregor68902322012-05-19 07:14:17 +0000805 _LIBCPP_INLINE_VISIBILITY
Bruce Mitchener170d8972020-11-24 12:53:53 -0500806 valarray() : __begin_(nullptr), __end_(nullptr) {}
Louis Dionneb4d05d72018-10-16 19:26:23 +0000807 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Eric Fiseliere529a802016-09-16 00:13:55 +0000808 explicit valarray(size_t __n);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000809 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +0000810 valarray(const value_type& __x, size_t __n);
811 valarray(const value_type* __p, size_t __n);
812 valarray(const valarray& __v);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000813#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000814 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant298aed92012-07-21 00:51:28 +0000815 valarray(valarray&& __v) _NOEXCEPT;
Douglas Gregor68902322012-05-19 07:14:17 +0000816 valarray(initializer_list<value_type> __il);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000817#endif // _LIBCPP_CXX03_LANG
Douglas Gregor68902322012-05-19 07:14:17 +0000818 valarray(const slice_array<value_type>& __sa);
819 valarray(const gslice_array<value_type>& __ga);
820 valarray(const mask_array<value_type>& __ma);
821 valarray(const indirect_array<value_type>& __ia);
Louis Dionneb4d05d72018-10-16 19:26:23 +0000822 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Douglas Gregor68902322012-05-19 07:14:17 +0000823 ~valarray();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000824
825 // assignment:
Douglas Gregor68902322012-05-19 07:14:17 +0000826 valarray& operator=(const valarray& __v);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000827#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000828 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant298aed92012-07-21 00:51:28 +0000829 valarray& operator=(valarray&& __v) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000830 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +0000831 valarray& operator=(initializer_list<value_type>);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000832#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000833 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +0000834 valarray& operator=(const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000835 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000836 valarray& operator=(const slice_array<value_type>& __sa);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000837 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000838 valarray& operator=(const gslice_array<value_type>& __ga);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000839 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000840 valarray& operator=(const mask_array<value_type>& __ma);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000841 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000842 valarray& operator=(const indirect_array<value_type>& __ia);
Howard Hinnant329cd412011-07-27 23:19:59 +0000843 template <class _ValExpr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000844 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant329cd412011-07-27 23:19:59 +0000845 valarray& operator=(const __val_expr<_ValExpr>& __v);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000846
847 // element access:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000848 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000849 const value_type& operator[](size_t __i) const {return __begin_[__i];}
850
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000851 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000852 value_type& operator[](size_t __i) {return __begin_[__i];}
853
854 // subset operations:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000855 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000856 __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000858 slice_array<value_type> operator[](slice __s);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000859 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860 __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000861 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000862 gslice_array<value_type> operator[](const gslice& __gs);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000863#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000864 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000865 __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000866 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000867 gslice_array<value_type> operator[](gslice&& __gs);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000868#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000870 __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000872 mask_array<value_type> operator[](const valarray<bool>& __vb);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000873#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000874 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000875 __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000877 mask_array<value_type> operator[](valarray<bool>&& __vb);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000878#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000879 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000880 __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000881 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000882 indirect_array<value_type> operator[](const valarray<size_t>& __vs);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000883#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000884 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000885 __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000886 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000887 indirect_array<value_type> operator[](valarray<size_t>&& __vs);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000888#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000889
890 // unary operators:
Douglas Gregor68902322012-05-19 07:14:17 +0000891 valarray operator+() const;
892 valarray operator-() const;
893 valarray operator~() const;
894 valarray<bool> operator!() const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000895
896 // computed assignment:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000898 valarray& operator*= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000899 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000900 valarray& operator/= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000902 valarray& operator%= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000904 valarray& operator+= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000906 valarray& operator-= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000908 valarray& operator^= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000910 valarray& operator&= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000912 valarray& operator|= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000914 valarray& operator<<=(const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000915 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916 valarray& operator>>=(const value_type& __x);
917
918 template <class _Expr>
919 typename enable_if
920 <
921 __is_val_expr<_Expr>::value,
922 valarray&
923 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000924 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000925 operator*= (const _Expr& __v);
926
927 template <class _Expr>
928 typename enable_if
929 <
930 __is_val_expr<_Expr>::value,
931 valarray&
932 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000934 operator/= (const _Expr& __v);
935
936 template <class _Expr>
937 typename enable_if
938 <
939 __is_val_expr<_Expr>::value,
940 valarray&
941 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000942 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000943 operator%= (const _Expr& __v);
944
945 template <class _Expr>
946 typename enable_if
947 <
948 __is_val_expr<_Expr>::value,
949 valarray&
950 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000951 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000952 operator+= (const _Expr& __v);
953
954 template <class _Expr>
955 typename enable_if
956 <
957 __is_val_expr<_Expr>::value,
958 valarray&
959 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000960 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000961 operator-= (const _Expr& __v);
962
963 template <class _Expr>
964 typename enable_if
965 <
966 __is_val_expr<_Expr>::value,
967 valarray&
968 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000970 operator^= (const _Expr& __v);
971
972 template <class _Expr>
973 typename enable_if
974 <
975 __is_val_expr<_Expr>::value,
976 valarray&
977 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000979 operator|= (const _Expr& __v);
980
981 template <class _Expr>
982 typename enable_if
983 <
984 __is_val_expr<_Expr>::value,
985 valarray&
986 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000987 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000988 operator&= (const _Expr& __v);
989
990 template <class _Expr>
991 typename enable_if
992 <
993 __is_val_expr<_Expr>::value,
994 valarray&
995 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000996 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000997 operator<<= (const _Expr& __v);
998
999 template <class _Expr>
1000 typename enable_if
1001 <
1002 __is_val_expr<_Expr>::value,
1003 valarray&
1004 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001005 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001006 operator>>= (const _Expr& __v);
1007
1008 // member functions:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001009 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant298aed92012-07-21 00:51:28 +00001010 void swap(valarray& __v) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001011
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001012 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant28b24882011-12-01 20:21:04 +00001013 size_t size() const {return static_cast<size_t>(__end_ - __begin_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001014
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001015 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +00001016 value_type sum() const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001017 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +00001018 value_type min() const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001019 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +00001020 value_type max() const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001021
Douglas Gregor68902322012-05-19 07:14:17 +00001022 valarray shift (int __i) const;
1023 valarray cshift(int __i) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001024 valarray apply(value_type __f(value_type)) const;
1025 valarray apply(value_type __f(const value_type&)) const;
1026 void resize(size_t __n, value_type __x = value_type());
1027
1028private:
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001029 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
1030 template <class> friend class _LIBCPP_TEMPLATE_VIS slice_array;
1031 template <class> friend class _LIBCPP_TEMPLATE_VIS gslice_array;
1032 template <class> friend class _LIBCPP_TEMPLATE_VIS mask_array;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001033 template <class> friend class __mask_expr;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001034 template <class> friend class _LIBCPP_TEMPLATE_VIS indirect_array;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001035 template <class> friend class __indirect_expr;
1036 template <class> friend class __val_expr;
1037
1038 template <class _Up>
1039 friend
1040 _Up*
1041 begin(valarray<_Up>& __v);
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001042
Howard Hinnantc51e1022010-05-11 19:42:16 +00001043 template <class _Up>
1044 friend
1045 const _Up*
1046 begin(const valarray<_Up>& __v);
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001047
Howard Hinnantc51e1022010-05-11 19:42:16 +00001048 template <class _Up>
1049 friend
1050 _Up*
1051 end(valarray<_Up>& __v);
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001052
Howard Hinnantc51e1022010-05-11 19:42:16 +00001053 template <class _Up>
1054 friend
1055 const _Up*
1056 end(const valarray<_Up>& __v);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00001057
Eric Fiseliera119c322018-10-25 17:43:26 +00001058 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2856ef82018-10-25 17:21:30 +00001059 void __clear(size_t __capacity);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00001060 valarray& __assign_range(const value_type* __f, const value_type* __l);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001061};
1062
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001063_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void valarray<size_t>::resize(size_t, size_t))
1064
Howard Hinnantc51e1022010-05-11 19:42:16 +00001065template <class _Op, class _Tp>
1066struct _UnaryOp<_Op, valarray<_Tp> >
1067{
1068 typedef typename _Op::result_type result_type;
1069 typedef _Tp value_type;
1070
1071 _Op __op_;
1072 const valarray<_Tp>& __a0_;
1073
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001074 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001075 _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
1076
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001077 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001078 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
1079
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081 size_t size() const {return __a0_.size();}
1082};
1083
1084template <class _Op, class _Tp, class _A1>
1085struct _BinaryOp<_Op, valarray<_Tp>, _A1>
1086{
1087 typedef typename _Op::result_type result_type;
1088 typedef _Tp value_type;
1089
1090 _Op __op_;
1091 const valarray<_Tp>& __a0_;
1092 _A1 __a1_;
1093
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001094 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001095 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
1096 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1097
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001099 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1100
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001102 size_t size() const {return __a0_.size();}
1103};
1104
1105template <class _Op, class _A0, class _Tp>
1106struct _BinaryOp<_Op, _A0, valarray<_Tp> >
1107{
1108 typedef typename _Op::result_type result_type;
1109 typedef _Tp value_type;
1110
1111 _Op __op_;
1112 _A0 __a0_;
1113 const valarray<_Tp>& __a1_;
1114
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001116 _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
1117 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1118
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001119 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001120 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1121
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001123 size_t size() const {return __a0_.size();}
1124};
1125
1126template <class _Op, class _Tp>
1127struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> >
1128{
1129 typedef typename _Op::result_type result_type;
1130 typedef _Tp value_type;
1131
1132 _Op __op_;
1133 const valarray<_Tp>& __a0_;
1134 const valarray<_Tp>& __a1_;
1135
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001136 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001137 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
1138 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1139
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001141 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1142
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001143 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001144 size_t size() const {return __a0_.size();}
1145};
1146
1147// slice_array
1148
1149template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001150class _LIBCPP_TEMPLATE_VIS slice_array
Howard Hinnantc51e1022010-05-11 19:42:16 +00001151{
1152public:
1153 typedef _Tp value_type;
1154
1155private:
1156 value_type* __vp_;
1157 size_t __size_;
1158 size_t __stride_;
1159
1160public:
1161 template <class _Expr>
1162 typename enable_if
1163 <
1164 __is_val_expr<_Expr>::value,
1165 void
1166 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001168 operator=(const _Expr& __v) const;
1169
1170 template <class _Expr>
1171 typename enable_if
1172 <
1173 __is_val_expr<_Expr>::value,
1174 void
1175 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001176 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001177 operator*=(const _Expr& __v) const;
1178
1179 template <class _Expr>
1180 typename enable_if
1181 <
1182 __is_val_expr<_Expr>::value,
1183 void
1184 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001186 operator/=(const _Expr& __v) const;
1187
1188 template <class _Expr>
1189 typename enable_if
1190 <
1191 __is_val_expr<_Expr>::value,
1192 void
1193 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001194 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001195 operator%=(const _Expr& __v) const;
1196
1197 template <class _Expr>
1198 typename enable_if
1199 <
1200 __is_val_expr<_Expr>::value,
1201 void
1202 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001203 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001204 operator+=(const _Expr& __v) const;
1205
1206 template <class _Expr>
1207 typename enable_if
1208 <
1209 __is_val_expr<_Expr>::value,
1210 void
1211 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001212 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001213 operator-=(const _Expr& __v) const;
1214
1215 template <class _Expr>
1216 typename enable_if
1217 <
1218 __is_val_expr<_Expr>::value,
1219 void
1220 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001221 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001222 operator^=(const _Expr& __v) const;
1223
1224 template <class _Expr>
1225 typename enable_if
1226 <
1227 __is_val_expr<_Expr>::value,
1228 void
1229 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001230 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001231 operator&=(const _Expr& __v) const;
1232
1233 template <class _Expr>
1234 typename enable_if
1235 <
1236 __is_val_expr<_Expr>::value,
1237 void
1238 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001239 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001240 operator|=(const _Expr& __v) const;
1241
1242 template <class _Expr>
1243 typename enable_if
1244 <
1245 __is_val_expr<_Expr>::value,
1246 void
1247 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001248 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001249 operator<<=(const _Expr& __v) const;
1250
1251 template <class _Expr>
1252 typename enable_if
1253 <
1254 __is_val_expr<_Expr>::value,
1255 void
1256 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001257 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001258 operator>>=(const _Expr& __v) const;
1259
Eric Fiselierb9f37ca2019-12-12 20:48:11 -05001260 slice_array(slice_array const&) = default;
1261
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001262 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001263 const slice_array& operator=(const slice_array& __sa) const;
1264
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001265 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001266 void operator=(const value_type& __x) const;
1267
zoecarver79fa7502020-12-02 10:49:20 -08001268 _LIBCPP_INLINE_VISIBILITY
1269 void operator=(const valarray<value_type>& __va) const;
1270
Howard Hinnantc51e1022010-05-11 19:42:16 +00001271private:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001272 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001273 slice_array(const slice& __sl, const valarray<value_type>& __v)
1274 : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())),
1275 __size_(__sl.size()),
1276 __stride_(__sl.stride())
1277 {}
1278
1279 template <class> friend class valarray;
1280 template <class> friend class sliceExpr;
1281};
1282
1283template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001284inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001285const slice_array<_Tp>&
1286slice_array<_Tp>::operator=(const slice_array& __sa) const
1287{
1288 value_type* __t = __vp_;
1289 const value_type* __s = __sa.__vp_;
1290 for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
1291 *__t = *__s;
Eric Fiselier3b80ce92014-08-12 00:06:58 +00001292 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001293}
1294
1295template <class _Tp>
1296template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001297inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001298typename enable_if
1299<
1300 __is_val_expr<_Expr>::value,
1301 void
1302>::type
1303slice_array<_Tp>::operator=(const _Expr& __v) const
1304{
1305 value_type* __t = __vp_;
1306 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1307 *__t = __v[__i];
1308}
1309
1310template <class _Tp>
zoecarver79fa7502020-12-02 10:49:20 -08001311inline void
1312slice_array<_Tp>::operator=(const valarray<value_type>& __va) const
1313{
1314 value_type* __t = __vp_;
1315 for (size_t __i = 0; __i < __va.size(); ++__i, __t += __stride_)
1316 *__t = __va[__i];
1317}
1318
1319template <class _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001320template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001321inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001322typename enable_if
1323<
1324 __is_val_expr<_Expr>::value,
1325 void
1326>::type
1327slice_array<_Tp>::operator*=(const _Expr& __v) const
1328{
1329 value_type* __t = __vp_;
1330 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1331 *__t *= __v[__i];
1332}
1333
1334template <class _Tp>
1335template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001336inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001337typename enable_if
1338<
1339 __is_val_expr<_Expr>::value,
1340 void
1341>::type
1342slice_array<_Tp>::operator/=(const _Expr& __v) const
1343{
1344 value_type* __t = __vp_;
1345 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1346 *__t /= __v[__i];
1347}
1348
1349template <class _Tp>
1350template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001351inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001352typename enable_if
1353<
1354 __is_val_expr<_Expr>::value,
1355 void
1356>::type
1357slice_array<_Tp>::operator%=(const _Expr& __v) const
1358{
1359 value_type* __t = __vp_;
1360 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1361 *__t %= __v[__i];
1362}
1363
1364template <class _Tp>
1365template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001366inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001367typename enable_if
1368<
1369 __is_val_expr<_Expr>::value,
1370 void
1371>::type
1372slice_array<_Tp>::operator+=(const _Expr& __v) const
1373{
1374 value_type* __t = __vp_;
1375 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1376 *__t += __v[__i];
1377}
1378
1379template <class _Tp>
1380template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001381inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001382typename enable_if
1383<
1384 __is_val_expr<_Expr>::value,
1385 void
1386>::type
1387slice_array<_Tp>::operator-=(const _Expr& __v) const
1388{
1389 value_type* __t = __vp_;
1390 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1391 *__t -= __v[__i];
1392}
1393
1394template <class _Tp>
1395template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001396inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001397typename enable_if
1398<
1399 __is_val_expr<_Expr>::value,
1400 void
1401>::type
1402slice_array<_Tp>::operator^=(const _Expr& __v) const
1403{
1404 value_type* __t = __vp_;
1405 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1406 *__t ^= __v[__i];
1407}
1408
1409template <class _Tp>
1410template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001411inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001412typename enable_if
1413<
1414 __is_val_expr<_Expr>::value,
1415 void
1416>::type
1417slice_array<_Tp>::operator&=(const _Expr& __v) const
1418{
1419 value_type* __t = __vp_;
1420 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1421 *__t &= __v[__i];
1422}
1423
1424template <class _Tp>
1425template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001426inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001427typename enable_if
1428<
1429 __is_val_expr<_Expr>::value,
1430 void
1431>::type
1432slice_array<_Tp>::operator|=(const _Expr& __v) const
1433{
1434 value_type* __t = __vp_;
1435 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1436 *__t |= __v[__i];
1437}
1438
1439template <class _Tp>
1440template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001441inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001442typename enable_if
1443<
1444 __is_val_expr<_Expr>::value,
1445 void
1446>::type
1447slice_array<_Tp>::operator<<=(const _Expr& __v) const
1448{
1449 value_type* __t = __vp_;
1450 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1451 *__t <<= __v[__i];
1452}
1453
1454template <class _Tp>
1455template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001456inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001457typename enable_if
1458<
1459 __is_val_expr<_Expr>::value,
1460 void
1461>::type
1462slice_array<_Tp>::operator>>=(const _Expr& __v) const
1463{
1464 value_type* __t = __vp_;
1465 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1466 *__t >>= __v[__i];
1467}
1468
1469template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001470inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001471void
1472slice_array<_Tp>::operator=(const value_type& __x) const
1473{
1474 value_type* __t = __vp_;
1475 for (size_t __n = __size_; __n; --__n, __t += __stride_)
1476 *__t = __x;
1477}
1478
1479// gslice
1480
Howard Hinnant8331b762013-03-06 23:30:19 +00001481class _LIBCPP_TYPE_VIS gslice
Howard Hinnantc51e1022010-05-11 19:42:16 +00001482{
1483 valarray<size_t> __size_;
1484 valarray<size_t> __stride_;
1485 valarray<size_t> __1d_;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001486
Howard Hinnantc51e1022010-05-11 19:42:16 +00001487public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001489 gslice() {}
Douglas Gregor68902322012-05-19 07:14:17 +00001490
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001492 gslice(size_t __start, const valarray<size_t>& __size,
1493 const valarray<size_t>& __stride)
1494 : __size_(__size),
1495 __stride_(__stride)
1496 {__init(__start);}
1497
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00001498#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001499
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001501 gslice(size_t __start, const valarray<size_t>& __size,
1502 valarray<size_t>&& __stride)
1503 : __size_(__size),
1504 __stride_(move(__stride))
1505 {__init(__start);}
1506
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001507 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001508 gslice(size_t __start, valarray<size_t>&& __size,
1509 const valarray<size_t>& __stride)
1510 : __size_(move(__size)),
1511 __stride_(__stride)
1512 {__init(__start);}
1513
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001515 gslice(size_t __start, valarray<size_t>&& __size,
1516 valarray<size_t>&& __stride)
1517 : __size_(move(__size)),
1518 __stride_(move(__stride))
1519 {__init(__start);}
1520
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00001521#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001522
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001523 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001524 size_t start() const {return __1d_.size() ? __1d_[0] : 0;}
1525
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001527 valarray<size_t> size() const {return __size_;}
1528
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001529 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001530 valarray<size_t> stride() const {return __stride_;}
1531
1532private:
1533 void __init(size_t __start);
1534
1535 template <class> friend class gslice_array;
1536 template <class> friend class valarray;
1537 template <class> friend class __val_expr;
1538};
1539
1540// gslice_array
1541
1542template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001543class _LIBCPP_TEMPLATE_VIS gslice_array
Howard Hinnantc51e1022010-05-11 19:42:16 +00001544{
1545public:
1546 typedef _Tp value_type;
1547
1548private:
1549 value_type* __vp_;
1550 valarray<size_t> __1d_;
1551
1552public:
1553 template <class _Expr>
1554 typename enable_if
1555 <
1556 __is_val_expr<_Expr>::value,
1557 void
1558 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001560 operator=(const _Expr& __v) const;
1561
1562 template <class _Expr>
1563 typename enable_if
1564 <
1565 __is_val_expr<_Expr>::value,
1566 void
1567 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001569 operator*=(const _Expr& __v) const;
1570
1571 template <class _Expr>
1572 typename enable_if
1573 <
1574 __is_val_expr<_Expr>::value,
1575 void
1576 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001578 operator/=(const _Expr& __v) const;
1579
1580 template <class _Expr>
1581 typename enable_if
1582 <
1583 __is_val_expr<_Expr>::value,
1584 void
1585 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001587 operator%=(const _Expr& __v) const;
1588
1589 template <class _Expr>
1590 typename enable_if
1591 <
1592 __is_val_expr<_Expr>::value,
1593 void
1594 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001596 operator+=(const _Expr& __v) const;
1597
1598 template <class _Expr>
1599 typename enable_if
1600 <
1601 __is_val_expr<_Expr>::value,
1602 void
1603 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001605 operator-=(const _Expr& __v) const;
1606
1607 template <class _Expr>
1608 typename enable_if
1609 <
1610 __is_val_expr<_Expr>::value,
1611 void
1612 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001613 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001614 operator^=(const _Expr& __v) const;
1615
1616 template <class _Expr>
1617 typename enable_if
1618 <
1619 __is_val_expr<_Expr>::value,
1620 void
1621 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001623 operator&=(const _Expr& __v) const;
1624
1625 template <class _Expr>
1626 typename enable_if
1627 <
1628 __is_val_expr<_Expr>::value,
1629 void
1630 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001632 operator|=(const _Expr& __v) const;
1633
1634 template <class _Expr>
1635 typename enable_if
1636 <
1637 __is_val_expr<_Expr>::value,
1638 void
1639 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001640 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001641 operator<<=(const _Expr& __v) const;
1642
1643 template <class _Expr>
1644 typename enable_if
1645 <
1646 __is_val_expr<_Expr>::value,
1647 void
1648 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001649 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001650 operator>>=(const _Expr& __v) const;
1651
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001653 const gslice_array& operator=(const gslice_array& __ga) const;
1654
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001655 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001656 void operator=(const value_type& __x) const;
1657
Eric Fiselierb9f37ca2019-12-12 20:48:11 -05001658 gslice_array(const gslice_array&) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001659
1660private:
Howard Hinnantc51e1022010-05-11 19:42:16 +00001661 gslice_array(const gslice& __gs, const valarray<value_type>& __v)
1662 : __vp_(const_cast<value_type*>(__v.__begin_)),
1663 __1d_(__gs.__1d_)
1664 {}
1665
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00001666#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001667 gslice_array(gslice&& __gs, const valarray<value_type>& __v)
1668 : __vp_(const_cast<value_type*>(__v.__begin_)),
1669 __1d_(move(__gs.__1d_))
1670 {}
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00001671#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001672
1673 template <class> friend class valarray;
1674};
1675
1676template <class _Tp>
1677template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001678inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001679typename enable_if
1680<
1681 __is_val_expr<_Expr>::value,
1682 void
1683>::type
1684gslice_array<_Tp>::operator=(const _Expr& __v) const
1685{
1686 typedef const size_t* _Ip;
1687 size_t __j = 0;
1688 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1689 __vp_[*__i] = __v[__j];
1690}
1691
1692template <class _Tp>
1693template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001694inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001695typename enable_if
1696<
1697 __is_val_expr<_Expr>::value,
1698 void
1699>::type
1700gslice_array<_Tp>::operator*=(const _Expr& __v) const
1701{
1702 typedef const size_t* _Ip;
1703 size_t __j = 0;
1704 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1705 __vp_[*__i] *= __v[__j];
1706}
1707
1708template <class _Tp>
1709template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001710inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001711typename enable_if
1712<
1713 __is_val_expr<_Expr>::value,
1714 void
1715>::type
1716gslice_array<_Tp>::operator/=(const _Expr& __v) const
1717{
1718 typedef const size_t* _Ip;
1719 size_t __j = 0;
1720 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1721 __vp_[*__i] /= __v[__j];
1722}
1723
1724template <class _Tp>
1725template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001726inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001727typename enable_if
1728<
1729 __is_val_expr<_Expr>::value,
1730 void
1731>::type
1732gslice_array<_Tp>::operator%=(const _Expr& __v) const
1733{
1734 typedef const size_t* _Ip;
1735 size_t __j = 0;
1736 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1737 __vp_[*__i] %= __v[__j];
1738}
1739
1740template <class _Tp>
1741template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001742inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001743typename enable_if
1744<
1745 __is_val_expr<_Expr>::value,
1746 void
1747>::type
1748gslice_array<_Tp>::operator+=(const _Expr& __v) const
1749{
1750 typedef const size_t* _Ip;
1751 size_t __j = 0;
1752 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1753 __vp_[*__i] += __v[__j];
1754}
1755
1756template <class _Tp>
1757template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001758inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001759typename enable_if
1760<
1761 __is_val_expr<_Expr>::value,
1762 void
1763>::type
1764gslice_array<_Tp>::operator-=(const _Expr& __v) const
1765{
1766 typedef const size_t* _Ip;
1767 size_t __j = 0;
1768 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1769 __vp_[*__i] -= __v[__j];
1770}
1771
1772template <class _Tp>
1773template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001774inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001775typename enable_if
1776<
1777 __is_val_expr<_Expr>::value,
1778 void
1779>::type
1780gslice_array<_Tp>::operator^=(const _Expr& __v) const
1781{
1782 typedef const size_t* _Ip;
1783 size_t __j = 0;
1784 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1785 __vp_[*__i] ^= __v[__j];
1786}
1787
1788template <class _Tp>
1789template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001790inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001791typename enable_if
1792<
1793 __is_val_expr<_Expr>::value,
1794 void
1795>::type
1796gslice_array<_Tp>::operator&=(const _Expr& __v) const
1797{
1798 typedef const size_t* _Ip;
1799 size_t __j = 0;
1800 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1801 __vp_[*__i] &= __v[__j];
1802}
1803
1804template <class _Tp>
1805template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001806inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001807typename enable_if
1808<
1809 __is_val_expr<_Expr>::value,
1810 void
1811>::type
1812gslice_array<_Tp>::operator|=(const _Expr& __v) const
1813{
1814 typedef const size_t* _Ip;
1815 size_t __j = 0;
1816 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1817 __vp_[*__i] |= __v[__j];
1818}
1819
1820template <class _Tp>
1821template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001822inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001823typename enable_if
1824<
1825 __is_val_expr<_Expr>::value,
1826 void
1827>::type
1828gslice_array<_Tp>::operator<<=(const _Expr& __v) const
1829{
1830 typedef const size_t* _Ip;
1831 size_t __j = 0;
1832 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1833 __vp_[*__i] <<= __v[__j];
1834}
1835
1836template <class _Tp>
1837template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001838inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001839typename enable_if
1840<
1841 __is_val_expr<_Expr>::value,
1842 void
1843>::type
1844gslice_array<_Tp>::operator>>=(const _Expr& __v) const
1845{
1846 typedef const size_t* _Ip;
1847 size_t __j = 0;
1848 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1849 __vp_[*__i] >>= __v[__j];
1850}
1851
1852template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001853inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001854const gslice_array<_Tp>&
1855gslice_array<_Tp>::operator=(const gslice_array& __ga) const
1856{
1857 typedef const size_t* _Ip;
1858 const value_type* __s = __ga.__vp_;
1859 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_;
1860 __i != __e; ++__i, ++__j)
1861 __vp_[*__i] = __s[*__j];
1862 return *this;
1863}
1864
1865template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001866inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001867void
1868gslice_array<_Tp>::operator=(const value_type& __x) const
1869{
1870 typedef const size_t* _Ip;
1871 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1872 __vp_[*__i] = __x;
1873}
1874
1875// mask_array
1876
1877template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001878class _LIBCPP_TEMPLATE_VIS mask_array
Howard Hinnantc51e1022010-05-11 19:42:16 +00001879{
1880public:
1881 typedef _Tp value_type;
1882
1883private:
1884 value_type* __vp_;
1885 valarray<size_t> __1d_;
1886
1887public:
1888 template <class _Expr>
1889 typename enable_if
1890 <
1891 __is_val_expr<_Expr>::value,
1892 void
1893 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001895 operator=(const _Expr& __v) const;
1896
1897 template <class _Expr>
1898 typename enable_if
1899 <
1900 __is_val_expr<_Expr>::value,
1901 void
1902 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001904 operator*=(const _Expr& __v) const;
1905
1906 template <class _Expr>
1907 typename enable_if
1908 <
1909 __is_val_expr<_Expr>::value,
1910 void
1911 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001912 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001913 operator/=(const _Expr& __v) const;
1914
1915 template <class _Expr>
1916 typename enable_if
1917 <
1918 __is_val_expr<_Expr>::value,
1919 void
1920 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001922 operator%=(const _Expr& __v) const;
1923
1924 template <class _Expr>
1925 typename enable_if
1926 <
1927 __is_val_expr<_Expr>::value,
1928 void
1929 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001930 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001931 operator+=(const _Expr& __v) const;
1932
1933 template <class _Expr>
1934 typename enable_if
1935 <
1936 __is_val_expr<_Expr>::value,
1937 void
1938 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001940 operator-=(const _Expr& __v) const;
1941
1942 template <class _Expr>
1943 typename enable_if
1944 <
1945 __is_val_expr<_Expr>::value,
1946 void
1947 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001948 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001949 operator^=(const _Expr& __v) const;
1950
1951 template <class _Expr>
1952 typename enable_if
1953 <
1954 __is_val_expr<_Expr>::value,
1955 void
1956 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001957 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001958 operator&=(const _Expr& __v) const;
1959
1960 template <class _Expr>
1961 typename enable_if
1962 <
1963 __is_val_expr<_Expr>::value,
1964 void
1965 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001966 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001967 operator|=(const _Expr& __v) const;
1968
1969 template <class _Expr>
1970 typename enable_if
1971 <
1972 __is_val_expr<_Expr>::value,
1973 void
1974 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001975 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001976 operator<<=(const _Expr& __v) const;
1977
1978 template <class _Expr>
1979 typename enable_if
1980 <
1981 __is_val_expr<_Expr>::value,
1982 void
1983 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001984 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001985 operator>>=(const _Expr& __v) const;
1986
Eric Fiselierb9f37ca2019-12-12 20:48:11 -05001987 mask_array(const mask_array&) = default;
1988
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001990 const mask_array& operator=(const mask_array& __ma) const;
1991
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001992 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001993 void operator=(const value_type& __x) const;
1994
Howard Hinnantc51e1022010-05-11 19:42:16 +00001995private:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001996 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001997 mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
1998 : __vp_(const_cast<value_type*>(__v.__begin_)),
Howard Hinnant28b24882011-12-01 20:21:04 +00001999 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002000 {
2001 size_t __j = 0;
2002 for (size_t __i = 0; __i < __vb.size(); ++__i)
2003 if (__vb[__i])
2004 __1d_[__j++] = __i;
2005 }
2006
2007 template <class> friend class valarray;
2008};
2009
2010template <class _Tp>
2011template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002012inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002013typename enable_if
2014<
2015 __is_val_expr<_Expr>::value,
2016 void
2017>::type
2018mask_array<_Tp>::operator=(const _Expr& __v) const
2019{
2020 size_t __n = __1d_.size();
2021 for (size_t __i = 0; __i < __n; ++__i)
2022 __vp_[__1d_[__i]] = __v[__i];
2023}
2024
2025template <class _Tp>
2026template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002027inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002028typename enable_if
2029<
2030 __is_val_expr<_Expr>::value,
2031 void
2032>::type
2033mask_array<_Tp>::operator*=(const _Expr& __v) const
2034{
2035 size_t __n = __1d_.size();
2036 for (size_t __i = 0; __i < __n; ++__i)
2037 __vp_[__1d_[__i]] *= __v[__i];
2038}
2039
2040template <class _Tp>
2041template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002042inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002043typename enable_if
2044<
2045 __is_val_expr<_Expr>::value,
2046 void
2047>::type
2048mask_array<_Tp>::operator/=(const _Expr& __v) const
2049{
2050 size_t __n = __1d_.size();
2051 for (size_t __i = 0; __i < __n; ++__i)
2052 __vp_[__1d_[__i]] /= __v[__i];
2053}
2054
2055template <class _Tp>
2056template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002057inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002058typename enable_if
2059<
2060 __is_val_expr<_Expr>::value,
2061 void
2062>::type
2063mask_array<_Tp>::operator%=(const _Expr& __v) const
2064{
2065 size_t __n = __1d_.size();
2066 for (size_t __i = 0; __i < __n; ++__i)
2067 __vp_[__1d_[__i]] %= __v[__i];
2068}
2069
2070template <class _Tp>
2071template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002072inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002073typename enable_if
2074<
2075 __is_val_expr<_Expr>::value,
2076 void
2077>::type
2078mask_array<_Tp>::operator+=(const _Expr& __v) const
2079{
2080 size_t __n = __1d_.size();
2081 for (size_t __i = 0; __i < __n; ++__i)
2082 __vp_[__1d_[__i]] += __v[__i];
2083}
2084
2085template <class _Tp>
2086template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002087inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002088typename enable_if
2089<
2090 __is_val_expr<_Expr>::value,
2091 void
2092>::type
2093mask_array<_Tp>::operator-=(const _Expr& __v) const
2094{
2095 size_t __n = __1d_.size();
2096 for (size_t __i = 0; __i < __n; ++__i)
2097 __vp_[__1d_[__i]] -= __v[__i];
2098}
2099
2100template <class _Tp>
2101template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002102inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002103typename enable_if
2104<
2105 __is_val_expr<_Expr>::value,
2106 void
2107>::type
2108mask_array<_Tp>::operator^=(const _Expr& __v) const
2109{
2110 size_t __n = __1d_.size();
2111 for (size_t __i = 0; __i < __n; ++__i)
2112 __vp_[__1d_[__i]] ^= __v[__i];
2113}
2114
2115template <class _Tp>
2116template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002117inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002118typename enable_if
2119<
2120 __is_val_expr<_Expr>::value,
2121 void
2122>::type
2123mask_array<_Tp>::operator&=(const _Expr& __v) const
2124{
2125 size_t __n = __1d_.size();
2126 for (size_t __i = 0; __i < __n; ++__i)
2127 __vp_[__1d_[__i]] &= __v[__i];
2128}
2129
2130template <class _Tp>
2131template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002132inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002133typename enable_if
2134<
2135 __is_val_expr<_Expr>::value,
2136 void
2137>::type
2138mask_array<_Tp>::operator|=(const _Expr& __v) const
2139{
2140 size_t __n = __1d_.size();
2141 for (size_t __i = 0; __i < __n; ++__i)
2142 __vp_[__1d_[__i]] |= __v[__i];
2143}
2144
2145template <class _Tp>
2146template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002147inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002148typename enable_if
2149<
2150 __is_val_expr<_Expr>::value,
2151 void
2152>::type
2153mask_array<_Tp>::operator<<=(const _Expr& __v) const
2154{
2155 size_t __n = __1d_.size();
2156 for (size_t __i = 0; __i < __n; ++__i)
2157 __vp_[__1d_[__i]] <<= __v[__i];
2158}
2159
2160template <class _Tp>
2161template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002162inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002163typename enable_if
2164<
2165 __is_val_expr<_Expr>::value,
2166 void
2167>::type
2168mask_array<_Tp>::operator>>=(const _Expr& __v) const
2169{
2170 size_t __n = __1d_.size();
2171 for (size_t __i = 0; __i < __n; ++__i)
2172 __vp_[__1d_[__i]] >>= __v[__i];
2173}
2174
2175template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002176inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002177const mask_array<_Tp>&
2178mask_array<_Tp>::operator=(const mask_array& __ma) const
2179{
2180 size_t __n = __1d_.size();
2181 for (size_t __i = 0; __i < __n; ++__i)
2182 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
Eric Fiselier3b80ce92014-08-12 00:06:58 +00002183 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002184}
2185
2186template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002187inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002188void
2189mask_array<_Tp>::operator=(const value_type& __x) const
2190{
2191 size_t __n = __1d_.size();
2192 for (size_t __i = 0; __i < __n; ++__i)
2193 __vp_[__1d_[__i]] = __x;
2194}
2195
2196template <class _ValExpr>
2197class __mask_expr
2198{
2199 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2200public:
2201 typedef typename _RmExpr::value_type value_type;
2202 typedef value_type result_type;
2203
2204private:
2205 _ValExpr __expr_;
2206 valarray<size_t> __1d_;
2207
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002208 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002209 __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
2210 : __expr_(__e),
Howard Hinnant28b24882011-12-01 20:21:04 +00002211 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002212 {
2213 size_t __j = 0;
2214 for (size_t __i = 0; __i < __vb.size(); ++__i)
2215 if (__vb[__i])
2216 __1d_[__j++] = __i;
2217 }
2218
2219public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002220 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002221 result_type operator[](size_t __i) const
2222 {return __expr_[__1d_[__i]];}
2223
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002224 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002225 size_t size() const {return __1d_.size();}
2226
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002227 template <class> friend class __val_expr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002228 template <class> friend class valarray;
2229};
2230
2231// indirect_array
2232
2233template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002234class _LIBCPP_TEMPLATE_VIS indirect_array
Howard Hinnantc51e1022010-05-11 19:42:16 +00002235{
2236public:
2237 typedef _Tp value_type;
2238
2239private:
2240 value_type* __vp_;
2241 valarray<size_t> __1d_;
2242
2243public:
2244 template <class _Expr>
2245 typename enable_if
2246 <
2247 __is_val_expr<_Expr>::value,
2248 void
2249 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002251 operator=(const _Expr& __v) const;
2252
2253 template <class _Expr>
2254 typename enable_if
2255 <
2256 __is_val_expr<_Expr>::value,
2257 void
2258 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002259 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002260 operator*=(const _Expr& __v) const;
2261
2262 template <class _Expr>
2263 typename enable_if
2264 <
2265 __is_val_expr<_Expr>::value,
2266 void
2267 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002268 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002269 operator/=(const _Expr& __v) const;
2270
2271 template <class _Expr>
2272 typename enable_if
2273 <
2274 __is_val_expr<_Expr>::value,
2275 void
2276 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002277 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002278 operator%=(const _Expr& __v) const;
2279
2280 template <class _Expr>
2281 typename enable_if
2282 <
2283 __is_val_expr<_Expr>::value,
2284 void
2285 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002286 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002287 operator+=(const _Expr& __v) const;
2288
2289 template <class _Expr>
2290 typename enable_if
2291 <
2292 __is_val_expr<_Expr>::value,
2293 void
2294 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002295 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002296 operator-=(const _Expr& __v) const;
2297
2298 template <class _Expr>
2299 typename enable_if
2300 <
2301 __is_val_expr<_Expr>::value,
2302 void
2303 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002304 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002305 operator^=(const _Expr& __v) const;
2306
2307 template <class _Expr>
2308 typename enable_if
2309 <
2310 __is_val_expr<_Expr>::value,
2311 void
2312 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002313 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002314 operator&=(const _Expr& __v) const;
2315
2316 template <class _Expr>
2317 typename enable_if
2318 <
2319 __is_val_expr<_Expr>::value,
2320 void
2321 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002322 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002323 operator|=(const _Expr& __v) const;
2324
2325 template <class _Expr>
2326 typename enable_if
2327 <
2328 __is_val_expr<_Expr>::value,
2329 void
2330 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002331 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002332 operator<<=(const _Expr& __v) const;
2333
2334 template <class _Expr>
2335 typename enable_if
2336 <
2337 __is_val_expr<_Expr>::value,
2338 void
2339 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002340 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002341 operator>>=(const _Expr& __v) const;
2342
Eric Fiselierb9f37ca2019-12-12 20:48:11 -05002343 indirect_array(const indirect_array&) = default;
2344
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002345 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002346 const indirect_array& operator=(const indirect_array& __ia) const;
2347
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002348 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002349 void operator=(const value_type& __x) const;
2350
Howard Hinnantc51e1022010-05-11 19:42:16 +00002351private:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002352 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002353 indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
2354 : __vp_(const_cast<value_type*>(__v.__begin_)),
2355 __1d_(__ia)
2356 {}
2357
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002358#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002359
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002360 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002361 indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
2362 : __vp_(const_cast<value_type*>(__v.__begin_)),
2363 __1d_(move(__ia))
2364 {}
2365
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002366#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002367
2368 template <class> friend class valarray;
2369};
2370
2371template <class _Tp>
2372template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002373inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002374typename enable_if
2375<
2376 __is_val_expr<_Expr>::value,
2377 void
2378>::type
2379indirect_array<_Tp>::operator=(const _Expr& __v) const
2380{
2381 size_t __n = __1d_.size();
2382 for (size_t __i = 0; __i < __n; ++__i)
2383 __vp_[__1d_[__i]] = __v[__i];
2384}
2385
2386template <class _Tp>
2387template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002388inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002389typename enable_if
2390<
2391 __is_val_expr<_Expr>::value,
2392 void
2393>::type
2394indirect_array<_Tp>::operator*=(const _Expr& __v) const
2395{
2396 size_t __n = __1d_.size();
2397 for (size_t __i = 0; __i < __n; ++__i)
2398 __vp_[__1d_[__i]] *= __v[__i];
2399}
2400
2401template <class _Tp>
2402template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002403inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002404typename enable_if
2405<
2406 __is_val_expr<_Expr>::value,
2407 void
2408>::type
2409indirect_array<_Tp>::operator/=(const _Expr& __v) const
2410{
2411 size_t __n = __1d_.size();
2412 for (size_t __i = 0; __i < __n; ++__i)
2413 __vp_[__1d_[__i]] /= __v[__i];
2414}
2415
2416template <class _Tp>
2417template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002418inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002419typename enable_if
2420<
2421 __is_val_expr<_Expr>::value,
2422 void
2423>::type
2424indirect_array<_Tp>::operator%=(const _Expr& __v) const
2425{
2426 size_t __n = __1d_.size();
2427 for (size_t __i = 0; __i < __n; ++__i)
2428 __vp_[__1d_[__i]] %= __v[__i];
2429}
2430
2431template <class _Tp>
2432template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002433inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002434typename enable_if
2435<
2436 __is_val_expr<_Expr>::value,
2437 void
2438>::type
2439indirect_array<_Tp>::operator+=(const _Expr& __v) const
2440{
2441 size_t __n = __1d_.size();
2442 for (size_t __i = 0; __i < __n; ++__i)
2443 __vp_[__1d_[__i]] += __v[__i];
2444}
2445
2446template <class _Tp>
2447template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002448inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002449typename enable_if
2450<
2451 __is_val_expr<_Expr>::value,
2452 void
2453>::type
2454indirect_array<_Tp>::operator-=(const _Expr& __v) const
2455{
2456 size_t __n = __1d_.size();
2457 for (size_t __i = 0; __i < __n; ++__i)
2458 __vp_[__1d_[__i]] -= __v[__i];
2459}
2460
2461template <class _Tp>
2462template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002463inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002464typename enable_if
2465<
2466 __is_val_expr<_Expr>::value,
2467 void
2468>::type
2469indirect_array<_Tp>::operator^=(const _Expr& __v) const
2470{
2471 size_t __n = __1d_.size();
2472 for (size_t __i = 0; __i < __n; ++__i)
2473 __vp_[__1d_[__i]] ^= __v[__i];
2474}
2475
2476template <class _Tp>
2477template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002478inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002479typename enable_if
2480<
2481 __is_val_expr<_Expr>::value,
2482 void
2483>::type
2484indirect_array<_Tp>::operator&=(const _Expr& __v) const
2485{
2486 size_t __n = __1d_.size();
2487 for (size_t __i = 0; __i < __n; ++__i)
2488 __vp_[__1d_[__i]] &= __v[__i];
2489}
2490
2491template <class _Tp>
2492template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002493inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002494typename enable_if
2495<
2496 __is_val_expr<_Expr>::value,
2497 void
2498>::type
2499indirect_array<_Tp>::operator|=(const _Expr& __v) const
2500{
2501 size_t __n = __1d_.size();
2502 for (size_t __i = 0; __i < __n; ++__i)
2503 __vp_[__1d_[__i]] |= __v[__i];
2504}
2505
2506template <class _Tp>
2507template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002508inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002509typename enable_if
2510<
2511 __is_val_expr<_Expr>::value,
2512 void
2513>::type
2514indirect_array<_Tp>::operator<<=(const _Expr& __v) const
2515{
2516 size_t __n = __1d_.size();
2517 for (size_t __i = 0; __i < __n; ++__i)
2518 __vp_[__1d_[__i]] <<= __v[__i];
2519}
2520
2521template <class _Tp>
2522template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002523inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002524typename enable_if
2525<
2526 __is_val_expr<_Expr>::value,
2527 void
2528>::type
2529indirect_array<_Tp>::operator>>=(const _Expr& __v) const
2530{
2531 size_t __n = __1d_.size();
2532 for (size_t __i = 0; __i < __n; ++__i)
2533 __vp_[__1d_[__i]] >>= __v[__i];
2534}
2535
2536template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002537inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002538const indirect_array<_Tp>&
2539indirect_array<_Tp>::operator=(const indirect_array& __ia) const
2540{
2541 typedef const size_t* _Ip;
2542 const value_type* __s = __ia.__vp_;
2543 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_;
2544 __i != __e; ++__i, ++__j)
2545 __vp_[*__i] = __s[*__j];
2546 return *this;
2547}
2548
2549template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002550inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002551void
2552indirect_array<_Tp>::operator=(const value_type& __x) const
2553{
2554 typedef const size_t* _Ip;
2555 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
2556 __vp_[*__i] = __x;
2557}
2558
2559template <class _ValExpr>
2560class __indirect_expr
2561{
2562 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2563public:
2564 typedef typename _RmExpr::value_type value_type;
2565 typedef value_type result_type;
2566
2567private:
2568 _ValExpr __expr_;
2569 valarray<size_t> __1d_;
2570
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002572 __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e)
2573 : __expr_(__e),
2574 __1d_(__ia)
2575 {}
2576
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002577#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002578
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002579 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002580 __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
2581 : __expr_(__e),
2582 __1d_(move(__ia))
2583 {}
2584
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002585#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002586
2587public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002588 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002589 result_type operator[](size_t __i) const
2590 {return __expr_[__1d_[__i]];}
2591
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002593 size_t size() const {return __1d_.size();}
2594
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002595 template <class> friend class __val_expr;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002596 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002597};
2598
2599template<class _ValExpr>
2600class __val_expr
2601{
2602 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2603
2604 _ValExpr __expr_;
2605public:
2606 typedef typename _RmExpr::value_type value_type;
2607 typedef typename _RmExpr::result_type result_type;
2608
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002610 explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
2611
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002613 result_type operator[](size_t __i) const
2614 {return __expr_[__i];}
2615
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002617 __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002618 {
2619 typedef __slice_expr<_ValExpr> _NewExpr;
2620 return __val_expr< _NewExpr >(_NewExpr(__s, __expr_));
2621 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002622
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002624 __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002625 {
2626 typedef __indirect_expr<_ValExpr> _NewExpr;
2627 return __val_expr<_NewExpr >(_NewExpr(__gs.__1d_, __expr_));
2628 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002629
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002631 __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002632 {
2633 typedef __mask_expr<_ValExpr> _NewExpr;
2634 return __val_expr< _NewExpr >( _NewExpr(__vb, __expr_));
2635 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002636
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002637 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002638 __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002639 {
2640 typedef __indirect_expr<_ValExpr> _NewExpr;
2641 return __val_expr< _NewExpr >(_NewExpr(__vs, __expr_));
2642 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002643
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002645 __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
2646 operator+() const
2647 {
2648 typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
2649 return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
2650 }
2651
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002653 __val_expr<_UnaryOp<negate<value_type>, _ValExpr> >
2654 operator-() const
2655 {
2656 typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
2657 return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
2658 }
2659
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002661 __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> >
2662 operator~() const
2663 {
2664 typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
2665 return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
2666 }
2667
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002669 __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> >
2670 operator!() const
2671 {
2672 typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
2673 return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
2674 }
2675
2676 operator valarray<result_type>() const;
2677
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002679 size_t size() const {return __expr_.size();}
2680
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002681 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002682 result_type sum() const
2683 {
2684 size_t __n = __expr_.size();
2685 result_type __r = __n ? __expr_[0] : result_type();
2686 for (size_t __i = 1; __i < __n; ++__i)
2687 __r += __expr_[__i];
2688 return __r;
2689 }
2690
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002691 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002692 result_type min() const
2693 {
2694 size_t __n = size();
2695 result_type __r = __n ? (*this)[0] : result_type();
2696 for (size_t __i = 1; __i < __n; ++__i)
2697 {
2698 result_type __x = __expr_[__i];
2699 if (__x < __r)
2700 __r = __x;
2701 }
2702 return __r;
2703 }
2704
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002706 result_type max() const
2707 {
2708 size_t __n = size();
2709 result_type __r = __n ? (*this)[0] : result_type();
2710 for (size_t __i = 1; __i < __n; ++__i)
2711 {
2712 result_type __x = __expr_[__i];
2713 if (__r < __x)
2714 __r = __x;
2715 }
2716 return __r;
2717 }
2718
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002719 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002720 __val_expr<__shift_expr<_ValExpr> > shift (int __i) const
2721 {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));}
2722
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002724 __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const
2725 {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));}
2726
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002728 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> >
2729 apply(value_type __f(value_type)) const
2730 {
2731 typedef __apply_expr<value_type, value_type(*)(value_type)> _Op;
2732 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2733 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2734 }
2735
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002737 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> >
2738 apply(value_type __f(const value_type&)) const
2739 {
2740 typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op;
2741 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2742 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2743 }
2744};
2745
2746template<class _ValExpr>
Howard Hinnanta77b71b2013-09-13 23:27:42 +00002747__val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00002748{
2749 valarray<result_type> __r;
2750 size_t __n = __expr_.size();
2751 if (__n)
2752 {
2753 __r.__begin_ =
Louis Dionne5ffe5152020-09-28 15:47:49 -04002754 __r.__end_ = allocator<result_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002755 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
2756 ::new (__r.__end_) result_type(__expr_[__i]);
2757 }
2758 return __r;
2759}
2760
2761// valarray
2762
2763template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002764inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002765valarray<_Tp>::valarray(size_t __n)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002766 : __begin_(nullptr),
2767 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002768{
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002769 if (__n)
2770 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002771 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002772#ifndef _LIBCPP_NO_EXCEPTIONS
2773 try
2774 {
2775#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002776 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002777 ::new (__end_) value_type();
2778#ifndef _LIBCPP_NO_EXCEPTIONS
2779 }
2780 catch (...)
2781 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002782 __clear(__n);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002783 throw;
2784 }
2785#endif // _LIBCPP_NO_EXCEPTIONS
2786 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002787}
2788
2789template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002790inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002791valarray<_Tp>::valarray(const value_type& __x, size_t __n)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002792 : __begin_(nullptr),
2793 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002794{
2795 resize(__n, __x);
2796}
2797
2798template <class _Tp>
2799valarray<_Tp>::valarray(const value_type* __p, size_t __n)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002800 : __begin_(nullptr),
2801 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002802{
2803 if (__n)
2804 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002805 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002806#ifndef _LIBCPP_NO_EXCEPTIONS
2807 try
2808 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002809#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002810 for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002811 ::new (__end_) value_type(*__p);
2812#ifndef _LIBCPP_NO_EXCEPTIONS
2813 }
2814 catch (...)
2815 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002816 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002817 throw;
2818 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002819#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002820 }
2821}
2822
2823template <class _Tp>
2824valarray<_Tp>::valarray(const valarray& __v)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002825 : __begin_(nullptr),
2826 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002827{
2828 if (__v.size())
2829 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002830 __begin_ = __end_ = allocator<value_type>().allocate(__v.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002831#ifndef _LIBCPP_NO_EXCEPTIONS
2832 try
2833 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002834#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002835 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
2836 ::new (__end_) value_type(*__p);
2837#ifndef _LIBCPP_NO_EXCEPTIONS
2838 }
2839 catch (...)
2840 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002841 __clear(__v.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002842 throw;
2843 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002844#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002845 }
2846}
2847
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002848#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002849
2850template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002851inline
Howard Hinnant298aed92012-07-21 00:51:28 +00002852valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002853 : __begin_(__v.__begin_),
2854 __end_(__v.__end_)
2855{
2856 __v.__begin_ = __v.__end_ = nullptr;
2857}
2858
2859template <class _Tp>
2860valarray<_Tp>::valarray(initializer_list<value_type> __il)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002861 : __begin_(nullptr),
2862 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002863{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002864 const size_t __n = __il.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002865 if (__n)
2866 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002867 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002868#ifndef _LIBCPP_NO_EXCEPTIONS
2869 try
2870 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002871#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002872 size_t __n_left = __n;
2873 for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002874 ::new (__end_) value_type(*__p);
2875#ifndef _LIBCPP_NO_EXCEPTIONS
2876 }
2877 catch (...)
2878 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002879 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002880 throw;
2881 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002882#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002883 }
2884}
2885
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002886#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002887
2888template <class _Tp>
2889valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002890 : __begin_(nullptr),
2891 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002892{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002893 const size_t __n = __sa.__size_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002894 if (__n)
2895 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002896 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002897#ifndef _LIBCPP_NO_EXCEPTIONS
2898 try
2899 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002900#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002901 size_t __n_left = __n;
2902 for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002903 ::new (__end_) value_type(*__p);
2904#ifndef _LIBCPP_NO_EXCEPTIONS
2905 }
2906 catch (...)
2907 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002908 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002909 throw;
2910 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002911#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002912 }
2913}
2914
2915template <class _Tp>
2916valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002917 : __begin_(nullptr),
2918 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002919{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002920 const size_t __n = __ga.__1d_.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002921 if (__n)
2922 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002923 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002924#ifndef _LIBCPP_NO_EXCEPTIONS
2925 try
2926 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002927#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002928 typedef const size_t* _Ip;
2929 const value_type* __s = __ga.__vp_;
2930 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2931 __i != __e; ++__i, ++__end_)
2932 ::new (__end_) value_type(__s[*__i]);
2933#ifndef _LIBCPP_NO_EXCEPTIONS
2934 }
2935 catch (...)
2936 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002937 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002938 throw;
2939 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002940#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002941 }
2942}
2943
2944template <class _Tp>
2945valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002946 : __begin_(nullptr),
2947 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002948{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002949 const size_t __n = __ma.__1d_.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002950 if (__n)
2951 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002952 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002953#ifndef _LIBCPP_NO_EXCEPTIONS
2954 try
2955 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002956#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002957 typedef const size_t* _Ip;
2958 const value_type* __s = __ma.__vp_;
2959 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2960 __i != __e; ++__i, ++__end_)
2961 ::new (__end_) value_type(__s[*__i]);
2962#ifndef _LIBCPP_NO_EXCEPTIONS
2963 }
2964 catch (...)
2965 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002966 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002967 throw;
2968 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002969#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002970 }
2971}
2972
2973template <class _Tp>
2974valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002975 : __begin_(nullptr),
2976 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002977{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002978 const size_t __n = __ia.__1d_.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002979 if (__n)
2980 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002981 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002982#ifndef _LIBCPP_NO_EXCEPTIONS
2983 try
2984 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002985#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002986 typedef const size_t* _Ip;
2987 const value_type* __s = __ia.__vp_;
2988 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2989 __i != __e; ++__i, ++__end_)
2990 ::new (__end_) value_type(__s[*__i]);
2991#ifndef _LIBCPP_NO_EXCEPTIONS
2992 }
2993 catch (...)
2994 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002995 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002996 throw;
2997 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002998#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002999 }
3000}
3001
3002template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003003inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003004valarray<_Tp>::~valarray()
3005{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003006 __clear(size());
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003007}
3008
3009template <class _Tp>
3010valarray<_Tp>&
3011valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l)
3012{
3013 size_t __n = __l - __f;
3014 if (size() != __n)
3015 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00003016 __clear(size());
Louis Dionne5ffe5152020-09-28 15:47:49 -04003017 __begin_ = allocator<value_type>().allocate(__n);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003018 __end_ = __begin_ + __n;
3019 _VSTD::uninitialized_copy(__f, __l, __begin_);
3020 } else {
3021 _VSTD::copy(__f, __l, __begin_);
3022 }
3023 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003024}
3025
3026template <class _Tp>
3027valarray<_Tp>&
3028valarray<_Tp>::operator=(const valarray& __v)
3029{
3030 if (this != &__v)
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003031 return __assign_range(__v.__begin_, __v.__end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003032 return *this;
3033}
3034
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003035#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003036
3037template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003038inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003039valarray<_Tp>&
Howard Hinnant298aed92012-07-21 00:51:28 +00003040valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003041{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003042 __clear(size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003043 __begin_ = __v.__begin_;
3044 __end_ = __v.__end_;
3045 __v.__begin_ = nullptr;
3046 __v.__end_ = nullptr;
3047 return *this;
3048}
3049
3050template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003051inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003052valarray<_Tp>&
3053valarray<_Tp>::operator=(initializer_list<value_type> __il)
3054{
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003055 return __assign_range(__il.begin(), __il.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003056}
3057
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003058#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003059
3060template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003061inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003062valarray<_Tp>&
3063valarray<_Tp>::operator=(const value_type& __x)
3064{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003065 _VSTD::fill(__begin_, __end_, __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003066 return *this;
3067}
3068
3069template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003070inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003071valarray<_Tp>&
3072valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
3073{
3074 value_type* __t = __begin_;
3075 const value_type* __s = __sa.__vp_;
3076 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
3077 *__t = *__s;
3078 return *this;
3079}
3080
3081template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003082inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003083valarray<_Tp>&
3084valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
3085{
3086 typedef const size_t* _Ip;
3087 value_type* __t = __begin_;
3088 const value_type* __s = __ga.__vp_;
3089 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
3090 __i != __e; ++__i, ++__t)
3091 *__t = __s[*__i];
3092 return *this;
3093}
3094
3095template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003096inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003097valarray<_Tp>&
3098valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
3099{
3100 typedef const size_t* _Ip;
3101 value_type* __t = __begin_;
3102 const value_type* __s = __ma.__vp_;
3103 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
3104 __i != __e; ++__i, ++__t)
3105 *__t = __s[*__i];
3106 return *this;
3107}
3108
3109template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003110inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003111valarray<_Tp>&
3112valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
3113{
3114 typedef const size_t* _Ip;
3115 value_type* __t = __begin_;
3116 const value_type* __s = __ia.__vp_;
3117 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
3118 __i != __e; ++__i, ++__t)
3119 *__t = __s[*__i];
3120 return *this;
3121}
3122
3123template <class _Tp>
Howard Hinnant329cd412011-07-27 23:19:59 +00003124template <class _ValExpr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003125inline
Howard Hinnant329cd412011-07-27 23:19:59 +00003126valarray<_Tp>&
3127valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
3128{
3129 size_t __n = __v.size();
3130 if (size() != __n)
3131 resize(__n);
3132 value_type* __t = __begin_;
3133 for (size_t __i = 0; __i != __n; ++__t, ++__i)
3134 *__t = result_type(__v[__i]);
3135 return *this;
3136}
3137
3138template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003139inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003140__val_expr<__slice_expr<const valarray<_Tp>&> >
3141valarray<_Tp>::operator[](slice __s) const
3142{
3143 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
3144}
3145
3146template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003147inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003148slice_array<_Tp>
3149valarray<_Tp>::operator[](slice __s)
3150{
3151 return slice_array<value_type>(__s, *this);
3152}
3153
3154template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003155inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003156__val_expr<__indirect_expr<const valarray<_Tp>&> >
3157valarray<_Tp>::operator[](const gslice& __gs) const
3158{
3159 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
3160}
3161
3162template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003163inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003164gslice_array<_Tp>
3165valarray<_Tp>::operator[](const gslice& __gs)
3166{
3167 return gslice_array<value_type>(__gs, *this);
3168}
3169
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003170#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003171
3172template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003173inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003174__val_expr<__indirect_expr<const valarray<_Tp>&> >
3175valarray<_Tp>::operator[](gslice&& __gs) const
3176{
3177 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
3178}
3179
3180template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003181inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003182gslice_array<_Tp>
3183valarray<_Tp>::operator[](gslice&& __gs)
3184{
3185 return gslice_array<value_type>(move(__gs), *this);
3186}
3187
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003188#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003189
3190template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003191inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003192__val_expr<__mask_expr<const valarray<_Tp>&> >
3193valarray<_Tp>::operator[](const valarray<bool>& __vb) const
3194{
3195 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
3196}
3197
3198template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003199inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003200mask_array<_Tp>
3201valarray<_Tp>::operator[](const valarray<bool>& __vb)
3202{
3203 return mask_array<value_type>(__vb, *this);
3204}
3205
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003206#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003207
3208template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003209inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003210__val_expr<__mask_expr<const valarray<_Tp>&> >
3211valarray<_Tp>::operator[](valarray<bool>&& __vb) const
3212{
3213 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
3214}
3215
3216template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003217inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003218mask_array<_Tp>
3219valarray<_Tp>::operator[](valarray<bool>&& __vb)
3220{
3221 return mask_array<value_type>(move(__vb), *this);
3222}
3223
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003224#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003225
3226template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003227inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003228__val_expr<__indirect_expr<const valarray<_Tp>&> >
3229valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
3230{
3231 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
3232}
3233
3234template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003235inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003236indirect_array<_Tp>
3237valarray<_Tp>::operator[](const valarray<size_t>& __vs)
3238{
3239 return indirect_array<value_type>(__vs, *this);
3240}
3241
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003242#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003243
3244template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003245inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003246__val_expr<__indirect_expr<const valarray<_Tp>&> >
3247valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
3248{
3249 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
3250}
3251
3252template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003253inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003254indirect_array<_Tp>
3255valarray<_Tp>::operator[](valarray<size_t>&& __vs)
3256{
3257 return indirect_array<value_type>(move(__vs), *this);
3258}
3259
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003260#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003261
3262template <class _Tp>
3263valarray<_Tp>
3264valarray<_Tp>::operator+() const
3265{
3266 valarray<value_type> __r;
3267 size_t __n = size();
3268 if (__n)
3269 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003270 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003271 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3272 ::new (__r.__end_) value_type(+*__p);
3273 }
3274 return __r;
3275}
3276
3277template <class _Tp>
3278valarray<_Tp>
3279valarray<_Tp>::operator-() const
3280{
3281 valarray<value_type> __r;
3282 size_t __n = size();
3283 if (__n)
3284 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003285 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003286 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3287 ::new (__r.__end_) value_type(-*__p);
3288 }
3289 return __r;
3290}
3291
3292template <class _Tp>
3293valarray<_Tp>
3294valarray<_Tp>::operator~() const
3295{
3296 valarray<value_type> __r;
3297 size_t __n = size();
3298 if (__n)
3299 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003300 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003301 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3302 ::new (__r.__end_) value_type(~*__p);
3303 }
3304 return __r;
3305}
3306
3307template <class _Tp>
3308valarray<bool>
3309valarray<_Tp>::operator!() const
3310{
3311 valarray<bool> __r;
3312 size_t __n = size();
3313 if (__n)
3314 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003315 __r.__begin_ = __r.__end_ = allocator<bool>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003316 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3317 ::new (__r.__end_) bool(!*__p);
3318 }
3319 return __r;
3320}
3321
3322template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003323inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003324valarray<_Tp>&
3325valarray<_Tp>::operator*=(const value_type& __x)
3326{
3327 for (value_type* __p = __begin_; __p != __end_; ++__p)
3328 *__p *= __x;
3329 return *this;
3330}
3331
3332template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003333inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003334valarray<_Tp>&
3335valarray<_Tp>::operator/=(const value_type& __x)
3336{
3337 for (value_type* __p = __begin_; __p != __end_; ++__p)
3338 *__p /= __x;
3339 return *this;
3340}
3341
3342template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003343inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003344valarray<_Tp>&
3345valarray<_Tp>::operator%=(const value_type& __x)
3346{
3347 for (value_type* __p = __begin_; __p != __end_; ++__p)
3348 *__p %= __x;
3349 return *this;
3350}
3351
3352template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003353inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003354valarray<_Tp>&
3355valarray<_Tp>::operator+=(const value_type& __x)
3356{
3357 for (value_type* __p = __begin_; __p != __end_; ++__p)
3358 *__p += __x;
3359 return *this;
3360}
3361
3362template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003363inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003364valarray<_Tp>&
3365valarray<_Tp>::operator-=(const value_type& __x)
3366{
3367 for (value_type* __p = __begin_; __p != __end_; ++__p)
3368 *__p -= __x;
3369 return *this;
3370}
3371
3372template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003373inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003374valarray<_Tp>&
3375valarray<_Tp>::operator^=(const value_type& __x)
3376{
3377 for (value_type* __p = __begin_; __p != __end_; ++__p)
3378 *__p ^= __x;
3379 return *this;
3380}
3381
3382template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003383inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003384valarray<_Tp>&
3385valarray<_Tp>::operator&=(const value_type& __x)
3386{
3387 for (value_type* __p = __begin_; __p != __end_; ++__p)
3388 *__p &= __x;
3389 return *this;
3390}
3391
3392template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003393inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003394valarray<_Tp>&
3395valarray<_Tp>::operator|=(const value_type& __x)
3396{
3397 for (value_type* __p = __begin_; __p != __end_; ++__p)
3398 *__p |= __x;
3399 return *this;
3400}
3401
3402template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003403inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003404valarray<_Tp>&
3405valarray<_Tp>::operator<<=(const value_type& __x)
3406{
3407 for (value_type* __p = __begin_; __p != __end_; ++__p)
3408 *__p <<= __x;
3409 return *this;
3410}
3411
3412template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003413inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003414valarray<_Tp>&
3415valarray<_Tp>::operator>>=(const value_type& __x)
3416{
3417 for (value_type* __p = __begin_; __p != __end_; ++__p)
3418 *__p >>= __x;
3419 return *this;
3420}
3421
3422template <class _Tp>
3423template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003424inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003425typename enable_if
3426<
3427 __is_val_expr<_Expr>::value,
3428 valarray<_Tp>&
3429>::type
3430valarray<_Tp>::operator*=(const _Expr& __v)
3431{
3432 size_t __i = 0;
3433 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3434 *__t *= __v[__i];
3435 return *this;
3436}
3437
3438template <class _Tp>
3439template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003440inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003441typename enable_if
3442<
3443 __is_val_expr<_Expr>::value,
3444 valarray<_Tp>&
3445>::type
3446valarray<_Tp>::operator/=(const _Expr& __v)
3447{
3448 size_t __i = 0;
3449 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3450 *__t /= __v[__i];
3451 return *this;
3452}
3453
3454template <class _Tp>
3455template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003456inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003457typename enable_if
3458<
3459 __is_val_expr<_Expr>::value,
3460 valarray<_Tp>&
3461>::type
3462valarray<_Tp>::operator%=(const _Expr& __v)
3463{
3464 size_t __i = 0;
3465 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3466 *__t %= __v[__i];
3467 return *this;
3468}
3469
3470template <class _Tp>
3471template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003472inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003473typename enable_if
3474<
3475 __is_val_expr<_Expr>::value,
3476 valarray<_Tp>&
3477>::type
3478valarray<_Tp>::operator+=(const _Expr& __v)
3479{
3480 size_t __i = 0;
3481 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3482 *__t += __v[__i];
3483 return *this;
3484}
3485
3486template <class _Tp>
3487template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003488inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003489typename enable_if
3490<
3491 __is_val_expr<_Expr>::value,
3492 valarray<_Tp>&
3493>::type
3494valarray<_Tp>::operator-=(const _Expr& __v)
3495{
3496 size_t __i = 0;
3497 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3498 *__t -= __v[__i];
3499 return *this;
3500}
3501
3502template <class _Tp>
3503template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003504inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003505typename enable_if
3506<
3507 __is_val_expr<_Expr>::value,
3508 valarray<_Tp>&
3509>::type
3510valarray<_Tp>::operator^=(const _Expr& __v)
3511{
3512 size_t __i = 0;
3513 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3514 *__t ^= __v[__i];
3515 return *this;
3516}
3517
3518template <class _Tp>
3519template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003520inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003521typename enable_if
3522<
3523 __is_val_expr<_Expr>::value,
3524 valarray<_Tp>&
3525>::type
3526valarray<_Tp>::operator|=(const _Expr& __v)
3527{
3528 size_t __i = 0;
3529 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3530 *__t |= __v[__i];
3531 return *this;
3532}
3533
3534template <class _Tp>
3535template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003536inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003537typename enable_if
3538<
3539 __is_val_expr<_Expr>::value,
3540 valarray<_Tp>&
3541>::type
3542valarray<_Tp>::operator&=(const _Expr& __v)
3543{
3544 size_t __i = 0;
3545 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3546 *__t &= __v[__i];
3547 return *this;
3548}
3549
3550template <class _Tp>
3551template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003552inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003553typename enable_if
3554<
3555 __is_val_expr<_Expr>::value,
3556 valarray<_Tp>&
3557>::type
3558valarray<_Tp>::operator<<=(const _Expr& __v)
3559{
3560 size_t __i = 0;
3561 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3562 *__t <<= __v[__i];
3563 return *this;
3564}
3565
3566template <class _Tp>
3567template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003568inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003569typename enable_if
3570<
3571 __is_val_expr<_Expr>::value,
3572 valarray<_Tp>&
3573>::type
3574valarray<_Tp>::operator>>=(const _Expr& __v)
3575{
3576 size_t __i = 0;
3577 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3578 *__t >>= __v[__i];
3579 return *this;
3580}
3581
3582template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003583inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003584void
Howard Hinnant298aed92012-07-21 00:51:28 +00003585valarray<_Tp>::swap(valarray& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003586{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003587 _VSTD::swap(__begin_, __v.__begin_);
3588 _VSTD::swap(__end_, __v.__end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003589}
3590
3591template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003592inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003593_Tp
3594valarray<_Tp>::sum() const
3595{
3596 if (__begin_ == __end_)
3597 return value_type();
3598 const value_type* __p = __begin_;
3599 _Tp __r = *__p;
3600 for (++__p; __p != __end_; ++__p)
3601 __r += *__p;
3602 return __r;
3603}
3604
3605template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003606inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003607_Tp
3608valarray<_Tp>::min() const
3609{
3610 if (__begin_ == __end_)
3611 return value_type();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003612 return *_VSTD::min_element(__begin_, __end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003613}
3614
3615template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003616inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003617_Tp
3618valarray<_Tp>::max() const
3619{
3620 if (__begin_ == __end_)
3621 return value_type();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003622 return *_VSTD::max_element(__begin_, __end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003623}
3624
3625template <class _Tp>
3626valarray<_Tp>
3627valarray<_Tp>::shift(int __i) const
3628{
3629 valarray<value_type> __r;
3630 size_t __n = size();
3631 if (__n)
3632 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003633 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003634 const value_type* __sb;
3635 value_type* __tb;
3636 value_type* __te;
3637 if (__i >= 0)
3638 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003639 __i = _VSTD::min(__i, static_cast<int>(__n));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003640 __sb = __begin_ + __i;
3641 __tb = __r.__begin_;
3642 __te = __r.__begin_ + (__n - __i);
3643 }
3644 else
3645 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003646 __i = _VSTD::min(-__i, static_cast<int>(__n));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003647 __sb = __begin_;
3648 __tb = __r.__begin_ + __i;
3649 __te = __r.__begin_ + __n;
3650 }
3651 for (; __r.__end_ != __tb; ++__r.__end_)
3652 ::new (__r.__end_) value_type();
3653 for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
3654 ::new (__r.__end_) value_type(*__sb);
3655 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
3656 ::new (__r.__end_) value_type();
3657 }
3658 return __r;
3659}
3660
3661template <class _Tp>
3662valarray<_Tp>
3663valarray<_Tp>::cshift(int __i) const
3664{
3665 valarray<value_type> __r;
3666 size_t __n = size();
3667 if (__n)
3668 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003669 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003670 __i %= static_cast<int>(__n);
3671 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
3672 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
3673 ::new (__r.__end_) value_type(*__s);
3674 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
3675 ::new (__r.__end_) value_type(*__s);
3676 }
3677 return __r;
3678}
3679
3680template <class _Tp>
3681valarray<_Tp>
3682valarray<_Tp>::apply(value_type __f(value_type)) const
3683{
3684 valarray<value_type> __r;
3685 size_t __n = size();
3686 if (__n)
3687 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003688 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003689 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3690 ::new (__r.__end_) value_type(__f(*__p));
3691 }
3692 return __r;
3693}
3694
3695template <class _Tp>
3696valarray<_Tp>
3697valarray<_Tp>::apply(value_type __f(const value_type&)) const
3698{
3699 valarray<value_type> __r;
3700 size_t __n = size();
3701 if (__n)
3702 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003703 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003704 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3705 ::new (__r.__end_) value_type(__f(*__p));
3706 }
3707 return __r;
3708}
3709
3710template <class _Tp>
Eric Fiseliera119c322018-10-25 17:43:26 +00003711inline
Eric Fiselier2856ef82018-10-25 17:21:30 +00003712void valarray<_Tp>::__clear(size_t __capacity)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003713{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003714 if (__begin_ != nullptr)
3715 {
3716 while (__end_ != __begin_)
3717 (--__end_)->~value_type();
Louis Dionne5ffe5152020-09-28 15:47:49 -04003718 allocator<value_type>().deallocate(__begin_, __capacity);
Eric Fiselier2856ef82018-10-25 17:21:30 +00003719 __begin_ = __end_ = nullptr;
3720 }
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003721}
3722
3723template <class _Tp>
3724void
3725valarray<_Tp>::resize(size_t __n, value_type __x)
3726{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003727 __clear(size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003728 if (__n)
3729 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003730 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003731#ifndef _LIBCPP_NO_EXCEPTIONS
3732 try
3733 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003734#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00003735 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003736 ::new (__end_) value_type(__x);
3737#ifndef _LIBCPP_NO_EXCEPTIONS
3738 }
3739 catch (...)
3740 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00003741 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003742 throw;
3743 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003744#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00003745 }
3746}
3747
3748template<class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003749inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003750void
Howard Hinnant298aed92012-07-21 00:51:28 +00003751swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003752{
3753 __x.swap(__y);
3754}
3755
3756template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003757inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003758typename enable_if
3759<
3760 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3761 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
3762>::type
3763operator*(const _Expr1& __x, const _Expr2& __y)
3764{
3765 typedef typename _Expr1::value_type value_type;
3766 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
3767 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
3768}
3769
3770template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003771inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003772typename enable_if
3773<
3774 __is_val_expr<_Expr>::value,
3775 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3776 _Expr, __scalar_expr<typename _Expr::value_type> > >
3777>::type
3778operator*(const _Expr& __x, const typename _Expr::value_type& __y)
3779{
3780 typedef typename _Expr::value_type value_type;
3781 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3782 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3783 __x, __scalar_expr<value_type>(__y, __x.size())));
3784}
3785
3786template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003787inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003788typename enable_if
3789<
3790 __is_val_expr<_Expr>::value,
3791 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3792 __scalar_expr<typename _Expr::value_type>, _Expr> >
3793>::type
3794operator*(const typename _Expr::value_type& __x, const _Expr& __y)
3795{
3796 typedef typename _Expr::value_type value_type;
3797 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3798 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3799 __scalar_expr<value_type>(__x, __y.size()), __y));
3800}
3801
3802template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003803inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003804typename enable_if
3805<
3806 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3807 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
3808>::type
3809operator/(const _Expr1& __x, const _Expr2& __y)
3810{
3811 typedef typename _Expr1::value_type value_type;
3812 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
3813 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
3814}
3815
3816template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003817inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003818typename enable_if
3819<
3820 __is_val_expr<_Expr>::value,
3821 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3822 _Expr, __scalar_expr<typename _Expr::value_type> > >
3823>::type
3824operator/(const _Expr& __x, const typename _Expr::value_type& __y)
3825{
3826 typedef typename _Expr::value_type value_type;
3827 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3828 return __val_expr<_Op>(_Op(divides<value_type>(),
3829 __x, __scalar_expr<value_type>(__y, __x.size())));
3830}
3831
3832template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003833inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003834typename enable_if
3835<
3836 __is_val_expr<_Expr>::value,
3837 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3838 __scalar_expr<typename _Expr::value_type>, _Expr> >
3839>::type
3840operator/(const typename _Expr::value_type& __x, const _Expr& __y)
3841{
3842 typedef typename _Expr::value_type value_type;
3843 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3844 return __val_expr<_Op>(_Op(divides<value_type>(),
3845 __scalar_expr<value_type>(__x, __y.size()), __y));
3846}
3847
3848template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003849inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003850typename enable_if
3851<
3852 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3853 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3854>::type
3855operator%(const _Expr1& __x, const _Expr2& __y)
3856{
3857 typedef typename _Expr1::value_type value_type;
3858 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
3859 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
3860}
3861
3862template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003863inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003864typename enable_if
3865<
3866 __is_val_expr<_Expr>::value,
3867 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3868 _Expr, __scalar_expr<typename _Expr::value_type> > >
3869>::type
3870operator%(const _Expr& __x, const typename _Expr::value_type& __y)
3871{
3872 typedef typename _Expr::value_type value_type;
3873 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3874 return __val_expr<_Op>(_Op(modulus<value_type>(),
3875 __x, __scalar_expr<value_type>(__y, __x.size())));
3876}
3877
3878template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003879inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003880typename enable_if
3881<
3882 __is_val_expr<_Expr>::value,
3883 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3884 __scalar_expr<typename _Expr::value_type>, _Expr> >
3885>::type
3886operator%(const typename _Expr::value_type& __x, const _Expr& __y)
3887{
3888 typedef typename _Expr::value_type value_type;
3889 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3890 return __val_expr<_Op>(_Op(modulus<value_type>(),
3891 __scalar_expr<value_type>(__x, __y.size()), __y));
3892}
3893
3894template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003895inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003896typename enable_if
3897<
3898 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3899 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3900>::type
3901operator+(const _Expr1& __x, const _Expr2& __y)
3902{
3903 typedef typename _Expr1::value_type value_type;
3904 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
3905 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
3906}
3907
3908template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003909inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003910typename enable_if
3911<
3912 __is_val_expr<_Expr>::value,
3913 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3914 _Expr, __scalar_expr<typename _Expr::value_type> > >
3915>::type
3916operator+(const _Expr& __x, const typename _Expr::value_type& __y)
3917{
3918 typedef typename _Expr::value_type value_type;
3919 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3920 return __val_expr<_Op>(_Op(plus<value_type>(),
3921 __x, __scalar_expr<value_type>(__y, __x.size())));
3922}
3923
3924template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003925inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003926typename enable_if
3927<
3928 __is_val_expr<_Expr>::value,
3929 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3930 __scalar_expr<typename _Expr::value_type>, _Expr> >
3931>::type
3932operator+(const typename _Expr::value_type& __x, const _Expr& __y)
3933{
3934 typedef typename _Expr::value_type value_type;
3935 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3936 return __val_expr<_Op>(_Op(plus<value_type>(),
3937 __scalar_expr<value_type>(__x, __y.size()), __y));
3938}
3939
3940template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003941inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003942typename enable_if
3943<
3944 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3945 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3946>::type
3947operator-(const _Expr1& __x, const _Expr2& __y)
3948{
3949 typedef typename _Expr1::value_type value_type;
3950 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
3951 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
3952}
3953
3954template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003955inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003956typename enable_if
3957<
3958 __is_val_expr<_Expr>::value,
3959 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3960 _Expr, __scalar_expr<typename _Expr::value_type> > >
3961>::type
3962operator-(const _Expr& __x, const typename _Expr::value_type& __y)
3963{
3964 typedef typename _Expr::value_type value_type;
3965 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3966 return __val_expr<_Op>(_Op(minus<value_type>(),
3967 __x, __scalar_expr<value_type>(__y, __x.size())));
3968}
3969
3970template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003971inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003972typename enable_if
3973<
3974 __is_val_expr<_Expr>::value,
3975 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3976 __scalar_expr<typename _Expr::value_type>, _Expr> >
3977>::type
3978operator-(const typename _Expr::value_type& __x, const _Expr& __y)
3979{
3980 typedef typename _Expr::value_type value_type;
3981 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3982 return __val_expr<_Op>(_Op(minus<value_type>(),
3983 __scalar_expr<value_type>(__x, __y.size()), __y));
3984}
3985
3986template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003987inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003988typename enable_if
3989<
3990 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3991 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
3992>::type
3993operator^(const _Expr1& __x, const _Expr2& __y)
3994{
3995 typedef typename _Expr1::value_type value_type;
3996 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
3997 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
3998}
3999
4000template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004001inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004002typename enable_if
4003<
4004 __is_val_expr<_Expr>::value,
4005 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
4006 _Expr, __scalar_expr<typename _Expr::value_type> > >
4007>::type
4008operator^(const _Expr& __x, const typename _Expr::value_type& __y)
4009{
4010 typedef typename _Expr::value_type value_type;
4011 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4012 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
4013 __x, __scalar_expr<value_type>(__y, __x.size())));
4014}
4015
4016template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004017inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004018typename enable_if
4019<
4020 __is_val_expr<_Expr>::value,
4021 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
4022 __scalar_expr<typename _Expr::value_type>, _Expr> >
4023>::type
4024operator^(const typename _Expr::value_type& __x, const _Expr& __y)
4025{
4026 typedef typename _Expr::value_type value_type;
4027 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4028 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
4029 __scalar_expr<value_type>(__x, __y.size()), __y));
4030}
4031
4032template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004033inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004034typename enable_if
4035<
4036 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4037 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4038>::type
4039operator&(const _Expr1& __x, const _Expr2& __y)
4040{
4041 typedef typename _Expr1::value_type value_type;
4042 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
4043 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
4044}
4045
4046template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004047inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004048typename enable_if
4049<
4050 __is_val_expr<_Expr>::value,
4051 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4052 _Expr, __scalar_expr<typename _Expr::value_type> > >
4053>::type
4054operator&(const _Expr& __x, const typename _Expr::value_type& __y)
4055{
4056 typedef typename _Expr::value_type value_type;
4057 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4058 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4059 __x, __scalar_expr<value_type>(__y, __x.size())));
4060}
4061
4062template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004063inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004064typename enable_if
4065<
4066 __is_val_expr<_Expr>::value,
4067 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4068 __scalar_expr<typename _Expr::value_type>, _Expr> >
4069>::type
4070operator&(const typename _Expr::value_type& __x, const _Expr& __y)
4071{
4072 typedef typename _Expr::value_type value_type;
4073 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4074 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4075 __scalar_expr<value_type>(__x, __y.size()), __y));
4076}
4077
4078template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004079inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004080typename enable_if
4081<
4082 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4083 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4084>::type
4085operator|(const _Expr1& __x, const _Expr2& __y)
4086{
4087 typedef typename _Expr1::value_type value_type;
4088 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
4089 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
4090}
4091
4092template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004093inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004094typename enable_if
4095<
4096 __is_val_expr<_Expr>::value,
4097 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4098 _Expr, __scalar_expr<typename _Expr::value_type> > >
4099>::type
4100operator|(const _Expr& __x, const typename _Expr::value_type& __y)
4101{
4102 typedef typename _Expr::value_type value_type;
4103 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4104 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4105 __x, __scalar_expr<value_type>(__y, __x.size())));
4106}
4107
4108template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004109inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004110typename enable_if
4111<
4112 __is_val_expr<_Expr>::value,
4113 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4114 __scalar_expr<typename _Expr::value_type>, _Expr> >
4115>::type
4116operator|(const typename _Expr::value_type& __x, const _Expr& __y)
4117{
4118 typedef typename _Expr::value_type value_type;
4119 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4120 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4121 __scalar_expr<value_type>(__x, __y.size()), __y));
4122}
4123
4124template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004125inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004126typename enable_if
4127<
4128 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4129 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
4130>::type
4131operator<<(const _Expr1& __x, const _Expr2& __y)
4132{
4133 typedef typename _Expr1::value_type value_type;
4134 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
4135 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
4136}
4137
4138template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004139inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004140typename enable_if
4141<
4142 __is_val_expr<_Expr>::value,
4143 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4144 _Expr, __scalar_expr<typename _Expr::value_type> > >
4145>::type
4146operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
4147{
4148 typedef typename _Expr::value_type value_type;
4149 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4150 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4151 __x, __scalar_expr<value_type>(__y, __x.size())));
4152}
4153
4154template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004155inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004156typename enable_if
4157<
4158 __is_val_expr<_Expr>::value,
4159 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4160 __scalar_expr<typename _Expr::value_type>, _Expr> >
4161>::type
4162operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
4163{
4164 typedef typename _Expr::value_type value_type;
4165 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4166 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4167 __scalar_expr<value_type>(__x, __y.size()), __y));
4168}
4169
4170template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004171inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004172typename enable_if
4173<
4174 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4175 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
4176>::type
4177operator>>(const _Expr1& __x, const _Expr2& __y)
4178{
4179 typedef typename _Expr1::value_type value_type;
4180 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
4181 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
4182}
4183
4184template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004185inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004186typename enable_if
4187<
4188 __is_val_expr<_Expr>::value,
4189 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4190 _Expr, __scalar_expr<typename _Expr::value_type> > >
4191>::type
4192operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
4193{
4194 typedef typename _Expr::value_type value_type;
4195 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4196 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4197 __x, __scalar_expr<value_type>(__y, __x.size())));
4198}
4199
4200template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004201inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004202typename enable_if
4203<
4204 __is_val_expr<_Expr>::value,
4205 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4206 __scalar_expr<typename _Expr::value_type>, _Expr> >
4207>::type
4208operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
4209{
4210 typedef typename _Expr::value_type value_type;
4211 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4212 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4213 __scalar_expr<value_type>(__x, __y.size()), __y));
4214}
4215
4216template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004217inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004218typename enable_if
4219<
4220 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4221 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4222>::type
4223operator&&(const _Expr1& __x, const _Expr2& __y)
4224{
4225 typedef typename _Expr1::value_type value_type;
4226 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
4227 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
4228}
4229
4230template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004231inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004232typename enable_if
4233<
4234 __is_val_expr<_Expr>::value,
4235 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4236 _Expr, __scalar_expr<typename _Expr::value_type> > >
4237>::type
4238operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
4239{
4240 typedef typename _Expr::value_type value_type;
4241 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4242 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4243 __x, __scalar_expr<value_type>(__y, __x.size())));
4244}
4245
4246template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004247inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004248typename enable_if
4249<
4250 __is_val_expr<_Expr>::value,
4251 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4252 __scalar_expr<typename _Expr::value_type>, _Expr> >
4253>::type
4254operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
4255{
4256 typedef typename _Expr::value_type value_type;
4257 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4258 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4259 __scalar_expr<value_type>(__x, __y.size()), __y));
4260}
4261
4262template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004263inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004264typename enable_if
4265<
4266 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4267 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4268>::type
4269operator||(const _Expr1& __x, const _Expr2& __y)
4270{
4271 typedef typename _Expr1::value_type value_type;
4272 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
4273 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
4274}
4275
4276template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004277inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004278typename enable_if
4279<
4280 __is_val_expr<_Expr>::value,
4281 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4282 _Expr, __scalar_expr<typename _Expr::value_type> > >
4283>::type
4284operator||(const _Expr& __x, const typename _Expr::value_type& __y)
4285{
4286 typedef typename _Expr::value_type value_type;
4287 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4288 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4289 __x, __scalar_expr<value_type>(__y, __x.size())));
4290}
4291
4292template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004293inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004294typename enable_if
4295<
4296 __is_val_expr<_Expr>::value,
4297 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4298 __scalar_expr<typename _Expr::value_type>, _Expr> >
4299>::type
4300operator||(const typename _Expr::value_type& __x, const _Expr& __y)
4301{
4302 typedef typename _Expr::value_type value_type;
4303 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4304 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4305 __scalar_expr<value_type>(__x, __y.size()), __y));
4306}
4307
4308template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004309inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004310typename enable_if
4311<
4312 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4313 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4314>::type
4315operator==(const _Expr1& __x, const _Expr2& __y)
4316{
4317 typedef typename _Expr1::value_type value_type;
4318 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
4319 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
4320}
4321
4322template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004323inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004324typename enable_if
4325<
4326 __is_val_expr<_Expr>::value,
4327 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4328 _Expr, __scalar_expr<typename _Expr::value_type> > >
4329>::type
4330operator==(const _Expr& __x, const typename _Expr::value_type& __y)
4331{
4332 typedef typename _Expr::value_type value_type;
4333 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4334 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4335 __x, __scalar_expr<value_type>(__y, __x.size())));
4336}
4337
4338template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004339inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004340typename enable_if
4341<
4342 __is_val_expr<_Expr>::value,
4343 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4344 __scalar_expr<typename _Expr::value_type>, _Expr> >
4345>::type
4346operator==(const typename _Expr::value_type& __x, const _Expr& __y)
4347{
4348 typedef typename _Expr::value_type value_type;
4349 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4350 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4351 __scalar_expr<value_type>(__x, __y.size()), __y));
4352}
4353
4354template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004355inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004356typename enable_if
4357<
4358 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4359 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4360>::type
4361operator!=(const _Expr1& __x, const _Expr2& __y)
4362{
4363 typedef typename _Expr1::value_type value_type;
4364 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
4365 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
4366}
4367
4368template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004369inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004370typename enable_if
4371<
4372 __is_val_expr<_Expr>::value,
4373 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4374 _Expr, __scalar_expr<typename _Expr::value_type> > >
4375>::type
4376operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
4377{
4378 typedef typename _Expr::value_type value_type;
4379 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4380 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4381 __x, __scalar_expr<value_type>(__y, __x.size())));
4382}
4383
4384template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004385inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004386typename enable_if
4387<
4388 __is_val_expr<_Expr>::value,
4389 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4390 __scalar_expr<typename _Expr::value_type>, _Expr> >
4391>::type
4392operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
4393{
4394 typedef typename _Expr::value_type value_type;
4395 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4396 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4397 __scalar_expr<value_type>(__x, __y.size()), __y));
4398}
4399
4400template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004401inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004402typename enable_if
4403<
4404 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4405 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
4406>::type
4407operator<(const _Expr1& __x, const _Expr2& __y)
4408{
4409 typedef typename _Expr1::value_type value_type;
4410 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
4411 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
4412}
4413
4414template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004415inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004416typename enable_if
4417<
4418 __is_val_expr<_Expr>::value,
4419 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4420 _Expr, __scalar_expr<typename _Expr::value_type> > >
4421>::type
4422operator<(const _Expr& __x, const typename _Expr::value_type& __y)
4423{
4424 typedef typename _Expr::value_type value_type;
4425 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4426 return __val_expr<_Op>(_Op(less<value_type>(),
4427 __x, __scalar_expr<value_type>(__y, __x.size())));
4428}
4429
4430template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004431inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004432typename enable_if
4433<
4434 __is_val_expr<_Expr>::value,
4435 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4436 __scalar_expr<typename _Expr::value_type>, _Expr> >
4437>::type
4438operator<(const typename _Expr::value_type& __x, const _Expr& __y)
4439{
4440 typedef typename _Expr::value_type value_type;
4441 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4442 return __val_expr<_Op>(_Op(less<value_type>(),
4443 __scalar_expr<value_type>(__x, __y.size()), __y));
4444}
4445
4446template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004447inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004448typename enable_if
4449<
4450 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4451 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
4452>::type
4453operator>(const _Expr1& __x, const _Expr2& __y)
4454{
4455 typedef typename _Expr1::value_type value_type;
4456 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
4457 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
4458}
4459
4460template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004461inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004462typename enable_if
4463<
4464 __is_val_expr<_Expr>::value,
4465 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4466 _Expr, __scalar_expr<typename _Expr::value_type> > >
4467>::type
4468operator>(const _Expr& __x, const typename _Expr::value_type& __y)
4469{
4470 typedef typename _Expr::value_type value_type;
4471 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4472 return __val_expr<_Op>(_Op(greater<value_type>(),
4473 __x, __scalar_expr<value_type>(__y, __x.size())));
4474}
4475
4476template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004477inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004478typename enable_if
4479<
4480 __is_val_expr<_Expr>::value,
4481 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4482 __scalar_expr<typename _Expr::value_type>, _Expr> >
4483>::type
4484operator>(const typename _Expr::value_type& __x, const _Expr& __y)
4485{
4486 typedef typename _Expr::value_type value_type;
4487 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4488 return __val_expr<_Op>(_Op(greater<value_type>(),
4489 __scalar_expr<value_type>(__x, __y.size()), __y));
4490}
4491
4492template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004493inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004494typename enable_if
4495<
4496 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4497 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4498>::type
4499operator<=(const _Expr1& __x, const _Expr2& __y)
4500{
4501 typedef typename _Expr1::value_type value_type;
4502 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
4503 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
4504}
4505
4506template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004507inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004508typename enable_if
4509<
4510 __is_val_expr<_Expr>::value,
4511 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4512 _Expr, __scalar_expr<typename _Expr::value_type> > >
4513>::type
4514operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
4515{
4516 typedef typename _Expr::value_type value_type;
4517 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4518 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4519 __x, __scalar_expr<value_type>(__y, __x.size())));
4520}
4521
4522template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004523inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004524typename enable_if
4525<
4526 __is_val_expr<_Expr>::value,
4527 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4528 __scalar_expr<typename _Expr::value_type>, _Expr> >
4529>::type
4530operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
4531{
4532 typedef typename _Expr::value_type value_type;
4533 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4534 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4535 __scalar_expr<value_type>(__x, __y.size()), __y));
4536}
4537
4538template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004539inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004540typename enable_if
4541<
4542 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4543 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4544>::type
4545operator>=(const _Expr1& __x, const _Expr2& __y)
4546{
4547 typedef typename _Expr1::value_type value_type;
4548 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
4549 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
4550}
4551
4552template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004553inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004554typename enable_if
4555<
4556 __is_val_expr<_Expr>::value,
4557 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4558 _Expr, __scalar_expr<typename _Expr::value_type> > >
4559>::type
4560operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
4561{
4562 typedef typename _Expr::value_type value_type;
4563 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4564 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4565 __x, __scalar_expr<value_type>(__y, __x.size())));
4566}
4567
4568template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004569inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004570typename enable_if
4571<
4572 __is_val_expr<_Expr>::value,
4573 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4574 __scalar_expr<typename _Expr::value_type>, _Expr> >
4575>::type
4576operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
4577{
4578 typedef typename _Expr::value_type value_type;
4579 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4580 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4581 __scalar_expr<value_type>(__x, __y.size()), __y));
4582}
4583
4584template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004585inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004586typename enable_if
4587<
4588 __is_val_expr<_Expr>::value,
4589 __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
4590>::type
4591abs(const _Expr& __x)
4592{
4593 typedef typename _Expr::value_type value_type;
4594 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
4595 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
4596}
4597
4598template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004599inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004600typename enable_if
4601<
4602 __is_val_expr<_Expr>::value,
4603 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
4604>::type
4605acos(const _Expr& __x)
4606{
4607 typedef typename _Expr::value_type value_type;
4608 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
4609 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
4610}
4611
4612template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004613inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004614typename enable_if
4615<
4616 __is_val_expr<_Expr>::value,
4617 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
4618>::type
4619asin(const _Expr& __x)
4620{
4621 typedef typename _Expr::value_type value_type;
4622 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
4623 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
4624}
4625
4626template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004627inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004628typename enable_if
4629<
4630 __is_val_expr<_Expr>::value,
4631 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
4632>::type
4633atan(const _Expr& __x)
4634{
4635 typedef typename _Expr::value_type value_type;
4636 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
4637 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
4638}
4639
4640template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004641inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004642typename enable_if
4643<
4644 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4645 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4646>::type
4647atan2(const _Expr1& __x, const _Expr2& __y)
4648{
4649 typedef typename _Expr1::value_type value_type;
4650 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
4651 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
4652}
4653
4654template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004655inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004656typename enable_if
4657<
4658 __is_val_expr<_Expr>::value,
4659 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4660 _Expr, __scalar_expr<typename _Expr::value_type> > >
4661>::type
4662atan2(const _Expr& __x, const typename _Expr::value_type& __y)
4663{
4664 typedef typename _Expr::value_type value_type;
4665 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4666 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4667 __x, __scalar_expr<value_type>(__y, __x.size())));
4668}
4669
4670template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004671inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004672typename enable_if
4673<
4674 __is_val_expr<_Expr>::value,
4675 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4676 __scalar_expr<typename _Expr::value_type>, _Expr> >
4677>::type
4678atan2(const typename _Expr::value_type& __x, const _Expr& __y)
4679{
4680 typedef typename _Expr::value_type value_type;
4681 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4682 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4683 __scalar_expr<value_type>(__x, __y.size()), __y));
4684}
4685
4686template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004687inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004688typename enable_if
4689<
4690 __is_val_expr<_Expr>::value,
4691 __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
4692>::type
4693cos(const _Expr& __x)
4694{
4695 typedef typename _Expr::value_type value_type;
4696 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
4697 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
4698}
4699
4700template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004701inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004702typename enable_if
4703<
4704 __is_val_expr<_Expr>::value,
4705 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
4706>::type
4707cosh(const _Expr& __x)
4708{
4709 typedef typename _Expr::value_type value_type;
4710 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
4711 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
4712}
4713
4714template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004715inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004716typename enable_if
4717<
4718 __is_val_expr<_Expr>::value,
4719 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
4720>::type
4721exp(const _Expr& __x)
4722{
4723 typedef typename _Expr::value_type value_type;
4724 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
4725 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
4726}
4727
4728template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004729inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004730typename enable_if
4731<
4732 __is_val_expr<_Expr>::value,
4733 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
4734>::type
4735log(const _Expr& __x)
4736{
4737 typedef typename _Expr::value_type value_type;
4738 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
4739 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
4740}
4741
4742template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004743inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004744typename enable_if
4745<
4746 __is_val_expr<_Expr>::value,
4747 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
4748>::type
4749log10(const _Expr& __x)
4750{
4751 typedef typename _Expr::value_type value_type;
4752 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
4753 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
4754}
4755
4756template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004757inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004758typename enable_if
4759<
4760 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4761 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4762>::type
4763pow(const _Expr1& __x, const _Expr2& __y)
4764{
4765 typedef typename _Expr1::value_type value_type;
4766 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
4767 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
4768}
4769
4770template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004771inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004772typename enable_if
4773<
4774 __is_val_expr<_Expr>::value,
4775 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4776 _Expr, __scalar_expr<typename _Expr::value_type> > >
4777>::type
4778pow(const _Expr& __x, const typename _Expr::value_type& __y)
4779{
4780 typedef typename _Expr::value_type value_type;
4781 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4782 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4783 __x, __scalar_expr<value_type>(__y, __x.size())));
4784}
4785
4786template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004787inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004788typename enable_if
4789<
4790 __is_val_expr<_Expr>::value,
4791 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4792 __scalar_expr<typename _Expr::value_type>, _Expr> >
4793>::type
4794pow(const typename _Expr::value_type& __x, const _Expr& __y)
4795{
4796 typedef typename _Expr::value_type value_type;
4797 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4798 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4799 __scalar_expr<value_type>(__x, __y.size()), __y));
4800}
4801
4802template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004803inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004804typename enable_if
4805<
4806 __is_val_expr<_Expr>::value,
4807 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
4808>::type
4809sin(const _Expr& __x)
4810{
4811 typedef typename _Expr::value_type value_type;
4812 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
4813 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
4814}
4815
4816template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004817inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004818typename enable_if
4819<
4820 __is_val_expr<_Expr>::value,
4821 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
4822>::type
4823sinh(const _Expr& __x)
4824{
4825 typedef typename _Expr::value_type value_type;
4826 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
4827 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
4828}
4829
4830template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004831inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004832typename enable_if
4833<
4834 __is_val_expr<_Expr>::value,
4835 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
4836>::type
4837sqrt(const _Expr& __x)
4838{
4839 typedef typename _Expr::value_type value_type;
4840 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
4841 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
4842}
4843
4844template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004845inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004846typename enable_if
4847<
4848 __is_val_expr<_Expr>::value,
4849 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
4850>::type
4851tan(const _Expr& __x)
4852{
4853 typedef typename _Expr::value_type value_type;
4854 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
4855 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
4856}
4857
4858template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004859inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004860typename enable_if
4861<
4862 __is_val_expr<_Expr>::value,
4863 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
4864>::type
4865tanh(const _Expr& __x)
4866{
4867 typedef typename _Expr::value_type value_type;
4868 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
4869 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
4870}
4871
4872template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004873inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004874_Tp*
4875begin(valarray<_Tp>& __v)
4876{
4877 return __v.__begin_;
4878}
4879
4880template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004881inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004882const _Tp*
4883begin(const valarray<_Tp>& __v)
4884{
4885 return __v.__begin_;
4886}
4887
4888template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004889inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004890_Tp*
4891end(valarray<_Tp>& __v)
4892{
4893 return __v.__end_;
4894}
4895
4896template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004897inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004898const _Tp*
4899end(const valarray<_Tp>& __v)
4900{
4901 return __v.__end_;
4902}
4903
Howard Hinnantc51e1022010-05-11 19:42:16 +00004904_LIBCPP_END_NAMESPACE_STD
4905
Eric Fiselierf4433a32017-05-31 22:07:49 +00004906_LIBCPP_POP_MACROS
4907
Howard Hinnantc51e1022010-05-11 19:42:16 +00004908#endif // _LIBCPP_VALARRAY