blob: c048a6d7e4989e5d284eacb8961f5a96863f81fe [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
805 valarray() : __begin_(0), __end_(0) {}
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_ =
2741 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00002742 static_cast<result_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002743 _VSTD::__libcpp_allocate(__n * sizeof(result_type), _LIBCPP_ALIGNOF(result_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002744 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
2745 ::new (__r.__end_) result_type(__expr_[__i]);
2746 }
2747 return __r;
2748}
2749
2750// valarray
2751
2752template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002753inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002754valarray<_Tp>::valarray(size_t __n)
2755 : __begin_(0),
2756 __end_(0)
2757{
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002758 if (__n)
2759 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002760 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002761 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002762#ifndef _LIBCPP_NO_EXCEPTIONS
2763 try
2764 {
2765#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002766 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002767 ::new (__end_) value_type();
2768#ifndef _LIBCPP_NO_EXCEPTIONS
2769 }
2770 catch (...)
2771 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002772 __clear(__n);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002773 throw;
2774 }
2775#endif // _LIBCPP_NO_EXCEPTIONS
2776 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002777}
2778
2779template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002780inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002781valarray<_Tp>::valarray(const value_type& __x, size_t __n)
2782 : __begin_(0),
2783 __end_(0)
2784{
2785 resize(__n, __x);
2786}
2787
2788template <class _Tp>
2789valarray<_Tp>::valarray(const value_type* __p, size_t __n)
2790 : __begin_(0),
2791 __end_(0)
2792{
2793 if (__n)
2794 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002795 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002796 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002797#ifndef _LIBCPP_NO_EXCEPTIONS
2798 try
2799 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002800#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002801 for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002802 ::new (__end_) value_type(*__p);
2803#ifndef _LIBCPP_NO_EXCEPTIONS
2804 }
2805 catch (...)
2806 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002807 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002808 throw;
2809 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002810#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002811 }
2812}
2813
2814template <class _Tp>
2815valarray<_Tp>::valarray(const valarray& __v)
2816 : __begin_(0),
2817 __end_(0)
2818{
2819 if (__v.size())
2820 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002821 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002822 _VSTD::__libcpp_allocate(__v.size() * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002823#ifndef _LIBCPP_NO_EXCEPTIONS
2824 try
2825 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002826#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002827 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
2828 ::new (__end_) value_type(*__p);
2829#ifndef _LIBCPP_NO_EXCEPTIONS
2830 }
2831 catch (...)
2832 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002833 __clear(__v.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002834 throw;
2835 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002836#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002837 }
2838}
2839
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002840#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002841
2842template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002843inline
Howard Hinnant298aed92012-07-21 00:51:28 +00002844valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002845 : __begin_(__v.__begin_),
2846 __end_(__v.__end_)
2847{
2848 __v.__begin_ = __v.__end_ = nullptr;
2849}
2850
2851template <class _Tp>
2852valarray<_Tp>::valarray(initializer_list<value_type> __il)
2853 : __begin_(0),
2854 __end_(0)
2855{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002856 const size_t __n = __il.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002857 if (__n)
2858 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002859 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002860_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002861#ifndef _LIBCPP_NO_EXCEPTIONS
2862 try
2863 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002864#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002865 size_t __n_left = __n;
2866 for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002867 ::new (__end_) value_type(*__p);
2868#ifndef _LIBCPP_NO_EXCEPTIONS
2869 }
2870 catch (...)
2871 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002872 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002873 throw;
2874 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002875#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002876 }
2877}
2878
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002879#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002880
2881template <class _Tp>
2882valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
2883 : __begin_(0),
2884 __end_(0)
2885{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002886 const size_t __n = __sa.__size_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002887 if (__n)
2888 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002889 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002890 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002891#ifndef _LIBCPP_NO_EXCEPTIONS
2892 try
2893 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002894#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002895 size_t __n_left = __n;
2896 for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002897 ::new (__end_) value_type(*__p);
2898#ifndef _LIBCPP_NO_EXCEPTIONS
2899 }
2900 catch (...)
2901 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002902 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002903 throw;
2904 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002905#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002906 }
2907}
2908
2909template <class _Tp>
2910valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
2911 : __begin_(0),
2912 __end_(0)
2913{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002914 const size_t __n = __ga.__1d_.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002915 if (__n)
2916 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002917 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002918 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002919#ifndef _LIBCPP_NO_EXCEPTIONS
2920 try
2921 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002922#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002923 typedef const size_t* _Ip;
2924 const value_type* __s = __ga.__vp_;
2925 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2926 __i != __e; ++__i, ++__end_)
2927 ::new (__end_) value_type(__s[*__i]);
2928#ifndef _LIBCPP_NO_EXCEPTIONS
2929 }
2930 catch (...)
2931 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002932 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002933 throw;
2934 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002935#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002936 }
2937}
2938
2939template <class _Tp>
2940valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
2941 : __begin_(0),
2942 __end_(0)
2943{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002944 const size_t __n = __ma.__1d_.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002945 if (__n)
2946 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002947 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002948 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002949#ifndef _LIBCPP_NO_EXCEPTIONS
2950 try
2951 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002952#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002953 typedef const size_t* _Ip;
2954 const value_type* __s = __ma.__vp_;
2955 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2956 __i != __e; ++__i, ++__end_)
2957 ::new (__end_) value_type(__s[*__i]);
2958#ifndef _LIBCPP_NO_EXCEPTIONS
2959 }
2960 catch (...)
2961 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002962 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002963 throw;
2964 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002965#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002966 }
2967}
2968
2969template <class _Tp>
2970valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
2971 : __begin_(0),
2972 __end_(0)
2973{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002974 const size_t __n = __ia.__1d_.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002975 if (__n)
2976 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002977 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002978 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002979#ifndef _LIBCPP_NO_EXCEPTIONS
2980 try
2981 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002982#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002983 typedef const size_t* _Ip;
2984 const value_type* __s = __ia.__vp_;
2985 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2986 __i != __e; ++__i, ++__end_)
2987 ::new (__end_) value_type(__s[*__i]);
2988#ifndef _LIBCPP_NO_EXCEPTIONS
2989 }
2990 catch (...)
2991 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002992 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002993 throw;
2994 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002995#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002996 }
2997}
2998
2999template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003000inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003001valarray<_Tp>::~valarray()
3002{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003003 __clear(size());
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003004}
3005
3006template <class _Tp>
3007valarray<_Tp>&
3008valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l)
3009{
3010 size_t __n = __l - __f;
3011 if (size() != __n)
3012 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00003013 __clear(size());
Eric Fiselier06548ab2018-03-22 04:42:56 +00003014 __begin_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003015 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003016 __end_ = __begin_ + __n;
3017 _VSTD::uninitialized_copy(__f, __l, __begin_);
3018 } else {
3019 _VSTD::copy(__f, __l, __begin_);
3020 }
3021 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003022}
3023
3024template <class _Tp>
3025valarray<_Tp>&
3026valarray<_Tp>::operator=(const valarray& __v)
3027{
3028 if (this != &__v)
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003029 return __assign_range(__v.__begin_, __v.__end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003030 return *this;
3031}
3032
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003033#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003034
3035template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003036inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003037valarray<_Tp>&
Howard Hinnant298aed92012-07-21 00:51:28 +00003038valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003039{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003040 __clear(size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003041 __begin_ = __v.__begin_;
3042 __end_ = __v.__end_;
3043 __v.__begin_ = nullptr;
3044 __v.__end_ = nullptr;
3045 return *this;
3046}
3047
3048template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003049inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003050valarray<_Tp>&
3051valarray<_Tp>::operator=(initializer_list<value_type> __il)
3052{
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003053 return __assign_range(__il.begin(), __il.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003054}
3055
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003056#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003057
3058template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003059inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003060valarray<_Tp>&
3061valarray<_Tp>::operator=(const value_type& __x)
3062{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003063 _VSTD::fill(__begin_, __end_, __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003064 return *this;
3065}
3066
3067template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003068inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003069valarray<_Tp>&
3070valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
3071{
3072 value_type* __t = __begin_;
3073 const value_type* __s = __sa.__vp_;
3074 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
3075 *__t = *__s;
3076 return *this;
3077}
3078
3079template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003080inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003081valarray<_Tp>&
3082valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
3083{
3084 typedef const size_t* _Ip;
3085 value_type* __t = __begin_;
3086 const value_type* __s = __ga.__vp_;
3087 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
3088 __i != __e; ++__i, ++__t)
3089 *__t = __s[*__i];
3090 return *this;
3091}
3092
3093template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003094inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003095valarray<_Tp>&
3096valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
3097{
3098 typedef const size_t* _Ip;
3099 value_type* __t = __begin_;
3100 const value_type* __s = __ma.__vp_;
3101 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
3102 __i != __e; ++__i, ++__t)
3103 *__t = __s[*__i];
3104 return *this;
3105}
3106
3107template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003108inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003109valarray<_Tp>&
3110valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
3111{
3112 typedef const size_t* _Ip;
3113 value_type* __t = __begin_;
3114 const value_type* __s = __ia.__vp_;
3115 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
3116 __i != __e; ++__i, ++__t)
3117 *__t = __s[*__i];
3118 return *this;
3119}
3120
3121template <class _Tp>
Howard Hinnant329cd412011-07-27 23:19:59 +00003122template <class _ValExpr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003123inline
Howard Hinnant329cd412011-07-27 23:19:59 +00003124valarray<_Tp>&
3125valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
3126{
3127 size_t __n = __v.size();
3128 if (size() != __n)
3129 resize(__n);
3130 value_type* __t = __begin_;
3131 for (size_t __i = 0; __i != __n; ++__t, ++__i)
3132 *__t = result_type(__v[__i]);
3133 return *this;
3134}
3135
3136template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003137inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003138__val_expr<__slice_expr<const valarray<_Tp>&> >
3139valarray<_Tp>::operator[](slice __s) const
3140{
3141 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
3142}
3143
3144template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003145inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003146slice_array<_Tp>
3147valarray<_Tp>::operator[](slice __s)
3148{
3149 return slice_array<value_type>(__s, *this);
3150}
3151
3152template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003153inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003154__val_expr<__indirect_expr<const valarray<_Tp>&> >
3155valarray<_Tp>::operator[](const gslice& __gs) const
3156{
3157 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
3158}
3159
3160template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003161inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003162gslice_array<_Tp>
3163valarray<_Tp>::operator[](const gslice& __gs)
3164{
3165 return gslice_array<value_type>(__gs, *this);
3166}
3167
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003168#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003169
3170template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003171inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003172__val_expr<__indirect_expr<const valarray<_Tp>&> >
3173valarray<_Tp>::operator[](gslice&& __gs) const
3174{
3175 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
3176}
3177
3178template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003179inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003180gslice_array<_Tp>
3181valarray<_Tp>::operator[](gslice&& __gs)
3182{
3183 return gslice_array<value_type>(move(__gs), *this);
3184}
3185
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003186#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003187
3188template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003189inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003190__val_expr<__mask_expr<const valarray<_Tp>&> >
3191valarray<_Tp>::operator[](const valarray<bool>& __vb) const
3192{
3193 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
3194}
3195
3196template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003197inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003198mask_array<_Tp>
3199valarray<_Tp>::operator[](const valarray<bool>& __vb)
3200{
3201 return mask_array<value_type>(__vb, *this);
3202}
3203
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003204#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003205
3206template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003207inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003208__val_expr<__mask_expr<const valarray<_Tp>&> >
3209valarray<_Tp>::operator[](valarray<bool>&& __vb) const
3210{
3211 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
3212}
3213
3214template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003215inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003216mask_array<_Tp>
3217valarray<_Tp>::operator[](valarray<bool>&& __vb)
3218{
3219 return mask_array<value_type>(move(__vb), *this);
3220}
3221
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003222#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003223
3224template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003225inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003226__val_expr<__indirect_expr<const valarray<_Tp>&> >
3227valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
3228{
3229 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
3230}
3231
3232template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003233inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003234indirect_array<_Tp>
3235valarray<_Tp>::operator[](const valarray<size_t>& __vs)
3236{
3237 return indirect_array<value_type>(__vs, *this);
3238}
3239
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003240#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003241
3242template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003243inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003244__val_expr<__indirect_expr<const valarray<_Tp>&> >
3245valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
3246{
3247 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
3248}
3249
3250template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003251inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003252indirect_array<_Tp>
3253valarray<_Tp>::operator[](valarray<size_t>&& __vs)
3254{
3255 return indirect_array<value_type>(move(__vs), *this);
3256}
3257
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003258#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003259
3260template <class _Tp>
3261valarray<_Tp>
3262valarray<_Tp>::operator+() const
3263{
3264 valarray<value_type> __r;
3265 size_t __n = size();
3266 if (__n)
3267 {
3268 __r.__begin_ =
3269 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003270 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003271 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003272 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3273 ::new (__r.__end_) value_type(+*__p);
3274 }
3275 return __r;
3276}
3277
3278template <class _Tp>
3279valarray<_Tp>
3280valarray<_Tp>::operator-() const
3281{
3282 valarray<value_type> __r;
3283 size_t __n = size();
3284 if (__n)
3285 {
3286 __r.__begin_ =
3287 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003288 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003289 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003290 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3291 ::new (__r.__end_) value_type(-*__p);
3292 }
3293 return __r;
3294}
3295
3296template <class _Tp>
3297valarray<_Tp>
3298valarray<_Tp>::operator~() const
3299{
3300 valarray<value_type> __r;
3301 size_t __n = size();
3302 if (__n)
3303 {
3304 __r.__begin_ =
3305 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003306 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003307 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003308 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3309 ::new (__r.__end_) value_type(~*__p);
3310 }
3311 return __r;
3312}
3313
3314template <class _Tp>
3315valarray<bool>
3316valarray<_Tp>::operator!() const
3317{
3318 valarray<bool> __r;
3319 size_t __n = size();
3320 if (__n)
3321 {
3322 __r.__begin_ =
3323 __r.__end_ =
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003324 static_cast<bool*>(_VSTD::__libcpp_allocate(__n * sizeof(bool), _LIBCPP_ALIGNOF(bool)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003325 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3326 ::new (__r.__end_) bool(!*__p);
3327 }
3328 return __r;
3329}
3330
3331template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003332inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003333valarray<_Tp>&
3334valarray<_Tp>::operator*=(const value_type& __x)
3335{
3336 for (value_type* __p = __begin_; __p != __end_; ++__p)
3337 *__p *= __x;
3338 return *this;
3339}
3340
3341template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003342inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003343valarray<_Tp>&
3344valarray<_Tp>::operator/=(const value_type& __x)
3345{
3346 for (value_type* __p = __begin_; __p != __end_; ++__p)
3347 *__p /= __x;
3348 return *this;
3349}
3350
3351template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003352inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003353valarray<_Tp>&
3354valarray<_Tp>::operator%=(const value_type& __x)
3355{
3356 for (value_type* __p = __begin_; __p != __end_; ++__p)
3357 *__p %= __x;
3358 return *this;
3359}
3360
3361template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003362inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003363valarray<_Tp>&
3364valarray<_Tp>::operator+=(const value_type& __x)
3365{
3366 for (value_type* __p = __begin_; __p != __end_; ++__p)
3367 *__p += __x;
3368 return *this;
3369}
3370
3371template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003372inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003373valarray<_Tp>&
3374valarray<_Tp>::operator-=(const value_type& __x)
3375{
3376 for (value_type* __p = __begin_; __p != __end_; ++__p)
3377 *__p -= __x;
3378 return *this;
3379}
3380
3381template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003382inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003383valarray<_Tp>&
3384valarray<_Tp>::operator^=(const value_type& __x)
3385{
3386 for (value_type* __p = __begin_; __p != __end_; ++__p)
3387 *__p ^= __x;
3388 return *this;
3389}
3390
3391template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003392inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003393valarray<_Tp>&
3394valarray<_Tp>::operator&=(const value_type& __x)
3395{
3396 for (value_type* __p = __begin_; __p != __end_; ++__p)
3397 *__p &= __x;
3398 return *this;
3399}
3400
3401template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003402inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003403valarray<_Tp>&
3404valarray<_Tp>::operator|=(const value_type& __x)
3405{
3406 for (value_type* __p = __begin_; __p != __end_; ++__p)
3407 *__p |= __x;
3408 return *this;
3409}
3410
3411template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003412inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003413valarray<_Tp>&
3414valarray<_Tp>::operator<<=(const value_type& __x)
3415{
3416 for (value_type* __p = __begin_; __p != __end_; ++__p)
3417 *__p <<= __x;
3418 return *this;
3419}
3420
3421template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003422inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003423valarray<_Tp>&
3424valarray<_Tp>::operator>>=(const value_type& __x)
3425{
3426 for (value_type* __p = __begin_; __p != __end_; ++__p)
3427 *__p >>= __x;
3428 return *this;
3429}
3430
3431template <class _Tp>
3432template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003433inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003434typename enable_if
3435<
3436 __is_val_expr<_Expr>::value,
3437 valarray<_Tp>&
3438>::type
3439valarray<_Tp>::operator*=(const _Expr& __v)
3440{
3441 size_t __i = 0;
3442 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3443 *__t *= __v[__i];
3444 return *this;
3445}
3446
3447template <class _Tp>
3448template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003449inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003450typename enable_if
3451<
3452 __is_val_expr<_Expr>::value,
3453 valarray<_Tp>&
3454>::type
3455valarray<_Tp>::operator/=(const _Expr& __v)
3456{
3457 size_t __i = 0;
3458 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3459 *__t /= __v[__i];
3460 return *this;
3461}
3462
3463template <class _Tp>
3464template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003465inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003466typename enable_if
3467<
3468 __is_val_expr<_Expr>::value,
3469 valarray<_Tp>&
3470>::type
3471valarray<_Tp>::operator%=(const _Expr& __v)
3472{
3473 size_t __i = 0;
3474 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3475 *__t %= __v[__i];
3476 return *this;
3477}
3478
3479template <class _Tp>
3480template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003481inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003482typename enable_if
3483<
3484 __is_val_expr<_Expr>::value,
3485 valarray<_Tp>&
3486>::type
3487valarray<_Tp>::operator+=(const _Expr& __v)
3488{
3489 size_t __i = 0;
3490 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3491 *__t += __v[__i];
3492 return *this;
3493}
3494
3495template <class _Tp>
3496template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003497inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003498typename enable_if
3499<
3500 __is_val_expr<_Expr>::value,
3501 valarray<_Tp>&
3502>::type
3503valarray<_Tp>::operator-=(const _Expr& __v)
3504{
3505 size_t __i = 0;
3506 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3507 *__t -= __v[__i];
3508 return *this;
3509}
3510
3511template <class _Tp>
3512template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003513inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003514typename enable_if
3515<
3516 __is_val_expr<_Expr>::value,
3517 valarray<_Tp>&
3518>::type
3519valarray<_Tp>::operator^=(const _Expr& __v)
3520{
3521 size_t __i = 0;
3522 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3523 *__t ^= __v[__i];
3524 return *this;
3525}
3526
3527template <class _Tp>
3528template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003529inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003530typename enable_if
3531<
3532 __is_val_expr<_Expr>::value,
3533 valarray<_Tp>&
3534>::type
3535valarray<_Tp>::operator|=(const _Expr& __v)
3536{
3537 size_t __i = 0;
3538 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3539 *__t |= __v[__i];
3540 return *this;
3541}
3542
3543template <class _Tp>
3544template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003545inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003546typename enable_if
3547<
3548 __is_val_expr<_Expr>::value,
3549 valarray<_Tp>&
3550>::type
3551valarray<_Tp>::operator&=(const _Expr& __v)
3552{
3553 size_t __i = 0;
3554 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3555 *__t &= __v[__i];
3556 return *this;
3557}
3558
3559template <class _Tp>
3560template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003561inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003562typename enable_if
3563<
3564 __is_val_expr<_Expr>::value,
3565 valarray<_Tp>&
3566>::type
3567valarray<_Tp>::operator<<=(const _Expr& __v)
3568{
3569 size_t __i = 0;
3570 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3571 *__t <<= __v[__i];
3572 return *this;
3573}
3574
3575template <class _Tp>
3576template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003577inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003578typename enable_if
3579<
3580 __is_val_expr<_Expr>::value,
3581 valarray<_Tp>&
3582>::type
3583valarray<_Tp>::operator>>=(const _Expr& __v)
3584{
3585 size_t __i = 0;
3586 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3587 *__t >>= __v[__i];
3588 return *this;
3589}
3590
3591template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003592inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003593void
Howard Hinnant298aed92012-07-21 00:51:28 +00003594valarray<_Tp>::swap(valarray& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003595{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003596 _VSTD::swap(__begin_, __v.__begin_);
3597 _VSTD::swap(__end_, __v.__end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003598}
3599
3600template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003601inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003602_Tp
3603valarray<_Tp>::sum() const
3604{
3605 if (__begin_ == __end_)
3606 return value_type();
3607 const value_type* __p = __begin_;
3608 _Tp __r = *__p;
3609 for (++__p; __p != __end_; ++__p)
3610 __r += *__p;
3611 return __r;
3612}
3613
3614template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003615inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003616_Tp
3617valarray<_Tp>::min() const
3618{
3619 if (__begin_ == __end_)
3620 return value_type();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003621 return *_VSTD::min_element(__begin_, __end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003622}
3623
3624template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003625inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003626_Tp
3627valarray<_Tp>::max() const
3628{
3629 if (__begin_ == __end_)
3630 return value_type();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003631 return *_VSTD::max_element(__begin_, __end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003632}
3633
3634template <class _Tp>
3635valarray<_Tp>
3636valarray<_Tp>::shift(int __i) const
3637{
3638 valarray<value_type> __r;
3639 size_t __n = size();
3640 if (__n)
3641 {
3642 __r.__begin_ =
3643 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003644 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003645 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003646 const value_type* __sb;
3647 value_type* __tb;
3648 value_type* __te;
3649 if (__i >= 0)
3650 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003651 __i = _VSTD::min(__i, static_cast<int>(__n));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003652 __sb = __begin_ + __i;
3653 __tb = __r.__begin_;
3654 __te = __r.__begin_ + (__n - __i);
3655 }
3656 else
3657 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003658 __i = _VSTD::min(-__i, static_cast<int>(__n));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003659 __sb = __begin_;
3660 __tb = __r.__begin_ + __i;
3661 __te = __r.__begin_ + __n;
3662 }
3663 for (; __r.__end_ != __tb; ++__r.__end_)
3664 ::new (__r.__end_) value_type();
3665 for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
3666 ::new (__r.__end_) value_type(*__sb);
3667 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
3668 ::new (__r.__end_) value_type();
3669 }
3670 return __r;
3671}
3672
3673template <class _Tp>
3674valarray<_Tp>
3675valarray<_Tp>::cshift(int __i) const
3676{
3677 valarray<value_type> __r;
3678 size_t __n = size();
3679 if (__n)
3680 {
3681 __r.__begin_ =
3682 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003683 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003684 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003685 __i %= static_cast<int>(__n);
3686 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
3687 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
3688 ::new (__r.__end_) value_type(*__s);
3689 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
3690 ::new (__r.__end_) value_type(*__s);
3691 }
3692 return __r;
3693}
3694
3695template <class _Tp>
3696valarray<_Tp>
3697valarray<_Tp>::apply(value_type __f(value_type)) const
3698{
3699 valarray<value_type> __r;
3700 size_t __n = size();
3701 if (__n)
3702 {
3703 __r.__begin_ =
3704 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003705 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003706 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003707 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3708 ::new (__r.__end_) value_type(__f(*__p));
3709 }
3710 return __r;
3711}
3712
3713template <class _Tp>
3714valarray<_Tp>
3715valarray<_Tp>::apply(value_type __f(const value_type&)) const
3716{
3717 valarray<value_type> __r;
3718 size_t __n = size();
3719 if (__n)
3720 {
3721 __r.__begin_ =
3722 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003723 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003724 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003725 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3726 ::new (__r.__end_) value_type(__f(*__p));
3727 }
3728 return __r;
3729}
3730
3731template <class _Tp>
Eric Fiseliera119c322018-10-25 17:43:26 +00003732inline
Eric Fiselier2856ef82018-10-25 17:21:30 +00003733void valarray<_Tp>::__clear(size_t __capacity)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003734{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003735 if (__begin_ != nullptr)
3736 {
3737 while (__end_ != __begin_)
3738 (--__end_)->~value_type();
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003739 _VSTD::__libcpp_deallocate(__begin_, __capacity * sizeof(value_type), _LIBCPP_ALIGNOF(value_type));
Eric Fiselier2856ef82018-10-25 17:21:30 +00003740 __begin_ = __end_ = nullptr;
3741 }
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003742}
3743
3744template <class _Tp>
3745void
3746valarray<_Tp>::resize(size_t __n, value_type __x)
3747{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003748 __clear(size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003749 if (__n)
3750 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00003751 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003752 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003753#ifndef _LIBCPP_NO_EXCEPTIONS
3754 try
3755 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003756#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00003757 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003758 ::new (__end_) value_type(__x);
3759#ifndef _LIBCPP_NO_EXCEPTIONS
3760 }
3761 catch (...)
3762 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00003763 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003764 throw;
3765 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003766#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00003767 }
3768}
3769
3770template<class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003771inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003772void
Howard Hinnant298aed92012-07-21 00:51:28 +00003773swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003774{
3775 __x.swap(__y);
3776}
3777
3778template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003779inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003780typename enable_if
3781<
3782 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3783 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
3784>::type
3785operator*(const _Expr1& __x, const _Expr2& __y)
3786{
3787 typedef typename _Expr1::value_type value_type;
3788 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
3789 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
3790}
3791
3792template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003793inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003794typename enable_if
3795<
3796 __is_val_expr<_Expr>::value,
3797 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3798 _Expr, __scalar_expr<typename _Expr::value_type> > >
3799>::type
3800operator*(const _Expr& __x, const typename _Expr::value_type& __y)
3801{
3802 typedef typename _Expr::value_type value_type;
3803 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3804 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3805 __x, __scalar_expr<value_type>(__y, __x.size())));
3806}
3807
3808template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003809inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003810typename enable_if
3811<
3812 __is_val_expr<_Expr>::value,
3813 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3814 __scalar_expr<typename _Expr::value_type>, _Expr> >
3815>::type
3816operator*(const typename _Expr::value_type& __x, const _Expr& __y)
3817{
3818 typedef typename _Expr::value_type value_type;
3819 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3820 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3821 __scalar_expr<value_type>(__x, __y.size()), __y));
3822}
3823
3824template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003825inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003826typename enable_if
3827<
3828 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3829 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
3830>::type
3831operator/(const _Expr1& __x, const _Expr2& __y)
3832{
3833 typedef typename _Expr1::value_type value_type;
3834 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
3835 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
3836}
3837
3838template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003839inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003840typename enable_if
3841<
3842 __is_val_expr<_Expr>::value,
3843 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3844 _Expr, __scalar_expr<typename _Expr::value_type> > >
3845>::type
3846operator/(const _Expr& __x, const typename _Expr::value_type& __y)
3847{
3848 typedef typename _Expr::value_type value_type;
3849 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3850 return __val_expr<_Op>(_Op(divides<value_type>(),
3851 __x, __scalar_expr<value_type>(__y, __x.size())));
3852}
3853
3854template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003855inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003856typename enable_if
3857<
3858 __is_val_expr<_Expr>::value,
3859 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3860 __scalar_expr<typename _Expr::value_type>, _Expr> >
3861>::type
3862operator/(const typename _Expr::value_type& __x, const _Expr& __y)
3863{
3864 typedef typename _Expr::value_type value_type;
3865 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3866 return __val_expr<_Op>(_Op(divides<value_type>(),
3867 __scalar_expr<value_type>(__x, __y.size()), __y));
3868}
3869
3870template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003871inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003872typename enable_if
3873<
3874 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3875 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3876>::type
3877operator%(const _Expr1& __x, const _Expr2& __y)
3878{
3879 typedef typename _Expr1::value_type value_type;
3880 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
3881 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
3882}
3883
3884template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003885inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003886typename enable_if
3887<
3888 __is_val_expr<_Expr>::value,
3889 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3890 _Expr, __scalar_expr<typename _Expr::value_type> > >
3891>::type
3892operator%(const _Expr& __x, const typename _Expr::value_type& __y)
3893{
3894 typedef typename _Expr::value_type value_type;
3895 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3896 return __val_expr<_Op>(_Op(modulus<value_type>(),
3897 __x, __scalar_expr<value_type>(__y, __x.size())));
3898}
3899
3900template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003901inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003902typename enable_if
3903<
3904 __is_val_expr<_Expr>::value,
3905 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3906 __scalar_expr<typename _Expr::value_type>, _Expr> >
3907>::type
3908operator%(const typename _Expr::value_type& __x, const _Expr& __y)
3909{
3910 typedef typename _Expr::value_type value_type;
3911 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3912 return __val_expr<_Op>(_Op(modulus<value_type>(),
3913 __scalar_expr<value_type>(__x, __y.size()), __y));
3914}
3915
3916template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003917inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003918typename enable_if
3919<
3920 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3921 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3922>::type
3923operator+(const _Expr1& __x, const _Expr2& __y)
3924{
3925 typedef typename _Expr1::value_type value_type;
3926 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
3927 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
3928}
3929
3930template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003931inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003932typename enable_if
3933<
3934 __is_val_expr<_Expr>::value,
3935 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3936 _Expr, __scalar_expr<typename _Expr::value_type> > >
3937>::type
3938operator+(const _Expr& __x, const typename _Expr::value_type& __y)
3939{
3940 typedef typename _Expr::value_type value_type;
3941 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3942 return __val_expr<_Op>(_Op(plus<value_type>(),
3943 __x, __scalar_expr<value_type>(__y, __x.size())));
3944}
3945
3946template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003947inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003948typename enable_if
3949<
3950 __is_val_expr<_Expr>::value,
3951 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3952 __scalar_expr<typename _Expr::value_type>, _Expr> >
3953>::type
3954operator+(const typename _Expr::value_type& __x, const _Expr& __y)
3955{
3956 typedef typename _Expr::value_type value_type;
3957 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3958 return __val_expr<_Op>(_Op(plus<value_type>(),
3959 __scalar_expr<value_type>(__x, __y.size()), __y));
3960}
3961
3962template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003963inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003964typename enable_if
3965<
3966 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3967 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3968>::type
3969operator-(const _Expr1& __x, const _Expr2& __y)
3970{
3971 typedef typename _Expr1::value_type value_type;
3972 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
3973 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
3974}
3975
3976template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003977inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003978typename enable_if
3979<
3980 __is_val_expr<_Expr>::value,
3981 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3982 _Expr, __scalar_expr<typename _Expr::value_type> > >
3983>::type
3984operator-(const _Expr& __x, const typename _Expr::value_type& __y)
3985{
3986 typedef typename _Expr::value_type value_type;
3987 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3988 return __val_expr<_Op>(_Op(minus<value_type>(),
3989 __x, __scalar_expr<value_type>(__y, __x.size())));
3990}
3991
3992template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003993inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003994typename enable_if
3995<
3996 __is_val_expr<_Expr>::value,
3997 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3998 __scalar_expr<typename _Expr::value_type>, _Expr> >
3999>::type
4000operator-(const typename _Expr::value_type& __x, const _Expr& __y)
4001{
4002 typedef typename _Expr::value_type value_type;
4003 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4004 return __val_expr<_Op>(_Op(minus<value_type>(),
4005 __scalar_expr<value_type>(__x, __y.size()), __y));
4006}
4007
4008template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004009inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004010typename enable_if
4011<
4012 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4013 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
4014>::type
4015operator^(const _Expr1& __x, const _Expr2& __y)
4016{
4017 typedef typename _Expr1::value_type value_type;
4018 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
4019 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
4020}
4021
4022template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004023inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004024typename enable_if
4025<
4026 __is_val_expr<_Expr>::value,
4027 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
4028 _Expr, __scalar_expr<typename _Expr::value_type> > >
4029>::type
4030operator^(const _Expr& __x, const typename _Expr::value_type& __y)
4031{
4032 typedef typename _Expr::value_type value_type;
4033 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4034 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
4035 __x, __scalar_expr<value_type>(__y, __x.size())));
4036}
4037
4038template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004039inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004040typename enable_if
4041<
4042 __is_val_expr<_Expr>::value,
4043 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
4044 __scalar_expr<typename _Expr::value_type>, _Expr> >
4045>::type
4046operator^(const typename _Expr::value_type& __x, const _Expr& __y)
4047{
4048 typedef typename _Expr::value_type value_type;
4049 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4050 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
4051 __scalar_expr<value_type>(__x, __y.size()), __y));
4052}
4053
4054template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004055inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004056typename enable_if
4057<
4058 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4059 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4060>::type
4061operator&(const _Expr1& __x, const _Expr2& __y)
4062{
4063 typedef typename _Expr1::value_type value_type;
4064 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
4065 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
4066}
4067
4068template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004069inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004070typename enable_if
4071<
4072 __is_val_expr<_Expr>::value,
4073 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4074 _Expr, __scalar_expr<typename _Expr::value_type> > >
4075>::type
4076operator&(const _Expr& __x, const typename _Expr::value_type& __y)
4077{
4078 typedef typename _Expr::value_type value_type;
4079 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4080 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4081 __x, __scalar_expr<value_type>(__y, __x.size())));
4082}
4083
4084template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004085inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004086typename enable_if
4087<
4088 __is_val_expr<_Expr>::value,
4089 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4090 __scalar_expr<typename _Expr::value_type>, _Expr> >
4091>::type
4092operator&(const typename _Expr::value_type& __x, const _Expr& __y)
4093{
4094 typedef typename _Expr::value_type value_type;
4095 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4096 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4097 __scalar_expr<value_type>(__x, __y.size()), __y));
4098}
4099
4100template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004101inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004102typename enable_if
4103<
4104 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4105 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4106>::type
4107operator|(const _Expr1& __x, const _Expr2& __y)
4108{
4109 typedef typename _Expr1::value_type value_type;
4110 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
4111 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
4112}
4113
4114template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004115inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004116typename enable_if
4117<
4118 __is_val_expr<_Expr>::value,
4119 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4120 _Expr, __scalar_expr<typename _Expr::value_type> > >
4121>::type
4122operator|(const _Expr& __x, const typename _Expr::value_type& __y)
4123{
4124 typedef typename _Expr::value_type value_type;
4125 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4126 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4127 __x, __scalar_expr<value_type>(__y, __x.size())));
4128}
4129
4130template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004131inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004132typename enable_if
4133<
4134 __is_val_expr<_Expr>::value,
4135 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4136 __scalar_expr<typename _Expr::value_type>, _Expr> >
4137>::type
4138operator|(const typename _Expr::value_type& __x, const _Expr& __y)
4139{
4140 typedef typename _Expr::value_type value_type;
4141 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4142 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4143 __scalar_expr<value_type>(__x, __y.size()), __y));
4144}
4145
4146template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004147inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004148typename enable_if
4149<
4150 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4151 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
4152>::type
4153operator<<(const _Expr1& __x, const _Expr2& __y)
4154{
4155 typedef typename _Expr1::value_type value_type;
4156 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
4157 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
4158}
4159
4160template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004161inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004162typename enable_if
4163<
4164 __is_val_expr<_Expr>::value,
4165 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4166 _Expr, __scalar_expr<typename _Expr::value_type> > >
4167>::type
4168operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
4169{
4170 typedef typename _Expr::value_type value_type;
4171 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4172 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4173 __x, __scalar_expr<value_type>(__y, __x.size())));
4174}
4175
4176template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004177inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004178typename enable_if
4179<
4180 __is_val_expr<_Expr>::value,
4181 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4182 __scalar_expr<typename _Expr::value_type>, _Expr> >
4183>::type
4184operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
4185{
4186 typedef typename _Expr::value_type value_type;
4187 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4188 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4189 __scalar_expr<value_type>(__x, __y.size()), __y));
4190}
4191
4192template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004193inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004194typename enable_if
4195<
4196 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4197 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
4198>::type
4199operator>>(const _Expr1& __x, const _Expr2& __y)
4200{
4201 typedef typename _Expr1::value_type value_type;
4202 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
4203 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
4204}
4205
4206template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004207inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004208typename enable_if
4209<
4210 __is_val_expr<_Expr>::value,
4211 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4212 _Expr, __scalar_expr<typename _Expr::value_type> > >
4213>::type
4214operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
4215{
4216 typedef typename _Expr::value_type value_type;
4217 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4218 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4219 __x, __scalar_expr<value_type>(__y, __x.size())));
4220}
4221
4222template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004223inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004224typename enable_if
4225<
4226 __is_val_expr<_Expr>::value,
4227 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4228 __scalar_expr<typename _Expr::value_type>, _Expr> >
4229>::type
4230operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
4231{
4232 typedef typename _Expr::value_type value_type;
4233 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4234 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4235 __scalar_expr<value_type>(__x, __y.size()), __y));
4236}
4237
4238template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004239inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004240typename enable_if
4241<
4242 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4243 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4244>::type
4245operator&&(const _Expr1& __x, const _Expr2& __y)
4246{
4247 typedef typename _Expr1::value_type value_type;
4248 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
4249 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
4250}
4251
4252template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004253inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004254typename enable_if
4255<
4256 __is_val_expr<_Expr>::value,
4257 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4258 _Expr, __scalar_expr<typename _Expr::value_type> > >
4259>::type
4260operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
4261{
4262 typedef typename _Expr::value_type value_type;
4263 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4264 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4265 __x, __scalar_expr<value_type>(__y, __x.size())));
4266}
4267
4268template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004269inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004270typename enable_if
4271<
4272 __is_val_expr<_Expr>::value,
4273 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4274 __scalar_expr<typename _Expr::value_type>, _Expr> >
4275>::type
4276operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
4277{
4278 typedef typename _Expr::value_type value_type;
4279 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4280 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4281 __scalar_expr<value_type>(__x, __y.size()), __y));
4282}
4283
4284template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004285inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004286typename enable_if
4287<
4288 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4289 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4290>::type
4291operator||(const _Expr1& __x, const _Expr2& __y)
4292{
4293 typedef typename _Expr1::value_type value_type;
4294 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
4295 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
4296}
4297
4298template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004299inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004300typename enable_if
4301<
4302 __is_val_expr<_Expr>::value,
4303 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4304 _Expr, __scalar_expr<typename _Expr::value_type> > >
4305>::type
4306operator||(const _Expr& __x, const typename _Expr::value_type& __y)
4307{
4308 typedef typename _Expr::value_type value_type;
4309 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4310 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4311 __x, __scalar_expr<value_type>(__y, __x.size())));
4312}
4313
4314template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004315inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004316typename enable_if
4317<
4318 __is_val_expr<_Expr>::value,
4319 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4320 __scalar_expr<typename _Expr::value_type>, _Expr> >
4321>::type
4322operator||(const typename _Expr::value_type& __x, const _Expr& __y)
4323{
4324 typedef typename _Expr::value_type value_type;
4325 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4326 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4327 __scalar_expr<value_type>(__x, __y.size()), __y));
4328}
4329
4330template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004331inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004332typename enable_if
4333<
4334 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4335 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4336>::type
4337operator==(const _Expr1& __x, const _Expr2& __y)
4338{
4339 typedef typename _Expr1::value_type value_type;
4340 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
4341 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
4342}
4343
4344template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004345inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004346typename enable_if
4347<
4348 __is_val_expr<_Expr>::value,
4349 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4350 _Expr, __scalar_expr<typename _Expr::value_type> > >
4351>::type
4352operator==(const _Expr& __x, const typename _Expr::value_type& __y)
4353{
4354 typedef typename _Expr::value_type value_type;
4355 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4356 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4357 __x, __scalar_expr<value_type>(__y, __x.size())));
4358}
4359
4360template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004361inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004362typename enable_if
4363<
4364 __is_val_expr<_Expr>::value,
4365 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4366 __scalar_expr<typename _Expr::value_type>, _Expr> >
4367>::type
4368operator==(const typename _Expr::value_type& __x, const _Expr& __y)
4369{
4370 typedef typename _Expr::value_type value_type;
4371 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4372 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4373 __scalar_expr<value_type>(__x, __y.size()), __y));
4374}
4375
4376template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004377inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004378typename enable_if
4379<
4380 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4381 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4382>::type
4383operator!=(const _Expr1& __x, const _Expr2& __y)
4384{
4385 typedef typename _Expr1::value_type value_type;
4386 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
4387 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
4388}
4389
4390template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004391inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004392typename enable_if
4393<
4394 __is_val_expr<_Expr>::value,
4395 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4396 _Expr, __scalar_expr<typename _Expr::value_type> > >
4397>::type
4398operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
4399{
4400 typedef typename _Expr::value_type value_type;
4401 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4402 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4403 __x, __scalar_expr<value_type>(__y, __x.size())));
4404}
4405
4406template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004407inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004408typename enable_if
4409<
4410 __is_val_expr<_Expr>::value,
4411 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4412 __scalar_expr<typename _Expr::value_type>, _Expr> >
4413>::type
4414operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
4415{
4416 typedef typename _Expr::value_type value_type;
4417 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4418 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4419 __scalar_expr<value_type>(__x, __y.size()), __y));
4420}
4421
4422template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004423inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004424typename enable_if
4425<
4426 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4427 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
4428>::type
4429operator<(const _Expr1& __x, const _Expr2& __y)
4430{
4431 typedef typename _Expr1::value_type value_type;
4432 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
4433 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
4434}
4435
4436template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004437inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004438typename enable_if
4439<
4440 __is_val_expr<_Expr>::value,
4441 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4442 _Expr, __scalar_expr<typename _Expr::value_type> > >
4443>::type
4444operator<(const _Expr& __x, const typename _Expr::value_type& __y)
4445{
4446 typedef typename _Expr::value_type value_type;
4447 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4448 return __val_expr<_Op>(_Op(less<value_type>(),
4449 __x, __scalar_expr<value_type>(__y, __x.size())));
4450}
4451
4452template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004453inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004454typename enable_if
4455<
4456 __is_val_expr<_Expr>::value,
4457 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4458 __scalar_expr<typename _Expr::value_type>, _Expr> >
4459>::type
4460operator<(const typename _Expr::value_type& __x, const _Expr& __y)
4461{
4462 typedef typename _Expr::value_type value_type;
4463 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4464 return __val_expr<_Op>(_Op(less<value_type>(),
4465 __scalar_expr<value_type>(__x, __y.size()), __y));
4466}
4467
4468template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004469inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004470typename enable_if
4471<
4472 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4473 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
4474>::type
4475operator>(const _Expr1& __x, const _Expr2& __y)
4476{
4477 typedef typename _Expr1::value_type value_type;
4478 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
4479 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
4480}
4481
4482template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004483inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004484typename enable_if
4485<
4486 __is_val_expr<_Expr>::value,
4487 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4488 _Expr, __scalar_expr<typename _Expr::value_type> > >
4489>::type
4490operator>(const _Expr& __x, const typename _Expr::value_type& __y)
4491{
4492 typedef typename _Expr::value_type value_type;
4493 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4494 return __val_expr<_Op>(_Op(greater<value_type>(),
4495 __x, __scalar_expr<value_type>(__y, __x.size())));
4496}
4497
4498template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004499inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004500typename enable_if
4501<
4502 __is_val_expr<_Expr>::value,
4503 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4504 __scalar_expr<typename _Expr::value_type>, _Expr> >
4505>::type
4506operator>(const typename _Expr::value_type& __x, const _Expr& __y)
4507{
4508 typedef typename _Expr::value_type value_type;
4509 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4510 return __val_expr<_Op>(_Op(greater<value_type>(),
4511 __scalar_expr<value_type>(__x, __y.size()), __y));
4512}
4513
4514template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004515inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004516typename enable_if
4517<
4518 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4519 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4520>::type
4521operator<=(const _Expr1& __x, const _Expr2& __y)
4522{
4523 typedef typename _Expr1::value_type value_type;
4524 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
4525 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
4526}
4527
4528template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004529inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004530typename enable_if
4531<
4532 __is_val_expr<_Expr>::value,
4533 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4534 _Expr, __scalar_expr<typename _Expr::value_type> > >
4535>::type
4536operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
4537{
4538 typedef typename _Expr::value_type value_type;
4539 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4540 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4541 __x, __scalar_expr<value_type>(__y, __x.size())));
4542}
4543
4544template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004545inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004546typename enable_if
4547<
4548 __is_val_expr<_Expr>::value,
4549 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4550 __scalar_expr<typename _Expr::value_type>, _Expr> >
4551>::type
4552operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
4553{
4554 typedef typename _Expr::value_type value_type;
4555 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4556 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4557 __scalar_expr<value_type>(__x, __y.size()), __y));
4558}
4559
4560template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004561inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004562typename enable_if
4563<
4564 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4565 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4566>::type
4567operator>=(const _Expr1& __x, const _Expr2& __y)
4568{
4569 typedef typename _Expr1::value_type value_type;
4570 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
4571 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
4572}
4573
4574template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004575inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004576typename enable_if
4577<
4578 __is_val_expr<_Expr>::value,
4579 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4580 _Expr, __scalar_expr<typename _Expr::value_type> > >
4581>::type
4582operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
4583{
4584 typedef typename _Expr::value_type value_type;
4585 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4586 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4587 __x, __scalar_expr<value_type>(__y, __x.size())));
4588}
4589
4590template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004591inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004592typename enable_if
4593<
4594 __is_val_expr<_Expr>::value,
4595 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4596 __scalar_expr<typename _Expr::value_type>, _Expr> >
4597>::type
4598operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
4599{
4600 typedef typename _Expr::value_type value_type;
4601 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4602 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4603 __scalar_expr<value_type>(__x, __y.size()), __y));
4604}
4605
4606template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004607inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004608typename enable_if
4609<
4610 __is_val_expr<_Expr>::value,
4611 __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
4612>::type
4613abs(const _Expr& __x)
4614{
4615 typedef typename _Expr::value_type value_type;
4616 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
4617 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
4618}
4619
4620template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004621inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004622typename enable_if
4623<
4624 __is_val_expr<_Expr>::value,
4625 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
4626>::type
4627acos(const _Expr& __x)
4628{
4629 typedef typename _Expr::value_type value_type;
4630 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
4631 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
4632}
4633
4634template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004635inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004636typename enable_if
4637<
4638 __is_val_expr<_Expr>::value,
4639 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
4640>::type
4641asin(const _Expr& __x)
4642{
4643 typedef typename _Expr::value_type value_type;
4644 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
4645 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
4646}
4647
4648template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004649inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004650typename enable_if
4651<
4652 __is_val_expr<_Expr>::value,
4653 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
4654>::type
4655atan(const _Expr& __x)
4656{
4657 typedef typename _Expr::value_type value_type;
4658 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
4659 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
4660}
4661
4662template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004663inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004664typename enable_if
4665<
4666 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4667 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4668>::type
4669atan2(const _Expr1& __x, const _Expr2& __y)
4670{
4671 typedef typename _Expr1::value_type value_type;
4672 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
4673 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
4674}
4675
4676template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004677inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004678typename enable_if
4679<
4680 __is_val_expr<_Expr>::value,
4681 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4682 _Expr, __scalar_expr<typename _Expr::value_type> > >
4683>::type
4684atan2(const _Expr& __x, const typename _Expr::value_type& __y)
4685{
4686 typedef typename _Expr::value_type value_type;
4687 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4688 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4689 __x, __scalar_expr<value_type>(__y, __x.size())));
4690}
4691
4692template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004693inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004694typename enable_if
4695<
4696 __is_val_expr<_Expr>::value,
4697 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4698 __scalar_expr<typename _Expr::value_type>, _Expr> >
4699>::type
4700atan2(const typename _Expr::value_type& __x, const _Expr& __y)
4701{
4702 typedef typename _Expr::value_type value_type;
4703 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4704 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4705 __scalar_expr<value_type>(__x, __y.size()), __y));
4706}
4707
4708template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004709inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004710typename enable_if
4711<
4712 __is_val_expr<_Expr>::value,
4713 __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
4714>::type
4715cos(const _Expr& __x)
4716{
4717 typedef typename _Expr::value_type value_type;
4718 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
4719 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
4720}
4721
4722template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004723inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004724typename enable_if
4725<
4726 __is_val_expr<_Expr>::value,
4727 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
4728>::type
4729cosh(const _Expr& __x)
4730{
4731 typedef typename _Expr::value_type value_type;
4732 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
4733 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
4734}
4735
4736template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004737inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004738typename enable_if
4739<
4740 __is_val_expr<_Expr>::value,
4741 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
4742>::type
4743exp(const _Expr& __x)
4744{
4745 typedef typename _Expr::value_type value_type;
4746 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
4747 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
4748}
4749
4750template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004751inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004752typename enable_if
4753<
4754 __is_val_expr<_Expr>::value,
4755 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
4756>::type
4757log(const _Expr& __x)
4758{
4759 typedef typename _Expr::value_type value_type;
4760 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
4761 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
4762}
4763
4764template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004765inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004766typename enable_if
4767<
4768 __is_val_expr<_Expr>::value,
4769 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
4770>::type
4771log10(const _Expr& __x)
4772{
4773 typedef typename _Expr::value_type value_type;
4774 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
4775 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
4776}
4777
4778template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004779inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004780typename enable_if
4781<
4782 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4783 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4784>::type
4785pow(const _Expr1& __x, const _Expr2& __y)
4786{
4787 typedef typename _Expr1::value_type value_type;
4788 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
4789 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
4790}
4791
4792template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004793inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004794typename enable_if
4795<
4796 __is_val_expr<_Expr>::value,
4797 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4798 _Expr, __scalar_expr<typename _Expr::value_type> > >
4799>::type
4800pow(const _Expr& __x, const typename _Expr::value_type& __y)
4801{
4802 typedef typename _Expr::value_type value_type;
4803 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4804 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4805 __x, __scalar_expr<value_type>(__y, __x.size())));
4806}
4807
4808template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004809inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004810typename enable_if
4811<
4812 __is_val_expr<_Expr>::value,
4813 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4814 __scalar_expr<typename _Expr::value_type>, _Expr> >
4815>::type
4816pow(const typename _Expr::value_type& __x, const _Expr& __y)
4817{
4818 typedef typename _Expr::value_type value_type;
4819 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4820 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4821 __scalar_expr<value_type>(__x, __y.size()), __y));
4822}
4823
4824template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004825inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004826typename enable_if
4827<
4828 __is_val_expr<_Expr>::value,
4829 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
4830>::type
4831sin(const _Expr& __x)
4832{
4833 typedef typename _Expr::value_type value_type;
4834 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
4835 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
4836}
4837
4838template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004839inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004840typename enable_if
4841<
4842 __is_val_expr<_Expr>::value,
4843 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
4844>::type
4845sinh(const _Expr& __x)
4846{
4847 typedef typename _Expr::value_type value_type;
4848 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
4849 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
4850}
4851
4852template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004853inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004854typename enable_if
4855<
4856 __is_val_expr<_Expr>::value,
4857 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
4858>::type
4859sqrt(const _Expr& __x)
4860{
4861 typedef typename _Expr::value_type value_type;
4862 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
4863 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
4864}
4865
4866template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004867inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004868typename enable_if
4869<
4870 __is_val_expr<_Expr>::value,
4871 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
4872>::type
4873tan(const _Expr& __x)
4874{
4875 typedef typename _Expr::value_type value_type;
4876 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
4877 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
4878}
4879
4880template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004881inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004882typename enable_if
4883<
4884 __is_val_expr<_Expr>::value,
4885 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
4886>::type
4887tanh(const _Expr& __x)
4888{
4889 typedef typename _Expr::value_type value_type;
4890 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
4891 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
4892}
4893
4894template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004895inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004896_Tp*
4897begin(valarray<_Tp>& __v)
4898{
4899 return __v.__begin_;
4900}
4901
4902template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004903inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004904const _Tp*
4905begin(const valarray<_Tp>& __v)
4906{
4907 return __v.__begin_;
4908}
4909
4910template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004911inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004912_Tp*
4913end(valarray<_Tp>& __v)
4914{
4915 return __v.__end_;
4916}
4917
4918template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004919inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004920const _Tp*
4921end(const valarray<_Tp>& __v)
4922{
4923 return __v.__end_;
4924}
4925
Howard Hinnantc51e1022010-05-11 19:42:16 +00004926_LIBCPP_END_NAMESPACE_STD
4927
Eric Fiselierf4433a32017-05-31 22:07:49 +00004928_LIBCPP_POP_MACROS
4929
Howard Hinnantc51e1022010-05-11 19:42:16 +00004930#endif // _LIBCPP_VALARRAY