blob: aaae6fbd5b3fb8033b3b17aeccc862b696dba0eb [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;
139
140 slice_array() = delete;
141};
142
143class gslice
144{
145public:
146 gslice();
147 gslice(size_t start, const valarray<size_t>& size,
148 const valarray<size_t>& stride);
149
150 size_t start() const;
151 valarray<size_t> size() const;
152 valarray<size_t> stride() const;
153};
154
155template <class T>
156class gslice_array
157{
158public:
159 typedef T value_type;
160
161 void operator= (const valarray<value_type>& v) const;
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
173 gslice_array(const gslice_array& ga);
174 ~gslice_array();
175 const gslice_array& operator=(const gslice_array& ga) const;
176 void operator=(const value_type& x) const;
177
178 gslice_array() = delete;
179};
180
181template <class T>
182class mask_array
183{
184public:
185 typedef T value_type;
186
187 void operator= (const valarray<value_type>& v) const;
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
199 mask_array(const mask_array& ma);
200 ~mask_array();
201 const mask_array& operator=(const mask_array& ma) const;
202 void operator=(const value_type& x) const;
203
204 mask_array() = delete;
205};
206
207template <class T>
208class indirect_array
209{
210public:
211 typedef T value_type;
212
213 void operator= (const valarray<value_type>& v) const;
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
225 indirect_array(const indirect_array& ia);
226 ~indirect_array();
227 const indirect_array& operator=(const indirect_array& ia) const;
228 void operator=(const value_type& x) const;
229
230 indirect_array() = delete;
231};
232
Howard Hinnant298aed92012-07-21 00:51:28 +0000233template<class T> void swap(valarray<T>& x, valarray<T>& y) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000234
235template<class T> valarray<T> operator* (const valarray<T>& x, const valarray<T>& y);
236template<class T> valarray<T> operator* (const valarray<T>& x, const T& y);
237template<class T> valarray<T> operator* (const T& x, const valarray<T>& y);
238
239template<class T> valarray<T> operator/ (const valarray<T>& x, const valarray<T>& y);
240template<class T> valarray<T> operator/ (const valarray<T>& x, const T& y);
241template<class T> valarray<T> operator/ (const T& x, const valarray<T>& y);
242
243template<class T> valarray<T> operator% (const valarray<T>& x, const valarray<T>& y);
244template<class T> valarray<T> operator% (const valarray<T>& x, const T& y);
245template<class T> valarray<T> operator% (const T& x, const valarray<T>& y);
246
247template<class T> valarray<T> operator+ (const valarray<T>& x, const valarray<T>& y);
248template<class T> valarray<T> operator+ (const valarray<T>& x, const T& y);
249template<class T> valarray<T> operator+ (const T& x, const valarray<T>& y);
250
251template<class T> valarray<T> operator- (const valarray<T>& x, const valarray<T>& y);
252template<class T> valarray<T> operator- (const valarray<T>& x, const T& y);
253template<class T> valarray<T> operator- (const T& x, const valarray<T>& y);
254
255template<class T> valarray<T> operator^ (const valarray<T>& x, const valarray<T>& y);
256template<class T> valarray<T> operator^ (const valarray<T>& x, const T& y);
257template<class T> valarray<T> operator^ (const T& x, const valarray<T>& y);
258
259template<class T> valarray<T> operator& (const valarray<T>& x, const valarray<T>& y);
260template<class T> valarray<T> operator& (const valarray<T>& x, const T& y);
261template<class T> valarray<T> operator& (const T& x, const valarray<T>& y);
262
263template<class T> valarray<T> operator| (const valarray<T>& x, const valarray<T>& y);
264template<class T> valarray<T> operator| (const valarray<T>& x, const T& y);
265template<class T> valarray<T> operator| (const T& x, const valarray<T>& y);
266
267template<class T> valarray<T> operator<<(const valarray<T>& x, const valarray<T>& y);
268template<class T> valarray<T> operator<<(const valarray<T>& x, const T& y);
269template<class T> valarray<T> operator<<(const T& x, const valarray<T>& y);
270
271template<class T> valarray<T> operator>>(const valarray<T>& x, const valarray<T>& y);
272template<class T> valarray<T> operator>>(const valarray<T>& x, const T& y);
273template<class T> valarray<T> operator>>(const T& x, const valarray<T>& y);
274
275template<class T> valarray<bool> operator&&(const valarray<T>& x, const valarray<T>& y);
276template<class T> valarray<bool> operator&&(const valarray<T>& x, const T& y);
277template<class T> valarray<bool> operator&&(const T& x, const valarray<T>& y);
278
279template<class T> valarray<bool> operator||(const valarray<T>& x, const valarray<T>& y);
280template<class T> valarray<bool> operator||(const valarray<T>& x, const T& y);
281template<class T> valarray<bool> operator||(const T& x, const valarray<T>& y);
282
283template<class T> valarray<bool> operator==(const valarray<T>& x, const valarray<T>& y);
284template<class T> valarray<bool> operator==(const valarray<T>& x, const T& y);
285template<class T> valarray<bool> operator==(const T& x, const valarray<T>& y);
286
287template<class T> valarray<bool> operator!=(const valarray<T>& x, const valarray<T>& y);
288template<class T> valarray<bool> operator!=(const valarray<T>& x, const T& y);
289template<class T> valarray<bool> operator!=(const T& x, const valarray<T>& y);
290
291template<class T> valarray<bool> operator< (const valarray<T>& x, const valarray<T>& y);
292template<class T> valarray<bool> operator< (const valarray<T>& x, const T& y);
293template<class T> valarray<bool> operator< (const T& x, const valarray<T>& y);
294
295template<class T> valarray<bool> operator> (const valarray<T>& x, const valarray<T>& y);
296template<class T> valarray<bool> operator> (const valarray<T>& x, const T& y);
297template<class T> valarray<bool> operator> (const T& x, const valarray<T>& y);
298
299template<class T> valarray<bool> operator<=(const valarray<T>& x, const valarray<T>& y);
300template<class T> valarray<bool> operator<=(const valarray<T>& x, const T& y);
301template<class T> valarray<bool> operator<=(const T& x, const valarray<T>& y);
302
303template<class T> valarray<bool> operator>=(const valarray<T>& x, const valarray<T>& y);
304template<class T> valarray<bool> operator>=(const valarray<T>& x, const T& y);
305template<class T> valarray<bool> operator>=(const T& x, const valarray<T>& y);
306
307template<class T> valarray<T> abs (const valarray<T>& x);
308template<class T> valarray<T> acos (const valarray<T>& x);
309template<class T> valarray<T> asin (const valarray<T>& x);
310template<class T> valarray<T> atan (const valarray<T>& x);
311
312template<class T> valarray<T> atan2(const valarray<T>& x, const valarray<T>& y);
313template<class T> valarray<T> atan2(const valarray<T>& x, const T& y);
314template<class T> valarray<T> atan2(const T& x, const valarray<T>& y);
315
316template<class T> valarray<T> cos (const valarray<T>& x);
317template<class T> valarray<T> cosh (const valarray<T>& x);
318template<class T> valarray<T> exp (const valarray<T>& x);
319template<class T> valarray<T> log (const valarray<T>& x);
320template<class T> valarray<T> log10(const valarray<T>& x);
321
322template<class T> valarray<T> pow(const valarray<T>& x, const valarray<T>& y);
323template<class T> valarray<T> pow(const valarray<T>& x, const T& y);
324template<class T> valarray<T> pow(const T& x, const valarray<T>& y);
325
326template<class T> valarray<T> sin (const valarray<T>& x);
327template<class T> valarray<T> sinh (const valarray<T>& x);
328template<class T> valarray<T> sqrt (const valarray<T>& x);
329template<class T> valarray<T> tan (const valarray<T>& x);
330template<class T> valarray<T> tanh (const valarray<T>& x);
331
332template <class T> unspecified1 begin(valarray<T>& v);
333template <class T> unspecified2 begin(const valarray<T>& v);
334template <class T> unspecified1 end(valarray<T>& v);
335template <class T> unspecified2 end(const valarray<T>& v);
336
337} // std
338
339*/
340
341#include <__config>
342#include <cstddef>
343#include <cmath>
344#include <initializer_list>
345#include <algorithm>
346#include <functional>
Richard Smith1f1c1472014-06-04 19:54:15 +0000347#include <new>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000348
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000349#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000350#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000351#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000352
Eric Fiselierf4433a32017-05-31 22:07:49 +0000353_LIBCPP_PUSH_MACROS
354#include <__undef_macros>
355
356
Howard Hinnantc51e1022010-05-11 19:42:16 +0000357_LIBCPP_BEGIN_NAMESPACE_STD
358
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000359template<class _Tp> class _LIBCPP_TEMPLATE_VIS valarray;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000361class _LIBCPP_TEMPLATE_VIS slice
Howard Hinnantc51e1022010-05-11 19:42:16 +0000362{
363 size_t __start_;
364 size_t __size_;
365 size_t __stride_;
366public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000367 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000368 slice()
369 : __start_(0),
370 __size_(0),
371 __stride_(0)
372 {}
373
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000374 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375 slice(size_t __start, size_t __size, size_t __stride)
376 : __start_(__start),
377 __size_(__size),
378 __stride_(__stride)
379 {}
380
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000381 _LIBCPP_INLINE_VISIBILITY size_t start() const {return __start_;}
382 _LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;}
383 _LIBCPP_INLINE_VISIBILITY size_t stride() const {return __stride_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000384};
385
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000386template <class _Tp> class _LIBCPP_TEMPLATE_VIS slice_array;
Howard Hinnant8331b762013-03-06 23:30:19 +0000387class _LIBCPP_TYPE_VIS gslice;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000388template <class _Tp> class _LIBCPP_TEMPLATE_VIS gslice_array;
389template <class _Tp> class _LIBCPP_TEMPLATE_VIS mask_array;
390template <class _Tp> class _LIBCPP_TEMPLATE_VIS indirect_array;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000391
392template <class _Tp>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000393_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000394_Tp*
395begin(valarray<_Tp>& __v);
396
397template <class _Tp>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000398_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000399const _Tp*
400begin(const valarray<_Tp>& __v);
401
402template <class _Tp>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000403_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000404_Tp*
405end(valarray<_Tp>& __v);
406
407template <class _Tp>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000408_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000409const _Tp*
410end(const valarray<_Tp>& __v);
411
412template <class _Op, class _A0>
413struct _UnaryOp
414{
415 typedef typename _Op::result_type result_type;
416 typedef typename _A0::value_type value_type;
417
418 _Op __op_;
419 _A0 __a0_;
420
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000422 _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {}
423
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000425 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
426
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000427 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428 size_t size() const {return __a0_.size();}
429};
430
431template <class _Op, class _A0, class _A1>
432struct _BinaryOp
433{
434 typedef typename _Op::result_type result_type;
435 typedef typename _A0::value_type value_type;
436
437 _Op __op_;
438 _A0 __a0_;
439 _A1 __a1_;
440
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000441 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000442 _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1)
443 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
444
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
447
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449 size_t size() const {return __a0_.size();}
450};
451
452template <class _Tp>
453class __scalar_expr
454{
455public:
456 typedef _Tp value_type;
457 typedef const _Tp& result_type;
458private:
459 const value_type& __t_;
460 size_t __s_;
461public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000463 explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {}
464
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000466 result_type operator[](size_t) const {return __t_;}
467
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000468 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000469 size_t size() const {return __s_;}
470};
471
472template <class _Tp>
473struct __unary_plus : unary_function<_Tp, _Tp>
474{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000476 _Tp operator()(const _Tp& __x) const
477 {return +__x;}
478};
479
480template <class _Tp>
481struct __bit_not : unary_function<_Tp, _Tp>
482{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000484 _Tp operator()(const _Tp& __x) const
485 {return ~__x;}
486};
487
488template <class _Tp>
489struct __bit_shift_left : binary_function<_Tp, _Tp, _Tp>
490{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000492 _Tp operator()(const _Tp& __x, const _Tp& __y) const
493 {return __x << __y;}
494};
495
496template <class _Tp>
497struct __bit_shift_right : binary_function<_Tp, _Tp, _Tp>
498{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000500 _Tp operator()(const _Tp& __x, const _Tp& __y) const
501 {return __x >> __y;}
502};
503
Howard Hinnantc834c512011-11-29 18:15:50 +0000504template <class _Tp, class _Fp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505struct __apply_expr : unary_function<_Tp, _Tp>
506{
507private:
Howard Hinnantc834c512011-11-29 18:15:50 +0000508 _Fp __f_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +0000511 explicit __apply_expr(_Fp __f) : __f_(__f) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000512
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000514 _Tp operator()(const _Tp& __x) const
515 {return __f_(__x);}
516};
517
518template <class _Tp>
519struct __abs_expr : unary_function<_Tp, _Tp>
520{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000521 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000522 _Tp operator()(const _Tp& __x) const
523 {return abs(__x);}
524};
525
526template <class _Tp>
527struct __acos_expr : unary_function<_Tp, _Tp>
528{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000529 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000530 _Tp operator()(const _Tp& __x) const
531 {return acos(__x);}
532};
533
534template <class _Tp>
535struct __asin_expr : unary_function<_Tp, _Tp>
536{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000538 _Tp operator()(const _Tp& __x) const
539 {return asin(__x);}
540};
541
542template <class _Tp>
543struct __atan_expr : unary_function<_Tp, _Tp>
544{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000545 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000546 _Tp operator()(const _Tp& __x) const
547 {return atan(__x);}
548};
549
550template <class _Tp>
551struct __atan2_expr : binary_function<_Tp, _Tp, _Tp>
552{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000554 _Tp operator()(const _Tp& __x, const _Tp& __y) const
555 {return atan2(__x, __y);}
556};
557
558template <class _Tp>
559struct __cos_expr : unary_function<_Tp, _Tp>
560{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562 _Tp operator()(const _Tp& __x) const
563 {return cos(__x);}
564};
565
566template <class _Tp>
567struct __cosh_expr : unary_function<_Tp, _Tp>
568{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570 _Tp operator()(const _Tp& __x) const
571 {return cosh(__x);}
572};
573
574template <class _Tp>
575struct __exp_expr : unary_function<_Tp, _Tp>
576{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000578 _Tp operator()(const _Tp& __x) const
579 {return exp(__x);}
580};
581
582template <class _Tp>
583struct __log_expr : unary_function<_Tp, _Tp>
584{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000585 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000586 _Tp operator()(const _Tp& __x) const
587 {return log(__x);}
588};
589
590template <class _Tp>
591struct __log10_expr : unary_function<_Tp, _Tp>
592{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000594 _Tp operator()(const _Tp& __x) const
595 {return log10(__x);}
596};
597
598template <class _Tp>
599struct __pow_expr : binary_function<_Tp, _Tp, _Tp>
600{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000601 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000602 _Tp operator()(const _Tp& __x, const _Tp& __y) const
603 {return pow(__x, __y);}
604};
605
606template <class _Tp>
607struct __sin_expr : unary_function<_Tp, _Tp>
608{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000610 _Tp operator()(const _Tp& __x) const
611 {return sin(__x);}
612};
613
614template <class _Tp>
615struct __sinh_expr : unary_function<_Tp, _Tp>
616{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000618 _Tp operator()(const _Tp& __x) const
619 {return sinh(__x);}
620};
621
622template <class _Tp>
623struct __sqrt_expr : unary_function<_Tp, _Tp>
624{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000626 _Tp operator()(const _Tp& __x) const
627 {return sqrt(__x);}
628};
629
630template <class _Tp>
631struct __tan_expr : unary_function<_Tp, _Tp>
632{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000633 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000634 _Tp operator()(const _Tp& __x) const
635 {return tan(__x);}
636};
637
638template <class _Tp>
639struct __tanh_expr : unary_function<_Tp, _Tp>
640{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000641 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642 _Tp operator()(const _Tp& __x) const
643 {return tanh(__x);}
644};
645
646template <class _ValExpr>
647class __slice_expr
648{
649 typedef typename remove_reference<_ValExpr>::type _RmExpr;
650public:
651 typedef typename _RmExpr::value_type value_type;
652 typedef value_type result_type;
653
654private:
655 _ValExpr __expr_;
656 size_t __start_;
657 size_t __size_;
658 size_t __stride_;
659
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000661 __slice_expr(const slice& __sl, const _RmExpr& __e)
662 : __expr_(__e),
663 __start_(__sl.start()),
664 __size_(__sl.size()),
665 __stride_(__sl.stride())
666 {}
667public:
668
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000670 result_type operator[](size_t __i) const
671 {return __expr_[__start_ + __i * __stride_];}
672
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000674 size_t size() const {return __size_;}
675
Eric Fiselier7b31ed02019-04-02 08:05:23 +0000676 template <class> friend class __val_expr;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000677 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000678};
679
680template <class _ValExpr>
681class __mask_expr;
682
683template <class _ValExpr>
684class __indirect_expr;
685
686template <class _ValExpr>
687class __shift_expr
688{
689 typedef typename remove_reference<_ValExpr>::type _RmExpr;
690public:
691 typedef typename _RmExpr::value_type value_type;
692 typedef value_type result_type;
693
694private:
695 _ValExpr __expr_;
696 size_t __size_;
697 ptrdiff_t __ul_;
698 ptrdiff_t __sn_;
699 ptrdiff_t __n_;
Howard Hinnantc834c512011-11-29 18:15:50 +0000700 static const ptrdiff_t _Np = static_cast<ptrdiff_t>(
Howard Hinnantc51e1022010-05-11 19:42:16 +0000701 sizeof(ptrdiff_t) * __CHAR_BIT__ - 1);
702
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000704 __shift_expr(int __n, const _RmExpr& __e)
705 : __expr_(__e),
706 __size_(__e.size()),
707 __n_(__n)
708 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000709 ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _Np);
710 __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _Np);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000711 __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n);
712 }
713public:
714
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000715 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000716 result_type operator[](size_t __j) const
717 {
Howard Hinnant28b24882011-12-01 20:21:04 +0000718 ptrdiff_t __i = static_cast<ptrdiff_t>(__j);
Howard Hinnantc834c512011-11-29 18:15:50 +0000719 ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000720 return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
721 }
722
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000724 size_t size() const {return __size_;}
725
726 template <class> friend class __val_expr;
727};
728
729template <class _ValExpr>
730class __cshift_expr
731{
732 typedef typename remove_reference<_ValExpr>::type _RmExpr;
733public:
734 typedef typename _RmExpr::value_type value_type;
735 typedef value_type result_type;
736
737private:
738 _ValExpr __expr_;
739 size_t __size_;
740 size_t __m_;
741 size_t __o1_;
742 size_t __o2_;
743
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000745 __cshift_expr(int __n, const _RmExpr& __e)
746 : __expr_(__e),
747 __size_(__e.size())
748 {
749 __n %= static_cast<int>(__size_);
750 if (__n >= 0)
751 {
752 __m_ = __size_ - __n;
753 __o1_ = __n;
754 __o2_ = __n - __size_;
755 }
756 else
757 {
758 __m_ = -__n;
759 __o1_ = __n + __size_;
760 __o2_ = __n;
761 }
762 }
763public:
764
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000766 result_type operator[](size_t __i) const
767 {
768 if (__i < __m_)
769 return __expr_[__i + __o1_];
770 return __expr_[__i + __o2_];
771 }
772
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000774 size_t size() const {return __size_;}
775
776 template <class> friend class __val_expr;
777};
778
779template<class _ValExpr>
780class __val_expr;
781
782template<class _ValExpr>
783struct __is_val_expr : false_type {};
784
785template<class _ValExpr>
786struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
787
788template<class _Tp>
789struct __is_val_expr<valarray<_Tp> > : true_type {};
790
791template<class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000792class _LIBCPP_TEMPLATE_VIS valarray
Howard Hinnantc51e1022010-05-11 19:42:16 +0000793{
794public:
795 typedef _Tp value_type;
796 typedef _Tp result_type;
797
798private:
799 value_type* __begin_;
800 value_type* __end_;
801
802public:
803 // construct/destroy:
Douglas Gregor68902322012-05-19 07:14:17 +0000804 _LIBCPP_INLINE_VISIBILITY
Bruce Mitchener170d8972020-11-24 12:53:53 -0500805 valarray() : __begin_(nullptr), __end_(nullptr) {}
Louis Dionneb4d05d72018-10-16 19:26:23 +0000806 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Eric Fiseliere529a802016-09-16 00:13:55 +0000807 explicit valarray(size_t __n);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000808 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +0000809 valarray(const value_type& __x, size_t __n);
810 valarray(const value_type* __p, size_t __n);
811 valarray(const valarray& __v);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000812#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000813 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant298aed92012-07-21 00:51:28 +0000814 valarray(valarray&& __v) _NOEXCEPT;
Douglas Gregor68902322012-05-19 07:14:17 +0000815 valarray(initializer_list<value_type> __il);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000816#endif // _LIBCPP_CXX03_LANG
Douglas Gregor68902322012-05-19 07:14:17 +0000817 valarray(const slice_array<value_type>& __sa);
818 valarray(const gslice_array<value_type>& __ga);
819 valarray(const mask_array<value_type>& __ma);
820 valarray(const indirect_array<value_type>& __ia);
Louis Dionneb4d05d72018-10-16 19:26:23 +0000821 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Douglas Gregor68902322012-05-19 07:14:17 +0000822 ~valarray();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000823
824 // assignment:
Douglas Gregor68902322012-05-19 07:14:17 +0000825 valarray& operator=(const valarray& __v);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000826#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant298aed92012-07-21 00:51:28 +0000828 valarray& operator=(valarray&& __v) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000829 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +0000830 valarray& operator=(initializer_list<value_type>);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000831#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000832 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +0000833 valarray& operator=(const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000835 valarray& operator=(const slice_array<value_type>& __sa);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000837 valarray& operator=(const gslice_array<value_type>& __ga);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000839 valarray& operator=(const mask_array<value_type>& __ma);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000841 valarray& operator=(const indirect_array<value_type>& __ia);
Howard Hinnant329cd412011-07-27 23:19:59 +0000842 template <class _ValExpr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000843 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant329cd412011-07-27 23:19:59 +0000844 valarray& operator=(const __val_expr<_ValExpr>& __v);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000845
846 // element access:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000848 const value_type& operator[](size_t __i) const {return __begin_[__i];}
849
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000851 value_type& operator[](size_t __i) {return __begin_[__i];}
852
853 // subset operations:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000854 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000855 __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857 slice_array<value_type> operator[](slice __s);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000859 __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000861 gslice_array<value_type> operator[](const gslice& __gs);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000862#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000864 __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866 gslice_array<value_type> operator[](gslice&& __gs);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000867#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000868 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000869 __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000871 mask_array<value_type> operator[](const valarray<bool>& __vb);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000872#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000874 __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000876 mask_array<value_type> operator[](valarray<bool>&& __vb);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000877#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000878 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000879 __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000881 indirect_array<value_type> operator[](const valarray<size_t>& __vs);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000882#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000884 __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000886 indirect_array<value_type> operator[](valarray<size_t>&& __vs);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000887#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000888
889 // unary operators:
Douglas Gregor68902322012-05-19 07:14:17 +0000890 valarray operator+() const;
891 valarray operator-() const;
892 valarray operator~() const;
893 valarray<bool> operator!() const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000894
895 // computed assignment:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000897 valarray& operator*= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000899 valarray& operator/= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000901 valarray& operator%= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000903 valarray& operator+= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000904 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000905 valarray& operator-= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000907 valarray& operator^= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000909 valarray& operator&= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911 valarray& operator|= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000912 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000913 valarray& operator<<=(const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000915 valarray& operator>>=(const value_type& __x);
916
917 template <class _Expr>
918 typename enable_if
919 <
920 __is_val_expr<_Expr>::value,
921 valarray&
922 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000924 operator*= (const _Expr& __v);
925
926 template <class _Expr>
927 typename enable_if
928 <
929 __is_val_expr<_Expr>::value,
930 valarray&
931 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000932 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000933 operator/= (const _Expr& __v);
934
935 template <class _Expr>
936 typename enable_if
937 <
938 __is_val_expr<_Expr>::value,
939 valarray&
940 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000941 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000942 operator%= (const _Expr& __v);
943
944 template <class _Expr>
945 typename enable_if
946 <
947 __is_val_expr<_Expr>::value,
948 valarray&
949 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000951 operator+= (const _Expr& __v);
952
953 template <class _Expr>
954 typename enable_if
955 <
956 __is_val_expr<_Expr>::value,
957 valarray&
958 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000959 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000960 operator-= (const _Expr& __v);
961
962 template <class _Expr>
963 typename enable_if
964 <
965 __is_val_expr<_Expr>::value,
966 valarray&
967 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000968 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000969 operator^= (const _Expr& __v);
970
971 template <class _Expr>
972 typename enable_if
973 <
974 __is_val_expr<_Expr>::value,
975 valarray&
976 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000977 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000978 operator|= (const _Expr& __v);
979
980 template <class _Expr>
981 typename enable_if
982 <
983 __is_val_expr<_Expr>::value,
984 valarray&
985 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000986 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000987 operator&= (const _Expr& __v);
988
989 template <class _Expr>
990 typename enable_if
991 <
992 __is_val_expr<_Expr>::value,
993 valarray&
994 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000996 operator<<= (const _Expr& __v);
997
998 template <class _Expr>
999 typename enable_if
1000 <
1001 __is_val_expr<_Expr>::value,
1002 valarray&
1003 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001004 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001005 operator>>= (const _Expr& __v);
1006
1007 // member functions:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant298aed92012-07-21 00:51:28 +00001009 void swap(valarray& __v) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001010
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001011 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant28b24882011-12-01 20:21:04 +00001012 size_t size() const {return static_cast<size_t>(__end_ - __begin_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001013
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001014 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +00001015 value_type sum() const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001016 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +00001017 value_type min() const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001018 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +00001019 value_type max() const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001020
Douglas Gregor68902322012-05-19 07:14:17 +00001021 valarray shift (int __i) const;
1022 valarray cshift(int __i) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001023 valarray apply(value_type __f(value_type)) const;
1024 valarray apply(value_type __f(const value_type&)) const;
1025 void resize(size_t __n, value_type __x = value_type());
1026
1027private:
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001028 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
1029 template <class> friend class _LIBCPP_TEMPLATE_VIS slice_array;
1030 template <class> friend class _LIBCPP_TEMPLATE_VIS gslice_array;
1031 template <class> friend class _LIBCPP_TEMPLATE_VIS mask_array;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001032 template <class> friend class __mask_expr;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001033 template <class> friend class _LIBCPP_TEMPLATE_VIS indirect_array;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001034 template <class> friend class __indirect_expr;
1035 template <class> friend class __val_expr;
1036
1037 template <class _Up>
1038 friend
1039 _Up*
1040 begin(valarray<_Up>& __v);
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001041
Howard Hinnantc51e1022010-05-11 19:42:16 +00001042 template <class _Up>
1043 friend
1044 const _Up*
1045 begin(const valarray<_Up>& __v);
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001046
Howard Hinnantc51e1022010-05-11 19:42:16 +00001047 template <class _Up>
1048 friend
1049 _Up*
1050 end(valarray<_Up>& __v);
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001051
Howard Hinnantc51e1022010-05-11 19:42:16 +00001052 template <class _Up>
1053 friend
1054 const _Up*
1055 end(const valarray<_Up>& __v);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00001056
Eric Fiseliera119c322018-10-25 17:43:26 +00001057 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2856ef82018-10-25 17:21:30 +00001058 void __clear(size_t __capacity);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00001059 valarray& __assign_range(const value_type* __f, const value_type* __l);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001060};
1061
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001062_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void valarray<size_t>::resize(size_t, size_t))
1063
Howard Hinnantc51e1022010-05-11 19:42:16 +00001064template <class _Op, class _Tp>
1065struct _UnaryOp<_Op, valarray<_Tp> >
1066{
1067 typedef typename _Op::result_type result_type;
1068 typedef _Tp value_type;
1069
1070 _Op __op_;
1071 const valarray<_Tp>& __a0_;
1072
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001073 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001074 _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
1075
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001076 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001077 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
1078
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001079 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001080 size_t size() const {return __a0_.size();}
1081};
1082
1083template <class _Op, class _Tp, class _A1>
1084struct _BinaryOp<_Op, valarray<_Tp>, _A1>
1085{
1086 typedef typename _Op::result_type result_type;
1087 typedef _Tp value_type;
1088
1089 _Op __op_;
1090 const valarray<_Tp>& __a0_;
1091 _A1 __a1_;
1092
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001094 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
1095 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1096
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001098 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1099
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001101 size_t size() const {return __a0_.size();}
1102};
1103
1104template <class _Op, class _A0, class _Tp>
1105struct _BinaryOp<_Op, _A0, valarray<_Tp> >
1106{
1107 typedef typename _Op::result_type result_type;
1108 typedef _Tp value_type;
1109
1110 _Op __op_;
1111 _A0 __a0_;
1112 const valarray<_Tp>& __a1_;
1113
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001114 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001115 _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
1116 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1117
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001118 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001119 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1120
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001121 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001122 size_t size() const {return __a0_.size();}
1123};
1124
1125template <class _Op, class _Tp>
1126struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> >
1127{
1128 typedef typename _Op::result_type result_type;
1129 typedef _Tp value_type;
1130
1131 _Op __op_;
1132 const valarray<_Tp>& __a0_;
1133 const valarray<_Tp>& __a1_;
1134
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001136 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
1137 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1138
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001139 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001140 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1141
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001142 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001143 size_t size() const {return __a0_.size();}
1144};
1145
1146// slice_array
1147
1148template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001149class _LIBCPP_TEMPLATE_VIS slice_array
Howard Hinnantc51e1022010-05-11 19:42:16 +00001150{
1151public:
1152 typedef _Tp value_type;
1153
1154private:
1155 value_type* __vp_;
1156 size_t __size_;
1157 size_t __stride_;
1158
1159public:
1160 template <class _Expr>
1161 typename enable_if
1162 <
1163 __is_val_expr<_Expr>::value,
1164 void
1165 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001166 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001167 operator=(const _Expr& __v) const;
1168
1169 template <class _Expr>
1170 typename enable_if
1171 <
1172 __is_val_expr<_Expr>::value,
1173 void
1174 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001175 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001176 operator*=(const _Expr& __v) const;
1177
1178 template <class _Expr>
1179 typename enable_if
1180 <
1181 __is_val_expr<_Expr>::value,
1182 void
1183 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001184 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001185 operator/=(const _Expr& __v) const;
1186
1187 template <class _Expr>
1188 typename enable_if
1189 <
1190 __is_val_expr<_Expr>::value,
1191 void
1192 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001193 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001194 operator%=(const _Expr& __v) const;
1195
1196 template <class _Expr>
1197 typename enable_if
1198 <
1199 __is_val_expr<_Expr>::value,
1200 void
1201 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001202 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001203 operator+=(const _Expr& __v) const;
1204
1205 template <class _Expr>
1206 typename enable_if
1207 <
1208 __is_val_expr<_Expr>::value,
1209 void
1210 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001211 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001212 operator-=(const _Expr& __v) const;
1213
1214 template <class _Expr>
1215 typename enable_if
1216 <
1217 __is_val_expr<_Expr>::value,
1218 void
1219 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001220 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001221 operator^=(const _Expr& __v) const;
1222
1223 template <class _Expr>
1224 typename enable_if
1225 <
1226 __is_val_expr<_Expr>::value,
1227 void
1228 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001229 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001230 operator&=(const _Expr& __v) const;
1231
1232 template <class _Expr>
1233 typename enable_if
1234 <
1235 __is_val_expr<_Expr>::value,
1236 void
1237 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001238 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001239 operator|=(const _Expr& __v) const;
1240
1241 template <class _Expr>
1242 typename enable_if
1243 <
1244 __is_val_expr<_Expr>::value,
1245 void
1246 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001247 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001248 operator<<=(const _Expr& __v) const;
1249
1250 template <class _Expr>
1251 typename enable_if
1252 <
1253 __is_val_expr<_Expr>::value,
1254 void
1255 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001256 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001257 operator>>=(const _Expr& __v) const;
1258
Eric Fiselierb9f37ca2019-12-12 20:48:11 -05001259 slice_array(slice_array const&) = default;
1260
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001261 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001262 const slice_array& operator=(const slice_array& __sa) const;
1263
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001264 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001265 void operator=(const value_type& __x) const;
1266
1267private:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001268 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001269 slice_array(const slice& __sl, const valarray<value_type>& __v)
1270 : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())),
1271 __size_(__sl.size()),
1272 __stride_(__sl.stride())
1273 {}
1274
1275 template <class> friend class valarray;
1276 template <class> friend class sliceExpr;
1277};
1278
1279template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001280inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001281const slice_array<_Tp>&
1282slice_array<_Tp>::operator=(const slice_array& __sa) const
1283{
1284 value_type* __t = __vp_;
1285 const value_type* __s = __sa.__vp_;
1286 for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
1287 *__t = *__s;
Eric Fiselier3b80ce92014-08-12 00:06:58 +00001288 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001289}
1290
1291template <class _Tp>
1292template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001293inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001294typename enable_if
1295<
1296 __is_val_expr<_Expr>::value,
1297 void
1298>::type
1299slice_array<_Tp>::operator=(const _Expr& __v) const
1300{
1301 value_type* __t = __vp_;
1302 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1303 *__t = __v[__i];
1304}
1305
1306template <class _Tp>
1307template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001308inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001309typename enable_if
1310<
1311 __is_val_expr<_Expr>::value,
1312 void
1313>::type
1314slice_array<_Tp>::operator*=(const _Expr& __v) const
1315{
1316 value_type* __t = __vp_;
1317 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1318 *__t *= __v[__i];
1319}
1320
1321template <class _Tp>
1322template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001323inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001324typename enable_if
1325<
1326 __is_val_expr<_Expr>::value,
1327 void
1328>::type
1329slice_array<_Tp>::operator/=(const _Expr& __v) const
1330{
1331 value_type* __t = __vp_;
1332 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1333 *__t /= __v[__i];
1334}
1335
1336template <class _Tp>
1337template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001338inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001339typename enable_if
1340<
1341 __is_val_expr<_Expr>::value,
1342 void
1343>::type
1344slice_array<_Tp>::operator%=(const _Expr& __v) const
1345{
1346 value_type* __t = __vp_;
1347 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1348 *__t %= __v[__i];
1349}
1350
1351template <class _Tp>
1352template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001353inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001354typename enable_if
1355<
1356 __is_val_expr<_Expr>::value,
1357 void
1358>::type
1359slice_array<_Tp>::operator+=(const _Expr& __v) const
1360{
1361 value_type* __t = __vp_;
1362 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1363 *__t += __v[__i];
1364}
1365
1366template <class _Tp>
1367template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001368inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001369typename enable_if
1370<
1371 __is_val_expr<_Expr>::value,
1372 void
1373>::type
1374slice_array<_Tp>::operator-=(const _Expr& __v) const
1375{
1376 value_type* __t = __vp_;
1377 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1378 *__t -= __v[__i];
1379}
1380
1381template <class _Tp>
1382template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001383inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001384typename enable_if
1385<
1386 __is_val_expr<_Expr>::value,
1387 void
1388>::type
1389slice_array<_Tp>::operator^=(const _Expr& __v) const
1390{
1391 value_type* __t = __vp_;
1392 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1393 *__t ^= __v[__i];
1394}
1395
1396template <class _Tp>
1397template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001398inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001399typename enable_if
1400<
1401 __is_val_expr<_Expr>::value,
1402 void
1403>::type
1404slice_array<_Tp>::operator&=(const _Expr& __v) const
1405{
1406 value_type* __t = __vp_;
1407 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1408 *__t &= __v[__i];
1409}
1410
1411template <class _Tp>
1412template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001413inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001414typename enable_if
1415<
1416 __is_val_expr<_Expr>::value,
1417 void
1418>::type
1419slice_array<_Tp>::operator|=(const _Expr& __v) const
1420{
1421 value_type* __t = __vp_;
1422 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1423 *__t |= __v[__i];
1424}
1425
1426template <class _Tp>
1427template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001428inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001429typename enable_if
1430<
1431 __is_val_expr<_Expr>::value,
1432 void
1433>::type
1434slice_array<_Tp>::operator<<=(const _Expr& __v) const
1435{
1436 value_type* __t = __vp_;
1437 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1438 *__t <<= __v[__i];
1439}
1440
1441template <class _Tp>
1442template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001443inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001444typename enable_if
1445<
1446 __is_val_expr<_Expr>::value,
1447 void
1448>::type
1449slice_array<_Tp>::operator>>=(const _Expr& __v) const
1450{
1451 value_type* __t = __vp_;
1452 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1453 *__t >>= __v[__i];
1454}
1455
1456template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001457inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001458void
1459slice_array<_Tp>::operator=(const value_type& __x) const
1460{
1461 value_type* __t = __vp_;
1462 for (size_t __n = __size_; __n; --__n, __t += __stride_)
1463 *__t = __x;
1464}
1465
1466// gslice
1467
Howard Hinnant8331b762013-03-06 23:30:19 +00001468class _LIBCPP_TYPE_VIS gslice
Howard Hinnantc51e1022010-05-11 19:42:16 +00001469{
1470 valarray<size_t> __size_;
1471 valarray<size_t> __stride_;
1472 valarray<size_t> __1d_;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001473
Howard Hinnantc51e1022010-05-11 19:42:16 +00001474public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001476 gslice() {}
Douglas Gregor68902322012-05-19 07:14:17 +00001477
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001478 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001479 gslice(size_t __start, const valarray<size_t>& __size,
1480 const valarray<size_t>& __stride)
1481 : __size_(__size),
1482 __stride_(__stride)
1483 {__init(__start);}
1484
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00001485#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001486
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001488 gslice(size_t __start, const valarray<size_t>& __size,
1489 valarray<size_t>&& __stride)
1490 : __size_(__size),
1491 __stride_(move(__stride))
1492 {__init(__start);}
1493
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001495 gslice(size_t __start, valarray<size_t>&& __size,
1496 const valarray<size_t>& __stride)
1497 : __size_(move(__size)),
1498 __stride_(__stride)
1499 {__init(__start);}
1500
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001501 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001502 gslice(size_t __start, valarray<size_t>&& __size,
1503 valarray<size_t>&& __stride)
1504 : __size_(move(__size)),
1505 __stride_(move(__stride))
1506 {__init(__start);}
1507
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00001508#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001509
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001511 size_t start() const {return __1d_.size() ? __1d_[0] : 0;}
1512
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001514 valarray<size_t> size() const {return __size_;}
1515
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001516 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001517 valarray<size_t> stride() const {return __stride_;}
1518
1519private:
1520 void __init(size_t __start);
1521
1522 template <class> friend class gslice_array;
1523 template <class> friend class valarray;
1524 template <class> friend class __val_expr;
1525};
1526
1527// gslice_array
1528
1529template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001530class _LIBCPP_TEMPLATE_VIS gslice_array
Howard Hinnantc51e1022010-05-11 19:42:16 +00001531{
1532public:
1533 typedef _Tp value_type;
1534
1535private:
1536 value_type* __vp_;
1537 valarray<size_t> __1d_;
1538
1539public:
1540 template <class _Expr>
1541 typename enable_if
1542 <
1543 __is_val_expr<_Expr>::value,
1544 void
1545 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001546 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001547 operator=(const _Expr& __v) const;
1548
1549 template <class _Expr>
1550 typename enable_if
1551 <
1552 __is_val_expr<_Expr>::value,
1553 void
1554 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001555 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001556 operator*=(const _Expr& __v) const;
1557
1558 template <class _Expr>
1559 typename enable_if
1560 <
1561 __is_val_expr<_Expr>::value,
1562 void
1563 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001564 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001565 operator/=(const _Expr& __v) const;
1566
1567 template <class _Expr>
1568 typename enable_if
1569 <
1570 __is_val_expr<_Expr>::value,
1571 void
1572 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001573 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001574 operator%=(const _Expr& __v) const;
1575
1576 template <class _Expr>
1577 typename enable_if
1578 <
1579 __is_val_expr<_Expr>::value,
1580 void
1581 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001583 operator+=(const _Expr& __v) const;
1584
1585 template <class _Expr>
1586 typename enable_if
1587 <
1588 __is_val_expr<_Expr>::value,
1589 void
1590 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001592 operator-=(const _Expr& __v) const;
1593
1594 template <class _Expr>
1595 typename enable_if
1596 <
1597 __is_val_expr<_Expr>::value,
1598 void
1599 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001601 operator^=(const _Expr& __v) const;
1602
1603 template <class _Expr>
1604 typename enable_if
1605 <
1606 __is_val_expr<_Expr>::value,
1607 void
1608 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001610 operator&=(const _Expr& __v) const;
1611
1612 template <class _Expr>
1613 typename enable_if
1614 <
1615 __is_val_expr<_Expr>::value,
1616 void
1617 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001619 operator|=(const _Expr& __v) const;
1620
1621 template <class _Expr>
1622 typename enable_if
1623 <
1624 __is_val_expr<_Expr>::value,
1625 void
1626 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001628 operator<<=(const _Expr& __v) const;
1629
1630 template <class _Expr>
1631 typename enable_if
1632 <
1633 __is_val_expr<_Expr>::value,
1634 void
1635 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001637 operator>>=(const _Expr& __v) const;
1638
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001640 const gslice_array& operator=(const gslice_array& __ga) const;
1641
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001643 void operator=(const value_type& __x) const;
1644
Eric Fiselierb9f37ca2019-12-12 20:48:11 -05001645 gslice_array(const gslice_array&) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001646
1647private:
Howard Hinnantc51e1022010-05-11 19:42:16 +00001648 gslice_array(const gslice& __gs, const valarray<value_type>& __v)
1649 : __vp_(const_cast<value_type*>(__v.__begin_)),
1650 __1d_(__gs.__1d_)
1651 {}
1652
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00001653#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001654 gslice_array(gslice&& __gs, const valarray<value_type>& __v)
1655 : __vp_(const_cast<value_type*>(__v.__begin_)),
1656 __1d_(move(__gs.__1d_))
1657 {}
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00001658#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001659
1660 template <class> friend class valarray;
1661};
1662
1663template <class _Tp>
1664template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001665inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001666typename enable_if
1667<
1668 __is_val_expr<_Expr>::value,
1669 void
1670>::type
1671gslice_array<_Tp>::operator=(const _Expr& __v) const
1672{
1673 typedef const size_t* _Ip;
1674 size_t __j = 0;
1675 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1676 __vp_[*__i] = __v[__j];
1677}
1678
1679template <class _Tp>
1680template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001681inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001682typename enable_if
1683<
1684 __is_val_expr<_Expr>::value,
1685 void
1686>::type
1687gslice_array<_Tp>::operator*=(const _Expr& __v) const
1688{
1689 typedef const size_t* _Ip;
1690 size_t __j = 0;
1691 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1692 __vp_[*__i] *= __v[__j];
1693}
1694
1695template <class _Tp>
1696template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001697inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001698typename enable_if
1699<
1700 __is_val_expr<_Expr>::value,
1701 void
1702>::type
1703gslice_array<_Tp>::operator/=(const _Expr& __v) const
1704{
1705 typedef const size_t* _Ip;
1706 size_t __j = 0;
1707 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1708 __vp_[*__i] /= __v[__j];
1709}
1710
1711template <class _Tp>
1712template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001713inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001714typename enable_if
1715<
1716 __is_val_expr<_Expr>::value,
1717 void
1718>::type
1719gslice_array<_Tp>::operator%=(const _Expr& __v) const
1720{
1721 typedef const size_t* _Ip;
1722 size_t __j = 0;
1723 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1724 __vp_[*__i] %= __v[__j];
1725}
1726
1727template <class _Tp>
1728template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001729inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001730typename enable_if
1731<
1732 __is_val_expr<_Expr>::value,
1733 void
1734>::type
1735gslice_array<_Tp>::operator+=(const _Expr& __v) const
1736{
1737 typedef const size_t* _Ip;
1738 size_t __j = 0;
1739 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1740 __vp_[*__i] += __v[__j];
1741}
1742
1743template <class _Tp>
1744template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001745inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001746typename enable_if
1747<
1748 __is_val_expr<_Expr>::value,
1749 void
1750>::type
1751gslice_array<_Tp>::operator-=(const _Expr& __v) const
1752{
1753 typedef const size_t* _Ip;
1754 size_t __j = 0;
1755 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1756 __vp_[*__i] -= __v[__j];
1757}
1758
1759template <class _Tp>
1760template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001761inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001762typename enable_if
1763<
1764 __is_val_expr<_Expr>::value,
1765 void
1766>::type
1767gslice_array<_Tp>::operator^=(const _Expr& __v) const
1768{
1769 typedef const size_t* _Ip;
1770 size_t __j = 0;
1771 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1772 __vp_[*__i] ^= __v[__j];
1773}
1774
1775template <class _Tp>
1776template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001777inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001778typename enable_if
1779<
1780 __is_val_expr<_Expr>::value,
1781 void
1782>::type
1783gslice_array<_Tp>::operator&=(const _Expr& __v) const
1784{
1785 typedef const size_t* _Ip;
1786 size_t __j = 0;
1787 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1788 __vp_[*__i] &= __v[__j];
1789}
1790
1791template <class _Tp>
1792template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001793inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001794typename enable_if
1795<
1796 __is_val_expr<_Expr>::value,
1797 void
1798>::type
1799gslice_array<_Tp>::operator|=(const _Expr& __v) const
1800{
1801 typedef const size_t* _Ip;
1802 size_t __j = 0;
1803 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1804 __vp_[*__i] |= __v[__j];
1805}
1806
1807template <class _Tp>
1808template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001809inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001810typename enable_if
1811<
1812 __is_val_expr<_Expr>::value,
1813 void
1814>::type
1815gslice_array<_Tp>::operator<<=(const _Expr& __v) const
1816{
1817 typedef const size_t* _Ip;
1818 size_t __j = 0;
1819 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1820 __vp_[*__i] <<= __v[__j];
1821}
1822
1823template <class _Tp>
1824template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001825inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001826typename enable_if
1827<
1828 __is_val_expr<_Expr>::value,
1829 void
1830>::type
1831gslice_array<_Tp>::operator>>=(const _Expr& __v) const
1832{
1833 typedef const size_t* _Ip;
1834 size_t __j = 0;
1835 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1836 __vp_[*__i] >>= __v[__j];
1837}
1838
1839template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001840inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001841const gslice_array<_Tp>&
1842gslice_array<_Tp>::operator=(const gslice_array& __ga) const
1843{
1844 typedef const size_t* _Ip;
1845 const value_type* __s = __ga.__vp_;
1846 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_;
1847 __i != __e; ++__i, ++__j)
1848 __vp_[*__i] = __s[*__j];
1849 return *this;
1850}
1851
1852template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001853inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001854void
1855gslice_array<_Tp>::operator=(const value_type& __x) const
1856{
1857 typedef const size_t* _Ip;
1858 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1859 __vp_[*__i] = __x;
1860}
1861
1862// mask_array
1863
1864template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001865class _LIBCPP_TEMPLATE_VIS mask_array
Howard Hinnantc51e1022010-05-11 19:42:16 +00001866{
1867public:
1868 typedef _Tp value_type;
1869
1870private:
1871 value_type* __vp_;
1872 valarray<size_t> __1d_;
1873
1874public:
1875 template <class _Expr>
1876 typename enable_if
1877 <
1878 __is_val_expr<_Expr>::value,
1879 void
1880 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001881 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001882 operator=(const _Expr& __v) const;
1883
1884 template <class _Expr>
1885 typename enable_if
1886 <
1887 __is_val_expr<_Expr>::value,
1888 void
1889 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001890 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001891 operator*=(const _Expr& __v) const;
1892
1893 template <class _Expr>
1894 typename enable_if
1895 <
1896 __is_val_expr<_Expr>::value,
1897 void
1898 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001899 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001900 operator/=(const _Expr& __v) const;
1901
1902 template <class _Expr>
1903 typename enable_if
1904 <
1905 __is_val_expr<_Expr>::value,
1906 void
1907 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001909 operator%=(const _Expr& __v) const;
1910
1911 template <class _Expr>
1912 typename enable_if
1913 <
1914 __is_val_expr<_Expr>::value,
1915 void
1916 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001917 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001918 operator+=(const _Expr& __v) const;
1919
1920 template <class _Expr>
1921 typename enable_if
1922 <
1923 __is_val_expr<_Expr>::value,
1924 void
1925 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001926 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001927 operator-=(const _Expr& __v) const;
1928
1929 template <class _Expr>
1930 typename enable_if
1931 <
1932 __is_val_expr<_Expr>::value,
1933 void
1934 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001935 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001936 operator^=(const _Expr& __v) const;
1937
1938 template <class _Expr>
1939 typename enable_if
1940 <
1941 __is_val_expr<_Expr>::value,
1942 void
1943 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001945 operator&=(const _Expr& __v) const;
1946
1947 template <class _Expr>
1948 typename enable_if
1949 <
1950 __is_val_expr<_Expr>::value,
1951 void
1952 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001954 operator|=(const _Expr& __v) const;
1955
1956 template <class _Expr>
1957 typename enable_if
1958 <
1959 __is_val_expr<_Expr>::value,
1960 void
1961 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001963 operator<<=(const _Expr& __v) const;
1964
1965 template <class _Expr>
1966 typename enable_if
1967 <
1968 __is_val_expr<_Expr>::value,
1969 void
1970 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001971 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001972 operator>>=(const _Expr& __v) const;
1973
Eric Fiselierb9f37ca2019-12-12 20:48:11 -05001974 mask_array(const mask_array&) = default;
1975
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001976 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001977 const mask_array& operator=(const mask_array& __ma) const;
1978
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001979 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001980 void operator=(const value_type& __x) const;
1981
Howard Hinnantc51e1022010-05-11 19:42:16 +00001982private:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001983 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001984 mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
1985 : __vp_(const_cast<value_type*>(__v.__begin_)),
Howard Hinnant28b24882011-12-01 20:21:04 +00001986 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001987 {
1988 size_t __j = 0;
1989 for (size_t __i = 0; __i < __vb.size(); ++__i)
1990 if (__vb[__i])
1991 __1d_[__j++] = __i;
1992 }
1993
1994 template <class> friend class valarray;
1995};
1996
1997template <class _Tp>
1998template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001999inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002000typename enable_if
2001<
2002 __is_val_expr<_Expr>::value,
2003 void
2004>::type
2005mask_array<_Tp>::operator=(const _Expr& __v) const
2006{
2007 size_t __n = __1d_.size();
2008 for (size_t __i = 0; __i < __n; ++__i)
2009 __vp_[__1d_[__i]] = __v[__i];
2010}
2011
2012template <class _Tp>
2013template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002014inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002015typename enable_if
2016<
2017 __is_val_expr<_Expr>::value,
2018 void
2019>::type
2020mask_array<_Tp>::operator*=(const _Expr& __v) const
2021{
2022 size_t __n = __1d_.size();
2023 for (size_t __i = 0; __i < __n; ++__i)
2024 __vp_[__1d_[__i]] *= __v[__i];
2025}
2026
2027template <class _Tp>
2028template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002029inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002030typename enable_if
2031<
2032 __is_val_expr<_Expr>::value,
2033 void
2034>::type
2035mask_array<_Tp>::operator/=(const _Expr& __v) const
2036{
2037 size_t __n = __1d_.size();
2038 for (size_t __i = 0; __i < __n; ++__i)
2039 __vp_[__1d_[__i]] /= __v[__i];
2040}
2041
2042template <class _Tp>
2043template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002044inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002045typename enable_if
2046<
2047 __is_val_expr<_Expr>::value,
2048 void
2049>::type
2050mask_array<_Tp>::operator%=(const _Expr& __v) const
2051{
2052 size_t __n = __1d_.size();
2053 for (size_t __i = 0; __i < __n; ++__i)
2054 __vp_[__1d_[__i]] %= __v[__i];
2055}
2056
2057template <class _Tp>
2058template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002059inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002060typename enable_if
2061<
2062 __is_val_expr<_Expr>::value,
2063 void
2064>::type
2065mask_array<_Tp>::operator+=(const _Expr& __v) const
2066{
2067 size_t __n = __1d_.size();
2068 for (size_t __i = 0; __i < __n; ++__i)
2069 __vp_[__1d_[__i]] += __v[__i];
2070}
2071
2072template <class _Tp>
2073template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002074inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002075typename enable_if
2076<
2077 __is_val_expr<_Expr>::value,
2078 void
2079>::type
2080mask_array<_Tp>::operator-=(const _Expr& __v) const
2081{
2082 size_t __n = __1d_.size();
2083 for (size_t __i = 0; __i < __n; ++__i)
2084 __vp_[__1d_[__i]] -= __v[__i];
2085}
2086
2087template <class _Tp>
2088template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002089inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002090typename enable_if
2091<
2092 __is_val_expr<_Expr>::value,
2093 void
2094>::type
2095mask_array<_Tp>::operator^=(const _Expr& __v) const
2096{
2097 size_t __n = __1d_.size();
2098 for (size_t __i = 0; __i < __n; ++__i)
2099 __vp_[__1d_[__i]] ^= __v[__i];
2100}
2101
2102template <class _Tp>
2103template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002104inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002105typename enable_if
2106<
2107 __is_val_expr<_Expr>::value,
2108 void
2109>::type
2110mask_array<_Tp>::operator&=(const _Expr& __v) const
2111{
2112 size_t __n = __1d_.size();
2113 for (size_t __i = 0; __i < __n; ++__i)
2114 __vp_[__1d_[__i]] &= __v[__i];
2115}
2116
2117template <class _Tp>
2118template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002119inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002120typename enable_if
2121<
2122 __is_val_expr<_Expr>::value,
2123 void
2124>::type
2125mask_array<_Tp>::operator|=(const _Expr& __v) const
2126{
2127 size_t __n = __1d_.size();
2128 for (size_t __i = 0; __i < __n; ++__i)
2129 __vp_[__1d_[__i]] |= __v[__i];
2130}
2131
2132template <class _Tp>
2133template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002134inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002135typename enable_if
2136<
2137 __is_val_expr<_Expr>::value,
2138 void
2139>::type
2140mask_array<_Tp>::operator<<=(const _Expr& __v) const
2141{
2142 size_t __n = __1d_.size();
2143 for (size_t __i = 0; __i < __n; ++__i)
2144 __vp_[__1d_[__i]] <<= __v[__i];
2145}
2146
2147template <class _Tp>
2148template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002149inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002150typename enable_if
2151<
2152 __is_val_expr<_Expr>::value,
2153 void
2154>::type
2155mask_array<_Tp>::operator>>=(const _Expr& __v) const
2156{
2157 size_t __n = __1d_.size();
2158 for (size_t __i = 0; __i < __n; ++__i)
2159 __vp_[__1d_[__i]] >>= __v[__i];
2160}
2161
2162template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002163inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002164const mask_array<_Tp>&
2165mask_array<_Tp>::operator=(const mask_array& __ma) const
2166{
2167 size_t __n = __1d_.size();
2168 for (size_t __i = 0; __i < __n; ++__i)
2169 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
Eric Fiselier3b80ce92014-08-12 00:06:58 +00002170 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002171}
2172
2173template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002174inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002175void
2176mask_array<_Tp>::operator=(const value_type& __x) const
2177{
2178 size_t __n = __1d_.size();
2179 for (size_t __i = 0; __i < __n; ++__i)
2180 __vp_[__1d_[__i]] = __x;
2181}
2182
2183template <class _ValExpr>
2184class __mask_expr
2185{
2186 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2187public:
2188 typedef typename _RmExpr::value_type value_type;
2189 typedef value_type result_type;
2190
2191private:
2192 _ValExpr __expr_;
2193 valarray<size_t> __1d_;
2194
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002195 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002196 __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
2197 : __expr_(__e),
Howard Hinnant28b24882011-12-01 20:21:04 +00002198 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002199 {
2200 size_t __j = 0;
2201 for (size_t __i = 0; __i < __vb.size(); ++__i)
2202 if (__vb[__i])
2203 __1d_[__j++] = __i;
2204 }
2205
2206public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002207 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002208 result_type operator[](size_t __i) const
2209 {return __expr_[__1d_[__i]];}
2210
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002211 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002212 size_t size() const {return __1d_.size();}
2213
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002214 template <class> friend class __val_expr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002215 template <class> friend class valarray;
2216};
2217
2218// indirect_array
2219
2220template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002221class _LIBCPP_TEMPLATE_VIS indirect_array
Howard Hinnantc51e1022010-05-11 19:42:16 +00002222{
2223public:
2224 typedef _Tp value_type;
2225
2226private:
2227 value_type* __vp_;
2228 valarray<size_t> __1d_;
2229
2230public:
2231 template <class _Expr>
2232 typename enable_if
2233 <
2234 __is_val_expr<_Expr>::value,
2235 void
2236 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002237 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002238 operator=(const _Expr& __v) const;
2239
2240 template <class _Expr>
2241 typename enable_if
2242 <
2243 __is_val_expr<_Expr>::value,
2244 void
2245 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002247 operator*=(const _Expr& __v) const;
2248
2249 template <class _Expr>
2250 typename enable_if
2251 <
2252 __is_val_expr<_Expr>::value,
2253 void
2254 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002256 operator/=(const _Expr& __v) const;
2257
2258 template <class _Expr>
2259 typename enable_if
2260 <
2261 __is_val_expr<_Expr>::value,
2262 void
2263 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002264 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002265 operator%=(const _Expr& __v) const;
2266
2267 template <class _Expr>
2268 typename enable_if
2269 <
2270 __is_val_expr<_Expr>::value,
2271 void
2272 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002273 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002274 operator+=(const _Expr& __v) const;
2275
2276 template <class _Expr>
2277 typename enable_if
2278 <
2279 __is_val_expr<_Expr>::value,
2280 void
2281 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002282 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002283 operator-=(const _Expr& __v) const;
2284
2285 template <class _Expr>
2286 typename enable_if
2287 <
2288 __is_val_expr<_Expr>::value,
2289 void
2290 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002292 operator^=(const _Expr& __v) const;
2293
2294 template <class _Expr>
2295 typename enable_if
2296 <
2297 __is_val_expr<_Expr>::value,
2298 void
2299 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002301 operator&=(const _Expr& __v) const;
2302
2303 template <class _Expr>
2304 typename enable_if
2305 <
2306 __is_val_expr<_Expr>::value,
2307 void
2308 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002309 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002310 operator|=(const _Expr& __v) const;
2311
2312 template <class _Expr>
2313 typename enable_if
2314 <
2315 __is_val_expr<_Expr>::value,
2316 void
2317 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002318 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002319 operator<<=(const _Expr& __v) const;
2320
2321 template <class _Expr>
2322 typename enable_if
2323 <
2324 __is_val_expr<_Expr>::value,
2325 void
2326 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002327 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002328 operator>>=(const _Expr& __v) const;
2329
Eric Fiselierb9f37ca2019-12-12 20:48:11 -05002330 indirect_array(const indirect_array&) = default;
2331
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002332 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002333 const indirect_array& operator=(const indirect_array& __ia) const;
2334
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002335 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002336 void operator=(const value_type& __x) const;
2337
Howard Hinnantc51e1022010-05-11 19:42:16 +00002338private:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002339 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002340 indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
2341 : __vp_(const_cast<value_type*>(__v.__begin_)),
2342 __1d_(__ia)
2343 {}
2344
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002345#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002346
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002347 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002348 indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
2349 : __vp_(const_cast<value_type*>(__v.__begin_)),
2350 __1d_(move(__ia))
2351 {}
2352
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002353#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002354
2355 template <class> friend class valarray;
2356};
2357
2358template <class _Tp>
2359template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002360inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002361typename enable_if
2362<
2363 __is_val_expr<_Expr>::value,
2364 void
2365>::type
2366indirect_array<_Tp>::operator=(const _Expr& __v) const
2367{
2368 size_t __n = __1d_.size();
2369 for (size_t __i = 0; __i < __n; ++__i)
2370 __vp_[__1d_[__i]] = __v[__i];
2371}
2372
2373template <class _Tp>
2374template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002375inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002376typename enable_if
2377<
2378 __is_val_expr<_Expr>::value,
2379 void
2380>::type
2381indirect_array<_Tp>::operator*=(const _Expr& __v) const
2382{
2383 size_t __n = __1d_.size();
2384 for (size_t __i = 0; __i < __n; ++__i)
2385 __vp_[__1d_[__i]] *= __v[__i];
2386}
2387
2388template <class _Tp>
2389template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002390inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002391typename enable_if
2392<
2393 __is_val_expr<_Expr>::value,
2394 void
2395>::type
2396indirect_array<_Tp>::operator/=(const _Expr& __v) const
2397{
2398 size_t __n = __1d_.size();
2399 for (size_t __i = 0; __i < __n; ++__i)
2400 __vp_[__1d_[__i]] /= __v[__i];
2401}
2402
2403template <class _Tp>
2404template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002405inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002406typename enable_if
2407<
2408 __is_val_expr<_Expr>::value,
2409 void
2410>::type
2411indirect_array<_Tp>::operator%=(const _Expr& __v) const
2412{
2413 size_t __n = __1d_.size();
2414 for (size_t __i = 0; __i < __n; ++__i)
2415 __vp_[__1d_[__i]] %= __v[__i];
2416}
2417
2418template <class _Tp>
2419template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002420inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002421typename enable_if
2422<
2423 __is_val_expr<_Expr>::value,
2424 void
2425>::type
2426indirect_array<_Tp>::operator+=(const _Expr& __v) const
2427{
2428 size_t __n = __1d_.size();
2429 for (size_t __i = 0; __i < __n; ++__i)
2430 __vp_[__1d_[__i]] += __v[__i];
2431}
2432
2433template <class _Tp>
2434template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002435inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002436typename enable_if
2437<
2438 __is_val_expr<_Expr>::value,
2439 void
2440>::type
2441indirect_array<_Tp>::operator-=(const _Expr& __v) const
2442{
2443 size_t __n = __1d_.size();
2444 for (size_t __i = 0; __i < __n; ++__i)
2445 __vp_[__1d_[__i]] -= __v[__i];
2446}
2447
2448template <class _Tp>
2449template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002450inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002451typename enable_if
2452<
2453 __is_val_expr<_Expr>::value,
2454 void
2455>::type
2456indirect_array<_Tp>::operator^=(const _Expr& __v) const
2457{
2458 size_t __n = __1d_.size();
2459 for (size_t __i = 0; __i < __n; ++__i)
2460 __vp_[__1d_[__i]] ^= __v[__i];
2461}
2462
2463template <class _Tp>
2464template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002465inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002466typename enable_if
2467<
2468 __is_val_expr<_Expr>::value,
2469 void
2470>::type
2471indirect_array<_Tp>::operator&=(const _Expr& __v) const
2472{
2473 size_t __n = __1d_.size();
2474 for (size_t __i = 0; __i < __n; ++__i)
2475 __vp_[__1d_[__i]] &= __v[__i];
2476}
2477
2478template <class _Tp>
2479template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002480inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002481typename enable_if
2482<
2483 __is_val_expr<_Expr>::value,
2484 void
2485>::type
2486indirect_array<_Tp>::operator|=(const _Expr& __v) const
2487{
2488 size_t __n = __1d_.size();
2489 for (size_t __i = 0; __i < __n; ++__i)
2490 __vp_[__1d_[__i]] |= __v[__i];
2491}
2492
2493template <class _Tp>
2494template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002495inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002496typename enable_if
2497<
2498 __is_val_expr<_Expr>::value,
2499 void
2500>::type
2501indirect_array<_Tp>::operator<<=(const _Expr& __v) const
2502{
2503 size_t __n = __1d_.size();
2504 for (size_t __i = 0; __i < __n; ++__i)
2505 __vp_[__1d_[__i]] <<= __v[__i];
2506}
2507
2508template <class _Tp>
2509template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002510inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002511typename enable_if
2512<
2513 __is_val_expr<_Expr>::value,
2514 void
2515>::type
2516indirect_array<_Tp>::operator>>=(const _Expr& __v) const
2517{
2518 size_t __n = __1d_.size();
2519 for (size_t __i = 0; __i < __n; ++__i)
2520 __vp_[__1d_[__i]] >>= __v[__i];
2521}
2522
2523template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002524inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002525const indirect_array<_Tp>&
2526indirect_array<_Tp>::operator=(const indirect_array& __ia) const
2527{
2528 typedef const size_t* _Ip;
2529 const value_type* __s = __ia.__vp_;
2530 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_;
2531 __i != __e; ++__i, ++__j)
2532 __vp_[*__i] = __s[*__j];
2533 return *this;
2534}
2535
2536template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002537inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002538void
2539indirect_array<_Tp>::operator=(const value_type& __x) const
2540{
2541 typedef const size_t* _Ip;
2542 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
2543 __vp_[*__i] = __x;
2544}
2545
2546template <class _ValExpr>
2547class __indirect_expr
2548{
2549 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2550public:
2551 typedef typename _RmExpr::value_type value_type;
2552 typedef value_type result_type;
2553
2554private:
2555 _ValExpr __expr_;
2556 valarray<size_t> __1d_;
2557
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002558 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002559 __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e)
2560 : __expr_(__e),
2561 __1d_(__ia)
2562 {}
2563
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002564#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002565
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002567 __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
2568 : __expr_(__e),
2569 __1d_(move(__ia))
2570 {}
2571
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002572#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002573
2574public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002576 result_type operator[](size_t __i) const
2577 {return __expr_[__1d_[__i]];}
2578
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002579 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002580 size_t size() const {return __1d_.size();}
2581
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002582 template <class> friend class __val_expr;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002583 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002584};
2585
2586template<class _ValExpr>
2587class __val_expr
2588{
2589 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2590
2591 _ValExpr __expr_;
2592public:
2593 typedef typename _RmExpr::value_type value_type;
2594 typedef typename _RmExpr::result_type result_type;
2595
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002597 explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
2598
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002600 result_type operator[](size_t __i) const
2601 {return __expr_[__i];}
2602
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002604 __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002605 {
2606 typedef __slice_expr<_ValExpr> _NewExpr;
2607 return __val_expr< _NewExpr >(_NewExpr(__s, __expr_));
2608 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002609
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002611 __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002612 {
2613 typedef __indirect_expr<_ValExpr> _NewExpr;
2614 return __val_expr<_NewExpr >(_NewExpr(__gs.__1d_, __expr_));
2615 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002616
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002618 __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002619 {
2620 typedef __mask_expr<_ValExpr> _NewExpr;
2621 return __val_expr< _NewExpr >( _NewExpr(__vb, __expr_));
2622 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002623
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002625 __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002626 {
2627 typedef __indirect_expr<_ValExpr> _NewExpr;
2628 return __val_expr< _NewExpr >(_NewExpr(__vs, __expr_));
2629 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002630
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002632 __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
2633 operator+() const
2634 {
2635 typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
2636 return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
2637 }
2638
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002640 __val_expr<_UnaryOp<negate<value_type>, _ValExpr> >
2641 operator-() const
2642 {
2643 typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
2644 return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
2645 }
2646
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002647 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002648 __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> >
2649 operator~() const
2650 {
2651 typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
2652 return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
2653 }
2654
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002655 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002656 __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> >
2657 operator!() const
2658 {
2659 typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
2660 return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
2661 }
2662
2663 operator valarray<result_type>() const;
2664
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002666 size_t size() const {return __expr_.size();}
2667
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002669 result_type sum() const
2670 {
2671 size_t __n = __expr_.size();
2672 result_type __r = __n ? __expr_[0] : result_type();
2673 for (size_t __i = 1; __i < __n; ++__i)
2674 __r += __expr_[__i];
2675 return __r;
2676 }
2677
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002679 result_type min() const
2680 {
2681 size_t __n = size();
2682 result_type __r = __n ? (*this)[0] : result_type();
2683 for (size_t __i = 1; __i < __n; ++__i)
2684 {
2685 result_type __x = __expr_[__i];
2686 if (__x < __r)
2687 __r = __x;
2688 }
2689 return __r;
2690 }
2691
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002693 result_type max() const
2694 {
2695 size_t __n = size();
2696 result_type __r = __n ? (*this)[0] : result_type();
2697 for (size_t __i = 1; __i < __n; ++__i)
2698 {
2699 result_type __x = __expr_[__i];
2700 if (__r < __x)
2701 __r = __x;
2702 }
2703 return __r;
2704 }
2705
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002707 __val_expr<__shift_expr<_ValExpr> > shift (int __i) const
2708 {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));}
2709
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002710 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002711 __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const
2712 {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));}
2713
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002715 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> >
2716 apply(value_type __f(value_type)) const
2717 {
2718 typedef __apply_expr<value_type, value_type(*)(value_type)> _Op;
2719 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2720 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2721 }
2722
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002724 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> >
2725 apply(value_type __f(const value_type&)) const
2726 {
2727 typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op;
2728 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2729 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2730 }
2731};
2732
2733template<class _ValExpr>
Howard Hinnanta77b71b2013-09-13 23:27:42 +00002734__val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00002735{
2736 valarray<result_type> __r;
2737 size_t __n = __expr_.size();
2738 if (__n)
2739 {
2740 __r.__begin_ =
Louis Dionne5ffe5152020-09-28 15:47:49 -04002741 __r.__end_ = allocator<result_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002742 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
2743 ::new (__r.__end_) result_type(__expr_[__i]);
2744 }
2745 return __r;
2746}
2747
2748// valarray
2749
2750template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002751inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002752valarray<_Tp>::valarray(size_t __n)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002753 : __begin_(nullptr),
2754 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002755{
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002756 if (__n)
2757 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002758 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002759#ifndef _LIBCPP_NO_EXCEPTIONS
2760 try
2761 {
2762#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002763 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002764 ::new (__end_) value_type();
2765#ifndef _LIBCPP_NO_EXCEPTIONS
2766 }
2767 catch (...)
2768 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002769 __clear(__n);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002770 throw;
2771 }
2772#endif // _LIBCPP_NO_EXCEPTIONS
2773 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002774}
2775
2776template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002777inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002778valarray<_Tp>::valarray(const value_type& __x, size_t __n)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002779 : __begin_(nullptr),
2780 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002781{
2782 resize(__n, __x);
2783}
2784
2785template <class _Tp>
2786valarray<_Tp>::valarray(const value_type* __p, size_t __n)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002787 : __begin_(nullptr),
2788 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002789{
2790 if (__n)
2791 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002792 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002793#ifndef _LIBCPP_NO_EXCEPTIONS
2794 try
2795 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002796#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002797 for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002798 ::new (__end_) value_type(*__p);
2799#ifndef _LIBCPP_NO_EXCEPTIONS
2800 }
2801 catch (...)
2802 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002803 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002804 throw;
2805 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002806#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002807 }
2808}
2809
2810template <class _Tp>
2811valarray<_Tp>::valarray(const valarray& __v)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002812 : __begin_(nullptr),
2813 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002814{
2815 if (__v.size())
2816 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002817 __begin_ = __end_ = allocator<value_type>().allocate(__v.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002818#ifndef _LIBCPP_NO_EXCEPTIONS
2819 try
2820 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002821#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002822 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
2823 ::new (__end_) value_type(*__p);
2824#ifndef _LIBCPP_NO_EXCEPTIONS
2825 }
2826 catch (...)
2827 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002828 __clear(__v.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002829 throw;
2830 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002831#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002832 }
2833}
2834
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002835#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002836
2837template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002838inline
Howard Hinnant298aed92012-07-21 00:51:28 +00002839valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002840 : __begin_(__v.__begin_),
2841 __end_(__v.__end_)
2842{
2843 __v.__begin_ = __v.__end_ = nullptr;
2844}
2845
2846template <class _Tp>
2847valarray<_Tp>::valarray(initializer_list<value_type> __il)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002848 : __begin_(nullptr),
2849 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002850{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002851 const size_t __n = __il.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002852 if (__n)
2853 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002854 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002855#ifndef _LIBCPP_NO_EXCEPTIONS
2856 try
2857 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002858#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002859 size_t __n_left = __n;
2860 for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002861 ::new (__end_) value_type(*__p);
2862#ifndef _LIBCPP_NO_EXCEPTIONS
2863 }
2864 catch (...)
2865 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002866 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002867 throw;
2868 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002869#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002870 }
2871}
2872
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002873#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002874
2875template <class _Tp>
2876valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002877 : __begin_(nullptr),
2878 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002879{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002880 const size_t __n = __sa.__size_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002881 if (__n)
2882 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002883 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002884#ifndef _LIBCPP_NO_EXCEPTIONS
2885 try
2886 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002887#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002888 size_t __n_left = __n;
2889 for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002890 ::new (__end_) value_type(*__p);
2891#ifndef _LIBCPP_NO_EXCEPTIONS
2892 }
2893 catch (...)
2894 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002895 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002896 throw;
2897 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002898#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002899 }
2900}
2901
2902template <class _Tp>
2903valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002904 : __begin_(nullptr),
2905 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002906{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002907 const size_t __n = __ga.__1d_.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002908 if (__n)
2909 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002910 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002911#ifndef _LIBCPP_NO_EXCEPTIONS
2912 try
2913 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002914#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002915 typedef const size_t* _Ip;
2916 const value_type* __s = __ga.__vp_;
2917 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2918 __i != __e; ++__i, ++__end_)
2919 ::new (__end_) value_type(__s[*__i]);
2920#ifndef _LIBCPP_NO_EXCEPTIONS
2921 }
2922 catch (...)
2923 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002924 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002925 throw;
2926 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002927#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002928 }
2929}
2930
2931template <class _Tp>
2932valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002933 : __begin_(nullptr),
2934 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002935{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002936 const size_t __n = __ma.__1d_.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002937 if (__n)
2938 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002939 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002940#ifndef _LIBCPP_NO_EXCEPTIONS
2941 try
2942 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002943#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002944 typedef const size_t* _Ip;
2945 const value_type* __s = __ma.__vp_;
2946 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2947 __i != __e; ++__i, ++__end_)
2948 ::new (__end_) value_type(__s[*__i]);
2949#ifndef _LIBCPP_NO_EXCEPTIONS
2950 }
2951 catch (...)
2952 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002953 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002954 throw;
2955 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002956#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002957 }
2958}
2959
2960template <class _Tp>
2961valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002962 : __begin_(nullptr),
2963 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002964{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002965 const size_t __n = __ia.__1d_.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002966 if (__n)
2967 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002968 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002969#ifndef _LIBCPP_NO_EXCEPTIONS
2970 try
2971 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002972#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002973 typedef const size_t* _Ip;
2974 const value_type* __s = __ia.__vp_;
2975 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2976 __i != __e; ++__i, ++__end_)
2977 ::new (__end_) value_type(__s[*__i]);
2978#ifndef _LIBCPP_NO_EXCEPTIONS
2979 }
2980 catch (...)
2981 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002982 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002983 throw;
2984 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002985#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002986 }
2987}
2988
2989template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002990inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002991valarray<_Tp>::~valarray()
2992{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002993 __clear(size());
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002994}
2995
2996template <class _Tp>
2997valarray<_Tp>&
2998valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l)
2999{
3000 size_t __n = __l - __f;
3001 if (size() != __n)
3002 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00003003 __clear(size());
Louis Dionne5ffe5152020-09-28 15:47:49 -04003004 __begin_ = allocator<value_type>().allocate(__n);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003005 __end_ = __begin_ + __n;
3006 _VSTD::uninitialized_copy(__f, __l, __begin_);
3007 } else {
3008 _VSTD::copy(__f, __l, __begin_);
3009 }
3010 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003011}
3012
3013template <class _Tp>
3014valarray<_Tp>&
3015valarray<_Tp>::operator=(const valarray& __v)
3016{
3017 if (this != &__v)
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003018 return __assign_range(__v.__begin_, __v.__end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003019 return *this;
3020}
3021
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003022#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003023
3024template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003025inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003026valarray<_Tp>&
Howard Hinnant298aed92012-07-21 00:51:28 +00003027valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003028{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003029 __clear(size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003030 __begin_ = __v.__begin_;
3031 __end_ = __v.__end_;
3032 __v.__begin_ = nullptr;
3033 __v.__end_ = nullptr;
3034 return *this;
3035}
3036
3037template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003038inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003039valarray<_Tp>&
3040valarray<_Tp>::operator=(initializer_list<value_type> __il)
3041{
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003042 return __assign_range(__il.begin(), __il.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003043}
3044
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003045#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003046
3047template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003048inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003049valarray<_Tp>&
3050valarray<_Tp>::operator=(const value_type& __x)
3051{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003052 _VSTD::fill(__begin_, __end_, __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003053 return *this;
3054}
3055
3056template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003057inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003058valarray<_Tp>&
3059valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
3060{
3061 value_type* __t = __begin_;
3062 const value_type* __s = __sa.__vp_;
3063 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
3064 *__t = *__s;
3065 return *this;
3066}
3067
3068template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003069inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003070valarray<_Tp>&
3071valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
3072{
3073 typedef const size_t* _Ip;
3074 value_type* __t = __begin_;
3075 const value_type* __s = __ga.__vp_;
3076 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
3077 __i != __e; ++__i, ++__t)
3078 *__t = __s[*__i];
3079 return *this;
3080}
3081
3082template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003083inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003084valarray<_Tp>&
3085valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
3086{
3087 typedef const size_t* _Ip;
3088 value_type* __t = __begin_;
3089 const value_type* __s = __ma.__vp_;
3090 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
3091 __i != __e; ++__i, ++__t)
3092 *__t = __s[*__i];
3093 return *this;
3094}
3095
3096template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003097inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003098valarray<_Tp>&
3099valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
3100{
3101 typedef const size_t* _Ip;
3102 value_type* __t = __begin_;
3103 const value_type* __s = __ia.__vp_;
3104 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
3105 __i != __e; ++__i, ++__t)
3106 *__t = __s[*__i];
3107 return *this;
3108}
3109
3110template <class _Tp>
Howard Hinnant329cd412011-07-27 23:19:59 +00003111template <class _ValExpr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003112inline
Howard Hinnant329cd412011-07-27 23:19:59 +00003113valarray<_Tp>&
3114valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
3115{
3116 size_t __n = __v.size();
3117 if (size() != __n)
3118 resize(__n);
3119 value_type* __t = __begin_;
3120 for (size_t __i = 0; __i != __n; ++__t, ++__i)
3121 *__t = result_type(__v[__i]);
3122 return *this;
3123}
3124
3125template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003126inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003127__val_expr<__slice_expr<const valarray<_Tp>&> >
3128valarray<_Tp>::operator[](slice __s) const
3129{
3130 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
3131}
3132
3133template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003134inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003135slice_array<_Tp>
3136valarray<_Tp>::operator[](slice __s)
3137{
3138 return slice_array<value_type>(__s, *this);
3139}
3140
3141template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003142inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003143__val_expr<__indirect_expr<const valarray<_Tp>&> >
3144valarray<_Tp>::operator[](const gslice& __gs) const
3145{
3146 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
3147}
3148
3149template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003150inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003151gslice_array<_Tp>
3152valarray<_Tp>::operator[](const gslice& __gs)
3153{
3154 return gslice_array<value_type>(__gs, *this);
3155}
3156
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003157#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003158
3159template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003160inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003161__val_expr<__indirect_expr<const valarray<_Tp>&> >
3162valarray<_Tp>::operator[](gslice&& __gs) const
3163{
3164 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
3165}
3166
3167template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003168inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003169gslice_array<_Tp>
3170valarray<_Tp>::operator[](gslice&& __gs)
3171{
3172 return gslice_array<value_type>(move(__gs), *this);
3173}
3174
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003175#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003176
3177template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003178inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003179__val_expr<__mask_expr<const valarray<_Tp>&> >
3180valarray<_Tp>::operator[](const valarray<bool>& __vb) const
3181{
3182 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
3183}
3184
3185template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003186inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003187mask_array<_Tp>
3188valarray<_Tp>::operator[](const valarray<bool>& __vb)
3189{
3190 return mask_array<value_type>(__vb, *this);
3191}
3192
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003193#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003194
3195template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003196inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003197__val_expr<__mask_expr<const valarray<_Tp>&> >
3198valarray<_Tp>::operator[](valarray<bool>&& __vb) const
3199{
3200 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
3201}
3202
3203template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003204inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003205mask_array<_Tp>
3206valarray<_Tp>::operator[](valarray<bool>&& __vb)
3207{
3208 return mask_array<value_type>(move(__vb), *this);
3209}
3210
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003211#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003212
3213template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003214inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003215__val_expr<__indirect_expr<const valarray<_Tp>&> >
3216valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
3217{
3218 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
3219}
3220
3221template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003222inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003223indirect_array<_Tp>
3224valarray<_Tp>::operator[](const valarray<size_t>& __vs)
3225{
3226 return indirect_array<value_type>(__vs, *this);
3227}
3228
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003229#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003230
3231template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003232inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003233__val_expr<__indirect_expr<const valarray<_Tp>&> >
3234valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
3235{
3236 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
3237}
3238
3239template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003240inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003241indirect_array<_Tp>
3242valarray<_Tp>::operator[](valarray<size_t>&& __vs)
3243{
3244 return indirect_array<value_type>(move(__vs), *this);
3245}
3246
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003247#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003248
3249template <class _Tp>
3250valarray<_Tp>
3251valarray<_Tp>::operator+() const
3252{
3253 valarray<value_type> __r;
3254 size_t __n = size();
3255 if (__n)
3256 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003257 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003258 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3259 ::new (__r.__end_) value_type(+*__p);
3260 }
3261 return __r;
3262}
3263
3264template <class _Tp>
3265valarray<_Tp>
3266valarray<_Tp>::operator-() const
3267{
3268 valarray<value_type> __r;
3269 size_t __n = size();
3270 if (__n)
3271 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003272 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003273 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3274 ::new (__r.__end_) value_type(-*__p);
3275 }
3276 return __r;
3277}
3278
3279template <class _Tp>
3280valarray<_Tp>
3281valarray<_Tp>::operator~() const
3282{
3283 valarray<value_type> __r;
3284 size_t __n = size();
3285 if (__n)
3286 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003287 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003288 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3289 ::new (__r.__end_) value_type(~*__p);
3290 }
3291 return __r;
3292}
3293
3294template <class _Tp>
3295valarray<bool>
3296valarray<_Tp>::operator!() const
3297{
3298 valarray<bool> __r;
3299 size_t __n = size();
3300 if (__n)
3301 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003302 __r.__begin_ = __r.__end_ = allocator<bool>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003303 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3304 ::new (__r.__end_) bool(!*__p);
3305 }
3306 return __r;
3307}
3308
3309template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003310inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003311valarray<_Tp>&
3312valarray<_Tp>::operator*=(const value_type& __x)
3313{
3314 for (value_type* __p = __begin_; __p != __end_; ++__p)
3315 *__p *= __x;
3316 return *this;
3317}
3318
3319template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003320inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003321valarray<_Tp>&
3322valarray<_Tp>::operator/=(const value_type& __x)
3323{
3324 for (value_type* __p = __begin_; __p != __end_; ++__p)
3325 *__p /= __x;
3326 return *this;
3327}
3328
3329template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003330inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003331valarray<_Tp>&
3332valarray<_Tp>::operator%=(const value_type& __x)
3333{
3334 for (value_type* __p = __begin_; __p != __end_; ++__p)
3335 *__p %= __x;
3336 return *this;
3337}
3338
3339template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003340inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003341valarray<_Tp>&
3342valarray<_Tp>::operator+=(const value_type& __x)
3343{
3344 for (value_type* __p = __begin_; __p != __end_; ++__p)
3345 *__p += __x;
3346 return *this;
3347}
3348
3349template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003350inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003351valarray<_Tp>&
3352valarray<_Tp>::operator-=(const value_type& __x)
3353{
3354 for (value_type* __p = __begin_; __p != __end_; ++__p)
3355 *__p -= __x;
3356 return *this;
3357}
3358
3359template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003360inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003361valarray<_Tp>&
3362valarray<_Tp>::operator^=(const value_type& __x)
3363{
3364 for (value_type* __p = __begin_; __p != __end_; ++__p)
3365 *__p ^= __x;
3366 return *this;
3367}
3368
3369template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003370inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003371valarray<_Tp>&
3372valarray<_Tp>::operator&=(const value_type& __x)
3373{
3374 for (value_type* __p = __begin_; __p != __end_; ++__p)
3375 *__p &= __x;
3376 return *this;
3377}
3378
3379template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003380inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003381valarray<_Tp>&
3382valarray<_Tp>::operator|=(const value_type& __x)
3383{
3384 for (value_type* __p = __begin_; __p != __end_; ++__p)
3385 *__p |= __x;
3386 return *this;
3387}
3388
3389template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003390inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003391valarray<_Tp>&
3392valarray<_Tp>::operator<<=(const value_type& __x)
3393{
3394 for (value_type* __p = __begin_; __p != __end_; ++__p)
3395 *__p <<= __x;
3396 return *this;
3397}
3398
3399template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003400inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003401valarray<_Tp>&
3402valarray<_Tp>::operator>>=(const value_type& __x)
3403{
3404 for (value_type* __p = __begin_; __p != __end_; ++__p)
3405 *__p >>= __x;
3406 return *this;
3407}
3408
3409template <class _Tp>
3410template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003411inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003412typename enable_if
3413<
3414 __is_val_expr<_Expr>::value,
3415 valarray<_Tp>&
3416>::type
3417valarray<_Tp>::operator*=(const _Expr& __v)
3418{
3419 size_t __i = 0;
3420 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3421 *__t *= __v[__i];
3422 return *this;
3423}
3424
3425template <class _Tp>
3426template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003427inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003428typename enable_if
3429<
3430 __is_val_expr<_Expr>::value,
3431 valarray<_Tp>&
3432>::type
3433valarray<_Tp>::operator/=(const _Expr& __v)
3434{
3435 size_t __i = 0;
3436 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3437 *__t /= __v[__i];
3438 return *this;
3439}
3440
3441template <class _Tp>
3442template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003443inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003444typename enable_if
3445<
3446 __is_val_expr<_Expr>::value,
3447 valarray<_Tp>&
3448>::type
3449valarray<_Tp>::operator%=(const _Expr& __v)
3450{
3451 size_t __i = 0;
3452 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3453 *__t %= __v[__i];
3454 return *this;
3455}
3456
3457template <class _Tp>
3458template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003459inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003460typename enable_if
3461<
3462 __is_val_expr<_Expr>::value,
3463 valarray<_Tp>&
3464>::type
3465valarray<_Tp>::operator+=(const _Expr& __v)
3466{
3467 size_t __i = 0;
3468 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3469 *__t += __v[__i];
3470 return *this;
3471}
3472
3473template <class _Tp>
3474template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003475inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003476typename enable_if
3477<
3478 __is_val_expr<_Expr>::value,
3479 valarray<_Tp>&
3480>::type
3481valarray<_Tp>::operator-=(const _Expr& __v)
3482{
3483 size_t __i = 0;
3484 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3485 *__t -= __v[__i];
3486 return *this;
3487}
3488
3489template <class _Tp>
3490template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003491inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003492typename enable_if
3493<
3494 __is_val_expr<_Expr>::value,
3495 valarray<_Tp>&
3496>::type
3497valarray<_Tp>::operator^=(const _Expr& __v)
3498{
3499 size_t __i = 0;
3500 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3501 *__t ^= __v[__i];
3502 return *this;
3503}
3504
3505template <class _Tp>
3506template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003507inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003508typename enable_if
3509<
3510 __is_val_expr<_Expr>::value,
3511 valarray<_Tp>&
3512>::type
3513valarray<_Tp>::operator|=(const _Expr& __v)
3514{
3515 size_t __i = 0;
3516 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3517 *__t |= __v[__i];
3518 return *this;
3519}
3520
3521template <class _Tp>
3522template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003523inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003524typename enable_if
3525<
3526 __is_val_expr<_Expr>::value,
3527 valarray<_Tp>&
3528>::type
3529valarray<_Tp>::operator&=(const _Expr& __v)
3530{
3531 size_t __i = 0;
3532 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3533 *__t &= __v[__i];
3534 return *this;
3535}
3536
3537template <class _Tp>
3538template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003539inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003540typename enable_if
3541<
3542 __is_val_expr<_Expr>::value,
3543 valarray<_Tp>&
3544>::type
3545valarray<_Tp>::operator<<=(const _Expr& __v)
3546{
3547 size_t __i = 0;
3548 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3549 *__t <<= __v[__i];
3550 return *this;
3551}
3552
3553template <class _Tp>
3554template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003555inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003556typename enable_if
3557<
3558 __is_val_expr<_Expr>::value,
3559 valarray<_Tp>&
3560>::type
3561valarray<_Tp>::operator>>=(const _Expr& __v)
3562{
3563 size_t __i = 0;
3564 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3565 *__t >>= __v[__i];
3566 return *this;
3567}
3568
3569template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003570inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003571void
Howard Hinnant298aed92012-07-21 00:51:28 +00003572valarray<_Tp>::swap(valarray& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003573{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003574 _VSTD::swap(__begin_, __v.__begin_);
3575 _VSTD::swap(__end_, __v.__end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003576}
3577
3578template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003579inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003580_Tp
3581valarray<_Tp>::sum() const
3582{
3583 if (__begin_ == __end_)
3584 return value_type();
3585 const value_type* __p = __begin_;
3586 _Tp __r = *__p;
3587 for (++__p; __p != __end_; ++__p)
3588 __r += *__p;
3589 return __r;
3590}
3591
3592template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003593inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003594_Tp
3595valarray<_Tp>::min() const
3596{
3597 if (__begin_ == __end_)
3598 return value_type();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003599 return *_VSTD::min_element(__begin_, __end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003600}
3601
3602template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003603inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003604_Tp
3605valarray<_Tp>::max() const
3606{
3607 if (__begin_ == __end_)
3608 return value_type();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003609 return *_VSTD::max_element(__begin_, __end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003610}
3611
3612template <class _Tp>
3613valarray<_Tp>
3614valarray<_Tp>::shift(int __i) const
3615{
3616 valarray<value_type> __r;
3617 size_t __n = size();
3618 if (__n)
3619 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003620 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003621 const value_type* __sb;
3622 value_type* __tb;
3623 value_type* __te;
3624 if (__i >= 0)
3625 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003626 __i = _VSTD::min(__i, static_cast<int>(__n));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003627 __sb = __begin_ + __i;
3628 __tb = __r.__begin_;
3629 __te = __r.__begin_ + (__n - __i);
3630 }
3631 else
3632 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003633 __i = _VSTD::min(-__i, static_cast<int>(__n));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003634 __sb = __begin_;
3635 __tb = __r.__begin_ + __i;
3636 __te = __r.__begin_ + __n;
3637 }
3638 for (; __r.__end_ != __tb; ++__r.__end_)
3639 ::new (__r.__end_) value_type();
3640 for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
3641 ::new (__r.__end_) value_type(*__sb);
3642 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
3643 ::new (__r.__end_) value_type();
3644 }
3645 return __r;
3646}
3647
3648template <class _Tp>
3649valarray<_Tp>
3650valarray<_Tp>::cshift(int __i) const
3651{
3652 valarray<value_type> __r;
3653 size_t __n = size();
3654 if (__n)
3655 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003656 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003657 __i %= static_cast<int>(__n);
3658 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
3659 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
3660 ::new (__r.__end_) value_type(*__s);
3661 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
3662 ::new (__r.__end_) value_type(*__s);
3663 }
3664 return __r;
3665}
3666
3667template <class _Tp>
3668valarray<_Tp>
3669valarray<_Tp>::apply(value_type __f(value_type)) const
3670{
3671 valarray<value_type> __r;
3672 size_t __n = size();
3673 if (__n)
3674 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003675 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003676 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3677 ::new (__r.__end_) value_type(__f(*__p));
3678 }
3679 return __r;
3680}
3681
3682template <class _Tp>
3683valarray<_Tp>
3684valarray<_Tp>::apply(value_type __f(const value_type&)) const
3685{
3686 valarray<value_type> __r;
3687 size_t __n = size();
3688 if (__n)
3689 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003690 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003691 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3692 ::new (__r.__end_) value_type(__f(*__p));
3693 }
3694 return __r;
3695}
3696
3697template <class _Tp>
Eric Fiseliera119c322018-10-25 17:43:26 +00003698inline
Eric Fiselier2856ef82018-10-25 17:21:30 +00003699void valarray<_Tp>::__clear(size_t __capacity)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003700{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003701 if (__begin_ != nullptr)
3702 {
3703 while (__end_ != __begin_)
3704 (--__end_)->~value_type();
Louis Dionne5ffe5152020-09-28 15:47:49 -04003705 allocator<value_type>().deallocate(__begin_, __capacity);
Eric Fiselier2856ef82018-10-25 17:21:30 +00003706 __begin_ = __end_ = nullptr;
3707 }
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003708}
3709
3710template <class _Tp>
3711void
3712valarray<_Tp>::resize(size_t __n, value_type __x)
3713{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003714 __clear(size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003715 if (__n)
3716 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003717 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003718#ifndef _LIBCPP_NO_EXCEPTIONS
3719 try
3720 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003721#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00003722 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003723 ::new (__end_) value_type(__x);
3724#ifndef _LIBCPP_NO_EXCEPTIONS
3725 }
3726 catch (...)
3727 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00003728 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003729 throw;
3730 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003731#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00003732 }
3733}
3734
3735template<class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003736inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003737void
Howard Hinnant298aed92012-07-21 00:51:28 +00003738swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003739{
3740 __x.swap(__y);
3741}
3742
3743template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003744inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003745typename enable_if
3746<
3747 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3748 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
3749>::type
3750operator*(const _Expr1& __x, const _Expr2& __y)
3751{
3752 typedef typename _Expr1::value_type value_type;
3753 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
3754 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
3755}
3756
3757template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003758inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003759typename enable_if
3760<
3761 __is_val_expr<_Expr>::value,
3762 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3763 _Expr, __scalar_expr<typename _Expr::value_type> > >
3764>::type
3765operator*(const _Expr& __x, const typename _Expr::value_type& __y)
3766{
3767 typedef typename _Expr::value_type value_type;
3768 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3769 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3770 __x, __scalar_expr<value_type>(__y, __x.size())));
3771}
3772
3773template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003774inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003775typename enable_if
3776<
3777 __is_val_expr<_Expr>::value,
3778 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3779 __scalar_expr<typename _Expr::value_type>, _Expr> >
3780>::type
3781operator*(const typename _Expr::value_type& __x, const _Expr& __y)
3782{
3783 typedef typename _Expr::value_type value_type;
3784 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3785 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3786 __scalar_expr<value_type>(__x, __y.size()), __y));
3787}
3788
3789template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003790inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003791typename enable_if
3792<
3793 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3794 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
3795>::type
3796operator/(const _Expr1& __x, const _Expr2& __y)
3797{
3798 typedef typename _Expr1::value_type value_type;
3799 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
3800 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
3801}
3802
3803template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003804inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003805typename enable_if
3806<
3807 __is_val_expr<_Expr>::value,
3808 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3809 _Expr, __scalar_expr<typename _Expr::value_type> > >
3810>::type
3811operator/(const _Expr& __x, const typename _Expr::value_type& __y)
3812{
3813 typedef typename _Expr::value_type value_type;
3814 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3815 return __val_expr<_Op>(_Op(divides<value_type>(),
3816 __x, __scalar_expr<value_type>(__y, __x.size())));
3817}
3818
3819template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003820inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003821typename enable_if
3822<
3823 __is_val_expr<_Expr>::value,
3824 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3825 __scalar_expr<typename _Expr::value_type>, _Expr> >
3826>::type
3827operator/(const typename _Expr::value_type& __x, const _Expr& __y)
3828{
3829 typedef typename _Expr::value_type value_type;
3830 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3831 return __val_expr<_Op>(_Op(divides<value_type>(),
3832 __scalar_expr<value_type>(__x, __y.size()), __y));
3833}
3834
3835template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003836inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003837typename enable_if
3838<
3839 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3840 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3841>::type
3842operator%(const _Expr1& __x, const _Expr2& __y)
3843{
3844 typedef typename _Expr1::value_type value_type;
3845 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
3846 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
3847}
3848
3849template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003850inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003851typename enable_if
3852<
3853 __is_val_expr<_Expr>::value,
3854 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3855 _Expr, __scalar_expr<typename _Expr::value_type> > >
3856>::type
3857operator%(const _Expr& __x, const typename _Expr::value_type& __y)
3858{
3859 typedef typename _Expr::value_type value_type;
3860 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3861 return __val_expr<_Op>(_Op(modulus<value_type>(),
3862 __x, __scalar_expr<value_type>(__y, __x.size())));
3863}
3864
3865template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003866inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003867typename enable_if
3868<
3869 __is_val_expr<_Expr>::value,
3870 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3871 __scalar_expr<typename _Expr::value_type>, _Expr> >
3872>::type
3873operator%(const typename _Expr::value_type& __x, const _Expr& __y)
3874{
3875 typedef typename _Expr::value_type value_type;
3876 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3877 return __val_expr<_Op>(_Op(modulus<value_type>(),
3878 __scalar_expr<value_type>(__x, __y.size()), __y));
3879}
3880
3881template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003882inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003883typename enable_if
3884<
3885 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3886 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3887>::type
3888operator+(const _Expr1& __x, const _Expr2& __y)
3889{
3890 typedef typename _Expr1::value_type value_type;
3891 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
3892 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
3893}
3894
3895template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003896inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003897typename enable_if
3898<
3899 __is_val_expr<_Expr>::value,
3900 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3901 _Expr, __scalar_expr<typename _Expr::value_type> > >
3902>::type
3903operator+(const _Expr& __x, const typename _Expr::value_type& __y)
3904{
3905 typedef typename _Expr::value_type value_type;
3906 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3907 return __val_expr<_Op>(_Op(plus<value_type>(),
3908 __x, __scalar_expr<value_type>(__y, __x.size())));
3909}
3910
3911template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003912inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003913typename enable_if
3914<
3915 __is_val_expr<_Expr>::value,
3916 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3917 __scalar_expr<typename _Expr::value_type>, _Expr> >
3918>::type
3919operator+(const typename _Expr::value_type& __x, const _Expr& __y)
3920{
3921 typedef typename _Expr::value_type value_type;
3922 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3923 return __val_expr<_Op>(_Op(plus<value_type>(),
3924 __scalar_expr<value_type>(__x, __y.size()), __y));
3925}
3926
3927template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003928inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003929typename enable_if
3930<
3931 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3932 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3933>::type
3934operator-(const _Expr1& __x, const _Expr2& __y)
3935{
3936 typedef typename _Expr1::value_type value_type;
3937 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
3938 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
3939}
3940
3941template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003942inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003943typename enable_if
3944<
3945 __is_val_expr<_Expr>::value,
3946 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3947 _Expr, __scalar_expr<typename _Expr::value_type> > >
3948>::type
3949operator-(const _Expr& __x, const typename _Expr::value_type& __y)
3950{
3951 typedef typename _Expr::value_type value_type;
3952 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3953 return __val_expr<_Op>(_Op(minus<value_type>(),
3954 __x, __scalar_expr<value_type>(__y, __x.size())));
3955}
3956
3957template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003958inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003959typename enable_if
3960<
3961 __is_val_expr<_Expr>::value,
3962 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3963 __scalar_expr<typename _Expr::value_type>, _Expr> >
3964>::type
3965operator-(const typename _Expr::value_type& __x, const _Expr& __y)
3966{
3967 typedef typename _Expr::value_type value_type;
3968 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3969 return __val_expr<_Op>(_Op(minus<value_type>(),
3970 __scalar_expr<value_type>(__x, __y.size()), __y));
3971}
3972
3973template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003974inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003975typename enable_if
3976<
3977 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3978 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
3979>::type
3980operator^(const _Expr1& __x, const _Expr2& __y)
3981{
3982 typedef typename _Expr1::value_type value_type;
3983 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
3984 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
3985}
3986
3987template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003988inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003989typename enable_if
3990<
3991 __is_val_expr<_Expr>::value,
3992 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
3993 _Expr, __scalar_expr<typename _Expr::value_type> > >
3994>::type
3995operator^(const _Expr& __x, const typename _Expr::value_type& __y)
3996{
3997 typedef typename _Expr::value_type value_type;
3998 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3999 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
4000 __x, __scalar_expr<value_type>(__y, __x.size())));
4001}
4002
4003template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004004inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004005typename enable_if
4006<
4007 __is_val_expr<_Expr>::value,
4008 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
4009 __scalar_expr<typename _Expr::value_type>, _Expr> >
4010>::type
4011operator^(const typename _Expr::value_type& __x, const _Expr& __y)
4012{
4013 typedef typename _Expr::value_type value_type;
4014 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4015 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
4016 __scalar_expr<value_type>(__x, __y.size()), __y));
4017}
4018
4019template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004020inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004021typename enable_if
4022<
4023 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4024 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4025>::type
4026operator&(const _Expr1& __x, const _Expr2& __y)
4027{
4028 typedef typename _Expr1::value_type value_type;
4029 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
4030 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
4031}
4032
4033template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004034inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004035typename enable_if
4036<
4037 __is_val_expr<_Expr>::value,
4038 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4039 _Expr, __scalar_expr<typename _Expr::value_type> > >
4040>::type
4041operator&(const _Expr& __x, const typename _Expr::value_type& __y)
4042{
4043 typedef typename _Expr::value_type value_type;
4044 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4045 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4046 __x, __scalar_expr<value_type>(__y, __x.size())));
4047}
4048
4049template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004050inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004051typename enable_if
4052<
4053 __is_val_expr<_Expr>::value,
4054 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4055 __scalar_expr<typename _Expr::value_type>, _Expr> >
4056>::type
4057operator&(const typename _Expr::value_type& __x, const _Expr& __y)
4058{
4059 typedef typename _Expr::value_type value_type;
4060 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4061 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4062 __scalar_expr<value_type>(__x, __y.size()), __y));
4063}
4064
4065template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004066inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004067typename enable_if
4068<
4069 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4070 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4071>::type
4072operator|(const _Expr1& __x, const _Expr2& __y)
4073{
4074 typedef typename _Expr1::value_type value_type;
4075 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
4076 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
4077}
4078
4079template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004080inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004081typename enable_if
4082<
4083 __is_val_expr<_Expr>::value,
4084 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4085 _Expr, __scalar_expr<typename _Expr::value_type> > >
4086>::type
4087operator|(const _Expr& __x, const typename _Expr::value_type& __y)
4088{
4089 typedef typename _Expr::value_type value_type;
4090 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4091 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4092 __x, __scalar_expr<value_type>(__y, __x.size())));
4093}
4094
4095template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004096inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004097typename enable_if
4098<
4099 __is_val_expr<_Expr>::value,
4100 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4101 __scalar_expr<typename _Expr::value_type>, _Expr> >
4102>::type
4103operator|(const typename _Expr::value_type& __x, const _Expr& __y)
4104{
4105 typedef typename _Expr::value_type value_type;
4106 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4107 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4108 __scalar_expr<value_type>(__x, __y.size()), __y));
4109}
4110
4111template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004112inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004113typename enable_if
4114<
4115 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4116 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
4117>::type
4118operator<<(const _Expr1& __x, const _Expr2& __y)
4119{
4120 typedef typename _Expr1::value_type value_type;
4121 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
4122 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
4123}
4124
4125template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004126inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004127typename enable_if
4128<
4129 __is_val_expr<_Expr>::value,
4130 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4131 _Expr, __scalar_expr<typename _Expr::value_type> > >
4132>::type
4133operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
4134{
4135 typedef typename _Expr::value_type value_type;
4136 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4137 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4138 __x, __scalar_expr<value_type>(__y, __x.size())));
4139}
4140
4141template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004142inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004143typename enable_if
4144<
4145 __is_val_expr<_Expr>::value,
4146 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4147 __scalar_expr<typename _Expr::value_type>, _Expr> >
4148>::type
4149operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
4150{
4151 typedef typename _Expr::value_type value_type;
4152 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4153 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4154 __scalar_expr<value_type>(__x, __y.size()), __y));
4155}
4156
4157template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004158inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004159typename enable_if
4160<
4161 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4162 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
4163>::type
4164operator>>(const _Expr1& __x, const _Expr2& __y)
4165{
4166 typedef typename _Expr1::value_type value_type;
4167 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
4168 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
4169}
4170
4171template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004172inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004173typename enable_if
4174<
4175 __is_val_expr<_Expr>::value,
4176 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4177 _Expr, __scalar_expr<typename _Expr::value_type> > >
4178>::type
4179operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
4180{
4181 typedef typename _Expr::value_type value_type;
4182 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4183 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4184 __x, __scalar_expr<value_type>(__y, __x.size())));
4185}
4186
4187template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004188inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004189typename enable_if
4190<
4191 __is_val_expr<_Expr>::value,
4192 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4193 __scalar_expr<typename _Expr::value_type>, _Expr> >
4194>::type
4195operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
4196{
4197 typedef typename _Expr::value_type value_type;
4198 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4199 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4200 __scalar_expr<value_type>(__x, __y.size()), __y));
4201}
4202
4203template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004204inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004205typename enable_if
4206<
4207 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4208 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4209>::type
4210operator&&(const _Expr1& __x, const _Expr2& __y)
4211{
4212 typedef typename _Expr1::value_type value_type;
4213 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
4214 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
4215}
4216
4217template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004218inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004219typename enable_if
4220<
4221 __is_val_expr<_Expr>::value,
4222 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4223 _Expr, __scalar_expr<typename _Expr::value_type> > >
4224>::type
4225operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
4226{
4227 typedef typename _Expr::value_type value_type;
4228 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4229 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4230 __x, __scalar_expr<value_type>(__y, __x.size())));
4231}
4232
4233template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004234inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004235typename enable_if
4236<
4237 __is_val_expr<_Expr>::value,
4238 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4239 __scalar_expr<typename _Expr::value_type>, _Expr> >
4240>::type
4241operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
4242{
4243 typedef typename _Expr::value_type value_type;
4244 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4245 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4246 __scalar_expr<value_type>(__x, __y.size()), __y));
4247}
4248
4249template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004250inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004251typename enable_if
4252<
4253 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4254 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4255>::type
4256operator||(const _Expr1& __x, const _Expr2& __y)
4257{
4258 typedef typename _Expr1::value_type value_type;
4259 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
4260 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
4261}
4262
4263template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004264inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004265typename enable_if
4266<
4267 __is_val_expr<_Expr>::value,
4268 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4269 _Expr, __scalar_expr<typename _Expr::value_type> > >
4270>::type
4271operator||(const _Expr& __x, const typename _Expr::value_type& __y)
4272{
4273 typedef typename _Expr::value_type value_type;
4274 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4275 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4276 __x, __scalar_expr<value_type>(__y, __x.size())));
4277}
4278
4279template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004280inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004281typename enable_if
4282<
4283 __is_val_expr<_Expr>::value,
4284 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4285 __scalar_expr<typename _Expr::value_type>, _Expr> >
4286>::type
4287operator||(const typename _Expr::value_type& __x, const _Expr& __y)
4288{
4289 typedef typename _Expr::value_type value_type;
4290 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4291 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4292 __scalar_expr<value_type>(__x, __y.size()), __y));
4293}
4294
4295template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004296inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004297typename enable_if
4298<
4299 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4300 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4301>::type
4302operator==(const _Expr1& __x, const _Expr2& __y)
4303{
4304 typedef typename _Expr1::value_type value_type;
4305 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
4306 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
4307}
4308
4309template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004310inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004311typename enable_if
4312<
4313 __is_val_expr<_Expr>::value,
4314 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4315 _Expr, __scalar_expr<typename _Expr::value_type> > >
4316>::type
4317operator==(const _Expr& __x, const typename _Expr::value_type& __y)
4318{
4319 typedef typename _Expr::value_type value_type;
4320 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4321 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4322 __x, __scalar_expr<value_type>(__y, __x.size())));
4323}
4324
4325template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004326inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004327typename enable_if
4328<
4329 __is_val_expr<_Expr>::value,
4330 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4331 __scalar_expr<typename _Expr::value_type>, _Expr> >
4332>::type
4333operator==(const typename _Expr::value_type& __x, const _Expr& __y)
4334{
4335 typedef typename _Expr::value_type value_type;
4336 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4337 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4338 __scalar_expr<value_type>(__x, __y.size()), __y));
4339}
4340
4341template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004342inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004343typename enable_if
4344<
4345 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4346 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4347>::type
4348operator!=(const _Expr1& __x, const _Expr2& __y)
4349{
4350 typedef typename _Expr1::value_type value_type;
4351 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
4352 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
4353}
4354
4355template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004356inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004357typename enable_if
4358<
4359 __is_val_expr<_Expr>::value,
4360 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4361 _Expr, __scalar_expr<typename _Expr::value_type> > >
4362>::type
4363operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
4364{
4365 typedef typename _Expr::value_type value_type;
4366 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4367 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4368 __x, __scalar_expr<value_type>(__y, __x.size())));
4369}
4370
4371template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004372inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004373typename enable_if
4374<
4375 __is_val_expr<_Expr>::value,
4376 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4377 __scalar_expr<typename _Expr::value_type>, _Expr> >
4378>::type
4379operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
4380{
4381 typedef typename _Expr::value_type value_type;
4382 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4383 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4384 __scalar_expr<value_type>(__x, __y.size()), __y));
4385}
4386
4387template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004388inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004389typename enable_if
4390<
4391 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4392 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
4393>::type
4394operator<(const _Expr1& __x, const _Expr2& __y)
4395{
4396 typedef typename _Expr1::value_type value_type;
4397 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
4398 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
4399}
4400
4401template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004402inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004403typename enable_if
4404<
4405 __is_val_expr<_Expr>::value,
4406 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4407 _Expr, __scalar_expr<typename _Expr::value_type> > >
4408>::type
4409operator<(const _Expr& __x, const typename _Expr::value_type& __y)
4410{
4411 typedef typename _Expr::value_type value_type;
4412 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4413 return __val_expr<_Op>(_Op(less<value_type>(),
4414 __x, __scalar_expr<value_type>(__y, __x.size())));
4415}
4416
4417template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004418inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004419typename enable_if
4420<
4421 __is_val_expr<_Expr>::value,
4422 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4423 __scalar_expr<typename _Expr::value_type>, _Expr> >
4424>::type
4425operator<(const typename _Expr::value_type& __x, const _Expr& __y)
4426{
4427 typedef typename _Expr::value_type value_type;
4428 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4429 return __val_expr<_Op>(_Op(less<value_type>(),
4430 __scalar_expr<value_type>(__x, __y.size()), __y));
4431}
4432
4433template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004434inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004435typename enable_if
4436<
4437 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4438 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
4439>::type
4440operator>(const _Expr1& __x, const _Expr2& __y)
4441{
4442 typedef typename _Expr1::value_type value_type;
4443 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
4444 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
4445}
4446
4447template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004448inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004449typename enable_if
4450<
4451 __is_val_expr<_Expr>::value,
4452 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4453 _Expr, __scalar_expr<typename _Expr::value_type> > >
4454>::type
4455operator>(const _Expr& __x, const typename _Expr::value_type& __y)
4456{
4457 typedef typename _Expr::value_type value_type;
4458 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4459 return __val_expr<_Op>(_Op(greater<value_type>(),
4460 __x, __scalar_expr<value_type>(__y, __x.size())));
4461}
4462
4463template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004464inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004465typename enable_if
4466<
4467 __is_val_expr<_Expr>::value,
4468 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4469 __scalar_expr<typename _Expr::value_type>, _Expr> >
4470>::type
4471operator>(const typename _Expr::value_type& __x, const _Expr& __y)
4472{
4473 typedef typename _Expr::value_type value_type;
4474 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4475 return __val_expr<_Op>(_Op(greater<value_type>(),
4476 __scalar_expr<value_type>(__x, __y.size()), __y));
4477}
4478
4479template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004480inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004481typename enable_if
4482<
4483 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4484 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4485>::type
4486operator<=(const _Expr1& __x, const _Expr2& __y)
4487{
4488 typedef typename _Expr1::value_type value_type;
4489 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
4490 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
4491}
4492
4493template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004494inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004495typename enable_if
4496<
4497 __is_val_expr<_Expr>::value,
4498 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4499 _Expr, __scalar_expr<typename _Expr::value_type> > >
4500>::type
4501operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
4502{
4503 typedef typename _Expr::value_type value_type;
4504 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4505 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4506 __x, __scalar_expr<value_type>(__y, __x.size())));
4507}
4508
4509template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004510inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004511typename enable_if
4512<
4513 __is_val_expr<_Expr>::value,
4514 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4515 __scalar_expr<typename _Expr::value_type>, _Expr> >
4516>::type
4517operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
4518{
4519 typedef typename _Expr::value_type value_type;
4520 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4521 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4522 __scalar_expr<value_type>(__x, __y.size()), __y));
4523}
4524
4525template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004526inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004527typename enable_if
4528<
4529 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4530 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4531>::type
4532operator>=(const _Expr1& __x, const _Expr2& __y)
4533{
4534 typedef typename _Expr1::value_type value_type;
4535 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
4536 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
4537}
4538
4539template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004540inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004541typename enable_if
4542<
4543 __is_val_expr<_Expr>::value,
4544 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4545 _Expr, __scalar_expr<typename _Expr::value_type> > >
4546>::type
4547operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
4548{
4549 typedef typename _Expr::value_type value_type;
4550 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4551 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4552 __x, __scalar_expr<value_type>(__y, __x.size())));
4553}
4554
4555template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004556inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004557typename enable_if
4558<
4559 __is_val_expr<_Expr>::value,
4560 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4561 __scalar_expr<typename _Expr::value_type>, _Expr> >
4562>::type
4563operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
4564{
4565 typedef typename _Expr::value_type value_type;
4566 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4567 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4568 __scalar_expr<value_type>(__x, __y.size()), __y));
4569}
4570
4571template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004572inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004573typename enable_if
4574<
4575 __is_val_expr<_Expr>::value,
4576 __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
4577>::type
4578abs(const _Expr& __x)
4579{
4580 typedef typename _Expr::value_type value_type;
4581 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
4582 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
4583}
4584
4585template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004586inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004587typename enable_if
4588<
4589 __is_val_expr<_Expr>::value,
4590 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
4591>::type
4592acos(const _Expr& __x)
4593{
4594 typedef typename _Expr::value_type value_type;
4595 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
4596 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
4597}
4598
4599template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004600inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004601typename enable_if
4602<
4603 __is_val_expr<_Expr>::value,
4604 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
4605>::type
4606asin(const _Expr& __x)
4607{
4608 typedef typename _Expr::value_type value_type;
4609 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
4610 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
4611}
4612
4613template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004614inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004615typename enable_if
4616<
4617 __is_val_expr<_Expr>::value,
4618 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
4619>::type
4620atan(const _Expr& __x)
4621{
4622 typedef typename _Expr::value_type value_type;
4623 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
4624 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
4625}
4626
4627template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004628inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004629typename enable_if
4630<
4631 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4632 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4633>::type
4634atan2(const _Expr1& __x, const _Expr2& __y)
4635{
4636 typedef typename _Expr1::value_type value_type;
4637 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
4638 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
4639}
4640
4641template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004642inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004643typename enable_if
4644<
4645 __is_val_expr<_Expr>::value,
4646 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4647 _Expr, __scalar_expr<typename _Expr::value_type> > >
4648>::type
4649atan2(const _Expr& __x, const typename _Expr::value_type& __y)
4650{
4651 typedef typename _Expr::value_type value_type;
4652 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4653 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4654 __x, __scalar_expr<value_type>(__y, __x.size())));
4655}
4656
4657template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004658inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004659typename enable_if
4660<
4661 __is_val_expr<_Expr>::value,
4662 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4663 __scalar_expr<typename _Expr::value_type>, _Expr> >
4664>::type
4665atan2(const typename _Expr::value_type& __x, const _Expr& __y)
4666{
4667 typedef typename _Expr::value_type value_type;
4668 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4669 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4670 __scalar_expr<value_type>(__x, __y.size()), __y));
4671}
4672
4673template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004674inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004675typename enable_if
4676<
4677 __is_val_expr<_Expr>::value,
4678 __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
4679>::type
4680cos(const _Expr& __x)
4681{
4682 typedef typename _Expr::value_type value_type;
4683 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
4684 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
4685}
4686
4687template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004688inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004689typename enable_if
4690<
4691 __is_val_expr<_Expr>::value,
4692 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
4693>::type
4694cosh(const _Expr& __x)
4695{
4696 typedef typename _Expr::value_type value_type;
4697 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
4698 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
4699}
4700
4701template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004702inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004703typename enable_if
4704<
4705 __is_val_expr<_Expr>::value,
4706 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
4707>::type
4708exp(const _Expr& __x)
4709{
4710 typedef typename _Expr::value_type value_type;
4711 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
4712 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
4713}
4714
4715template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004716inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004717typename enable_if
4718<
4719 __is_val_expr<_Expr>::value,
4720 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
4721>::type
4722log(const _Expr& __x)
4723{
4724 typedef typename _Expr::value_type value_type;
4725 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
4726 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
4727}
4728
4729template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004730inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004731typename enable_if
4732<
4733 __is_val_expr<_Expr>::value,
4734 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
4735>::type
4736log10(const _Expr& __x)
4737{
4738 typedef typename _Expr::value_type value_type;
4739 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
4740 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
4741}
4742
4743template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004744inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004745typename enable_if
4746<
4747 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4748 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4749>::type
4750pow(const _Expr1& __x, const _Expr2& __y)
4751{
4752 typedef typename _Expr1::value_type value_type;
4753 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
4754 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
4755}
4756
4757template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004758inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004759typename enable_if
4760<
4761 __is_val_expr<_Expr>::value,
4762 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4763 _Expr, __scalar_expr<typename _Expr::value_type> > >
4764>::type
4765pow(const _Expr& __x, const typename _Expr::value_type& __y)
4766{
4767 typedef typename _Expr::value_type value_type;
4768 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4769 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4770 __x, __scalar_expr<value_type>(__y, __x.size())));
4771}
4772
4773template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004774inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004775typename enable_if
4776<
4777 __is_val_expr<_Expr>::value,
4778 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4779 __scalar_expr<typename _Expr::value_type>, _Expr> >
4780>::type
4781pow(const typename _Expr::value_type& __x, const _Expr& __y)
4782{
4783 typedef typename _Expr::value_type value_type;
4784 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4785 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4786 __scalar_expr<value_type>(__x, __y.size()), __y));
4787}
4788
4789template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004790inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004791typename enable_if
4792<
4793 __is_val_expr<_Expr>::value,
4794 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
4795>::type
4796sin(const _Expr& __x)
4797{
4798 typedef typename _Expr::value_type value_type;
4799 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
4800 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
4801}
4802
4803template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004804inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004805typename enable_if
4806<
4807 __is_val_expr<_Expr>::value,
4808 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
4809>::type
4810sinh(const _Expr& __x)
4811{
4812 typedef typename _Expr::value_type value_type;
4813 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
4814 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
4815}
4816
4817template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004818inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004819typename enable_if
4820<
4821 __is_val_expr<_Expr>::value,
4822 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
4823>::type
4824sqrt(const _Expr& __x)
4825{
4826 typedef typename _Expr::value_type value_type;
4827 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
4828 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
4829}
4830
4831template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004832inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004833typename enable_if
4834<
4835 __is_val_expr<_Expr>::value,
4836 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
4837>::type
4838tan(const _Expr& __x)
4839{
4840 typedef typename _Expr::value_type value_type;
4841 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
4842 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
4843}
4844
4845template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004846inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004847typename enable_if
4848<
4849 __is_val_expr<_Expr>::value,
4850 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
4851>::type
4852tanh(const _Expr& __x)
4853{
4854 typedef typename _Expr::value_type value_type;
4855 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
4856 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
4857}
4858
4859template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004860inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004861_Tp*
4862begin(valarray<_Tp>& __v)
4863{
4864 return __v.__begin_;
4865}
4866
4867template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004868inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004869const _Tp*
4870begin(const valarray<_Tp>& __v)
4871{
4872 return __v.__begin_;
4873}
4874
4875template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004876inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004877_Tp*
4878end(valarray<_Tp>& __v)
4879{
4880 return __v.__end_;
4881}
4882
4883template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004884inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004885const _Tp*
4886end(const valarray<_Tp>& __v)
4887{
4888 return __v.__end_;
4889}
4890
Howard Hinnantc51e1022010-05-11 19:42:16 +00004891_LIBCPP_END_NAMESPACE_STD
4892
Eric Fiselierf4433a32017-05-31 22:07:49 +00004893_LIBCPP_POP_MACROS
4894
Howard Hinnantc51e1022010-05-11 19:42:16 +00004895#endif // _LIBCPP_VALARRAY