blob: beb0e1d7031ad8862c80ab1c71369c72569a9510 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- valarray ----------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_VALARRAY
11#define _LIBCPP_VALARRAY
12
13/*
14 valarray synopsis
15
16namespace std
17{
18
19template<class T>
20class valarray
21{
22public:
23 typedef T value_type;
24
25 // construct/destroy:
26 valarray();
27 explicit valarray(size_t n);
28 valarray(const value_type& x, size_t n);
29 valarray(const value_type* px, size_t n);
30 valarray(const valarray& v);
Howard Hinnant298aed92012-07-21 00:51:28 +000031 valarray(valarray&& v) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000032 valarray(const slice_array<value_type>& sa);
33 valarray(const gslice_array<value_type>& ga);
34 valarray(const mask_array<value_type>& ma);
35 valarray(const indirect_array<value_type>& ia);
36 valarray(initializer_list<value_type> il);
37 ~valarray();
38
39 // assignment:
40 valarray& operator=(const valarray& v);
Howard Hinnant298aed92012-07-21 00:51:28 +000041 valarray& operator=(valarray&& v) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000042 valarray& operator=(initializer_list<value_type> il);
43 valarray& operator=(const value_type& x);
44 valarray& operator=(const slice_array<value_type>& sa);
45 valarray& operator=(const gslice_array<value_type>& ga);
46 valarray& operator=(const mask_array<value_type>& ma);
47 valarray& operator=(const indirect_array<value_type>& ia);
48
49 // element access:
50 const value_type& operator[](size_t i) const;
51 value_type& operator[](size_t i);
52
53 // subset operations:
54 valarray operator[](slice s) const;
55 slice_array<value_type> operator[](slice s);
56 valarray operator[](const gslice& gs) const;
57 gslice_array<value_type> operator[](const gslice& gs);
58 valarray operator[](const valarray<bool>& vb) const;
59 mask_array<value_type> operator[](const valarray<bool>& vb);
60 valarray operator[](const valarray<size_t>& vs) const;
61 indirect_array<value_type> operator[](const valarray<size_t>& vs);
62
63 // unary operators:
64 valarray operator+() const;
65 valarray operator-() const;
66 valarray operator~() const;
67 valarray<bool> operator!() const;
68
69 // computed assignment:
70 valarray& operator*= (const value_type& x);
71 valarray& operator/= (const value_type& x);
72 valarray& operator%= (const value_type& x);
73 valarray& operator+= (const value_type& x);
74 valarray& operator-= (const value_type& x);
75 valarray& operator^= (const value_type& x);
76 valarray& operator&= (const value_type& x);
77 valarray& operator|= (const value_type& x);
78 valarray& operator<<=(const value_type& x);
79 valarray& operator>>=(const value_type& x);
80
81 valarray& operator*= (const valarray& v);
82 valarray& operator/= (const valarray& v);
83 valarray& operator%= (const valarray& v);
84 valarray& operator+= (const valarray& v);
85 valarray& operator-= (const valarray& v);
86 valarray& operator^= (const valarray& v);
87 valarray& operator|= (const valarray& v);
88 valarray& operator&= (const valarray& v);
89 valarray& operator<<=(const valarray& v);
90 valarray& operator>>=(const valarray& v);
91
92 // member functions:
Howard Hinnant298aed92012-07-21 00:51:28 +000093 void swap(valarray& v) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000094
95 size_t size() const;
96
97 value_type sum() const;
98 value_type min() const;
99 value_type max() const;
100
101 valarray shift (int i) const;
102 valarray cshift(int i) const;
103 valarray apply(value_type f(value_type)) const;
104 valarray apply(value_type f(const value_type&)) const;
105 void resize(size_t n, value_type x = value_type());
106};
107
108class slice
109{
110public:
111 slice();
112 slice(size_t start, size_t size, size_t stride);
113
114 size_t start() const;
115 size_t size() const;
116 size_t stride() const;
117};
118
119template <class T>
120class slice_array
121{
122public:
123 typedef T value_type;
124
125 const slice_array& operator=(const slice_array& sa) const;
126 void operator= (const valarray<value_type>& v) const;
127 void operator*= (const valarray<value_type>& v) const;
128 void operator/= (const valarray<value_type>& v) const;
129 void operator%= (const valarray<value_type>& v) const;
130 void operator+= (const valarray<value_type>& v) const;
131 void operator-= (const valarray<value_type>& v) const;
132 void operator^= (const valarray<value_type>& v) const;
133 void operator&= (const valarray<value_type>& v) const;
134 void operator|= (const valarray<value_type>& v) const;
135 void operator<<=(const valarray<value_type>& v) const;
136 void operator>>=(const valarray<value_type>& v) const;
137
138 void operator=(const value_type& x) const;
zoecarver79fa7502020-12-02 10:49:20 -0800139 void operator=(const valarray<T>& val_arr) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000140
141 slice_array() = delete;
142};
143
144class gslice
145{
146public:
147 gslice();
148 gslice(size_t start, const valarray<size_t>& size,
149 const valarray<size_t>& stride);
150
151 size_t start() const;
152 valarray<size_t> size() const;
153 valarray<size_t> stride() const;
154};
155
156template <class T>
157class gslice_array
158{
159public:
160 typedef T value_type;
161
162 void operator= (const valarray<value_type>& v) const;
163 void operator*= (const valarray<value_type>& v) const;
164 void operator/= (const valarray<value_type>& v) const;
165 void operator%= (const valarray<value_type>& v) const;
166 void operator+= (const valarray<value_type>& v) const;
167 void operator-= (const valarray<value_type>& v) const;
168 void operator^= (const valarray<value_type>& v) const;
169 void operator&= (const valarray<value_type>& v) const;
170 void operator|= (const valarray<value_type>& v) const;
171 void operator<<=(const valarray<value_type>& v) const;
172 void operator>>=(const valarray<value_type>& v) const;
173
174 gslice_array(const gslice_array& ga);
175 ~gslice_array();
176 const gslice_array& operator=(const gslice_array& ga) const;
177 void operator=(const value_type& x) const;
178
179 gslice_array() = delete;
180};
181
182template <class T>
183class mask_array
184{
185public:
186 typedef T value_type;
187
188 void operator= (const valarray<value_type>& v) const;
189 void operator*= (const valarray<value_type>& v) const;
190 void operator/= (const valarray<value_type>& v) const;
191 void operator%= (const valarray<value_type>& v) const;
192 void operator+= (const valarray<value_type>& v) const;
193 void operator-= (const valarray<value_type>& v) const;
194 void operator^= (const valarray<value_type>& v) const;
195 void operator&= (const valarray<value_type>& v) const;
196 void operator|= (const valarray<value_type>& v) const;
197 void operator<<=(const valarray<value_type>& v) const;
198 void operator>>=(const valarray<value_type>& v) const;
199
200 mask_array(const mask_array& ma);
201 ~mask_array();
202 const mask_array& operator=(const mask_array& ma) const;
203 void operator=(const value_type& x) const;
204
205 mask_array() = delete;
206};
207
208template <class T>
209class indirect_array
210{
211public:
212 typedef T value_type;
213
214 void operator= (const valarray<value_type>& v) const;
215 void operator*= (const valarray<value_type>& v) const;
216 void operator/= (const valarray<value_type>& v) const;
217 void operator%= (const valarray<value_type>& v) const;
218 void operator+= (const valarray<value_type>& v) const;
219 void operator-= (const valarray<value_type>& v) const;
220 void operator^= (const valarray<value_type>& v) const;
221 void operator&= (const valarray<value_type>& v) const;
222 void operator|= (const valarray<value_type>& v) const;
223 void operator<<=(const valarray<value_type>& v) const;
224 void operator>>=(const valarray<value_type>& v) const;
225
226 indirect_array(const indirect_array& ia);
227 ~indirect_array();
228 const indirect_array& operator=(const indirect_array& ia) const;
229 void operator=(const value_type& x) const;
230
231 indirect_array() = delete;
232};
233
Howard Hinnant298aed92012-07-21 00:51:28 +0000234template<class T> void swap(valarray<T>& x, valarray<T>& y) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000235
236template<class T> valarray<T> operator* (const valarray<T>& x, const valarray<T>& y);
237template<class T> valarray<T> operator* (const valarray<T>& x, const T& y);
238template<class T> valarray<T> operator* (const T& x, const valarray<T>& y);
239
240template<class T> valarray<T> operator/ (const valarray<T>& x, const valarray<T>& y);
241template<class T> valarray<T> operator/ (const valarray<T>& x, const T& y);
242template<class T> valarray<T> operator/ (const T& x, const valarray<T>& y);
243
244template<class T> valarray<T> operator% (const valarray<T>& x, const valarray<T>& y);
245template<class T> valarray<T> operator% (const valarray<T>& x, const T& y);
246template<class T> valarray<T> operator% (const T& x, const valarray<T>& y);
247
248template<class T> valarray<T> operator+ (const valarray<T>& x, const valarray<T>& y);
249template<class T> valarray<T> operator+ (const valarray<T>& x, const T& y);
250template<class T> valarray<T> operator+ (const T& x, const valarray<T>& y);
251
252template<class T> valarray<T> operator- (const valarray<T>& x, const valarray<T>& y);
253template<class T> valarray<T> operator- (const valarray<T>& x, const T& y);
254template<class T> valarray<T> operator- (const T& x, const valarray<T>& y);
255
256template<class T> valarray<T> operator^ (const valarray<T>& x, const valarray<T>& y);
257template<class T> valarray<T> operator^ (const valarray<T>& x, const T& y);
258template<class T> valarray<T> operator^ (const T& x, const valarray<T>& y);
259
260template<class T> valarray<T> operator& (const valarray<T>& x, const valarray<T>& y);
261template<class T> valarray<T> operator& (const valarray<T>& x, const T& y);
262template<class T> valarray<T> operator& (const T& x, const valarray<T>& y);
263
264template<class T> valarray<T> operator| (const valarray<T>& x, const valarray<T>& y);
265template<class T> valarray<T> operator| (const valarray<T>& x, const T& y);
266template<class T> valarray<T> operator| (const T& x, const valarray<T>& y);
267
268template<class T> valarray<T> operator<<(const valarray<T>& x, const valarray<T>& y);
269template<class T> valarray<T> operator<<(const valarray<T>& x, const T& y);
270template<class T> valarray<T> operator<<(const T& x, const valarray<T>& y);
271
272template<class T> valarray<T> operator>>(const valarray<T>& x, const valarray<T>& y);
273template<class T> valarray<T> operator>>(const valarray<T>& x, const T& y);
274template<class T> valarray<T> operator>>(const T& x, const valarray<T>& y);
275
276template<class T> valarray<bool> operator&&(const valarray<T>& x, const valarray<T>& y);
277template<class T> valarray<bool> operator&&(const valarray<T>& x, const T& y);
278template<class T> valarray<bool> operator&&(const T& x, const valarray<T>& y);
279
280template<class T> valarray<bool> operator||(const valarray<T>& x, const valarray<T>& y);
281template<class T> valarray<bool> operator||(const valarray<T>& x, const T& y);
282template<class T> valarray<bool> operator||(const T& x, const valarray<T>& y);
283
284template<class T> valarray<bool> operator==(const valarray<T>& x, const valarray<T>& y);
285template<class T> valarray<bool> operator==(const valarray<T>& x, const T& y);
286template<class T> valarray<bool> operator==(const T& x, const valarray<T>& y);
287
288template<class T> valarray<bool> operator!=(const valarray<T>& x, const valarray<T>& y);
289template<class T> valarray<bool> operator!=(const valarray<T>& x, const T& y);
290template<class T> valarray<bool> operator!=(const T& x, const valarray<T>& y);
291
292template<class T> valarray<bool> operator< (const valarray<T>& x, const valarray<T>& y);
293template<class T> valarray<bool> operator< (const valarray<T>& x, const T& y);
294template<class T> valarray<bool> operator< (const T& x, const valarray<T>& y);
295
296template<class T> valarray<bool> operator> (const valarray<T>& x, const valarray<T>& y);
297template<class T> valarray<bool> operator> (const valarray<T>& x, const T& y);
298template<class T> valarray<bool> operator> (const T& x, const valarray<T>& y);
299
300template<class T> valarray<bool> operator<=(const valarray<T>& x, const valarray<T>& y);
301template<class T> valarray<bool> operator<=(const valarray<T>& x, const T& y);
302template<class T> valarray<bool> operator<=(const T& x, const valarray<T>& y);
303
304template<class T> valarray<bool> operator>=(const valarray<T>& x, const valarray<T>& y);
305template<class T> valarray<bool> operator>=(const valarray<T>& x, const T& y);
306template<class T> valarray<bool> operator>=(const T& x, const valarray<T>& y);
307
308template<class T> valarray<T> abs (const valarray<T>& x);
309template<class T> valarray<T> acos (const valarray<T>& x);
310template<class T> valarray<T> asin (const valarray<T>& x);
311template<class T> valarray<T> atan (const valarray<T>& x);
312
313template<class T> valarray<T> atan2(const valarray<T>& x, const valarray<T>& y);
314template<class T> valarray<T> atan2(const valarray<T>& x, const T& y);
315template<class T> valarray<T> atan2(const T& x, const valarray<T>& y);
316
317template<class T> valarray<T> cos (const valarray<T>& x);
318template<class T> valarray<T> cosh (const valarray<T>& x);
319template<class T> valarray<T> exp (const valarray<T>& x);
320template<class T> valarray<T> log (const valarray<T>& x);
321template<class T> valarray<T> log10(const valarray<T>& x);
322
323template<class T> valarray<T> pow(const valarray<T>& x, const valarray<T>& y);
324template<class T> valarray<T> pow(const valarray<T>& x, const T& y);
325template<class T> valarray<T> pow(const T& x, const valarray<T>& y);
326
327template<class T> valarray<T> sin (const valarray<T>& x);
328template<class T> valarray<T> sinh (const valarray<T>& x);
329template<class T> valarray<T> sqrt (const valarray<T>& x);
330template<class T> valarray<T> tan (const valarray<T>& x);
331template<class T> valarray<T> tanh (const valarray<T>& x);
332
333template <class T> unspecified1 begin(valarray<T>& v);
334template <class T> unspecified2 begin(const valarray<T>& v);
335template <class T> unspecified1 end(valarray<T>& v);
336template <class T> unspecified2 end(const valarray<T>& v);
337
338} // std
339
340*/
341
342#include <__config>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000343#include <algorithm>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400344#include <cmath>
345#include <cstddef>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000346#include <functional>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400347#include <initializer_list>
Richard Smith1f1c1472014-06-04 19:54:15 +0000348#include <new>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000349
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000350#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000351#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000352#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000353
Eric Fiselierf4433a32017-05-31 22:07:49 +0000354_LIBCPP_PUSH_MACROS
355#include <__undef_macros>
356
Howard Hinnantc51e1022010-05-11 19:42:16 +0000357_LIBCPP_BEGIN_NAMESPACE_STD
358
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000359template<class _Tp> class _LIBCPP_TEMPLATE_VIS valarray;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000361class _LIBCPP_TEMPLATE_VIS slice
Howard Hinnantc51e1022010-05-11 19:42:16 +0000362{
363 size_t __start_;
364 size_t __size_;
365 size_t __stride_;
366public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000367 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000368 slice()
369 : __start_(0),
370 __size_(0),
371 __stride_(0)
372 {}
373
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000374 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375 slice(size_t __start, size_t __size, size_t __stride)
376 : __start_(__start),
377 __size_(__size),
378 __stride_(__stride)
379 {}
380
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000381 _LIBCPP_INLINE_VISIBILITY size_t start() const {return __start_;}
382 _LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;}
383 _LIBCPP_INLINE_VISIBILITY size_t stride() const {return __stride_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000384};
385
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000386template <class _Tp> class _LIBCPP_TEMPLATE_VIS slice_array;
Howard Hinnant8331b762013-03-06 23:30:19 +0000387class _LIBCPP_TYPE_VIS gslice;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000388template <class _Tp> class _LIBCPP_TEMPLATE_VIS gslice_array;
389template <class _Tp> class _LIBCPP_TEMPLATE_VIS mask_array;
390template <class _Tp> class _LIBCPP_TEMPLATE_VIS indirect_array;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000391
392template <class _Tp>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000393_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000394_Tp*
395begin(valarray<_Tp>& __v);
396
397template <class _Tp>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000398_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000399const _Tp*
400begin(const valarray<_Tp>& __v);
401
402template <class _Tp>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000403_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000404_Tp*
405end(valarray<_Tp>& __v);
406
407template <class _Tp>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000408_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000409const _Tp*
410end(const valarray<_Tp>& __v);
411
412template <class _Op, class _A0>
413struct _UnaryOp
414{
415 typedef typename _Op::result_type result_type;
416 typedef typename _A0::value_type value_type;
417
418 _Op __op_;
419 _A0 __a0_;
420
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000422 _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {}
423
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000425 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
426
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000427 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428 size_t size() const {return __a0_.size();}
429};
430
431template <class _Op, class _A0, class _A1>
432struct _BinaryOp
433{
434 typedef typename _Op::result_type result_type;
435 typedef typename _A0::value_type value_type;
436
437 _Op __op_;
438 _A0 __a0_;
439 _A1 __a1_;
440
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000441 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000442 _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1)
443 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
444
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
447
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449 size_t size() const {return __a0_.size();}
450};
451
452template <class _Tp>
453class __scalar_expr
454{
455public:
456 typedef _Tp value_type;
457 typedef const _Tp& result_type;
458private:
459 const value_type& __t_;
460 size_t __s_;
461public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000463 explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {}
464
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000466 result_type operator[](size_t) const {return __t_;}
467
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000468 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000469 size_t size() const {return __s_;}
470};
471
472template <class _Tp>
473struct __unary_plus : unary_function<_Tp, _Tp>
474{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000476 _Tp operator()(const _Tp& __x) const
477 {return +__x;}
478};
479
480template <class _Tp>
481struct __bit_not : unary_function<_Tp, _Tp>
482{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000484 _Tp operator()(const _Tp& __x) const
485 {return ~__x;}
486};
487
488template <class _Tp>
489struct __bit_shift_left : binary_function<_Tp, _Tp, _Tp>
490{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000492 _Tp operator()(const _Tp& __x, const _Tp& __y) const
493 {return __x << __y;}
494};
495
496template <class _Tp>
497struct __bit_shift_right : binary_function<_Tp, _Tp, _Tp>
498{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000500 _Tp operator()(const _Tp& __x, const _Tp& __y) const
501 {return __x >> __y;}
502};
503
Howard Hinnantc834c512011-11-29 18:15:50 +0000504template <class _Tp, class _Fp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505struct __apply_expr : unary_function<_Tp, _Tp>
506{
507private:
Howard Hinnantc834c512011-11-29 18:15:50 +0000508 _Fp __f_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +0000511 explicit __apply_expr(_Fp __f) : __f_(__f) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000512
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000514 _Tp operator()(const _Tp& __x) const
515 {return __f_(__x);}
516};
517
518template <class _Tp>
519struct __abs_expr : unary_function<_Tp, _Tp>
520{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000521 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000522 _Tp operator()(const _Tp& __x) const
523 {return abs(__x);}
524};
525
526template <class _Tp>
527struct __acos_expr : unary_function<_Tp, _Tp>
528{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000529 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000530 _Tp operator()(const _Tp& __x) const
531 {return acos(__x);}
532};
533
534template <class _Tp>
535struct __asin_expr : unary_function<_Tp, _Tp>
536{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000538 _Tp operator()(const _Tp& __x) const
539 {return asin(__x);}
540};
541
542template <class _Tp>
543struct __atan_expr : unary_function<_Tp, _Tp>
544{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000545 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000546 _Tp operator()(const _Tp& __x) const
547 {return atan(__x);}
548};
549
550template <class _Tp>
551struct __atan2_expr : binary_function<_Tp, _Tp, _Tp>
552{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000554 _Tp operator()(const _Tp& __x, const _Tp& __y) const
555 {return atan2(__x, __y);}
556};
557
558template <class _Tp>
559struct __cos_expr : unary_function<_Tp, _Tp>
560{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562 _Tp operator()(const _Tp& __x) const
563 {return cos(__x);}
564};
565
566template <class _Tp>
567struct __cosh_expr : unary_function<_Tp, _Tp>
568{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570 _Tp operator()(const _Tp& __x) const
571 {return cosh(__x);}
572};
573
574template <class _Tp>
575struct __exp_expr : unary_function<_Tp, _Tp>
576{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000578 _Tp operator()(const _Tp& __x) const
579 {return exp(__x);}
580};
581
582template <class _Tp>
583struct __log_expr : unary_function<_Tp, _Tp>
584{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000585 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000586 _Tp operator()(const _Tp& __x) const
587 {return log(__x);}
588};
589
590template <class _Tp>
591struct __log10_expr : unary_function<_Tp, _Tp>
592{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000594 _Tp operator()(const _Tp& __x) const
595 {return log10(__x);}
596};
597
598template <class _Tp>
599struct __pow_expr : binary_function<_Tp, _Tp, _Tp>
600{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000601 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000602 _Tp operator()(const _Tp& __x, const _Tp& __y) const
603 {return pow(__x, __y);}
604};
605
606template <class _Tp>
607struct __sin_expr : unary_function<_Tp, _Tp>
608{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000610 _Tp operator()(const _Tp& __x) const
611 {return sin(__x);}
612};
613
614template <class _Tp>
615struct __sinh_expr : unary_function<_Tp, _Tp>
616{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000618 _Tp operator()(const _Tp& __x) const
619 {return sinh(__x);}
620};
621
622template <class _Tp>
623struct __sqrt_expr : unary_function<_Tp, _Tp>
624{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000626 _Tp operator()(const _Tp& __x) const
627 {return sqrt(__x);}
628};
629
630template <class _Tp>
631struct __tan_expr : unary_function<_Tp, _Tp>
632{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000633 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000634 _Tp operator()(const _Tp& __x) const
635 {return tan(__x);}
636};
637
638template <class _Tp>
639struct __tanh_expr : unary_function<_Tp, _Tp>
640{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000641 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642 _Tp operator()(const _Tp& __x) const
643 {return tanh(__x);}
644};
645
646template <class _ValExpr>
647class __slice_expr
648{
649 typedef typename remove_reference<_ValExpr>::type _RmExpr;
650public:
651 typedef typename _RmExpr::value_type value_type;
652 typedef value_type result_type;
653
654private:
655 _ValExpr __expr_;
656 size_t __start_;
657 size_t __size_;
658 size_t __stride_;
659
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000661 __slice_expr(const slice& __sl, const _RmExpr& __e)
662 : __expr_(__e),
663 __start_(__sl.start()),
664 __size_(__sl.size()),
665 __stride_(__sl.stride())
666 {}
667public:
668
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000670 result_type operator[](size_t __i) const
671 {return __expr_[__start_ + __i * __stride_];}
672
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000674 size_t size() const {return __size_;}
675
Eric Fiselier7b31ed02019-04-02 08:05:23 +0000676 template <class> friend class __val_expr;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000677 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000678};
679
680template <class _ValExpr>
681class __mask_expr;
682
683template <class _ValExpr>
684class __indirect_expr;
685
686template <class _ValExpr>
687class __shift_expr
688{
689 typedef typename remove_reference<_ValExpr>::type _RmExpr;
690public:
691 typedef typename _RmExpr::value_type value_type;
692 typedef value_type result_type;
693
694private:
695 _ValExpr __expr_;
696 size_t __size_;
697 ptrdiff_t __ul_;
698 ptrdiff_t __sn_;
699 ptrdiff_t __n_;
Howard Hinnantc834c512011-11-29 18:15:50 +0000700 static const ptrdiff_t _Np = static_cast<ptrdiff_t>(
Howard Hinnantc51e1022010-05-11 19:42:16 +0000701 sizeof(ptrdiff_t) * __CHAR_BIT__ - 1);
702
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000704 __shift_expr(int __n, const _RmExpr& __e)
705 : __expr_(__e),
706 __size_(__e.size()),
707 __n_(__n)
708 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000709 ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _Np);
710 __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _Np);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000711 __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n);
712 }
713public:
714
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000715 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000716 result_type operator[](size_t __j) const
717 {
Howard Hinnant28b24882011-12-01 20:21:04 +0000718 ptrdiff_t __i = static_cast<ptrdiff_t>(__j);
Howard Hinnantc834c512011-11-29 18:15:50 +0000719 ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000720 return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
721 }
722
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000724 size_t size() const {return __size_;}
725
726 template <class> friend class __val_expr;
727};
728
729template <class _ValExpr>
730class __cshift_expr
731{
732 typedef typename remove_reference<_ValExpr>::type _RmExpr;
733public:
734 typedef typename _RmExpr::value_type value_type;
735 typedef value_type result_type;
736
737private:
738 _ValExpr __expr_;
739 size_t __size_;
740 size_t __m_;
741 size_t __o1_;
742 size_t __o2_;
743
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000745 __cshift_expr(int __n, const _RmExpr& __e)
746 : __expr_(__e),
747 __size_(__e.size())
748 {
749 __n %= static_cast<int>(__size_);
750 if (__n >= 0)
751 {
752 __m_ = __size_ - __n;
753 __o1_ = __n;
754 __o2_ = __n - __size_;
755 }
756 else
757 {
758 __m_ = -__n;
759 __o1_ = __n + __size_;
760 __o2_ = __n;
761 }
762 }
763public:
764
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000766 result_type operator[](size_t __i) const
767 {
768 if (__i < __m_)
769 return __expr_[__i + __o1_];
770 return __expr_[__i + __o2_];
771 }
772
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000774 size_t size() const {return __size_;}
775
776 template <class> friend class __val_expr;
777};
778
779template<class _ValExpr>
780class __val_expr;
781
782template<class _ValExpr>
783struct __is_val_expr : false_type {};
784
785template<class _ValExpr>
786struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
787
788template<class _Tp>
789struct __is_val_expr<valarray<_Tp> > : true_type {};
790
791template<class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000792class _LIBCPP_TEMPLATE_VIS valarray
Howard Hinnantc51e1022010-05-11 19:42:16 +0000793{
794public:
795 typedef _Tp value_type;
796 typedef _Tp result_type;
797
798private:
799 value_type* __begin_;
800 value_type* __end_;
801
802public:
803 // construct/destroy:
Douglas Gregor68902322012-05-19 07:14:17 +0000804 _LIBCPP_INLINE_VISIBILITY
Bruce Mitchener170d8972020-11-24 12:53:53 -0500805 valarray() : __begin_(nullptr), __end_(nullptr) {}
Louis Dionneb4d05d72018-10-16 19:26:23 +0000806 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Eric Fiseliere529a802016-09-16 00:13:55 +0000807 explicit valarray(size_t __n);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000808 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +0000809 valarray(const value_type& __x, size_t __n);
810 valarray(const value_type* __p, size_t __n);
811 valarray(const valarray& __v);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000812#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000813 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant298aed92012-07-21 00:51:28 +0000814 valarray(valarray&& __v) _NOEXCEPT;
Douglas Gregor68902322012-05-19 07:14:17 +0000815 valarray(initializer_list<value_type> __il);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400816#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>);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400831#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);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400867#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);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400877#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);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400887#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
zoecarver79fa7502020-12-02 10:49:20 -08001267 _LIBCPP_INLINE_VISIBILITY
1268 void operator=(const valarray<value_type>& __va) const;
1269
Howard Hinnantc51e1022010-05-11 19:42:16 +00001270private:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001271 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001272 slice_array(const slice& __sl, const valarray<value_type>& __v)
1273 : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())),
1274 __size_(__sl.size()),
1275 __stride_(__sl.stride())
1276 {}
1277
1278 template <class> friend class valarray;
1279 template <class> friend class sliceExpr;
1280};
1281
1282template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001283inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001284const slice_array<_Tp>&
1285slice_array<_Tp>::operator=(const slice_array& __sa) const
1286{
1287 value_type* __t = __vp_;
1288 const value_type* __s = __sa.__vp_;
1289 for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
1290 *__t = *__s;
Eric Fiselier3b80ce92014-08-12 00:06:58 +00001291 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001292}
1293
1294template <class _Tp>
1295template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001296inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001297typename enable_if
1298<
1299 __is_val_expr<_Expr>::value,
1300 void
1301>::type
1302slice_array<_Tp>::operator=(const _Expr& __v) const
1303{
1304 value_type* __t = __vp_;
1305 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1306 *__t = __v[__i];
1307}
1308
1309template <class _Tp>
zoecarver79fa7502020-12-02 10:49:20 -08001310inline void
1311slice_array<_Tp>::operator=(const valarray<value_type>& __va) const
1312{
1313 value_type* __t = __vp_;
1314 for (size_t __i = 0; __i < __va.size(); ++__i, __t += __stride_)
1315 *__t = __va[__i];
1316}
1317
1318template <class _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001319template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001320inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001321typename enable_if
1322<
1323 __is_val_expr<_Expr>::value,
1324 void
1325>::type
1326slice_array<_Tp>::operator*=(const _Expr& __v) const
1327{
1328 value_type* __t = __vp_;
1329 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1330 *__t *= __v[__i];
1331}
1332
1333template <class _Tp>
1334template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001335inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001336typename enable_if
1337<
1338 __is_val_expr<_Expr>::value,
1339 void
1340>::type
1341slice_array<_Tp>::operator/=(const _Expr& __v) const
1342{
1343 value_type* __t = __vp_;
1344 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1345 *__t /= __v[__i];
1346}
1347
1348template <class _Tp>
1349template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001350inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001351typename enable_if
1352<
1353 __is_val_expr<_Expr>::value,
1354 void
1355>::type
1356slice_array<_Tp>::operator%=(const _Expr& __v) const
1357{
1358 value_type* __t = __vp_;
1359 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1360 *__t %= __v[__i];
1361}
1362
1363template <class _Tp>
1364template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001365inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001366typename enable_if
1367<
1368 __is_val_expr<_Expr>::value,
1369 void
1370>::type
1371slice_array<_Tp>::operator+=(const _Expr& __v) const
1372{
1373 value_type* __t = __vp_;
1374 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1375 *__t += __v[__i];
1376}
1377
1378template <class _Tp>
1379template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001380inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001381typename enable_if
1382<
1383 __is_val_expr<_Expr>::value,
1384 void
1385>::type
1386slice_array<_Tp>::operator-=(const _Expr& __v) const
1387{
1388 value_type* __t = __vp_;
1389 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1390 *__t -= __v[__i];
1391}
1392
1393template <class _Tp>
1394template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001395inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001396typename enable_if
1397<
1398 __is_val_expr<_Expr>::value,
1399 void
1400>::type
1401slice_array<_Tp>::operator^=(const _Expr& __v) const
1402{
1403 value_type* __t = __vp_;
1404 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1405 *__t ^= __v[__i];
1406}
1407
1408template <class _Tp>
1409template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001410inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001411typename enable_if
1412<
1413 __is_val_expr<_Expr>::value,
1414 void
1415>::type
1416slice_array<_Tp>::operator&=(const _Expr& __v) const
1417{
1418 value_type* __t = __vp_;
1419 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1420 *__t &= __v[__i];
1421}
1422
1423template <class _Tp>
1424template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001425inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001426typename enable_if
1427<
1428 __is_val_expr<_Expr>::value,
1429 void
1430>::type
1431slice_array<_Tp>::operator|=(const _Expr& __v) const
1432{
1433 value_type* __t = __vp_;
1434 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1435 *__t |= __v[__i];
1436}
1437
1438template <class _Tp>
1439template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001440inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001441typename enable_if
1442<
1443 __is_val_expr<_Expr>::value,
1444 void
1445>::type
1446slice_array<_Tp>::operator<<=(const _Expr& __v) const
1447{
1448 value_type* __t = __vp_;
1449 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1450 *__t <<= __v[__i];
1451}
1452
1453template <class _Tp>
1454template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001455inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001456typename enable_if
1457<
1458 __is_val_expr<_Expr>::value,
1459 void
1460>::type
1461slice_array<_Tp>::operator>>=(const _Expr& __v) const
1462{
1463 value_type* __t = __vp_;
1464 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1465 *__t >>= __v[__i];
1466}
1467
1468template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001469inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001470void
1471slice_array<_Tp>::operator=(const value_type& __x) const
1472{
1473 value_type* __t = __vp_;
1474 for (size_t __n = __size_; __n; --__n, __t += __stride_)
1475 *__t = __x;
1476}
1477
1478// gslice
1479
Howard Hinnant8331b762013-03-06 23:30:19 +00001480class _LIBCPP_TYPE_VIS gslice
Howard Hinnantc51e1022010-05-11 19:42:16 +00001481{
1482 valarray<size_t> __size_;
1483 valarray<size_t> __stride_;
1484 valarray<size_t> __1d_;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001485
Howard Hinnantc51e1022010-05-11 19:42:16 +00001486public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001488 gslice() {}
Douglas Gregor68902322012-05-19 07:14:17 +00001489
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001491 gslice(size_t __start, const valarray<size_t>& __size,
1492 const valarray<size_t>& __stride)
1493 : __size_(__size),
1494 __stride_(__stride)
1495 {__init(__start);}
1496
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00001497#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001498
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001500 gslice(size_t __start, const valarray<size_t>& __size,
1501 valarray<size_t>&& __stride)
1502 : __size_(__size),
1503 __stride_(move(__stride))
1504 {__init(__start);}
1505
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001506 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001507 gslice(size_t __start, valarray<size_t>&& __size,
1508 const valarray<size_t>& __stride)
1509 : __size_(move(__size)),
1510 __stride_(__stride)
1511 {__init(__start);}
1512
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001514 gslice(size_t __start, valarray<size_t>&& __size,
1515 valarray<size_t>&& __stride)
1516 : __size_(move(__size)),
1517 __stride_(move(__stride))
1518 {__init(__start);}
1519
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001520#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001521
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001523 size_t start() const {return __1d_.size() ? __1d_[0] : 0;}
1524
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001526 valarray<size_t> size() const {return __size_;}
1527
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001529 valarray<size_t> stride() const {return __stride_;}
1530
1531private:
1532 void __init(size_t __start);
1533
1534 template <class> friend class gslice_array;
1535 template <class> friend class valarray;
1536 template <class> friend class __val_expr;
1537};
1538
1539// gslice_array
1540
1541template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001542class _LIBCPP_TEMPLATE_VIS gslice_array
Howard Hinnantc51e1022010-05-11 19:42:16 +00001543{
1544public:
1545 typedef _Tp value_type;
1546
1547private:
1548 value_type* __vp_;
1549 valarray<size_t> __1d_;
1550
1551public:
1552 template <class _Expr>
1553 typename enable_if
1554 <
1555 __is_val_expr<_Expr>::value,
1556 void
1557 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001558 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001559 operator=(const _Expr& __v) const;
1560
1561 template <class _Expr>
1562 typename enable_if
1563 <
1564 __is_val_expr<_Expr>::value,
1565 void
1566 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001568 operator*=(const _Expr& __v) const;
1569
1570 template <class _Expr>
1571 typename enable_if
1572 <
1573 __is_val_expr<_Expr>::value,
1574 void
1575 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001576 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001577 operator/=(const _Expr& __v) const;
1578
1579 template <class _Expr>
1580 typename enable_if
1581 <
1582 __is_val_expr<_Expr>::value,
1583 void
1584 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001585 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001586 operator%=(const _Expr& __v) const;
1587
1588 template <class _Expr>
1589 typename enable_if
1590 <
1591 __is_val_expr<_Expr>::value,
1592 void
1593 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001595 operator+=(const _Expr& __v) const;
1596
1597 template <class _Expr>
1598 typename enable_if
1599 <
1600 __is_val_expr<_Expr>::value,
1601 void
1602 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001604 operator-=(const _Expr& __v) const;
1605
1606 template <class _Expr>
1607 typename enable_if
1608 <
1609 __is_val_expr<_Expr>::value,
1610 void
1611 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001613 operator^=(const _Expr& __v) const;
1614
1615 template <class _Expr>
1616 typename enable_if
1617 <
1618 __is_val_expr<_Expr>::value,
1619 void
1620 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001622 operator&=(const _Expr& __v) const;
1623
1624 template <class _Expr>
1625 typename enable_if
1626 <
1627 __is_val_expr<_Expr>::value,
1628 void
1629 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001631 operator|=(const _Expr& __v) const;
1632
1633 template <class _Expr>
1634 typename enable_if
1635 <
1636 __is_val_expr<_Expr>::value,
1637 void
1638 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001640 operator<<=(const _Expr& __v) const;
1641
1642 template <class _Expr>
1643 typename enable_if
1644 <
1645 __is_val_expr<_Expr>::value,
1646 void
1647 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001648 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001649 operator>>=(const _Expr& __v) const;
1650
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001651 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001652 const gslice_array& operator=(const gslice_array& __ga) const;
1653
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001655 void operator=(const value_type& __x) const;
1656
Eric Fiselierb9f37ca2019-12-12 20:48:11 -05001657 gslice_array(const gslice_array&) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001658
1659private:
Howard Hinnantc51e1022010-05-11 19:42:16 +00001660 gslice_array(const gslice& __gs, const valarray<value_type>& __v)
1661 : __vp_(const_cast<value_type*>(__v.__begin_)),
1662 __1d_(__gs.__1d_)
1663 {}
1664
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00001665#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001666 gslice_array(gslice&& __gs, const valarray<value_type>& __v)
1667 : __vp_(const_cast<value_type*>(__v.__begin_)),
1668 __1d_(move(__gs.__1d_))
1669 {}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001670#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001671
1672 template <class> friend class valarray;
1673};
1674
1675template <class _Tp>
1676template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001677inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001678typename enable_if
1679<
1680 __is_val_expr<_Expr>::value,
1681 void
1682>::type
1683gslice_array<_Tp>::operator=(const _Expr& __v) const
1684{
1685 typedef const size_t* _Ip;
1686 size_t __j = 0;
1687 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1688 __vp_[*__i] = __v[__j];
1689}
1690
1691template <class _Tp>
1692template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001693inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001694typename enable_if
1695<
1696 __is_val_expr<_Expr>::value,
1697 void
1698>::type
1699gslice_array<_Tp>::operator*=(const _Expr& __v) const
1700{
1701 typedef const size_t* _Ip;
1702 size_t __j = 0;
1703 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1704 __vp_[*__i] *= __v[__j];
1705}
1706
1707template <class _Tp>
1708template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001709inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001710typename enable_if
1711<
1712 __is_val_expr<_Expr>::value,
1713 void
1714>::type
1715gslice_array<_Tp>::operator/=(const _Expr& __v) const
1716{
1717 typedef const size_t* _Ip;
1718 size_t __j = 0;
1719 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1720 __vp_[*__i] /= __v[__j];
1721}
1722
1723template <class _Tp>
1724template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001725inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001726typename enable_if
1727<
1728 __is_val_expr<_Expr>::value,
1729 void
1730>::type
1731gslice_array<_Tp>::operator%=(const _Expr& __v) const
1732{
1733 typedef const size_t* _Ip;
1734 size_t __j = 0;
1735 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1736 __vp_[*__i] %= __v[__j];
1737}
1738
1739template <class _Tp>
1740template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001741inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001742typename enable_if
1743<
1744 __is_val_expr<_Expr>::value,
1745 void
1746>::type
1747gslice_array<_Tp>::operator+=(const _Expr& __v) const
1748{
1749 typedef const size_t* _Ip;
1750 size_t __j = 0;
1751 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1752 __vp_[*__i] += __v[__j];
1753}
1754
1755template <class _Tp>
1756template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001757inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001758typename enable_if
1759<
1760 __is_val_expr<_Expr>::value,
1761 void
1762>::type
1763gslice_array<_Tp>::operator-=(const _Expr& __v) const
1764{
1765 typedef const size_t* _Ip;
1766 size_t __j = 0;
1767 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1768 __vp_[*__i] -= __v[__j];
1769}
1770
1771template <class _Tp>
1772template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001773inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001774typename enable_if
1775<
1776 __is_val_expr<_Expr>::value,
1777 void
1778>::type
1779gslice_array<_Tp>::operator^=(const _Expr& __v) const
1780{
1781 typedef const size_t* _Ip;
1782 size_t __j = 0;
1783 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1784 __vp_[*__i] ^= __v[__j];
1785}
1786
1787template <class _Tp>
1788template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001789inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001790typename enable_if
1791<
1792 __is_val_expr<_Expr>::value,
1793 void
1794>::type
1795gslice_array<_Tp>::operator&=(const _Expr& __v) const
1796{
1797 typedef const size_t* _Ip;
1798 size_t __j = 0;
1799 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1800 __vp_[*__i] &= __v[__j];
1801}
1802
1803template <class _Tp>
1804template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001805inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001806typename enable_if
1807<
1808 __is_val_expr<_Expr>::value,
1809 void
1810>::type
1811gslice_array<_Tp>::operator|=(const _Expr& __v) const
1812{
1813 typedef const size_t* _Ip;
1814 size_t __j = 0;
1815 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1816 __vp_[*__i] |= __v[__j];
1817}
1818
1819template <class _Tp>
1820template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001821inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001822typename enable_if
1823<
1824 __is_val_expr<_Expr>::value,
1825 void
1826>::type
1827gslice_array<_Tp>::operator<<=(const _Expr& __v) const
1828{
1829 typedef const size_t* _Ip;
1830 size_t __j = 0;
1831 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1832 __vp_[*__i] <<= __v[__j];
1833}
1834
1835template <class _Tp>
1836template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001837inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001838typename enable_if
1839<
1840 __is_val_expr<_Expr>::value,
1841 void
1842>::type
1843gslice_array<_Tp>::operator>>=(const _Expr& __v) const
1844{
1845 typedef const size_t* _Ip;
1846 size_t __j = 0;
1847 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1848 __vp_[*__i] >>= __v[__j];
1849}
1850
1851template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001852inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001853const gslice_array<_Tp>&
1854gslice_array<_Tp>::operator=(const gslice_array& __ga) const
1855{
1856 typedef const size_t* _Ip;
1857 const value_type* __s = __ga.__vp_;
1858 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_;
1859 __i != __e; ++__i, ++__j)
1860 __vp_[*__i] = __s[*__j];
1861 return *this;
1862}
1863
1864template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001865inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001866void
1867gslice_array<_Tp>::operator=(const value_type& __x) const
1868{
1869 typedef const size_t* _Ip;
1870 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1871 __vp_[*__i] = __x;
1872}
1873
1874// mask_array
1875
1876template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001877class _LIBCPP_TEMPLATE_VIS mask_array
Howard Hinnantc51e1022010-05-11 19:42:16 +00001878{
1879public:
1880 typedef _Tp value_type;
1881
1882private:
1883 value_type* __vp_;
1884 valarray<size_t> __1d_;
1885
1886public:
1887 template <class _Expr>
1888 typename enable_if
1889 <
1890 __is_val_expr<_Expr>::value,
1891 void
1892 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001894 operator=(const _Expr& __v) const;
1895
1896 template <class _Expr>
1897 typename enable_if
1898 <
1899 __is_val_expr<_Expr>::value,
1900 void
1901 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001903 operator*=(const _Expr& __v) const;
1904
1905 template <class _Expr>
1906 typename enable_if
1907 <
1908 __is_val_expr<_Expr>::value,
1909 void
1910 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001912 operator/=(const _Expr& __v) const;
1913
1914 template <class _Expr>
1915 typename enable_if
1916 <
1917 __is_val_expr<_Expr>::value,
1918 void
1919 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001920 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001921 operator%=(const _Expr& __v) const;
1922
1923 template <class _Expr>
1924 typename enable_if
1925 <
1926 __is_val_expr<_Expr>::value,
1927 void
1928 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001929 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001930 operator+=(const _Expr& __v) const;
1931
1932 template <class _Expr>
1933 typename enable_if
1934 <
1935 __is_val_expr<_Expr>::value,
1936 void
1937 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001938 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001939 operator-=(const _Expr& __v) const;
1940
1941 template <class _Expr>
1942 typename enable_if
1943 <
1944 __is_val_expr<_Expr>::value,
1945 void
1946 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001947 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001948 operator^=(const _Expr& __v) const;
1949
1950 template <class _Expr>
1951 typename enable_if
1952 <
1953 __is_val_expr<_Expr>::value,
1954 void
1955 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001956 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001957 operator&=(const _Expr& __v) const;
1958
1959 template <class _Expr>
1960 typename enable_if
1961 <
1962 __is_val_expr<_Expr>::value,
1963 void
1964 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001965 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001966 operator|=(const _Expr& __v) const;
1967
1968 template <class _Expr>
1969 typename enable_if
1970 <
1971 __is_val_expr<_Expr>::value,
1972 void
1973 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001974 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001975 operator<<=(const _Expr& __v) const;
1976
1977 template <class _Expr>
1978 typename enable_if
1979 <
1980 __is_val_expr<_Expr>::value,
1981 void
1982 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001983 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001984 operator>>=(const _Expr& __v) const;
1985
Eric Fiselierb9f37ca2019-12-12 20:48:11 -05001986 mask_array(const mask_array&) = default;
1987
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001988 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001989 const mask_array& operator=(const mask_array& __ma) const;
1990
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001991 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001992 void operator=(const value_type& __x) const;
1993
Howard Hinnantc51e1022010-05-11 19:42:16 +00001994private:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001996 mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
1997 : __vp_(const_cast<value_type*>(__v.__begin_)),
Howard Hinnant28b24882011-12-01 20:21:04 +00001998 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001999 {
2000 size_t __j = 0;
2001 for (size_t __i = 0; __i < __vb.size(); ++__i)
2002 if (__vb[__i])
2003 __1d_[__j++] = __i;
2004 }
2005
2006 template <class> friend class valarray;
2007};
2008
2009template <class _Tp>
2010template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002011inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002012typename enable_if
2013<
2014 __is_val_expr<_Expr>::value,
2015 void
2016>::type
2017mask_array<_Tp>::operator=(const _Expr& __v) const
2018{
2019 size_t __n = __1d_.size();
2020 for (size_t __i = 0; __i < __n; ++__i)
2021 __vp_[__1d_[__i]] = __v[__i];
2022}
2023
2024template <class _Tp>
2025template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002026inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002027typename enable_if
2028<
2029 __is_val_expr<_Expr>::value,
2030 void
2031>::type
2032mask_array<_Tp>::operator*=(const _Expr& __v) const
2033{
2034 size_t __n = __1d_.size();
2035 for (size_t __i = 0; __i < __n; ++__i)
2036 __vp_[__1d_[__i]] *= __v[__i];
2037}
2038
2039template <class _Tp>
2040template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002041inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002042typename enable_if
2043<
2044 __is_val_expr<_Expr>::value,
2045 void
2046>::type
2047mask_array<_Tp>::operator/=(const _Expr& __v) const
2048{
2049 size_t __n = __1d_.size();
2050 for (size_t __i = 0; __i < __n; ++__i)
2051 __vp_[__1d_[__i]] /= __v[__i];
2052}
2053
2054template <class _Tp>
2055template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002056inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002057typename enable_if
2058<
2059 __is_val_expr<_Expr>::value,
2060 void
2061>::type
2062mask_array<_Tp>::operator%=(const _Expr& __v) const
2063{
2064 size_t __n = __1d_.size();
2065 for (size_t __i = 0; __i < __n; ++__i)
2066 __vp_[__1d_[__i]] %= __v[__i];
2067}
2068
2069template <class _Tp>
2070template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002071inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002072typename enable_if
2073<
2074 __is_val_expr<_Expr>::value,
2075 void
2076>::type
2077mask_array<_Tp>::operator+=(const _Expr& __v) const
2078{
2079 size_t __n = __1d_.size();
2080 for (size_t __i = 0; __i < __n; ++__i)
2081 __vp_[__1d_[__i]] += __v[__i];
2082}
2083
2084template <class _Tp>
2085template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002086inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002087typename enable_if
2088<
2089 __is_val_expr<_Expr>::value,
2090 void
2091>::type
2092mask_array<_Tp>::operator-=(const _Expr& __v) const
2093{
2094 size_t __n = __1d_.size();
2095 for (size_t __i = 0; __i < __n; ++__i)
2096 __vp_[__1d_[__i]] -= __v[__i];
2097}
2098
2099template <class _Tp>
2100template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002101inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002102typename enable_if
2103<
2104 __is_val_expr<_Expr>::value,
2105 void
2106>::type
2107mask_array<_Tp>::operator^=(const _Expr& __v) const
2108{
2109 size_t __n = __1d_.size();
2110 for (size_t __i = 0; __i < __n; ++__i)
2111 __vp_[__1d_[__i]] ^= __v[__i];
2112}
2113
2114template <class _Tp>
2115template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002116inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002117typename enable_if
2118<
2119 __is_val_expr<_Expr>::value,
2120 void
2121>::type
2122mask_array<_Tp>::operator&=(const _Expr& __v) const
2123{
2124 size_t __n = __1d_.size();
2125 for (size_t __i = 0; __i < __n; ++__i)
2126 __vp_[__1d_[__i]] &= __v[__i];
2127}
2128
2129template <class _Tp>
2130template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002131inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002132typename enable_if
2133<
2134 __is_val_expr<_Expr>::value,
2135 void
2136>::type
2137mask_array<_Tp>::operator|=(const _Expr& __v) const
2138{
2139 size_t __n = __1d_.size();
2140 for (size_t __i = 0; __i < __n; ++__i)
2141 __vp_[__1d_[__i]] |= __v[__i];
2142}
2143
2144template <class _Tp>
2145template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002146inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002147typename enable_if
2148<
2149 __is_val_expr<_Expr>::value,
2150 void
2151>::type
2152mask_array<_Tp>::operator<<=(const _Expr& __v) const
2153{
2154 size_t __n = __1d_.size();
2155 for (size_t __i = 0; __i < __n; ++__i)
2156 __vp_[__1d_[__i]] <<= __v[__i];
2157}
2158
2159template <class _Tp>
2160template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002161inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002162typename enable_if
2163<
2164 __is_val_expr<_Expr>::value,
2165 void
2166>::type
2167mask_array<_Tp>::operator>>=(const _Expr& __v) const
2168{
2169 size_t __n = __1d_.size();
2170 for (size_t __i = 0; __i < __n; ++__i)
2171 __vp_[__1d_[__i]] >>= __v[__i];
2172}
2173
2174template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002175inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002176const mask_array<_Tp>&
2177mask_array<_Tp>::operator=(const mask_array& __ma) const
2178{
2179 size_t __n = __1d_.size();
2180 for (size_t __i = 0; __i < __n; ++__i)
2181 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
Eric Fiselier3b80ce92014-08-12 00:06:58 +00002182 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002183}
2184
2185template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002186inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002187void
2188mask_array<_Tp>::operator=(const value_type& __x) const
2189{
2190 size_t __n = __1d_.size();
2191 for (size_t __i = 0; __i < __n; ++__i)
2192 __vp_[__1d_[__i]] = __x;
2193}
2194
2195template <class _ValExpr>
2196class __mask_expr
2197{
2198 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2199public:
2200 typedef typename _RmExpr::value_type value_type;
2201 typedef value_type result_type;
2202
2203private:
2204 _ValExpr __expr_;
2205 valarray<size_t> __1d_;
2206
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002207 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002208 __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
2209 : __expr_(__e),
Howard Hinnant28b24882011-12-01 20:21:04 +00002210 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002211 {
2212 size_t __j = 0;
2213 for (size_t __i = 0; __i < __vb.size(); ++__i)
2214 if (__vb[__i])
2215 __1d_[__j++] = __i;
2216 }
2217
2218public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002219 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002220 result_type operator[](size_t __i) const
2221 {return __expr_[__1d_[__i]];}
2222
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002223 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002224 size_t size() const {return __1d_.size();}
2225
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002226 template <class> friend class __val_expr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002227 template <class> friend class valarray;
2228};
2229
2230// indirect_array
2231
2232template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002233class _LIBCPP_TEMPLATE_VIS indirect_array
Howard Hinnantc51e1022010-05-11 19:42:16 +00002234{
2235public:
2236 typedef _Tp value_type;
2237
2238private:
2239 value_type* __vp_;
2240 valarray<size_t> __1d_;
2241
2242public:
2243 template <class _Expr>
2244 typename enable_if
2245 <
2246 __is_val_expr<_Expr>::value,
2247 void
2248 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002249 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002250 operator=(const _Expr& __v) const;
2251
2252 template <class _Expr>
2253 typename enable_if
2254 <
2255 __is_val_expr<_Expr>::value,
2256 void
2257 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002259 operator*=(const _Expr& __v) const;
2260
2261 template <class _Expr>
2262 typename enable_if
2263 <
2264 __is_val_expr<_Expr>::value,
2265 void
2266 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002267 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002268 operator/=(const _Expr& __v) const;
2269
2270 template <class _Expr>
2271 typename enable_if
2272 <
2273 __is_val_expr<_Expr>::value,
2274 void
2275 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002277 operator%=(const _Expr& __v) const;
2278
2279 template <class _Expr>
2280 typename enable_if
2281 <
2282 __is_val_expr<_Expr>::value,
2283 void
2284 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002286 operator+=(const _Expr& __v) const;
2287
2288 template <class _Expr>
2289 typename enable_if
2290 <
2291 __is_val_expr<_Expr>::value,
2292 void
2293 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002294 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002295 operator-=(const _Expr& __v) const;
2296
2297 template <class _Expr>
2298 typename enable_if
2299 <
2300 __is_val_expr<_Expr>::value,
2301 void
2302 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002303 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002304 operator^=(const _Expr& __v) const;
2305
2306 template <class _Expr>
2307 typename enable_if
2308 <
2309 __is_val_expr<_Expr>::value,
2310 void
2311 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002312 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002313 operator&=(const _Expr& __v) const;
2314
2315 template <class _Expr>
2316 typename enable_if
2317 <
2318 __is_val_expr<_Expr>::value,
2319 void
2320 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002321 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002322 operator|=(const _Expr& __v) const;
2323
2324 template <class _Expr>
2325 typename enable_if
2326 <
2327 __is_val_expr<_Expr>::value,
2328 void
2329 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002330 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002331 operator<<=(const _Expr& __v) const;
2332
2333 template <class _Expr>
2334 typename enable_if
2335 <
2336 __is_val_expr<_Expr>::value,
2337 void
2338 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002339 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002340 operator>>=(const _Expr& __v) const;
2341
Eric Fiselierb9f37ca2019-12-12 20:48:11 -05002342 indirect_array(const indirect_array&) = default;
2343
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002344 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002345 const indirect_array& operator=(const indirect_array& __ia) const;
2346
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002347 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002348 void operator=(const value_type& __x) const;
2349
Howard Hinnantc51e1022010-05-11 19:42:16 +00002350private:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002351 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002352 indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
2353 : __vp_(const_cast<value_type*>(__v.__begin_)),
2354 __1d_(__ia)
2355 {}
2356
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002357#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002358
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002359 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002360 indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
2361 : __vp_(const_cast<value_type*>(__v.__begin_)),
2362 __1d_(move(__ia))
2363 {}
2364
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002365#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002366
2367 template <class> friend class valarray;
2368};
2369
2370template <class _Tp>
2371template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002372inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002373typename enable_if
2374<
2375 __is_val_expr<_Expr>::value,
2376 void
2377>::type
2378indirect_array<_Tp>::operator=(const _Expr& __v) const
2379{
2380 size_t __n = __1d_.size();
2381 for (size_t __i = 0; __i < __n; ++__i)
2382 __vp_[__1d_[__i]] = __v[__i];
2383}
2384
2385template <class _Tp>
2386template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002387inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002388typename enable_if
2389<
2390 __is_val_expr<_Expr>::value,
2391 void
2392>::type
2393indirect_array<_Tp>::operator*=(const _Expr& __v) const
2394{
2395 size_t __n = __1d_.size();
2396 for (size_t __i = 0; __i < __n; ++__i)
2397 __vp_[__1d_[__i]] *= __v[__i];
2398}
2399
2400template <class _Tp>
2401template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002402inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002403typename enable_if
2404<
2405 __is_val_expr<_Expr>::value,
2406 void
2407>::type
2408indirect_array<_Tp>::operator/=(const _Expr& __v) const
2409{
2410 size_t __n = __1d_.size();
2411 for (size_t __i = 0; __i < __n; ++__i)
2412 __vp_[__1d_[__i]] /= __v[__i];
2413}
2414
2415template <class _Tp>
2416template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002417inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002418typename enable_if
2419<
2420 __is_val_expr<_Expr>::value,
2421 void
2422>::type
2423indirect_array<_Tp>::operator%=(const _Expr& __v) const
2424{
2425 size_t __n = __1d_.size();
2426 for (size_t __i = 0; __i < __n; ++__i)
2427 __vp_[__1d_[__i]] %= __v[__i];
2428}
2429
2430template <class _Tp>
2431template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002432inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002433typename enable_if
2434<
2435 __is_val_expr<_Expr>::value,
2436 void
2437>::type
2438indirect_array<_Tp>::operator+=(const _Expr& __v) const
2439{
2440 size_t __n = __1d_.size();
2441 for (size_t __i = 0; __i < __n; ++__i)
2442 __vp_[__1d_[__i]] += __v[__i];
2443}
2444
2445template <class _Tp>
2446template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002447inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002448typename enable_if
2449<
2450 __is_val_expr<_Expr>::value,
2451 void
2452>::type
2453indirect_array<_Tp>::operator-=(const _Expr& __v) const
2454{
2455 size_t __n = __1d_.size();
2456 for (size_t __i = 0; __i < __n; ++__i)
2457 __vp_[__1d_[__i]] -= __v[__i];
2458}
2459
2460template <class _Tp>
2461template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002462inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002463typename enable_if
2464<
2465 __is_val_expr<_Expr>::value,
2466 void
2467>::type
2468indirect_array<_Tp>::operator^=(const _Expr& __v) const
2469{
2470 size_t __n = __1d_.size();
2471 for (size_t __i = 0; __i < __n; ++__i)
2472 __vp_[__1d_[__i]] ^= __v[__i];
2473}
2474
2475template <class _Tp>
2476template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002477inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002478typename enable_if
2479<
2480 __is_val_expr<_Expr>::value,
2481 void
2482>::type
2483indirect_array<_Tp>::operator&=(const _Expr& __v) const
2484{
2485 size_t __n = __1d_.size();
2486 for (size_t __i = 0; __i < __n; ++__i)
2487 __vp_[__1d_[__i]] &= __v[__i];
2488}
2489
2490template <class _Tp>
2491template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002492inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002493typename enable_if
2494<
2495 __is_val_expr<_Expr>::value,
2496 void
2497>::type
2498indirect_array<_Tp>::operator|=(const _Expr& __v) const
2499{
2500 size_t __n = __1d_.size();
2501 for (size_t __i = 0; __i < __n; ++__i)
2502 __vp_[__1d_[__i]] |= __v[__i];
2503}
2504
2505template <class _Tp>
2506template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002507inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002508typename enable_if
2509<
2510 __is_val_expr<_Expr>::value,
2511 void
2512>::type
2513indirect_array<_Tp>::operator<<=(const _Expr& __v) const
2514{
2515 size_t __n = __1d_.size();
2516 for (size_t __i = 0; __i < __n; ++__i)
2517 __vp_[__1d_[__i]] <<= __v[__i];
2518}
2519
2520template <class _Tp>
2521template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002522inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002523typename enable_if
2524<
2525 __is_val_expr<_Expr>::value,
2526 void
2527>::type
2528indirect_array<_Tp>::operator>>=(const _Expr& __v) const
2529{
2530 size_t __n = __1d_.size();
2531 for (size_t __i = 0; __i < __n; ++__i)
2532 __vp_[__1d_[__i]] >>= __v[__i];
2533}
2534
2535template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002536inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002537const indirect_array<_Tp>&
2538indirect_array<_Tp>::operator=(const indirect_array& __ia) const
2539{
2540 typedef const size_t* _Ip;
2541 const value_type* __s = __ia.__vp_;
2542 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_;
2543 __i != __e; ++__i, ++__j)
2544 __vp_[*__i] = __s[*__j];
2545 return *this;
2546}
2547
2548template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002549inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002550void
2551indirect_array<_Tp>::operator=(const value_type& __x) const
2552{
2553 typedef const size_t* _Ip;
2554 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
2555 __vp_[*__i] = __x;
2556}
2557
2558template <class _ValExpr>
2559class __indirect_expr
2560{
2561 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2562public:
2563 typedef typename _RmExpr::value_type value_type;
2564 typedef value_type result_type;
2565
2566private:
2567 _ValExpr __expr_;
2568 valarray<size_t> __1d_;
2569
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002571 __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e)
2572 : __expr_(__e),
2573 __1d_(__ia)
2574 {}
2575
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002576#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002577
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002579 __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
2580 : __expr_(__e),
2581 __1d_(move(__ia))
2582 {}
2583
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002584#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002585
2586public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002588 result_type operator[](size_t __i) const
2589 {return __expr_[__1d_[__i]];}
2590
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002592 size_t size() const {return __1d_.size();}
2593
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002594 template <class> friend class __val_expr;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002595 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002596};
2597
2598template<class _ValExpr>
2599class __val_expr
2600{
2601 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2602
2603 _ValExpr __expr_;
2604public:
2605 typedef typename _RmExpr::value_type value_type;
2606 typedef typename _RmExpr::result_type result_type;
2607
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002608 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002609 explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
2610
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002612 result_type operator[](size_t __i) const
2613 {return __expr_[__i];}
2614
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002615 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002616 __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002617 {
2618 typedef __slice_expr<_ValExpr> _NewExpr;
2619 return __val_expr< _NewExpr >(_NewExpr(__s, __expr_));
2620 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002621
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002623 __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002624 {
2625 typedef __indirect_expr<_ValExpr> _NewExpr;
2626 return __val_expr<_NewExpr >(_NewExpr(__gs.__1d_, __expr_));
2627 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002628
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002629 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002630 __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002631 {
2632 typedef __mask_expr<_ValExpr> _NewExpr;
2633 return __val_expr< _NewExpr >( _NewExpr(__vb, __expr_));
2634 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002635
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002637 __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002638 {
2639 typedef __indirect_expr<_ValExpr> _NewExpr;
2640 return __val_expr< _NewExpr >(_NewExpr(__vs, __expr_));
2641 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002642
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002644 __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
2645 operator+() const
2646 {
2647 typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
2648 return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
2649 }
2650
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002651 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002652 __val_expr<_UnaryOp<negate<value_type>, _ValExpr> >
2653 operator-() const
2654 {
2655 typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
2656 return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
2657 }
2658
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002659 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002660 __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> >
2661 operator~() const
2662 {
2663 typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
2664 return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
2665 }
2666
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002667 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002668 __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> >
2669 operator!() const
2670 {
2671 typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
2672 return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
2673 }
2674
2675 operator valarray<result_type>() const;
2676
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002678 size_t size() const {return __expr_.size();}
2679
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002681 result_type sum() const
2682 {
2683 size_t __n = __expr_.size();
2684 result_type __r = __n ? __expr_[0] : result_type();
2685 for (size_t __i = 1; __i < __n; ++__i)
2686 __r += __expr_[__i];
2687 return __r;
2688 }
2689
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002691 result_type min() const
2692 {
2693 size_t __n = size();
2694 result_type __r = __n ? (*this)[0] : result_type();
2695 for (size_t __i = 1; __i < __n; ++__i)
2696 {
2697 result_type __x = __expr_[__i];
2698 if (__x < __r)
2699 __r = __x;
2700 }
2701 return __r;
2702 }
2703
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002704 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002705 result_type max() const
2706 {
2707 size_t __n = size();
2708 result_type __r = __n ? (*this)[0] : result_type();
2709 for (size_t __i = 1; __i < __n; ++__i)
2710 {
2711 result_type __x = __expr_[__i];
2712 if (__r < __x)
2713 __r = __x;
2714 }
2715 return __r;
2716 }
2717
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002718 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002719 __val_expr<__shift_expr<_ValExpr> > shift (int __i) const
2720 {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));}
2721
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002723 __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const
2724 {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));}
2725
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002726 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002727 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> >
2728 apply(value_type __f(value_type)) const
2729 {
2730 typedef __apply_expr<value_type, value_type(*)(value_type)> _Op;
2731 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2732 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2733 }
2734
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002735 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002736 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> >
2737 apply(value_type __f(const value_type&)) const
2738 {
2739 typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op;
2740 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2741 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2742 }
2743};
2744
2745template<class _ValExpr>
Howard Hinnanta77b71b2013-09-13 23:27:42 +00002746__val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00002747{
2748 valarray<result_type> __r;
2749 size_t __n = __expr_.size();
2750 if (__n)
2751 {
2752 __r.__begin_ =
Louis Dionne5ffe5152020-09-28 15:47:49 -04002753 __r.__end_ = allocator<result_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002754 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002755 ::new ((void*)__r.__end_) result_type(__expr_[__i]);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002756 }
2757 return __r;
2758}
2759
2760// valarray
2761
2762template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002763inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002764valarray<_Tp>::valarray(size_t __n)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002765 : __begin_(nullptr),
2766 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002767{
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002768 if (__n)
2769 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002770 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002771#ifndef _LIBCPP_NO_EXCEPTIONS
2772 try
2773 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002774#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002775 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002776 ::new ((void*)__end_) value_type();
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002777#ifndef _LIBCPP_NO_EXCEPTIONS
2778 }
2779 catch (...)
2780 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002781 __clear(__n);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002782 throw;
2783 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002784#endif // _LIBCPP_NO_EXCEPTIONS
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002785 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002786}
2787
2788template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002789inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002790valarray<_Tp>::valarray(const value_type& __x, size_t __n)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002791 : __begin_(nullptr),
2792 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002793{
2794 resize(__n, __x);
2795}
2796
2797template <class _Tp>
2798valarray<_Tp>::valarray(const value_type* __p, size_t __n)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002799 : __begin_(nullptr),
2800 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002801{
2802 if (__n)
2803 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002804 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002805#ifndef _LIBCPP_NO_EXCEPTIONS
2806 try
2807 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002808#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002809 for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002810 ::new ((void*)__end_) value_type(*__p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002811#ifndef _LIBCPP_NO_EXCEPTIONS
2812 }
2813 catch (...)
2814 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002815 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002816 throw;
2817 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002818#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002819 }
2820}
2821
2822template <class _Tp>
2823valarray<_Tp>::valarray(const valarray& __v)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002824 : __begin_(nullptr),
2825 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002826{
2827 if (__v.size())
2828 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002829 __begin_ = __end_ = allocator<value_type>().allocate(__v.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002830#ifndef _LIBCPP_NO_EXCEPTIONS
2831 try
2832 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002833#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002834 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002835 ::new ((void*)__end_) value_type(*__p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002836#ifndef _LIBCPP_NO_EXCEPTIONS
2837 }
2838 catch (...)
2839 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002840 __clear(__v.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002841 throw;
2842 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002843#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002844 }
2845}
2846
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002847#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002848
2849template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002850inline
Howard Hinnant298aed92012-07-21 00:51:28 +00002851valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002852 : __begin_(__v.__begin_),
2853 __end_(__v.__end_)
2854{
2855 __v.__begin_ = __v.__end_ = nullptr;
2856}
2857
2858template <class _Tp>
2859valarray<_Tp>::valarray(initializer_list<value_type> __il)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002860 : __begin_(nullptr),
2861 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002862{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002863 const size_t __n = __il.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002864 if (__n)
2865 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002866 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002867#ifndef _LIBCPP_NO_EXCEPTIONS
2868 try
2869 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002870#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002871 size_t __n_left = __n;
2872 for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002873 ::new ((void*)__end_) value_type(*__p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002874#ifndef _LIBCPP_NO_EXCEPTIONS
2875 }
2876 catch (...)
2877 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002878 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002879 throw;
2880 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002881#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002882 }
2883}
2884
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002885#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002886
2887template <class _Tp>
2888valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002889 : __begin_(nullptr),
2890 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002891{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002892 const size_t __n = __sa.__size_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002893 if (__n)
2894 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002895 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002896#ifndef _LIBCPP_NO_EXCEPTIONS
2897 try
2898 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002899#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002900 size_t __n_left = __n;
2901 for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002902 ::new ((void*)__end_) value_type(*__p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002903#ifndef _LIBCPP_NO_EXCEPTIONS
2904 }
2905 catch (...)
2906 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002907 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002908 throw;
2909 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002910#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002911 }
2912}
2913
2914template <class _Tp>
2915valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002916 : __begin_(nullptr),
2917 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002918{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002919 const size_t __n = __ga.__1d_.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002920 if (__n)
2921 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002922 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002923#ifndef _LIBCPP_NO_EXCEPTIONS
2924 try
2925 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002926#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002927 typedef const size_t* _Ip;
2928 const value_type* __s = __ga.__vp_;
2929 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2930 __i != __e; ++__i, ++__end_)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002931 ::new ((void*)__end_) value_type(__s[*__i]);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002932#ifndef _LIBCPP_NO_EXCEPTIONS
2933 }
2934 catch (...)
2935 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002936 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002937 throw;
2938 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002939#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002940 }
2941}
2942
2943template <class _Tp>
2944valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002945 : __begin_(nullptr),
2946 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002947{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002948 const size_t __n = __ma.__1d_.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002949 if (__n)
2950 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002951 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002952#ifndef _LIBCPP_NO_EXCEPTIONS
2953 try
2954 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002955#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002956 typedef const size_t* _Ip;
2957 const value_type* __s = __ma.__vp_;
2958 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2959 __i != __e; ++__i, ++__end_)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002960 ::new ((void*)__end_) value_type(__s[*__i]);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002961#ifndef _LIBCPP_NO_EXCEPTIONS
2962 }
2963 catch (...)
2964 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002965 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002966 throw;
2967 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002968#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002969 }
2970}
2971
2972template <class _Tp>
2973valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
Bruce Mitchener170d8972020-11-24 12:53:53 -05002974 : __begin_(nullptr),
2975 __end_(nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002976{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002977 const size_t __n = __ia.__1d_.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002978 if (__n)
2979 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04002980 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002981#ifndef _LIBCPP_NO_EXCEPTIONS
2982 try
2983 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002984#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002985 typedef const size_t* _Ip;
2986 const value_type* __s = __ia.__vp_;
2987 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2988 __i != __e; ++__i, ++__end_)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002989 ::new ((void*)__end_) value_type(__s[*__i]);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002990#ifndef _LIBCPP_NO_EXCEPTIONS
2991 }
2992 catch (...)
2993 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002994 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002995 throw;
2996 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002997#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002998 }
2999}
3000
3001template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003002inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003003valarray<_Tp>::~valarray()
3004{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003005 __clear(size());
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003006}
3007
3008template <class _Tp>
3009valarray<_Tp>&
3010valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l)
3011{
3012 size_t __n = __l - __f;
3013 if (size() != __n)
3014 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00003015 __clear(size());
Louis Dionne5ffe5152020-09-28 15:47:49 -04003016 __begin_ = allocator<value_type>().allocate(__n);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003017 __end_ = __begin_ + __n;
3018 _VSTD::uninitialized_copy(__f, __l, __begin_);
3019 } else {
3020 _VSTD::copy(__f, __l, __begin_);
3021 }
3022 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003023}
3024
3025template <class _Tp>
3026valarray<_Tp>&
3027valarray<_Tp>::operator=(const valarray& __v)
3028{
3029 if (this != &__v)
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003030 return __assign_range(__v.__begin_, __v.__end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003031 return *this;
3032}
3033
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003034#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003035
3036template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003037inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003038valarray<_Tp>&
Howard Hinnant298aed92012-07-21 00:51:28 +00003039valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003040{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003041 __clear(size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003042 __begin_ = __v.__begin_;
3043 __end_ = __v.__end_;
3044 __v.__begin_ = nullptr;
3045 __v.__end_ = nullptr;
3046 return *this;
3047}
3048
3049template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003050inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003051valarray<_Tp>&
3052valarray<_Tp>::operator=(initializer_list<value_type> __il)
3053{
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003054 return __assign_range(__il.begin(), __il.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003055}
3056
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003057#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003058
3059template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003060inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003061valarray<_Tp>&
3062valarray<_Tp>::operator=(const value_type& __x)
3063{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003064 _VSTD::fill(__begin_, __end_, __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003065 return *this;
3066}
3067
3068template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003069inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003070valarray<_Tp>&
3071valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
3072{
3073 value_type* __t = __begin_;
3074 const value_type* __s = __sa.__vp_;
3075 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
3076 *__t = *__s;
3077 return *this;
3078}
3079
3080template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003081inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003082valarray<_Tp>&
3083valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
3084{
3085 typedef const size_t* _Ip;
3086 value_type* __t = __begin_;
3087 const value_type* __s = __ga.__vp_;
3088 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
3089 __i != __e; ++__i, ++__t)
3090 *__t = __s[*__i];
3091 return *this;
3092}
3093
3094template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003095inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003096valarray<_Tp>&
3097valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
3098{
3099 typedef const size_t* _Ip;
3100 value_type* __t = __begin_;
3101 const value_type* __s = __ma.__vp_;
3102 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
3103 __i != __e; ++__i, ++__t)
3104 *__t = __s[*__i];
3105 return *this;
3106}
3107
3108template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003109inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003110valarray<_Tp>&
3111valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
3112{
3113 typedef const size_t* _Ip;
3114 value_type* __t = __begin_;
3115 const value_type* __s = __ia.__vp_;
3116 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
3117 __i != __e; ++__i, ++__t)
3118 *__t = __s[*__i];
3119 return *this;
3120}
3121
3122template <class _Tp>
Howard Hinnant329cd412011-07-27 23:19:59 +00003123template <class _ValExpr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003124inline
Howard Hinnant329cd412011-07-27 23:19:59 +00003125valarray<_Tp>&
3126valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
3127{
3128 size_t __n = __v.size();
3129 if (size() != __n)
3130 resize(__n);
3131 value_type* __t = __begin_;
3132 for (size_t __i = 0; __i != __n; ++__t, ++__i)
3133 *__t = result_type(__v[__i]);
3134 return *this;
3135}
3136
3137template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003138inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003139__val_expr<__slice_expr<const valarray<_Tp>&> >
3140valarray<_Tp>::operator[](slice __s) const
3141{
3142 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
3143}
3144
3145template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003146inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003147slice_array<_Tp>
3148valarray<_Tp>::operator[](slice __s)
3149{
3150 return slice_array<value_type>(__s, *this);
3151}
3152
3153template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003154inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003155__val_expr<__indirect_expr<const valarray<_Tp>&> >
3156valarray<_Tp>::operator[](const gslice& __gs) const
3157{
3158 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
3159}
3160
3161template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003162inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003163gslice_array<_Tp>
3164valarray<_Tp>::operator[](const gslice& __gs)
3165{
3166 return gslice_array<value_type>(__gs, *this);
3167}
3168
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003169#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003170
3171template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003172inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003173__val_expr<__indirect_expr<const valarray<_Tp>&> >
3174valarray<_Tp>::operator[](gslice&& __gs) const
3175{
3176 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
3177}
3178
3179template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003180inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003181gslice_array<_Tp>
3182valarray<_Tp>::operator[](gslice&& __gs)
3183{
3184 return gslice_array<value_type>(move(__gs), *this);
3185}
3186
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003187#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003188
3189template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003190inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003191__val_expr<__mask_expr<const valarray<_Tp>&> >
3192valarray<_Tp>::operator[](const valarray<bool>& __vb) const
3193{
3194 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
3195}
3196
3197template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003198inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003199mask_array<_Tp>
3200valarray<_Tp>::operator[](const valarray<bool>& __vb)
3201{
3202 return mask_array<value_type>(__vb, *this);
3203}
3204
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003205#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003206
3207template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003208inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003209__val_expr<__mask_expr<const valarray<_Tp>&> >
3210valarray<_Tp>::operator[](valarray<bool>&& __vb) const
3211{
3212 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
3213}
3214
3215template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003216inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003217mask_array<_Tp>
3218valarray<_Tp>::operator[](valarray<bool>&& __vb)
3219{
3220 return mask_array<value_type>(move(__vb), *this);
3221}
3222
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003223#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003224
3225template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003226inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003227__val_expr<__indirect_expr<const valarray<_Tp>&> >
3228valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
3229{
3230 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
3231}
3232
3233template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003234inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003235indirect_array<_Tp>
3236valarray<_Tp>::operator[](const valarray<size_t>& __vs)
3237{
3238 return indirect_array<value_type>(__vs, *this);
3239}
3240
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003241#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003242
3243template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003244inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003245__val_expr<__indirect_expr<const valarray<_Tp>&> >
3246valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
3247{
3248 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
3249}
3250
3251template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003252inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003253indirect_array<_Tp>
3254valarray<_Tp>::operator[](valarray<size_t>&& __vs)
3255{
3256 return indirect_array<value_type>(move(__vs), *this);
3257}
3258
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003259#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003260
3261template <class _Tp>
3262valarray<_Tp>
3263valarray<_Tp>::operator+() const
3264{
3265 valarray<value_type> __r;
3266 size_t __n = size();
3267 if (__n)
3268 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003269 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003270 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05003271 ::new ((void*)__r.__end_) value_type(+*__p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003272 }
3273 return __r;
3274}
3275
3276template <class _Tp>
3277valarray<_Tp>
3278valarray<_Tp>::operator-() const
3279{
3280 valarray<value_type> __r;
3281 size_t __n = size();
3282 if (__n)
3283 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003284 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003285 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05003286 ::new ((void*)__r.__end_) value_type(-*__p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003287 }
3288 return __r;
3289}
3290
3291template <class _Tp>
3292valarray<_Tp>
3293valarray<_Tp>::operator~() const
3294{
3295 valarray<value_type> __r;
3296 size_t __n = size();
3297 if (__n)
3298 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003299 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003300 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05003301 ::new ((void*)__r.__end_) value_type(~*__p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003302 }
3303 return __r;
3304}
3305
3306template <class _Tp>
3307valarray<bool>
3308valarray<_Tp>::operator!() const
3309{
3310 valarray<bool> __r;
3311 size_t __n = size();
3312 if (__n)
3313 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003314 __r.__begin_ = __r.__end_ = allocator<bool>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003315 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05003316 ::new ((void*)__r.__end_) bool(!*__p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003317 }
3318 return __r;
3319}
3320
3321template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003322inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003323valarray<_Tp>&
3324valarray<_Tp>::operator*=(const value_type& __x)
3325{
3326 for (value_type* __p = __begin_; __p != __end_; ++__p)
3327 *__p *= __x;
3328 return *this;
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>
3422template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003423inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003424typename enable_if
3425<
3426 __is_val_expr<_Expr>::value,
3427 valarray<_Tp>&
3428>::type
3429valarray<_Tp>::operator*=(const _Expr& __v)
3430{
3431 size_t __i = 0;
3432 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3433 *__t *= __v[__i];
3434 return *this;
3435}
3436
3437template <class _Tp>
3438template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003439inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003440typename enable_if
3441<
3442 __is_val_expr<_Expr>::value,
3443 valarray<_Tp>&
3444>::type
3445valarray<_Tp>::operator/=(const _Expr& __v)
3446{
3447 size_t __i = 0;
3448 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3449 *__t /= __v[__i];
3450 return *this;
3451}
3452
3453template <class _Tp>
3454template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003455inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003456typename enable_if
3457<
3458 __is_val_expr<_Expr>::value,
3459 valarray<_Tp>&
3460>::type
3461valarray<_Tp>::operator%=(const _Expr& __v)
3462{
3463 size_t __i = 0;
3464 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3465 *__t %= __v[__i];
3466 return *this;
3467}
3468
3469template <class _Tp>
3470template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003471inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003472typename enable_if
3473<
3474 __is_val_expr<_Expr>::value,
3475 valarray<_Tp>&
3476>::type
3477valarray<_Tp>::operator+=(const _Expr& __v)
3478{
3479 size_t __i = 0;
3480 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3481 *__t += __v[__i];
3482 return *this;
3483}
3484
3485template <class _Tp>
3486template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003487inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003488typename enable_if
3489<
3490 __is_val_expr<_Expr>::value,
3491 valarray<_Tp>&
3492>::type
3493valarray<_Tp>::operator-=(const _Expr& __v)
3494{
3495 size_t __i = 0;
3496 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3497 *__t -= __v[__i];
3498 return *this;
3499}
3500
3501template <class _Tp>
3502template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003503inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003504typename enable_if
3505<
3506 __is_val_expr<_Expr>::value,
3507 valarray<_Tp>&
3508>::type
3509valarray<_Tp>::operator^=(const _Expr& __v)
3510{
3511 size_t __i = 0;
3512 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3513 *__t ^= __v[__i];
3514 return *this;
3515}
3516
3517template <class _Tp>
3518template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003519inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003520typename enable_if
3521<
3522 __is_val_expr<_Expr>::value,
3523 valarray<_Tp>&
3524>::type
3525valarray<_Tp>::operator|=(const _Expr& __v)
3526{
3527 size_t __i = 0;
3528 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3529 *__t |= __v[__i];
3530 return *this;
3531}
3532
3533template <class _Tp>
3534template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003535inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003536typename enable_if
3537<
3538 __is_val_expr<_Expr>::value,
3539 valarray<_Tp>&
3540>::type
3541valarray<_Tp>::operator&=(const _Expr& __v)
3542{
3543 size_t __i = 0;
3544 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3545 *__t &= __v[__i];
3546 return *this;
3547}
3548
3549template <class _Tp>
3550template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003551inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003552typename enable_if
3553<
3554 __is_val_expr<_Expr>::value,
3555 valarray<_Tp>&
3556>::type
3557valarray<_Tp>::operator<<=(const _Expr& __v)
3558{
3559 size_t __i = 0;
3560 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3561 *__t <<= __v[__i];
3562 return *this;
3563}
3564
3565template <class _Tp>
3566template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003567inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003568typename enable_if
3569<
3570 __is_val_expr<_Expr>::value,
3571 valarray<_Tp>&
3572>::type
3573valarray<_Tp>::operator>>=(const _Expr& __v)
3574{
3575 size_t __i = 0;
3576 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3577 *__t >>= __v[__i];
3578 return *this;
3579}
3580
3581template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003582inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003583void
Howard Hinnant298aed92012-07-21 00:51:28 +00003584valarray<_Tp>::swap(valarray& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003585{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003586 _VSTD::swap(__begin_, __v.__begin_);
3587 _VSTD::swap(__end_, __v.__end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003588}
3589
3590template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003591inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003592_Tp
3593valarray<_Tp>::sum() const
3594{
3595 if (__begin_ == __end_)
3596 return value_type();
3597 const value_type* __p = __begin_;
3598 _Tp __r = *__p;
3599 for (++__p; __p != __end_; ++__p)
3600 __r += *__p;
3601 return __r;
3602}
3603
3604template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003605inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003606_Tp
3607valarray<_Tp>::min() const
3608{
3609 if (__begin_ == __end_)
3610 return value_type();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003611 return *_VSTD::min_element(__begin_, __end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003612}
3613
3614template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003615inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003616_Tp
3617valarray<_Tp>::max() const
3618{
3619 if (__begin_ == __end_)
3620 return value_type();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003621 return *_VSTD::max_element(__begin_, __end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003622}
3623
3624template <class _Tp>
3625valarray<_Tp>
3626valarray<_Tp>::shift(int __i) const
3627{
3628 valarray<value_type> __r;
3629 size_t __n = size();
3630 if (__n)
3631 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003632 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003633 const value_type* __sb;
3634 value_type* __tb;
3635 value_type* __te;
3636 if (__i >= 0)
3637 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003638 __i = _VSTD::min(__i, static_cast<int>(__n));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003639 __sb = __begin_ + __i;
3640 __tb = __r.__begin_;
3641 __te = __r.__begin_ + (__n - __i);
3642 }
3643 else
3644 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003645 __i = _VSTD::min(-__i, static_cast<int>(__n));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003646 __sb = __begin_;
3647 __tb = __r.__begin_ + __i;
3648 __te = __r.__begin_ + __n;
3649 }
3650 for (; __r.__end_ != __tb; ++__r.__end_)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05003651 ::new ((void*)__r.__end_) value_type();
Howard Hinnantc51e1022010-05-11 19:42:16 +00003652 for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05003653 ::new ((void*)__r.__end_) value_type(*__sb);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003654 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05003655 ::new ((void*)__r.__end_) value_type();
Howard Hinnantc51e1022010-05-11 19:42:16 +00003656 }
3657 return __r;
3658}
3659
3660template <class _Tp>
3661valarray<_Tp>
3662valarray<_Tp>::cshift(int __i) const
3663{
3664 valarray<value_type> __r;
3665 size_t __n = size();
3666 if (__n)
3667 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003668 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003669 __i %= static_cast<int>(__n);
3670 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
3671 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05003672 ::new ((void*)__r.__end_) value_type(*__s);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003673 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05003674 ::new ((void*)__r.__end_) value_type(*__s);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003675 }
3676 return __r;
3677}
3678
3679template <class _Tp>
3680valarray<_Tp>
3681valarray<_Tp>::apply(value_type __f(value_type)) const
3682{
3683 valarray<value_type> __r;
3684 size_t __n = size();
3685 if (__n)
3686 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003687 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003688 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05003689 ::new ((void*)__r.__end_) value_type(__f(*__p));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003690 }
3691 return __r;
3692}
3693
3694template <class _Tp>
3695valarray<_Tp>
3696valarray<_Tp>::apply(value_type __f(const value_type&)) const
3697{
3698 valarray<value_type> __r;
3699 size_t __n = size();
3700 if (__n)
3701 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003702 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003703 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05003704 ::new ((void*)__r.__end_) value_type(__f(*__p));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003705 }
3706 return __r;
3707}
3708
3709template <class _Tp>
Eric Fiseliera119c322018-10-25 17:43:26 +00003710inline
Eric Fiselier2856ef82018-10-25 17:21:30 +00003711void valarray<_Tp>::__clear(size_t __capacity)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003712{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003713 if (__begin_ != nullptr)
3714 {
3715 while (__end_ != __begin_)
3716 (--__end_)->~value_type();
Louis Dionne5ffe5152020-09-28 15:47:49 -04003717 allocator<value_type>().deallocate(__begin_, __capacity);
Eric Fiselier2856ef82018-10-25 17:21:30 +00003718 __begin_ = __end_ = nullptr;
3719 }
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003720}
3721
3722template <class _Tp>
3723void
3724valarray<_Tp>::resize(size_t __n, value_type __x)
3725{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003726 __clear(size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003727 if (__n)
3728 {
Louis Dionne5ffe5152020-09-28 15:47:49 -04003729 __begin_ = __end_ = allocator<value_type>().allocate(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003730#ifndef _LIBCPP_NO_EXCEPTIONS
3731 try
3732 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003733#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00003734 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05003735 ::new ((void*)__end_) value_type(__x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003736#ifndef _LIBCPP_NO_EXCEPTIONS
3737 }
3738 catch (...)
3739 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00003740 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003741 throw;
3742 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003743#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00003744 }
3745}
3746
3747template<class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003748inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003749void
Howard Hinnant298aed92012-07-21 00:51:28 +00003750swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003751{
3752 __x.swap(__y);
3753}
3754
3755template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003756inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003757typename enable_if
3758<
3759 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3760 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
3761>::type
3762operator*(const _Expr1& __x, const _Expr2& __y)
3763{
3764 typedef typename _Expr1::value_type value_type;
3765 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
3766 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
3767}
3768
3769template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003770inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003771typename enable_if
3772<
3773 __is_val_expr<_Expr>::value,
3774 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3775 _Expr, __scalar_expr<typename _Expr::value_type> > >
3776>::type
3777operator*(const _Expr& __x, const typename _Expr::value_type& __y)
3778{
3779 typedef typename _Expr::value_type value_type;
3780 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3781 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3782 __x, __scalar_expr<value_type>(__y, __x.size())));
3783}
3784
3785template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003786inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003787typename enable_if
3788<
3789 __is_val_expr<_Expr>::value,
3790 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3791 __scalar_expr<typename _Expr::value_type>, _Expr> >
3792>::type
3793operator*(const typename _Expr::value_type& __x, const _Expr& __y)
3794{
3795 typedef typename _Expr::value_type value_type;
3796 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3797 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3798 __scalar_expr<value_type>(__x, __y.size()), __y));
3799}
3800
3801template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003802inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003803typename enable_if
3804<
3805 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3806 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
3807>::type
3808operator/(const _Expr1& __x, const _Expr2& __y)
3809{
3810 typedef typename _Expr1::value_type value_type;
3811 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
3812 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
3813}
3814
3815template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003816inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003817typename enable_if
3818<
3819 __is_val_expr<_Expr>::value,
3820 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3821 _Expr, __scalar_expr<typename _Expr::value_type> > >
3822>::type
3823operator/(const _Expr& __x, const typename _Expr::value_type& __y)
3824{
3825 typedef typename _Expr::value_type value_type;
3826 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3827 return __val_expr<_Op>(_Op(divides<value_type>(),
3828 __x, __scalar_expr<value_type>(__y, __x.size())));
3829}
3830
3831template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003832inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003833typename enable_if
3834<
3835 __is_val_expr<_Expr>::value,
3836 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3837 __scalar_expr<typename _Expr::value_type>, _Expr> >
3838>::type
3839operator/(const typename _Expr::value_type& __x, const _Expr& __y)
3840{
3841 typedef typename _Expr::value_type value_type;
3842 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3843 return __val_expr<_Op>(_Op(divides<value_type>(),
3844 __scalar_expr<value_type>(__x, __y.size()), __y));
3845}
3846
3847template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003848inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003849typename enable_if
3850<
3851 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3852 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3853>::type
3854operator%(const _Expr1& __x, const _Expr2& __y)
3855{
3856 typedef typename _Expr1::value_type value_type;
3857 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
3858 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
3859}
3860
3861template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003862inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003863typename enable_if
3864<
3865 __is_val_expr<_Expr>::value,
3866 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3867 _Expr, __scalar_expr<typename _Expr::value_type> > >
3868>::type
3869operator%(const _Expr& __x, const typename _Expr::value_type& __y)
3870{
3871 typedef typename _Expr::value_type value_type;
3872 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3873 return __val_expr<_Op>(_Op(modulus<value_type>(),
3874 __x, __scalar_expr<value_type>(__y, __x.size())));
3875}
3876
3877template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003878inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003879typename enable_if
3880<
3881 __is_val_expr<_Expr>::value,
3882 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3883 __scalar_expr<typename _Expr::value_type>, _Expr> >
3884>::type
3885operator%(const typename _Expr::value_type& __x, const _Expr& __y)
3886{
3887 typedef typename _Expr::value_type value_type;
3888 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3889 return __val_expr<_Op>(_Op(modulus<value_type>(),
3890 __scalar_expr<value_type>(__x, __y.size()), __y));
3891}
3892
3893template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003894inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003895typename enable_if
3896<
3897 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3898 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3899>::type
3900operator+(const _Expr1& __x, const _Expr2& __y)
3901{
3902 typedef typename _Expr1::value_type value_type;
3903 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
3904 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
3905}
3906
3907template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003908inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003909typename enable_if
3910<
3911 __is_val_expr<_Expr>::value,
3912 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3913 _Expr, __scalar_expr<typename _Expr::value_type> > >
3914>::type
3915operator+(const _Expr& __x, const typename _Expr::value_type& __y)
3916{
3917 typedef typename _Expr::value_type value_type;
3918 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3919 return __val_expr<_Op>(_Op(plus<value_type>(),
3920 __x, __scalar_expr<value_type>(__y, __x.size())));
3921}
3922
3923template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003924inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003925typename enable_if
3926<
3927 __is_val_expr<_Expr>::value,
3928 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3929 __scalar_expr<typename _Expr::value_type>, _Expr> >
3930>::type
3931operator+(const typename _Expr::value_type& __x, const _Expr& __y)
3932{
3933 typedef typename _Expr::value_type value_type;
3934 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3935 return __val_expr<_Op>(_Op(plus<value_type>(),
3936 __scalar_expr<value_type>(__x, __y.size()), __y));
3937}
3938
3939template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003940inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003941typename enable_if
3942<
3943 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3944 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3945>::type
3946operator-(const _Expr1& __x, const _Expr2& __y)
3947{
3948 typedef typename _Expr1::value_type value_type;
3949 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
3950 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
3951}
3952
3953template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003954inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003955typename enable_if
3956<
3957 __is_val_expr<_Expr>::value,
3958 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3959 _Expr, __scalar_expr<typename _Expr::value_type> > >
3960>::type
3961operator-(const _Expr& __x, const typename _Expr::value_type& __y)
3962{
3963 typedef typename _Expr::value_type value_type;
3964 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3965 return __val_expr<_Op>(_Op(minus<value_type>(),
3966 __x, __scalar_expr<value_type>(__y, __x.size())));
3967}
3968
3969template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003970inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003971typename enable_if
3972<
3973 __is_val_expr<_Expr>::value,
3974 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3975 __scalar_expr<typename _Expr::value_type>, _Expr> >
3976>::type
3977operator-(const typename _Expr::value_type& __x, const _Expr& __y)
3978{
3979 typedef typename _Expr::value_type value_type;
3980 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3981 return __val_expr<_Op>(_Op(minus<value_type>(),
3982 __scalar_expr<value_type>(__x, __y.size()), __y));
3983}
3984
3985template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003986inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003987typename enable_if
3988<
3989 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3990 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
3991>::type
3992operator^(const _Expr1& __x, const _Expr2& __y)
3993{
3994 typedef typename _Expr1::value_type value_type;
3995 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
3996 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
3997}
3998
3999template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004000inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004001typename enable_if
4002<
4003 __is_val_expr<_Expr>::value,
4004 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
4005 _Expr, __scalar_expr<typename _Expr::value_type> > >
4006>::type
4007operator^(const _Expr& __x, const typename _Expr::value_type& __y)
4008{
4009 typedef typename _Expr::value_type value_type;
4010 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4011 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
4012 __x, __scalar_expr<value_type>(__y, __x.size())));
4013}
4014
4015template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004016inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004017typename enable_if
4018<
4019 __is_val_expr<_Expr>::value,
4020 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
4021 __scalar_expr<typename _Expr::value_type>, _Expr> >
4022>::type
4023operator^(const typename _Expr::value_type& __x, const _Expr& __y)
4024{
4025 typedef typename _Expr::value_type value_type;
4026 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4027 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
4028 __scalar_expr<value_type>(__x, __y.size()), __y));
4029}
4030
4031template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004032inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004033typename enable_if
4034<
4035 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4036 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4037>::type
4038operator&(const _Expr1& __x, const _Expr2& __y)
4039{
4040 typedef typename _Expr1::value_type value_type;
4041 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
4042 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
4043}
4044
4045template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004046inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004047typename enable_if
4048<
4049 __is_val_expr<_Expr>::value,
4050 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4051 _Expr, __scalar_expr<typename _Expr::value_type> > >
4052>::type
4053operator&(const _Expr& __x, const typename _Expr::value_type& __y)
4054{
4055 typedef typename _Expr::value_type value_type;
4056 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4057 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4058 __x, __scalar_expr<value_type>(__y, __x.size())));
4059}
4060
4061template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004062inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004063typename enable_if
4064<
4065 __is_val_expr<_Expr>::value,
4066 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4067 __scalar_expr<typename _Expr::value_type>, _Expr> >
4068>::type
4069operator&(const typename _Expr::value_type& __x, const _Expr& __y)
4070{
4071 typedef typename _Expr::value_type value_type;
4072 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4073 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4074 __scalar_expr<value_type>(__x, __y.size()), __y));
4075}
4076
4077template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004078inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004079typename enable_if
4080<
4081 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4082 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4083>::type
4084operator|(const _Expr1& __x, const _Expr2& __y)
4085{
4086 typedef typename _Expr1::value_type value_type;
4087 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
4088 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
4089}
4090
4091template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004092inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004093typename enable_if
4094<
4095 __is_val_expr<_Expr>::value,
4096 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4097 _Expr, __scalar_expr<typename _Expr::value_type> > >
4098>::type
4099operator|(const _Expr& __x, const typename _Expr::value_type& __y)
4100{
4101 typedef typename _Expr::value_type value_type;
4102 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4103 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4104 __x, __scalar_expr<value_type>(__y, __x.size())));
4105}
4106
4107template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004108inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004109typename enable_if
4110<
4111 __is_val_expr<_Expr>::value,
4112 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4113 __scalar_expr<typename _Expr::value_type>, _Expr> >
4114>::type
4115operator|(const typename _Expr::value_type& __x, const _Expr& __y)
4116{
4117 typedef typename _Expr::value_type value_type;
4118 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4119 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4120 __scalar_expr<value_type>(__x, __y.size()), __y));
4121}
4122
4123template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004124inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004125typename enable_if
4126<
4127 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4128 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
4129>::type
4130operator<<(const _Expr1& __x, const _Expr2& __y)
4131{
4132 typedef typename _Expr1::value_type value_type;
4133 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
4134 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
4135}
4136
4137template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004138inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004139typename enable_if
4140<
4141 __is_val_expr<_Expr>::value,
4142 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4143 _Expr, __scalar_expr<typename _Expr::value_type> > >
4144>::type
4145operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
4146{
4147 typedef typename _Expr::value_type value_type;
4148 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4149 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4150 __x, __scalar_expr<value_type>(__y, __x.size())));
4151}
4152
4153template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004154inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004155typename enable_if
4156<
4157 __is_val_expr<_Expr>::value,
4158 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4159 __scalar_expr<typename _Expr::value_type>, _Expr> >
4160>::type
4161operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
4162{
4163 typedef typename _Expr::value_type value_type;
4164 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4165 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4166 __scalar_expr<value_type>(__x, __y.size()), __y));
4167}
4168
4169template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004170inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004171typename enable_if
4172<
4173 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4174 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
4175>::type
4176operator>>(const _Expr1& __x, const _Expr2& __y)
4177{
4178 typedef typename _Expr1::value_type value_type;
4179 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
4180 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
4181}
4182
4183template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004184inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004185typename enable_if
4186<
4187 __is_val_expr<_Expr>::value,
4188 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4189 _Expr, __scalar_expr<typename _Expr::value_type> > >
4190>::type
4191operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
4192{
4193 typedef typename _Expr::value_type value_type;
4194 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4195 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4196 __x, __scalar_expr<value_type>(__y, __x.size())));
4197}
4198
4199template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004200inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004201typename enable_if
4202<
4203 __is_val_expr<_Expr>::value,
4204 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4205 __scalar_expr<typename _Expr::value_type>, _Expr> >
4206>::type
4207operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
4208{
4209 typedef typename _Expr::value_type value_type;
4210 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4211 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4212 __scalar_expr<value_type>(__x, __y.size()), __y));
4213}
4214
4215template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004216inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004217typename enable_if
4218<
4219 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4220 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4221>::type
4222operator&&(const _Expr1& __x, const _Expr2& __y)
4223{
4224 typedef typename _Expr1::value_type value_type;
4225 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
4226 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
4227}
4228
4229template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004230inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004231typename enable_if
4232<
4233 __is_val_expr<_Expr>::value,
4234 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4235 _Expr, __scalar_expr<typename _Expr::value_type> > >
4236>::type
4237operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
4238{
4239 typedef typename _Expr::value_type value_type;
4240 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4241 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4242 __x, __scalar_expr<value_type>(__y, __x.size())));
4243}
4244
4245template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004246inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004247typename enable_if
4248<
4249 __is_val_expr<_Expr>::value,
4250 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4251 __scalar_expr<typename _Expr::value_type>, _Expr> >
4252>::type
4253operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
4254{
4255 typedef typename _Expr::value_type value_type;
4256 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4257 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4258 __scalar_expr<value_type>(__x, __y.size()), __y));
4259}
4260
4261template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004262inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004263typename enable_if
4264<
4265 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4266 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4267>::type
4268operator||(const _Expr1& __x, const _Expr2& __y)
4269{
4270 typedef typename _Expr1::value_type value_type;
4271 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
4272 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
4273}
4274
4275template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004276inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004277typename enable_if
4278<
4279 __is_val_expr<_Expr>::value,
4280 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4281 _Expr, __scalar_expr<typename _Expr::value_type> > >
4282>::type
4283operator||(const _Expr& __x, const typename _Expr::value_type& __y)
4284{
4285 typedef typename _Expr::value_type value_type;
4286 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4287 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4288 __x, __scalar_expr<value_type>(__y, __x.size())));
4289}
4290
4291template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004292inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004293typename enable_if
4294<
4295 __is_val_expr<_Expr>::value,
4296 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4297 __scalar_expr<typename _Expr::value_type>, _Expr> >
4298>::type
4299operator||(const typename _Expr::value_type& __x, const _Expr& __y)
4300{
4301 typedef typename _Expr::value_type value_type;
4302 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4303 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4304 __scalar_expr<value_type>(__x, __y.size()), __y));
4305}
4306
4307template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004308inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004309typename enable_if
4310<
4311 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4312 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4313>::type
4314operator==(const _Expr1& __x, const _Expr2& __y)
4315{
4316 typedef typename _Expr1::value_type value_type;
4317 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
4318 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
4319}
4320
4321template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004322inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004323typename enable_if
4324<
4325 __is_val_expr<_Expr>::value,
4326 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4327 _Expr, __scalar_expr<typename _Expr::value_type> > >
4328>::type
4329operator==(const _Expr& __x, const typename _Expr::value_type& __y)
4330{
4331 typedef typename _Expr::value_type value_type;
4332 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4333 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4334 __x, __scalar_expr<value_type>(__y, __x.size())));
4335}
4336
4337template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004338inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004339typename enable_if
4340<
4341 __is_val_expr<_Expr>::value,
4342 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4343 __scalar_expr<typename _Expr::value_type>, _Expr> >
4344>::type
4345operator==(const typename _Expr::value_type& __x, const _Expr& __y)
4346{
4347 typedef typename _Expr::value_type value_type;
4348 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4349 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4350 __scalar_expr<value_type>(__x, __y.size()), __y));
4351}
4352
4353template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004354inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004355typename enable_if
4356<
4357 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4358 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4359>::type
4360operator!=(const _Expr1& __x, const _Expr2& __y)
4361{
4362 typedef typename _Expr1::value_type value_type;
4363 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
4364 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
4365}
4366
4367template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004368inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004369typename enable_if
4370<
4371 __is_val_expr<_Expr>::value,
4372 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4373 _Expr, __scalar_expr<typename _Expr::value_type> > >
4374>::type
4375operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
4376{
4377 typedef typename _Expr::value_type value_type;
4378 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4379 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4380 __x, __scalar_expr<value_type>(__y, __x.size())));
4381}
4382
4383template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004384inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004385typename enable_if
4386<
4387 __is_val_expr<_Expr>::value,
4388 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4389 __scalar_expr<typename _Expr::value_type>, _Expr> >
4390>::type
4391operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
4392{
4393 typedef typename _Expr::value_type value_type;
4394 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4395 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4396 __scalar_expr<value_type>(__x, __y.size()), __y));
4397}
4398
4399template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004400inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004401typename enable_if
4402<
4403 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4404 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
4405>::type
4406operator<(const _Expr1& __x, const _Expr2& __y)
4407{
4408 typedef typename _Expr1::value_type value_type;
4409 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
4410 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
4411}
4412
4413template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004414inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004415typename enable_if
4416<
4417 __is_val_expr<_Expr>::value,
4418 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4419 _Expr, __scalar_expr<typename _Expr::value_type> > >
4420>::type
4421operator<(const _Expr& __x, const typename _Expr::value_type& __y)
4422{
4423 typedef typename _Expr::value_type value_type;
4424 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4425 return __val_expr<_Op>(_Op(less<value_type>(),
4426 __x, __scalar_expr<value_type>(__y, __x.size())));
4427}
4428
4429template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004430inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004431typename enable_if
4432<
4433 __is_val_expr<_Expr>::value,
4434 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4435 __scalar_expr<typename _Expr::value_type>, _Expr> >
4436>::type
4437operator<(const typename _Expr::value_type& __x, const _Expr& __y)
4438{
4439 typedef typename _Expr::value_type value_type;
4440 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4441 return __val_expr<_Op>(_Op(less<value_type>(),
4442 __scalar_expr<value_type>(__x, __y.size()), __y));
4443}
4444
4445template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004446inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004447typename enable_if
4448<
4449 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4450 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
4451>::type
4452operator>(const _Expr1& __x, const _Expr2& __y)
4453{
4454 typedef typename _Expr1::value_type value_type;
4455 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
4456 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
4457}
4458
4459template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004460inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004461typename enable_if
4462<
4463 __is_val_expr<_Expr>::value,
4464 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4465 _Expr, __scalar_expr<typename _Expr::value_type> > >
4466>::type
4467operator>(const _Expr& __x, const typename _Expr::value_type& __y)
4468{
4469 typedef typename _Expr::value_type value_type;
4470 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4471 return __val_expr<_Op>(_Op(greater<value_type>(),
4472 __x, __scalar_expr<value_type>(__y, __x.size())));
4473}
4474
4475template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004476inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004477typename enable_if
4478<
4479 __is_val_expr<_Expr>::value,
4480 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4481 __scalar_expr<typename _Expr::value_type>, _Expr> >
4482>::type
4483operator>(const typename _Expr::value_type& __x, const _Expr& __y)
4484{
4485 typedef typename _Expr::value_type value_type;
4486 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4487 return __val_expr<_Op>(_Op(greater<value_type>(),
4488 __scalar_expr<value_type>(__x, __y.size()), __y));
4489}
4490
4491template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004492inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004493typename enable_if
4494<
4495 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4496 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4497>::type
4498operator<=(const _Expr1& __x, const _Expr2& __y)
4499{
4500 typedef typename _Expr1::value_type value_type;
4501 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
4502 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
4503}
4504
4505template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004506inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004507typename enable_if
4508<
4509 __is_val_expr<_Expr>::value,
4510 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4511 _Expr, __scalar_expr<typename _Expr::value_type> > >
4512>::type
4513operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
4514{
4515 typedef typename _Expr::value_type value_type;
4516 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4517 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4518 __x, __scalar_expr<value_type>(__y, __x.size())));
4519}
4520
4521template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004522inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004523typename enable_if
4524<
4525 __is_val_expr<_Expr>::value,
4526 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4527 __scalar_expr<typename _Expr::value_type>, _Expr> >
4528>::type
4529operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
4530{
4531 typedef typename _Expr::value_type value_type;
4532 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4533 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4534 __scalar_expr<value_type>(__x, __y.size()), __y));
4535}
4536
4537template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004538inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004539typename enable_if
4540<
4541 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4542 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4543>::type
4544operator>=(const _Expr1& __x, const _Expr2& __y)
4545{
4546 typedef typename _Expr1::value_type value_type;
4547 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
4548 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
4549}
4550
4551template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004552inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004553typename enable_if
4554<
4555 __is_val_expr<_Expr>::value,
4556 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4557 _Expr, __scalar_expr<typename _Expr::value_type> > >
4558>::type
4559operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
4560{
4561 typedef typename _Expr::value_type value_type;
4562 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4563 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4564 __x, __scalar_expr<value_type>(__y, __x.size())));
4565}
4566
4567template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004568inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004569typename enable_if
4570<
4571 __is_val_expr<_Expr>::value,
4572 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4573 __scalar_expr<typename _Expr::value_type>, _Expr> >
4574>::type
4575operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
4576{
4577 typedef typename _Expr::value_type value_type;
4578 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4579 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4580 __scalar_expr<value_type>(__x, __y.size()), __y));
4581}
4582
4583template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004584inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004585typename enable_if
4586<
4587 __is_val_expr<_Expr>::value,
4588 __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
4589>::type
4590abs(const _Expr& __x)
4591{
4592 typedef typename _Expr::value_type value_type;
4593 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
4594 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
4595}
4596
4597template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004598inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004599typename enable_if
4600<
4601 __is_val_expr<_Expr>::value,
4602 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
4603>::type
4604acos(const _Expr& __x)
4605{
4606 typedef typename _Expr::value_type value_type;
4607 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
4608 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
4609}
4610
4611template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004612inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004613typename enable_if
4614<
4615 __is_val_expr<_Expr>::value,
4616 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
4617>::type
4618asin(const _Expr& __x)
4619{
4620 typedef typename _Expr::value_type value_type;
4621 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
4622 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
4623}
4624
4625template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004626inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004627typename enable_if
4628<
4629 __is_val_expr<_Expr>::value,
4630 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
4631>::type
4632atan(const _Expr& __x)
4633{
4634 typedef typename _Expr::value_type value_type;
4635 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
4636 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
4637}
4638
4639template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004640inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004641typename enable_if
4642<
4643 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4644 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4645>::type
4646atan2(const _Expr1& __x, const _Expr2& __y)
4647{
4648 typedef typename _Expr1::value_type value_type;
4649 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
4650 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
4651}
4652
4653template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004654inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004655typename enable_if
4656<
4657 __is_val_expr<_Expr>::value,
4658 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4659 _Expr, __scalar_expr<typename _Expr::value_type> > >
4660>::type
4661atan2(const _Expr& __x, const typename _Expr::value_type& __y)
4662{
4663 typedef typename _Expr::value_type value_type;
4664 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4665 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4666 __x, __scalar_expr<value_type>(__y, __x.size())));
4667}
4668
4669template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004670inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004671typename enable_if
4672<
4673 __is_val_expr<_Expr>::value,
4674 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4675 __scalar_expr<typename _Expr::value_type>, _Expr> >
4676>::type
4677atan2(const typename _Expr::value_type& __x, const _Expr& __y)
4678{
4679 typedef typename _Expr::value_type value_type;
4680 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4681 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4682 __scalar_expr<value_type>(__x, __y.size()), __y));
4683}
4684
4685template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004686inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004687typename enable_if
4688<
4689 __is_val_expr<_Expr>::value,
4690 __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
4691>::type
4692cos(const _Expr& __x)
4693{
4694 typedef typename _Expr::value_type value_type;
4695 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
4696 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
4697}
4698
4699template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004700inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004701typename enable_if
4702<
4703 __is_val_expr<_Expr>::value,
4704 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
4705>::type
4706cosh(const _Expr& __x)
4707{
4708 typedef typename _Expr::value_type value_type;
4709 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
4710 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
4711}
4712
4713template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004714inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004715typename enable_if
4716<
4717 __is_val_expr<_Expr>::value,
4718 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
4719>::type
4720exp(const _Expr& __x)
4721{
4722 typedef typename _Expr::value_type value_type;
4723 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
4724 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
4725}
4726
4727template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004728inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004729typename enable_if
4730<
4731 __is_val_expr<_Expr>::value,
4732 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
4733>::type
4734log(const _Expr& __x)
4735{
4736 typedef typename _Expr::value_type value_type;
4737 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
4738 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
4739}
4740
4741template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004742inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004743typename enable_if
4744<
4745 __is_val_expr<_Expr>::value,
4746 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
4747>::type
4748log10(const _Expr& __x)
4749{
4750 typedef typename _Expr::value_type value_type;
4751 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
4752 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
4753}
4754
4755template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004756inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004757typename enable_if
4758<
4759 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4760 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4761>::type
4762pow(const _Expr1& __x, const _Expr2& __y)
4763{
4764 typedef typename _Expr1::value_type value_type;
4765 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
4766 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
4767}
4768
4769template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004770inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004771typename enable_if
4772<
4773 __is_val_expr<_Expr>::value,
4774 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4775 _Expr, __scalar_expr<typename _Expr::value_type> > >
4776>::type
4777pow(const _Expr& __x, const typename _Expr::value_type& __y)
4778{
4779 typedef typename _Expr::value_type value_type;
4780 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4781 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4782 __x, __scalar_expr<value_type>(__y, __x.size())));
4783}
4784
4785template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004786inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004787typename enable_if
4788<
4789 __is_val_expr<_Expr>::value,
4790 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4791 __scalar_expr<typename _Expr::value_type>, _Expr> >
4792>::type
4793pow(const typename _Expr::value_type& __x, const _Expr& __y)
4794{
4795 typedef typename _Expr::value_type value_type;
4796 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4797 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4798 __scalar_expr<value_type>(__x, __y.size()), __y));
4799}
4800
4801template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004802inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004803typename enable_if
4804<
4805 __is_val_expr<_Expr>::value,
4806 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
4807>::type
4808sin(const _Expr& __x)
4809{
4810 typedef typename _Expr::value_type value_type;
4811 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
4812 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
4813}
4814
4815template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004816inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004817typename enable_if
4818<
4819 __is_val_expr<_Expr>::value,
4820 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
4821>::type
4822sinh(const _Expr& __x)
4823{
4824 typedef typename _Expr::value_type value_type;
4825 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
4826 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
4827}
4828
4829template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004830inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004831typename enable_if
4832<
4833 __is_val_expr<_Expr>::value,
4834 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
4835>::type
4836sqrt(const _Expr& __x)
4837{
4838 typedef typename _Expr::value_type value_type;
4839 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
4840 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
4841}
4842
4843template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004844inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004845typename enable_if
4846<
4847 __is_val_expr<_Expr>::value,
4848 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
4849>::type
4850tan(const _Expr& __x)
4851{
4852 typedef typename _Expr::value_type value_type;
4853 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
4854 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
4855}
4856
4857template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004858inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004859typename enable_if
4860<
4861 __is_val_expr<_Expr>::value,
4862 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
4863>::type
4864tanh(const _Expr& __x)
4865{
4866 typedef typename _Expr::value_type value_type;
4867 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
4868 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
4869}
4870
4871template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004872inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004873_Tp*
4874begin(valarray<_Tp>& __v)
4875{
4876 return __v.__begin_;
4877}
4878
4879template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004880inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004881const _Tp*
4882begin(const valarray<_Tp>& __v)
4883{
4884 return __v.__begin_;
4885}
4886
4887template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004888inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004889_Tp*
4890end(valarray<_Tp>& __v)
4891{
4892 return __v.__end_;
4893}
4894
4895template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004896inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004897const _Tp*
4898end(const valarray<_Tp>& __v)
4899{
4900 return __v.__end_;
4901}
4902
Howard Hinnantc51e1022010-05-11 19:42:16 +00004903_LIBCPP_END_NAMESPACE_STD
4904
Eric Fiselierf4433a32017-05-31 22:07:49 +00004905_LIBCPP_POP_MACROS
4906
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04004907#endif // _LIBCPP_VALARRAY