blob: 8f6221ab3f39c1437a103cf688d19c08d2619d14 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- valarray ----------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_VALARRAY
11#define _LIBCPP_VALARRAY
12
13/*
14 valarray synopsis
15
16namespace std
17{
18
19template<class T>
20class valarray
21{
22public:
23 typedef T value_type;
24
25 // construct/destroy:
26 valarray();
27 explicit valarray(size_t n);
28 valarray(const value_type& x, size_t n);
29 valarray(const value_type* px, size_t n);
30 valarray(const valarray& v);
Howard Hinnant298aed92012-07-21 00:51:28 +000031 valarray(valarray&& v) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000032 valarray(const slice_array<value_type>& sa);
33 valarray(const gslice_array<value_type>& ga);
34 valarray(const mask_array<value_type>& ma);
35 valarray(const indirect_array<value_type>& ia);
36 valarray(initializer_list<value_type> il);
37 ~valarray();
38
39 // assignment:
40 valarray& operator=(const valarray& v);
Howard Hinnant298aed92012-07-21 00:51:28 +000041 valarray& operator=(valarray&& v) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000042 valarray& operator=(initializer_list<value_type> il);
43 valarray& operator=(const value_type& x);
44 valarray& operator=(const slice_array<value_type>& sa);
45 valarray& operator=(const gslice_array<value_type>& ga);
46 valarray& operator=(const mask_array<value_type>& ma);
47 valarray& operator=(const indirect_array<value_type>& ia);
48
49 // element access:
50 const value_type& operator[](size_t i) const;
51 value_type& operator[](size_t i);
52
53 // subset operations:
54 valarray operator[](slice s) const;
55 slice_array<value_type> operator[](slice s);
56 valarray operator[](const gslice& gs) const;
57 gslice_array<value_type> operator[](const gslice& gs);
58 valarray operator[](const valarray<bool>& vb) const;
59 mask_array<value_type> operator[](const valarray<bool>& vb);
60 valarray operator[](const valarray<size_t>& vs) const;
61 indirect_array<value_type> operator[](const valarray<size_t>& vs);
62
63 // unary operators:
64 valarray operator+() const;
65 valarray operator-() const;
66 valarray operator~() const;
67 valarray<bool> operator!() const;
68
69 // computed assignment:
70 valarray& operator*= (const value_type& x);
71 valarray& operator/= (const value_type& x);
72 valarray& operator%= (const value_type& x);
73 valarray& operator+= (const value_type& x);
74 valarray& operator-= (const value_type& x);
75 valarray& operator^= (const value_type& x);
76 valarray& operator&= (const value_type& x);
77 valarray& operator|= (const value_type& x);
78 valarray& operator<<=(const value_type& x);
79 valarray& operator>>=(const value_type& x);
80
81 valarray& operator*= (const valarray& v);
82 valarray& operator/= (const valarray& v);
83 valarray& operator%= (const valarray& v);
84 valarray& operator+= (const valarray& v);
85 valarray& operator-= (const valarray& v);
86 valarray& operator^= (const valarray& v);
87 valarray& operator|= (const valarray& v);
88 valarray& operator&= (const valarray& v);
89 valarray& operator<<=(const valarray& v);
90 valarray& operator>>=(const valarray& v);
91
92 // member functions:
Howard Hinnant298aed92012-07-21 00:51:28 +000093 void swap(valarray& v) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000094
95 size_t size() const;
96
97 value_type sum() const;
98 value_type min() const;
99 value_type max() const;
100
101 valarray shift (int i) const;
102 valarray cshift(int i) const;
103 valarray apply(value_type f(value_type)) const;
104 valarray apply(value_type f(const value_type&)) const;
105 void resize(size_t n, value_type x = value_type());
106};
107
108class slice
109{
110public:
111 slice();
112 slice(size_t start, size_t size, size_t stride);
113
114 size_t start() const;
115 size_t size() const;
116 size_t stride() const;
117};
118
119template <class T>
120class slice_array
121{
122public:
123 typedef T value_type;
124
125 const slice_array& operator=(const slice_array& sa) const;
126 void operator= (const valarray<value_type>& v) const;
127 void operator*= (const valarray<value_type>& v) const;
128 void operator/= (const valarray<value_type>& v) const;
129 void operator%= (const valarray<value_type>& v) const;
130 void operator+= (const valarray<value_type>& v) const;
131 void operator-= (const valarray<value_type>& v) const;
132 void operator^= (const valarray<value_type>& v) const;
133 void operator&= (const valarray<value_type>& v) const;
134 void operator|= (const valarray<value_type>& v) const;
135 void operator<<=(const valarray<value_type>& v) const;
136 void operator>>=(const valarray<value_type>& v) const;
137
138 void operator=(const value_type& x) const;
139
140 slice_array() = delete;
141};
142
143class gslice
144{
145public:
146 gslice();
147 gslice(size_t start, const valarray<size_t>& size,
148 const valarray<size_t>& stride);
149
150 size_t start() const;
151 valarray<size_t> size() const;
152 valarray<size_t> stride() const;
153};
154
155template <class T>
156class gslice_array
157{
158public:
159 typedef T value_type;
160
161 void operator= (const valarray<value_type>& v) const;
162 void operator*= (const valarray<value_type>& v) const;
163 void operator/= (const valarray<value_type>& v) const;
164 void operator%= (const valarray<value_type>& v) const;
165 void operator+= (const valarray<value_type>& v) const;
166 void operator-= (const valarray<value_type>& v) const;
167 void operator^= (const valarray<value_type>& v) const;
168 void operator&= (const valarray<value_type>& v) const;
169 void operator|= (const valarray<value_type>& v) const;
170 void operator<<=(const valarray<value_type>& v) const;
171 void operator>>=(const valarray<value_type>& v) const;
172
173 gslice_array(const gslice_array& ga);
174 ~gslice_array();
175 const gslice_array& operator=(const gslice_array& ga) const;
176 void operator=(const value_type& x) const;
177
178 gslice_array() = delete;
179};
180
181template <class T>
182class mask_array
183{
184public:
185 typedef T value_type;
186
187 void operator= (const valarray<value_type>& v) const;
188 void operator*= (const valarray<value_type>& v) const;
189 void operator/= (const valarray<value_type>& v) const;
190 void operator%= (const valarray<value_type>& v) const;
191 void operator+= (const valarray<value_type>& v) const;
192 void operator-= (const valarray<value_type>& v) const;
193 void operator^= (const valarray<value_type>& v) const;
194 void operator&= (const valarray<value_type>& v) const;
195 void operator|= (const valarray<value_type>& v) const;
196 void operator<<=(const valarray<value_type>& v) const;
197 void operator>>=(const valarray<value_type>& v) const;
198
199 mask_array(const mask_array& ma);
200 ~mask_array();
201 const mask_array& operator=(const mask_array& ma) const;
202 void operator=(const value_type& x) const;
203
204 mask_array() = delete;
205};
206
207template <class T>
208class indirect_array
209{
210public:
211 typedef T value_type;
212
213 void operator= (const valarray<value_type>& v) const;
214 void operator*= (const valarray<value_type>& v) const;
215 void operator/= (const valarray<value_type>& v) const;
216 void operator%= (const valarray<value_type>& v) const;
217 void operator+= (const valarray<value_type>& v) const;
218 void operator-= (const valarray<value_type>& v) const;
219 void operator^= (const valarray<value_type>& v) const;
220 void operator&= (const valarray<value_type>& v) const;
221 void operator|= (const valarray<value_type>& v) const;
222 void operator<<=(const valarray<value_type>& v) const;
223 void operator>>=(const valarray<value_type>& v) const;
224
225 indirect_array(const indirect_array& ia);
226 ~indirect_array();
227 const indirect_array& operator=(const indirect_array& ia) const;
228 void operator=(const value_type& x) const;
229
230 indirect_array() = delete;
231};
232
Howard Hinnant298aed92012-07-21 00:51:28 +0000233template<class T> void swap(valarray<T>& x, valarray<T>& y) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000234
235template<class T> valarray<T> operator* (const valarray<T>& x, const valarray<T>& y);
236template<class T> valarray<T> operator* (const valarray<T>& x, const T& y);
237template<class T> valarray<T> operator* (const T& x, const valarray<T>& y);
238
239template<class T> valarray<T> operator/ (const valarray<T>& x, const valarray<T>& y);
240template<class T> valarray<T> operator/ (const valarray<T>& x, const T& y);
241template<class T> valarray<T> operator/ (const T& x, const valarray<T>& y);
242
243template<class T> valarray<T> operator% (const valarray<T>& x, const valarray<T>& y);
244template<class T> valarray<T> operator% (const valarray<T>& x, const T& y);
245template<class T> valarray<T> operator% (const T& x, const valarray<T>& y);
246
247template<class T> valarray<T> operator+ (const valarray<T>& x, const valarray<T>& y);
248template<class T> valarray<T> operator+ (const valarray<T>& x, const T& y);
249template<class T> valarray<T> operator+ (const T& x, const valarray<T>& y);
250
251template<class T> valarray<T> operator- (const valarray<T>& x, const valarray<T>& y);
252template<class T> valarray<T> operator- (const valarray<T>& x, const T& y);
253template<class T> valarray<T> operator- (const T& x, const valarray<T>& y);
254
255template<class T> valarray<T> operator^ (const valarray<T>& x, const valarray<T>& y);
256template<class T> valarray<T> operator^ (const valarray<T>& x, const T& y);
257template<class T> valarray<T> operator^ (const T& x, const valarray<T>& y);
258
259template<class T> valarray<T> operator& (const valarray<T>& x, const valarray<T>& y);
260template<class T> valarray<T> operator& (const valarray<T>& x, const T& y);
261template<class T> valarray<T> operator& (const T& x, const valarray<T>& y);
262
263template<class T> valarray<T> operator| (const valarray<T>& x, const valarray<T>& y);
264template<class T> valarray<T> operator| (const valarray<T>& x, const T& y);
265template<class T> valarray<T> operator| (const T& x, const valarray<T>& y);
266
267template<class T> valarray<T> operator<<(const valarray<T>& x, const valarray<T>& y);
268template<class T> valarray<T> operator<<(const valarray<T>& x, const T& y);
269template<class T> valarray<T> operator<<(const T& x, const valarray<T>& y);
270
271template<class T> valarray<T> operator>>(const valarray<T>& x, const valarray<T>& y);
272template<class T> valarray<T> operator>>(const valarray<T>& x, const T& y);
273template<class T> valarray<T> operator>>(const T& x, const valarray<T>& y);
274
275template<class T> valarray<bool> operator&&(const valarray<T>& x, const valarray<T>& y);
276template<class T> valarray<bool> operator&&(const valarray<T>& x, const T& y);
277template<class T> valarray<bool> operator&&(const T& x, const valarray<T>& y);
278
279template<class T> valarray<bool> operator||(const valarray<T>& x, const valarray<T>& y);
280template<class T> valarray<bool> operator||(const valarray<T>& x, const T& y);
281template<class T> valarray<bool> operator||(const T& x, const valarray<T>& y);
282
283template<class T> valarray<bool> operator==(const valarray<T>& x, const valarray<T>& y);
284template<class T> valarray<bool> operator==(const valarray<T>& x, const T& y);
285template<class T> valarray<bool> operator==(const T& x, const valarray<T>& y);
286
287template<class T> valarray<bool> operator!=(const valarray<T>& x, const valarray<T>& y);
288template<class T> valarray<bool> operator!=(const valarray<T>& x, const T& y);
289template<class T> valarray<bool> operator!=(const T& x, const valarray<T>& y);
290
291template<class T> valarray<bool> operator< (const valarray<T>& x, const valarray<T>& y);
292template<class T> valarray<bool> operator< (const valarray<T>& x, const T& y);
293template<class T> valarray<bool> operator< (const T& x, const valarray<T>& y);
294
295template<class T> valarray<bool> operator> (const valarray<T>& x, const valarray<T>& y);
296template<class T> valarray<bool> operator> (const valarray<T>& x, const T& y);
297template<class T> valarray<bool> operator> (const T& x, const valarray<T>& y);
298
299template<class T> valarray<bool> operator<=(const valarray<T>& x, const valarray<T>& y);
300template<class T> valarray<bool> operator<=(const valarray<T>& x, const T& y);
301template<class T> valarray<bool> operator<=(const T& x, const valarray<T>& y);
302
303template<class T> valarray<bool> operator>=(const valarray<T>& x, const valarray<T>& y);
304template<class T> valarray<bool> operator>=(const valarray<T>& x, const T& y);
305template<class T> valarray<bool> operator>=(const T& x, const valarray<T>& y);
306
307template<class T> valarray<T> abs (const valarray<T>& x);
308template<class T> valarray<T> acos (const valarray<T>& x);
309template<class T> valarray<T> asin (const valarray<T>& x);
310template<class T> valarray<T> atan (const valarray<T>& x);
311
312template<class T> valarray<T> atan2(const valarray<T>& x, const valarray<T>& y);
313template<class T> valarray<T> atan2(const valarray<T>& x, const T& y);
314template<class T> valarray<T> atan2(const T& x, const valarray<T>& y);
315
316template<class T> valarray<T> cos (const valarray<T>& x);
317template<class T> valarray<T> cosh (const valarray<T>& x);
318template<class T> valarray<T> exp (const valarray<T>& x);
319template<class T> valarray<T> log (const valarray<T>& x);
320template<class T> valarray<T> log10(const valarray<T>& x);
321
322template<class T> valarray<T> pow(const valarray<T>& x, const valarray<T>& y);
323template<class T> valarray<T> pow(const valarray<T>& x, const T& y);
324template<class T> valarray<T> pow(const T& x, const valarray<T>& y);
325
326template<class T> valarray<T> sin (const valarray<T>& x);
327template<class T> valarray<T> sinh (const valarray<T>& x);
328template<class T> valarray<T> sqrt (const valarray<T>& x);
329template<class T> valarray<T> tan (const valarray<T>& x);
330template<class T> valarray<T> tanh (const valarray<T>& x);
331
332template <class T> unspecified1 begin(valarray<T>& v);
333template <class T> unspecified2 begin(const valarray<T>& v);
334template <class T> unspecified1 end(valarray<T>& v);
335template <class T> unspecified2 end(const valarray<T>& v);
336
337} // std
338
339*/
340
341#include <__config>
342#include <cstddef>
343#include <cmath>
344#include <initializer_list>
345#include <algorithm>
346#include <functional>
Richard Smith1f1c1472014-06-04 19:54:15 +0000347#include <new>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000348
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000349#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000350#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000351#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000352
Eric Fiselierf4433a32017-05-31 22:07:49 +0000353_LIBCPP_PUSH_MACROS
354#include <__undef_macros>
355
356
Howard Hinnantc51e1022010-05-11 19:42:16 +0000357_LIBCPP_BEGIN_NAMESPACE_STD
358
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000359template<class _Tp> class _LIBCPP_TEMPLATE_VIS valarray;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000361class _LIBCPP_TEMPLATE_VIS slice
Howard Hinnantc51e1022010-05-11 19:42:16 +0000362{
363 size_t __start_;
364 size_t __size_;
365 size_t __stride_;
366public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000367 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000368 slice()
369 : __start_(0),
370 __size_(0),
371 __stride_(0)
372 {}
373
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000374 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375 slice(size_t __start, size_t __size, size_t __stride)
376 : __start_(__start),
377 __size_(__size),
378 __stride_(__stride)
379 {}
380
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000381 _LIBCPP_INLINE_VISIBILITY size_t start() const {return __start_;}
382 _LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;}
383 _LIBCPP_INLINE_VISIBILITY size_t stride() const {return __stride_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000384};
385
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000386template <class _Tp> class _LIBCPP_TEMPLATE_VIS slice_array;
Howard Hinnant8331b762013-03-06 23:30:19 +0000387class _LIBCPP_TYPE_VIS gslice;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000388template <class _Tp> class _LIBCPP_TEMPLATE_VIS gslice_array;
389template <class _Tp> class _LIBCPP_TEMPLATE_VIS mask_array;
390template <class _Tp> class _LIBCPP_TEMPLATE_VIS indirect_array;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000391
392template <class _Tp>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000393_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000394_Tp*
395begin(valarray<_Tp>& __v);
396
397template <class _Tp>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000398_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000399const _Tp*
400begin(const valarray<_Tp>& __v);
401
402template <class _Tp>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000403_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000404_Tp*
405end(valarray<_Tp>& __v);
406
407template <class _Tp>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000408_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000409const _Tp*
410end(const valarray<_Tp>& __v);
411
412template <class _Op, class _A0>
413struct _UnaryOp
414{
415 typedef typename _Op::result_type result_type;
416 typedef typename _A0::value_type value_type;
417
418 _Op __op_;
419 _A0 __a0_;
420
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000422 _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {}
423
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000425 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
426
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000427 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428 size_t size() const {return __a0_.size();}
429};
430
431template <class _Op, class _A0, class _A1>
432struct _BinaryOp
433{
434 typedef typename _Op::result_type result_type;
435 typedef typename _A0::value_type value_type;
436
437 _Op __op_;
438 _A0 __a0_;
439 _A1 __a1_;
440
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000441 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000442 _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1)
443 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
444
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
447
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449 size_t size() const {return __a0_.size();}
450};
451
452template <class _Tp>
453class __scalar_expr
454{
455public:
456 typedef _Tp value_type;
457 typedef const _Tp& result_type;
458private:
459 const value_type& __t_;
460 size_t __s_;
461public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000463 explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {}
464
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000466 result_type operator[](size_t) const {return __t_;}
467
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000468 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000469 size_t size() const {return __s_;}
470};
471
472template <class _Tp>
473struct __unary_plus : unary_function<_Tp, _Tp>
474{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000476 _Tp operator()(const _Tp& __x) const
477 {return +__x;}
478};
479
480template <class _Tp>
481struct __bit_not : unary_function<_Tp, _Tp>
482{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000484 _Tp operator()(const _Tp& __x) const
485 {return ~__x;}
486};
487
488template <class _Tp>
489struct __bit_shift_left : binary_function<_Tp, _Tp, _Tp>
490{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000492 _Tp operator()(const _Tp& __x, const _Tp& __y) const
493 {return __x << __y;}
494};
495
496template <class _Tp>
497struct __bit_shift_right : binary_function<_Tp, _Tp, _Tp>
498{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000500 _Tp operator()(const _Tp& __x, const _Tp& __y) const
501 {return __x >> __y;}
502};
503
Howard Hinnantc834c512011-11-29 18:15:50 +0000504template <class _Tp, class _Fp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505struct __apply_expr : unary_function<_Tp, _Tp>
506{
507private:
Howard Hinnantc834c512011-11-29 18:15:50 +0000508 _Fp __f_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +0000511 explicit __apply_expr(_Fp __f) : __f_(__f) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000512
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000514 _Tp operator()(const _Tp& __x) const
515 {return __f_(__x);}
516};
517
518template <class _Tp>
519struct __abs_expr : unary_function<_Tp, _Tp>
520{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000521 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000522 _Tp operator()(const _Tp& __x) const
523 {return abs(__x);}
524};
525
526template <class _Tp>
527struct __acos_expr : unary_function<_Tp, _Tp>
528{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000529 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000530 _Tp operator()(const _Tp& __x) const
531 {return acos(__x);}
532};
533
534template <class _Tp>
535struct __asin_expr : unary_function<_Tp, _Tp>
536{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000538 _Tp operator()(const _Tp& __x) const
539 {return asin(__x);}
540};
541
542template <class _Tp>
543struct __atan_expr : unary_function<_Tp, _Tp>
544{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000545 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000546 _Tp operator()(const _Tp& __x) const
547 {return atan(__x);}
548};
549
550template <class _Tp>
551struct __atan2_expr : binary_function<_Tp, _Tp, _Tp>
552{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000554 _Tp operator()(const _Tp& __x, const _Tp& __y) const
555 {return atan2(__x, __y);}
556};
557
558template <class _Tp>
559struct __cos_expr : unary_function<_Tp, _Tp>
560{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562 _Tp operator()(const _Tp& __x) const
563 {return cos(__x);}
564};
565
566template <class _Tp>
567struct __cosh_expr : unary_function<_Tp, _Tp>
568{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570 _Tp operator()(const _Tp& __x) const
571 {return cosh(__x);}
572};
573
574template <class _Tp>
575struct __exp_expr : unary_function<_Tp, _Tp>
576{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000578 _Tp operator()(const _Tp& __x) const
579 {return exp(__x);}
580};
581
582template <class _Tp>
583struct __log_expr : unary_function<_Tp, _Tp>
584{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000585 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000586 _Tp operator()(const _Tp& __x) const
587 {return log(__x);}
588};
589
590template <class _Tp>
591struct __log10_expr : unary_function<_Tp, _Tp>
592{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000594 _Tp operator()(const _Tp& __x) const
595 {return log10(__x);}
596};
597
598template <class _Tp>
599struct __pow_expr : binary_function<_Tp, _Tp, _Tp>
600{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000601 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000602 _Tp operator()(const _Tp& __x, const _Tp& __y) const
603 {return pow(__x, __y);}
604};
605
606template <class _Tp>
607struct __sin_expr : unary_function<_Tp, _Tp>
608{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000610 _Tp operator()(const _Tp& __x) const
611 {return sin(__x);}
612};
613
614template <class _Tp>
615struct __sinh_expr : unary_function<_Tp, _Tp>
616{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000618 _Tp operator()(const _Tp& __x) const
619 {return sinh(__x);}
620};
621
622template <class _Tp>
623struct __sqrt_expr : unary_function<_Tp, _Tp>
624{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000626 _Tp operator()(const _Tp& __x) const
627 {return sqrt(__x);}
628};
629
630template <class _Tp>
631struct __tan_expr : unary_function<_Tp, _Tp>
632{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000633 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000634 _Tp operator()(const _Tp& __x) const
635 {return tan(__x);}
636};
637
638template <class _Tp>
639struct __tanh_expr : unary_function<_Tp, _Tp>
640{
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000641 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642 _Tp operator()(const _Tp& __x) const
643 {return tanh(__x);}
644};
645
646template <class _ValExpr>
647class __slice_expr
648{
649 typedef typename remove_reference<_ValExpr>::type _RmExpr;
650public:
651 typedef typename _RmExpr::value_type value_type;
652 typedef value_type result_type;
653
654private:
655 _ValExpr __expr_;
656 size_t __start_;
657 size_t __size_;
658 size_t __stride_;
659
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000661 __slice_expr(const slice& __sl, const _RmExpr& __e)
662 : __expr_(__e),
663 __start_(__sl.start()),
664 __size_(__sl.size()),
665 __stride_(__sl.stride())
666 {}
667public:
668
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000670 result_type operator[](size_t __i) const
671 {return __expr_[__start_ + __i * __stride_];}
672
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000674 size_t size() const {return __size_;}
675
Eric Fiselier7b31ed02019-04-02 08:05:23 +0000676 template <class> friend class __val_expr;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000677 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000678};
679
680template <class _ValExpr>
681class __mask_expr;
682
683template <class _ValExpr>
684class __indirect_expr;
685
686template <class _ValExpr>
687class __shift_expr
688{
689 typedef typename remove_reference<_ValExpr>::type _RmExpr;
690public:
691 typedef typename _RmExpr::value_type value_type;
692 typedef value_type result_type;
693
694private:
695 _ValExpr __expr_;
696 size_t __size_;
697 ptrdiff_t __ul_;
698 ptrdiff_t __sn_;
699 ptrdiff_t __n_;
Howard Hinnantc834c512011-11-29 18:15:50 +0000700 static const ptrdiff_t _Np = static_cast<ptrdiff_t>(
Howard Hinnantc51e1022010-05-11 19:42:16 +0000701 sizeof(ptrdiff_t) * __CHAR_BIT__ - 1);
702
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000704 __shift_expr(int __n, const _RmExpr& __e)
705 : __expr_(__e),
706 __size_(__e.size()),
707 __n_(__n)
708 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000709 ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _Np);
710 __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _Np);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000711 __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n);
712 }
713public:
714
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000715 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000716 result_type operator[](size_t __j) const
717 {
Howard Hinnant28b24882011-12-01 20:21:04 +0000718 ptrdiff_t __i = static_cast<ptrdiff_t>(__j);
Howard Hinnantc834c512011-11-29 18:15:50 +0000719 ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000720 return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
721 }
722
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000724 size_t size() const {return __size_;}
725
726 template <class> friend class __val_expr;
727};
728
729template <class _ValExpr>
730class __cshift_expr
731{
732 typedef typename remove_reference<_ValExpr>::type _RmExpr;
733public:
734 typedef typename _RmExpr::value_type value_type;
735 typedef value_type result_type;
736
737private:
738 _ValExpr __expr_;
739 size_t __size_;
740 size_t __m_;
741 size_t __o1_;
742 size_t __o2_;
743
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000745 __cshift_expr(int __n, const _RmExpr& __e)
746 : __expr_(__e),
747 __size_(__e.size())
748 {
749 __n %= static_cast<int>(__size_);
750 if (__n >= 0)
751 {
752 __m_ = __size_ - __n;
753 __o1_ = __n;
754 __o2_ = __n - __size_;
755 }
756 else
757 {
758 __m_ = -__n;
759 __o1_ = __n + __size_;
760 __o2_ = __n;
761 }
762 }
763public:
764
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000766 result_type operator[](size_t __i) const
767 {
768 if (__i < __m_)
769 return __expr_[__i + __o1_];
770 return __expr_[__i + __o2_];
771 }
772
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000774 size_t size() const {return __size_;}
775
776 template <class> friend class __val_expr;
777};
778
779template<class _ValExpr>
780class __val_expr;
781
782template<class _ValExpr>
783struct __is_val_expr : false_type {};
784
785template<class _ValExpr>
786struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
787
788template<class _Tp>
789struct __is_val_expr<valarray<_Tp> > : true_type {};
790
791template<class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000792class _LIBCPP_TEMPLATE_VIS valarray
Howard Hinnantc51e1022010-05-11 19:42:16 +0000793{
794public:
795 typedef _Tp value_type;
796 typedef _Tp result_type;
797
798private:
799 value_type* __begin_;
800 value_type* __end_;
801
802public:
803 // construct/destroy:
Douglas Gregor68902322012-05-19 07:14:17 +0000804 _LIBCPP_INLINE_VISIBILITY
805 valarray() : __begin_(0), __end_(0) {}
Louis Dionneb4d05d72018-10-16 19:26:23 +0000806 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Eric Fiseliere529a802016-09-16 00:13:55 +0000807 explicit valarray(size_t __n);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000808 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +0000809 valarray(const value_type& __x, size_t __n);
810 valarray(const value_type* __p, size_t __n);
811 valarray(const valarray& __v);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000812#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000813 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant298aed92012-07-21 00:51:28 +0000814 valarray(valarray&& __v) _NOEXCEPT;
Douglas Gregor68902322012-05-19 07:14:17 +0000815 valarray(initializer_list<value_type> __il);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000816#endif // _LIBCPP_CXX03_LANG
Douglas Gregor68902322012-05-19 07:14:17 +0000817 valarray(const slice_array<value_type>& __sa);
818 valarray(const gslice_array<value_type>& __ga);
819 valarray(const mask_array<value_type>& __ma);
820 valarray(const indirect_array<value_type>& __ia);
Louis Dionneb4d05d72018-10-16 19:26:23 +0000821 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Douglas Gregor68902322012-05-19 07:14:17 +0000822 ~valarray();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000823
824 // assignment:
Douglas Gregor68902322012-05-19 07:14:17 +0000825 valarray& operator=(const valarray& __v);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000826#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant298aed92012-07-21 00:51:28 +0000828 valarray& operator=(valarray&& __v) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000829 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +0000830 valarray& operator=(initializer_list<value_type>);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000831#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000832 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +0000833 valarray& operator=(const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000835 valarray& operator=(const slice_array<value_type>& __sa);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000837 valarray& operator=(const gslice_array<value_type>& __ga);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000839 valarray& operator=(const mask_array<value_type>& __ma);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000841 valarray& operator=(const indirect_array<value_type>& __ia);
Howard Hinnant329cd412011-07-27 23:19:59 +0000842 template <class _ValExpr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000843 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant329cd412011-07-27 23:19:59 +0000844 valarray& operator=(const __val_expr<_ValExpr>& __v);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000845
846 // element access:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000848 const value_type& operator[](size_t __i) const {return __begin_[__i];}
849
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000851 value_type& operator[](size_t __i) {return __begin_[__i];}
852
853 // subset operations:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000854 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000855 __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857 slice_array<value_type> operator[](slice __s);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000859 __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000861 gslice_array<value_type> operator[](const gslice& __gs);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000862#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000864 __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866 gslice_array<value_type> operator[](gslice&& __gs);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000867#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000868 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000869 __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000871 mask_array<value_type> operator[](const valarray<bool>& __vb);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000872#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000874 __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000876 mask_array<value_type> operator[](valarray<bool>&& __vb);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000877#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000878 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000879 __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000881 indirect_array<value_type> operator[](const valarray<size_t>& __vs);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000882#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000884 __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000886 indirect_array<value_type> operator[](valarray<size_t>&& __vs);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000887#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000888
889 // unary operators:
Douglas Gregor68902322012-05-19 07:14:17 +0000890 valarray operator+() const;
891 valarray operator-() const;
892 valarray operator~() const;
893 valarray<bool> operator!() const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000894
895 // computed assignment:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000897 valarray& operator*= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000899 valarray& operator/= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000901 valarray& operator%= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000903 valarray& operator+= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000904 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000905 valarray& operator-= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000907 valarray& operator^= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000909 valarray& operator&= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911 valarray& operator|= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000912 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000913 valarray& operator<<=(const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000915 valarray& operator>>=(const value_type& __x);
916
917 template <class _Expr>
918 typename enable_if
919 <
920 __is_val_expr<_Expr>::value,
921 valarray&
922 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000924 operator*= (const _Expr& __v);
925
926 template <class _Expr>
927 typename enable_if
928 <
929 __is_val_expr<_Expr>::value,
930 valarray&
931 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000932 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000933 operator/= (const _Expr& __v);
934
935 template <class _Expr>
936 typename enable_if
937 <
938 __is_val_expr<_Expr>::value,
939 valarray&
940 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000941 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000942 operator%= (const _Expr& __v);
943
944 template <class _Expr>
945 typename enable_if
946 <
947 __is_val_expr<_Expr>::value,
948 valarray&
949 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000951 operator+= (const _Expr& __v);
952
953 template <class _Expr>
954 typename enable_if
955 <
956 __is_val_expr<_Expr>::value,
957 valarray&
958 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000959 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000960 operator-= (const _Expr& __v);
961
962 template <class _Expr>
963 typename enable_if
964 <
965 __is_val_expr<_Expr>::value,
966 valarray&
967 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000968 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000969 operator^= (const _Expr& __v);
970
971 template <class _Expr>
972 typename enable_if
973 <
974 __is_val_expr<_Expr>::value,
975 valarray&
976 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000977 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000978 operator|= (const _Expr& __v);
979
980 template <class _Expr>
981 typename enable_if
982 <
983 __is_val_expr<_Expr>::value,
984 valarray&
985 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000986 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000987 operator&= (const _Expr& __v);
988
989 template <class _Expr>
990 typename enable_if
991 <
992 __is_val_expr<_Expr>::value,
993 valarray&
994 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000996 operator<<= (const _Expr& __v);
997
998 template <class _Expr>
999 typename enable_if
1000 <
1001 __is_val_expr<_Expr>::value,
1002 valarray&
1003 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001004 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001005 operator>>= (const _Expr& __v);
1006
1007 // member functions:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant298aed92012-07-21 00:51:28 +00001009 void swap(valarray& __v) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001010
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001011 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant28b24882011-12-01 20:21:04 +00001012 size_t size() const {return static_cast<size_t>(__end_ - __begin_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001013
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001014 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +00001015 value_type sum() const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001016 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +00001017 value_type min() const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001018 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +00001019 value_type max() const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001020
Douglas Gregor68902322012-05-19 07:14:17 +00001021 valarray shift (int __i) const;
1022 valarray cshift(int __i) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001023 valarray apply(value_type __f(value_type)) const;
1024 valarray apply(value_type __f(const value_type&)) const;
1025 void resize(size_t __n, value_type __x = value_type());
1026
1027private:
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001028 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
1029 template <class> friend class _LIBCPP_TEMPLATE_VIS slice_array;
1030 template <class> friend class _LIBCPP_TEMPLATE_VIS gslice_array;
1031 template <class> friend class _LIBCPP_TEMPLATE_VIS mask_array;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001032 template <class> friend class __mask_expr;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001033 template <class> friend class _LIBCPP_TEMPLATE_VIS indirect_array;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001034 template <class> friend class __indirect_expr;
1035 template <class> friend class __val_expr;
1036
1037 template <class _Up>
1038 friend
1039 _Up*
1040 begin(valarray<_Up>& __v);
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001041
Howard Hinnantc51e1022010-05-11 19:42:16 +00001042 template <class _Up>
1043 friend
1044 const _Up*
1045 begin(const valarray<_Up>& __v);
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001046
Howard Hinnantc51e1022010-05-11 19:42:16 +00001047 template <class _Up>
1048 friend
1049 _Up*
1050 end(valarray<_Up>& __v);
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001051
Howard Hinnantc51e1022010-05-11 19:42:16 +00001052 template <class _Up>
1053 friend
1054 const _Up*
1055 end(const valarray<_Up>& __v);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00001056
Eric Fiseliera119c322018-10-25 17:43:26 +00001057 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2856ef82018-10-25 17:21:30 +00001058 void __clear(size_t __capacity);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00001059 valarray& __assign_range(const value_type* __f, const value_type* __l);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001060};
1061
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001062_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void valarray<size_t>::resize(size_t, size_t))
1063
Howard Hinnantc51e1022010-05-11 19:42:16 +00001064template <class _Op, class _Tp>
1065struct _UnaryOp<_Op, valarray<_Tp> >
1066{
1067 typedef typename _Op::result_type result_type;
1068 typedef _Tp value_type;
1069
1070 _Op __op_;
1071 const valarray<_Tp>& __a0_;
1072
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001073 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001074 _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
1075
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001076 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001077 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
1078
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001079 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001080 size_t size() const {return __a0_.size();}
1081};
1082
1083template <class _Op, class _Tp, class _A1>
1084struct _BinaryOp<_Op, valarray<_Tp>, _A1>
1085{
1086 typedef typename _Op::result_type result_type;
1087 typedef _Tp value_type;
1088
1089 _Op __op_;
1090 const valarray<_Tp>& __a0_;
1091 _A1 __a1_;
1092
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001094 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
1095 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1096
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001098 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1099
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001101 size_t size() const {return __a0_.size();}
1102};
1103
1104template <class _Op, class _A0, class _Tp>
1105struct _BinaryOp<_Op, _A0, valarray<_Tp> >
1106{
1107 typedef typename _Op::result_type result_type;
1108 typedef _Tp value_type;
1109
1110 _Op __op_;
1111 _A0 __a0_;
1112 const valarray<_Tp>& __a1_;
1113
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001114 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001115 _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
1116 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1117
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001118 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001119 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1120
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001121 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001122 size_t size() const {return __a0_.size();}
1123};
1124
1125template <class _Op, class _Tp>
1126struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> >
1127{
1128 typedef typename _Op::result_type result_type;
1129 typedef _Tp value_type;
1130
1131 _Op __op_;
1132 const valarray<_Tp>& __a0_;
1133 const valarray<_Tp>& __a1_;
1134
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001136 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
1137 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1138
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001139 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001140 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1141
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001142 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001143 size_t size() const {return __a0_.size();}
1144};
1145
1146// slice_array
1147
1148template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001149class _LIBCPP_TEMPLATE_VIS slice_array
Howard Hinnantc51e1022010-05-11 19:42:16 +00001150{
1151public:
1152 typedef _Tp value_type;
1153
1154private:
1155 value_type* __vp_;
1156 size_t __size_;
1157 size_t __stride_;
1158
1159public:
1160 template <class _Expr>
1161 typename enable_if
1162 <
1163 __is_val_expr<_Expr>::value,
1164 void
1165 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001166 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001167 operator=(const _Expr& __v) const;
1168
1169 template <class _Expr>
1170 typename enable_if
1171 <
1172 __is_val_expr<_Expr>::value,
1173 void
1174 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001175 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001176 operator*=(const _Expr& __v) const;
1177
1178 template <class _Expr>
1179 typename enable_if
1180 <
1181 __is_val_expr<_Expr>::value,
1182 void
1183 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001184 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001185 operator/=(const _Expr& __v) const;
1186
1187 template <class _Expr>
1188 typename enable_if
1189 <
1190 __is_val_expr<_Expr>::value,
1191 void
1192 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001193 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001194 operator%=(const _Expr& __v) const;
1195
1196 template <class _Expr>
1197 typename enable_if
1198 <
1199 __is_val_expr<_Expr>::value,
1200 void
1201 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001202 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001203 operator+=(const _Expr& __v) const;
1204
1205 template <class _Expr>
1206 typename enable_if
1207 <
1208 __is_val_expr<_Expr>::value,
1209 void
1210 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001211 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001212 operator-=(const _Expr& __v) const;
1213
1214 template <class _Expr>
1215 typename enable_if
1216 <
1217 __is_val_expr<_Expr>::value,
1218 void
1219 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001220 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001221 operator^=(const _Expr& __v) const;
1222
1223 template <class _Expr>
1224 typename enable_if
1225 <
1226 __is_val_expr<_Expr>::value,
1227 void
1228 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001229 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001230 operator&=(const _Expr& __v) const;
1231
1232 template <class _Expr>
1233 typename enable_if
1234 <
1235 __is_val_expr<_Expr>::value,
1236 void
1237 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001238 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001239 operator|=(const _Expr& __v) const;
1240
1241 template <class _Expr>
1242 typename enable_if
1243 <
1244 __is_val_expr<_Expr>::value,
1245 void
1246 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001247 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001248 operator<<=(const _Expr& __v) const;
1249
1250 template <class _Expr>
1251 typename enable_if
1252 <
1253 __is_val_expr<_Expr>::value,
1254 void
1255 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001256 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001257 operator>>=(const _Expr& __v) const;
1258
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001259 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001260 const slice_array& operator=(const slice_array& __sa) const;
1261
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001262 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001263 void operator=(const value_type& __x) const;
1264
1265private:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001266 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001267 slice_array(const slice& __sl, const valarray<value_type>& __v)
1268 : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())),
1269 __size_(__sl.size()),
1270 __stride_(__sl.stride())
1271 {}
1272
1273 template <class> friend class valarray;
1274 template <class> friend class sliceExpr;
1275};
1276
1277template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001278inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001279const slice_array<_Tp>&
1280slice_array<_Tp>::operator=(const slice_array& __sa) const
1281{
1282 value_type* __t = __vp_;
1283 const value_type* __s = __sa.__vp_;
1284 for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
1285 *__t = *__s;
Eric Fiselier3b80ce92014-08-12 00:06:58 +00001286 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001287}
1288
1289template <class _Tp>
1290template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001291inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001292typename enable_if
1293<
1294 __is_val_expr<_Expr>::value,
1295 void
1296>::type
1297slice_array<_Tp>::operator=(const _Expr& __v) const
1298{
1299 value_type* __t = __vp_;
1300 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1301 *__t = __v[__i];
1302}
1303
1304template <class _Tp>
1305template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001306inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001307typename enable_if
1308<
1309 __is_val_expr<_Expr>::value,
1310 void
1311>::type
1312slice_array<_Tp>::operator*=(const _Expr& __v) const
1313{
1314 value_type* __t = __vp_;
1315 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1316 *__t *= __v[__i];
1317}
1318
1319template <class _Tp>
1320template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001321inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001322typename enable_if
1323<
1324 __is_val_expr<_Expr>::value,
1325 void
1326>::type
1327slice_array<_Tp>::operator/=(const _Expr& __v) const
1328{
1329 value_type* __t = __vp_;
1330 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1331 *__t /= __v[__i];
1332}
1333
1334template <class _Tp>
1335template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001336inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001337typename enable_if
1338<
1339 __is_val_expr<_Expr>::value,
1340 void
1341>::type
1342slice_array<_Tp>::operator%=(const _Expr& __v) const
1343{
1344 value_type* __t = __vp_;
1345 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1346 *__t %= __v[__i];
1347}
1348
1349template <class _Tp>
1350template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001351inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001352typename enable_if
1353<
1354 __is_val_expr<_Expr>::value,
1355 void
1356>::type
1357slice_array<_Tp>::operator+=(const _Expr& __v) const
1358{
1359 value_type* __t = __vp_;
1360 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1361 *__t += __v[__i];
1362}
1363
1364template <class _Tp>
1365template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001366inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001367typename enable_if
1368<
1369 __is_val_expr<_Expr>::value,
1370 void
1371>::type
1372slice_array<_Tp>::operator-=(const _Expr& __v) const
1373{
1374 value_type* __t = __vp_;
1375 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1376 *__t -= __v[__i];
1377}
1378
1379template <class _Tp>
1380template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001381inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001382typename enable_if
1383<
1384 __is_val_expr<_Expr>::value,
1385 void
1386>::type
1387slice_array<_Tp>::operator^=(const _Expr& __v) const
1388{
1389 value_type* __t = __vp_;
1390 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1391 *__t ^= __v[__i];
1392}
1393
1394template <class _Tp>
1395template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001396inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001397typename enable_if
1398<
1399 __is_val_expr<_Expr>::value,
1400 void
1401>::type
1402slice_array<_Tp>::operator&=(const _Expr& __v) const
1403{
1404 value_type* __t = __vp_;
1405 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1406 *__t &= __v[__i];
1407}
1408
1409template <class _Tp>
1410template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001411inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001412typename enable_if
1413<
1414 __is_val_expr<_Expr>::value,
1415 void
1416>::type
1417slice_array<_Tp>::operator|=(const _Expr& __v) const
1418{
1419 value_type* __t = __vp_;
1420 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1421 *__t |= __v[__i];
1422}
1423
1424template <class _Tp>
1425template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001426inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001427typename enable_if
1428<
1429 __is_val_expr<_Expr>::value,
1430 void
1431>::type
1432slice_array<_Tp>::operator<<=(const _Expr& __v) const
1433{
1434 value_type* __t = __vp_;
1435 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1436 *__t <<= __v[__i];
1437}
1438
1439template <class _Tp>
1440template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001441inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001442typename enable_if
1443<
1444 __is_val_expr<_Expr>::value,
1445 void
1446>::type
1447slice_array<_Tp>::operator>>=(const _Expr& __v) const
1448{
1449 value_type* __t = __vp_;
1450 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1451 *__t >>= __v[__i];
1452}
1453
1454template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001455inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001456void
1457slice_array<_Tp>::operator=(const value_type& __x) const
1458{
1459 value_type* __t = __vp_;
1460 for (size_t __n = __size_; __n; --__n, __t += __stride_)
1461 *__t = __x;
1462}
1463
1464// gslice
1465
Howard Hinnant8331b762013-03-06 23:30:19 +00001466class _LIBCPP_TYPE_VIS gslice
Howard Hinnantc51e1022010-05-11 19:42:16 +00001467{
1468 valarray<size_t> __size_;
1469 valarray<size_t> __stride_;
1470 valarray<size_t> __1d_;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001471
Howard Hinnantc51e1022010-05-11 19:42:16 +00001472public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001474 gslice() {}
Douglas Gregor68902322012-05-19 07:14:17 +00001475
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001477 gslice(size_t __start, const valarray<size_t>& __size,
1478 const valarray<size_t>& __stride)
1479 : __size_(__size),
1480 __stride_(__stride)
1481 {__init(__start);}
1482
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00001483#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001484
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001485 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001486 gslice(size_t __start, const valarray<size_t>& __size,
1487 valarray<size_t>&& __stride)
1488 : __size_(__size),
1489 __stride_(move(__stride))
1490 {__init(__start);}
1491
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001493 gslice(size_t __start, valarray<size_t>&& __size,
1494 const valarray<size_t>& __stride)
1495 : __size_(move(__size)),
1496 __stride_(__stride)
1497 {__init(__start);}
1498
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001500 gslice(size_t __start, valarray<size_t>&& __size,
1501 valarray<size_t>&& __stride)
1502 : __size_(move(__size)),
1503 __stride_(move(__stride))
1504 {__init(__start);}
1505
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00001506#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001507
1508// gslice(const gslice&) = default;
1509// gslice(gslice&&) = default;
1510// gslice& operator=(const gslice&) = default;
1511// gslice& operator=(gslice&&) = default;
1512
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001514 size_t start() const {return __1d_.size() ? __1d_[0] : 0;}
1515
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001516 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001517 valarray<size_t> size() const {return __size_;}
1518
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001520 valarray<size_t> stride() const {return __stride_;}
1521
1522private:
1523 void __init(size_t __start);
1524
1525 template <class> friend class gslice_array;
1526 template <class> friend class valarray;
1527 template <class> friend class __val_expr;
1528};
1529
1530// gslice_array
1531
1532template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001533class _LIBCPP_TEMPLATE_VIS gslice_array
Howard Hinnantc51e1022010-05-11 19:42:16 +00001534{
1535public:
1536 typedef _Tp value_type;
1537
1538private:
1539 value_type* __vp_;
1540 valarray<size_t> __1d_;
1541
1542public:
1543 template <class _Expr>
1544 typename enable_if
1545 <
1546 __is_val_expr<_Expr>::value,
1547 void
1548 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001550 operator=(const _Expr& __v) const;
1551
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
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001643 const gslice_array& operator=(const gslice_array& __ga) const;
1644
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001646 void operator=(const value_type& __x) const;
1647
1648// gslice_array(const gslice_array&) = default;
1649// gslice_array(gslice_array&&) = default;
1650// gslice_array& operator=(const gslice_array&) = default;
1651// gslice_array& operator=(gslice_array&&) = default;
1652
1653private:
Howard Hinnantc51e1022010-05-11 19:42:16 +00001654 gslice_array(const gslice& __gs, const valarray<value_type>& __v)
1655 : __vp_(const_cast<value_type*>(__v.__begin_)),
1656 __1d_(__gs.__1d_)
1657 {}
1658
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00001659#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001660 gslice_array(gslice&& __gs, const valarray<value_type>& __v)
1661 : __vp_(const_cast<value_type*>(__v.__begin_)),
1662 __1d_(move(__gs.__1d_))
1663 {}
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00001664#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001665
1666 template <class> friend class valarray;
1667};
1668
1669template <class _Tp>
1670template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001671inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001672typename enable_if
1673<
1674 __is_val_expr<_Expr>::value,
1675 void
1676>::type
1677gslice_array<_Tp>::operator=(const _Expr& __v) const
1678{
1679 typedef const size_t* _Ip;
1680 size_t __j = 0;
1681 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1682 __vp_[*__i] = __v[__j];
1683}
1684
1685template <class _Tp>
1686template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001687inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001688typename enable_if
1689<
1690 __is_val_expr<_Expr>::value,
1691 void
1692>::type
1693gslice_array<_Tp>::operator*=(const _Expr& __v) const
1694{
1695 typedef const size_t* _Ip;
1696 size_t __j = 0;
1697 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1698 __vp_[*__i] *= __v[__j];
1699}
1700
1701template <class _Tp>
1702template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001703inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001704typename enable_if
1705<
1706 __is_val_expr<_Expr>::value,
1707 void
1708>::type
1709gslice_array<_Tp>::operator/=(const _Expr& __v) const
1710{
1711 typedef const size_t* _Ip;
1712 size_t __j = 0;
1713 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1714 __vp_[*__i] /= __v[__j];
1715}
1716
1717template <class _Tp>
1718template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001719inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001720typename enable_if
1721<
1722 __is_val_expr<_Expr>::value,
1723 void
1724>::type
1725gslice_array<_Tp>::operator%=(const _Expr& __v) const
1726{
1727 typedef const size_t* _Ip;
1728 size_t __j = 0;
1729 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1730 __vp_[*__i] %= __v[__j];
1731}
1732
1733template <class _Tp>
1734template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001735inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001736typename enable_if
1737<
1738 __is_val_expr<_Expr>::value,
1739 void
1740>::type
1741gslice_array<_Tp>::operator+=(const _Expr& __v) const
1742{
1743 typedef const size_t* _Ip;
1744 size_t __j = 0;
1745 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1746 __vp_[*__i] += __v[__j];
1747}
1748
1749template <class _Tp>
1750template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001751inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001752typename enable_if
1753<
1754 __is_val_expr<_Expr>::value,
1755 void
1756>::type
1757gslice_array<_Tp>::operator-=(const _Expr& __v) const
1758{
1759 typedef const size_t* _Ip;
1760 size_t __j = 0;
1761 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1762 __vp_[*__i] -= __v[__j];
1763}
1764
1765template <class _Tp>
1766template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001767inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001768typename enable_if
1769<
1770 __is_val_expr<_Expr>::value,
1771 void
1772>::type
1773gslice_array<_Tp>::operator^=(const _Expr& __v) const
1774{
1775 typedef const size_t* _Ip;
1776 size_t __j = 0;
1777 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1778 __vp_[*__i] ^= __v[__j];
1779}
1780
1781template <class _Tp>
1782template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001783inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001784typename enable_if
1785<
1786 __is_val_expr<_Expr>::value,
1787 void
1788>::type
1789gslice_array<_Tp>::operator&=(const _Expr& __v) const
1790{
1791 typedef const size_t* _Ip;
1792 size_t __j = 0;
1793 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1794 __vp_[*__i] &= __v[__j];
1795}
1796
1797template <class _Tp>
1798template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001799inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001800typename enable_if
1801<
1802 __is_val_expr<_Expr>::value,
1803 void
1804>::type
1805gslice_array<_Tp>::operator|=(const _Expr& __v) const
1806{
1807 typedef const size_t* _Ip;
1808 size_t __j = 0;
1809 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1810 __vp_[*__i] |= __v[__j];
1811}
1812
1813template <class _Tp>
1814template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001815inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001816typename enable_if
1817<
1818 __is_val_expr<_Expr>::value,
1819 void
1820>::type
1821gslice_array<_Tp>::operator<<=(const _Expr& __v) const
1822{
1823 typedef const size_t* _Ip;
1824 size_t __j = 0;
1825 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1826 __vp_[*__i] <<= __v[__j];
1827}
1828
1829template <class _Tp>
1830template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001831inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001832typename enable_if
1833<
1834 __is_val_expr<_Expr>::value,
1835 void
1836>::type
1837gslice_array<_Tp>::operator>>=(const _Expr& __v) const
1838{
1839 typedef const size_t* _Ip;
1840 size_t __j = 0;
1841 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1842 __vp_[*__i] >>= __v[__j];
1843}
1844
1845template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001846inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001847const gslice_array<_Tp>&
1848gslice_array<_Tp>::operator=(const gslice_array& __ga) const
1849{
1850 typedef const size_t* _Ip;
1851 const value_type* __s = __ga.__vp_;
1852 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_;
1853 __i != __e; ++__i, ++__j)
1854 __vp_[*__i] = __s[*__j];
1855 return *this;
1856}
1857
1858template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001859inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001860void
1861gslice_array<_Tp>::operator=(const value_type& __x) const
1862{
1863 typedef const size_t* _Ip;
1864 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1865 __vp_[*__i] = __x;
1866}
1867
1868// mask_array
1869
1870template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001871class _LIBCPP_TEMPLATE_VIS mask_array
Howard Hinnantc51e1022010-05-11 19:42:16 +00001872{
1873public:
1874 typedef _Tp value_type;
1875
1876private:
1877 value_type* __vp_;
1878 valarray<size_t> __1d_;
1879
1880public:
1881 template <class _Expr>
1882 typename enable_if
1883 <
1884 __is_val_expr<_Expr>::value,
1885 void
1886 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001888 operator=(const _Expr& __v) const;
1889
1890 template <class _Expr>
1891 typename enable_if
1892 <
1893 __is_val_expr<_Expr>::value,
1894 void
1895 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001897 operator*=(const _Expr& __v) const;
1898
1899 template <class _Expr>
1900 typename enable_if
1901 <
1902 __is_val_expr<_Expr>::value,
1903 void
1904 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001906 operator/=(const _Expr& __v) const;
1907
1908 template <class _Expr>
1909 typename enable_if
1910 <
1911 __is_val_expr<_Expr>::value,
1912 void
1913 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001915 operator%=(const _Expr& __v) const;
1916
1917 template <class _Expr>
1918 typename enable_if
1919 <
1920 __is_val_expr<_Expr>::value,
1921 void
1922 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001924 operator+=(const _Expr& __v) const;
1925
1926 template <class _Expr>
1927 typename enable_if
1928 <
1929 __is_val_expr<_Expr>::value,
1930 void
1931 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001932 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001933 operator-=(const _Expr& __v) const;
1934
1935 template <class _Expr>
1936 typename enable_if
1937 <
1938 __is_val_expr<_Expr>::value,
1939 void
1940 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001941 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001942 operator^=(const _Expr& __v) const;
1943
1944 template <class _Expr>
1945 typename enable_if
1946 <
1947 __is_val_expr<_Expr>::value,
1948 void
1949 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001951 operator&=(const _Expr& __v) const;
1952
1953 template <class _Expr>
1954 typename enable_if
1955 <
1956 __is_val_expr<_Expr>::value,
1957 void
1958 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001959 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001960 operator|=(const _Expr& __v) const;
1961
1962 template <class _Expr>
1963 typename enable_if
1964 <
1965 __is_val_expr<_Expr>::value,
1966 void
1967 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001968 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001969 operator<<=(const _Expr& __v) const;
1970
1971 template <class _Expr>
1972 typename enable_if
1973 <
1974 __is_val_expr<_Expr>::value,
1975 void
1976 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001977 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001978 operator>>=(const _Expr& __v) const;
1979
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001981 const mask_array& operator=(const mask_array& __ma) const;
1982
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001983 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001984 void operator=(const value_type& __x) const;
1985
1986// mask_array(const mask_array&) = default;
1987// mask_array(mask_array&&) = default;
1988// mask_array& operator=(const mask_array&) = default;
1989// mask_array& operator=(mask_array&&) = default;
1990
1991private:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001992 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001993 mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
1994 : __vp_(const_cast<value_type*>(__v.__begin_)),
Howard Hinnant28b24882011-12-01 20:21:04 +00001995 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001996 {
1997 size_t __j = 0;
1998 for (size_t __i = 0; __i < __vb.size(); ++__i)
1999 if (__vb[__i])
2000 __1d_[__j++] = __i;
2001 }
2002
2003 template <class> friend class valarray;
2004};
2005
2006template <class _Tp>
2007template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002008inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002009typename enable_if
2010<
2011 __is_val_expr<_Expr>::value,
2012 void
2013>::type
2014mask_array<_Tp>::operator=(const _Expr& __v) const
2015{
2016 size_t __n = __1d_.size();
2017 for (size_t __i = 0; __i < __n; ++__i)
2018 __vp_[__1d_[__i]] = __v[__i];
2019}
2020
2021template <class _Tp>
2022template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002023inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002024typename enable_if
2025<
2026 __is_val_expr<_Expr>::value,
2027 void
2028>::type
2029mask_array<_Tp>::operator*=(const _Expr& __v) const
2030{
2031 size_t __n = __1d_.size();
2032 for (size_t __i = 0; __i < __n; ++__i)
2033 __vp_[__1d_[__i]] *= __v[__i];
2034}
2035
2036template <class _Tp>
2037template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002038inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002039typename enable_if
2040<
2041 __is_val_expr<_Expr>::value,
2042 void
2043>::type
2044mask_array<_Tp>::operator/=(const _Expr& __v) const
2045{
2046 size_t __n = __1d_.size();
2047 for (size_t __i = 0; __i < __n; ++__i)
2048 __vp_[__1d_[__i]] /= __v[__i];
2049}
2050
2051template <class _Tp>
2052template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002053inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002054typename enable_if
2055<
2056 __is_val_expr<_Expr>::value,
2057 void
2058>::type
2059mask_array<_Tp>::operator%=(const _Expr& __v) const
2060{
2061 size_t __n = __1d_.size();
2062 for (size_t __i = 0; __i < __n; ++__i)
2063 __vp_[__1d_[__i]] %= __v[__i];
2064}
2065
2066template <class _Tp>
2067template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002068inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002069typename enable_if
2070<
2071 __is_val_expr<_Expr>::value,
2072 void
2073>::type
2074mask_array<_Tp>::operator+=(const _Expr& __v) const
2075{
2076 size_t __n = __1d_.size();
2077 for (size_t __i = 0; __i < __n; ++__i)
2078 __vp_[__1d_[__i]] += __v[__i];
2079}
2080
2081template <class _Tp>
2082template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002083inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002084typename enable_if
2085<
2086 __is_val_expr<_Expr>::value,
2087 void
2088>::type
2089mask_array<_Tp>::operator-=(const _Expr& __v) const
2090{
2091 size_t __n = __1d_.size();
2092 for (size_t __i = 0; __i < __n; ++__i)
2093 __vp_[__1d_[__i]] -= __v[__i];
2094}
2095
2096template <class _Tp>
2097template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002098inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002099typename enable_if
2100<
2101 __is_val_expr<_Expr>::value,
2102 void
2103>::type
2104mask_array<_Tp>::operator^=(const _Expr& __v) const
2105{
2106 size_t __n = __1d_.size();
2107 for (size_t __i = 0; __i < __n; ++__i)
2108 __vp_[__1d_[__i]] ^= __v[__i];
2109}
2110
2111template <class _Tp>
2112template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002113inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002114typename enable_if
2115<
2116 __is_val_expr<_Expr>::value,
2117 void
2118>::type
2119mask_array<_Tp>::operator&=(const _Expr& __v) const
2120{
2121 size_t __n = __1d_.size();
2122 for (size_t __i = 0; __i < __n; ++__i)
2123 __vp_[__1d_[__i]] &= __v[__i];
2124}
2125
2126template <class _Tp>
2127template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002128inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002129typename enable_if
2130<
2131 __is_val_expr<_Expr>::value,
2132 void
2133>::type
2134mask_array<_Tp>::operator|=(const _Expr& __v) const
2135{
2136 size_t __n = __1d_.size();
2137 for (size_t __i = 0; __i < __n; ++__i)
2138 __vp_[__1d_[__i]] |= __v[__i];
2139}
2140
2141template <class _Tp>
2142template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002143inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002144typename enable_if
2145<
2146 __is_val_expr<_Expr>::value,
2147 void
2148>::type
2149mask_array<_Tp>::operator<<=(const _Expr& __v) const
2150{
2151 size_t __n = __1d_.size();
2152 for (size_t __i = 0; __i < __n; ++__i)
2153 __vp_[__1d_[__i]] <<= __v[__i];
2154}
2155
2156template <class _Tp>
2157template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002158inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002159typename enable_if
2160<
2161 __is_val_expr<_Expr>::value,
2162 void
2163>::type
2164mask_array<_Tp>::operator>>=(const _Expr& __v) const
2165{
2166 size_t __n = __1d_.size();
2167 for (size_t __i = 0; __i < __n; ++__i)
2168 __vp_[__1d_[__i]] >>= __v[__i];
2169}
2170
2171template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002172inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002173const mask_array<_Tp>&
2174mask_array<_Tp>::operator=(const mask_array& __ma) const
2175{
2176 size_t __n = __1d_.size();
2177 for (size_t __i = 0; __i < __n; ++__i)
2178 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
Eric Fiselier3b80ce92014-08-12 00:06:58 +00002179 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002180}
2181
2182template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002183inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002184void
2185mask_array<_Tp>::operator=(const value_type& __x) const
2186{
2187 size_t __n = __1d_.size();
2188 for (size_t __i = 0; __i < __n; ++__i)
2189 __vp_[__1d_[__i]] = __x;
2190}
2191
2192template <class _ValExpr>
2193class __mask_expr
2194{
2195 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2196public:
2197 typedef typename _RmExpr::value_type value_type;
2198 typedef value_type result_type;
2199
2200private:
2201 _ValExpr __expr_;
2202 valarray<size_t> __1d_;
2203
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002204 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002205 __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
2206 : __expr_(__e),
Howard Hinnant28b24882011-12-01 20:21:04 +00002207 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002208 {
2209 size_t __j = 0;
2210 for (size_t __i = 0; __i < __vb.size(); ++__i)
2211 if (__vb[__i])
2212 __1d_[__j++] = __i;
2213 }
2214
2215public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002216 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002217 result_type operator[](size_t __i) const
2218 {return __expr_[__1d_[__i]];}
2219
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002220 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002221 size_t size() const {return __1d_.size();}
2222
Eric Fiselier7b31ed02019-04-02 08:05:23 +00002223 template <class> friend class __val_expr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002224 template <class> friend class valarray;
2225};
2226
2227// indirect_array
2228
2229template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002230class _LIBCPP_TEMPLATE_VIS indirect_array
Howard Hinnantc51e1022010-05-11 19:42:16 +00002231{
2232public:
2233 typedef _Tp value_type;
2234
2235private:
2236 value_type* __vp_;
2237 valarray<size_t> __1d_;
2238
2239public:
2240 template <class _Expr>
2241 typename enable_if
2242 <
2243 __is_val_expr<_Expr>::value,
2244 void
2245 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002247 operator=(const _Expr& __v) const;
2248
2249 template <class _Expr>
2250 typename enable_if
2251 <
2252 __is_val_expr<_Expr>::value,
2253 void
2254 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002256 operator*=(const _Expr& __v) const;
2257
2258 template <class _Expr>
2259 typename enable_if
2260 <
2261 __is_val_expr<_Expr>::value,
2262 void
2263 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002264 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002265 operator/=(const _Expr& __v) const;
2266
2267 template <class _Expr>
2268 typename enable_if
2269 <
2270 __is_val_expr<_Expr>::value,
2271 void
2272 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002273 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002274 operator%=(const _Expr& __v) const;
2275
2276 template <class _Expr>
2277 typename enable_if
2278 <
2279 __is_val_expr<_Expr>::value,
2280 void
2281 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002282 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002283 operator+=(const _Expr& __v) const;
2284
2285 template <class _Expr>
2286 typename enable_if
2287 <
2288 __is_val_expr<_Expr>::value,
2289 void
2290 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002292 operator-=(const _Expr& __v) const;
2293
2294 template <class _Expr>
2295 typename enable_if
2296 <
2297 __is_val_expr<_Expr>::value,
2298 void
2299 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002301 operator^=(const _Expr& __v) const;
2302
2303 template <class _Expr>
2304 typename enable_if
2305 <
2306 __is_val_expr<_Expr>::value,
2307 void
2308 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002309 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002310 operator&=(const _Expr& __v) const;
2311
2312 template <class _Expr>
2313 typename enable_if
2314 <
2315 __is_val_expr<_Expr>::value,
2316 void
2317 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002318 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002319 operator|=(const _Expr& __v) const;
2320
2321 template <class _Expr>
2322 typename enable_if
2323 <
2324 __is_val_expr<_Expr>::value,
2325 void
2326 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002327 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002328 operator<<=(const _Expr& __v) const;
2329
2330 template <class _Expr>
2331 typename enable_if
2332 <
2333 __is_val_expr<_Expr>::value,
2334 void
2335 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002336 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002337 operator>>=(const _Expr& __v) const;
2338
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002339 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002340 const indirect_array& operator=(const indirect_array& __ia) const;
2341
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002342 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002343 void operator=(const value_type& __x) const;
2344
2345// indirect_array(const indirect_array&) = default;
2346// indirect_array(indirect_array&&) = default;
2347// indirect_array& operator=(const indirect_array&) = default;
2348// indirect_array& operator=(indirect_array&&) = default;
2349
2350private:
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
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002365#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
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002584#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_ =
2753 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00002754 static_cast<result_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002755 _VSTD::__libcpp_allocate(__n * sizeof(result_type), _LIBCPP_ALIGNOF(result_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002756 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
2757 ::new (__r.__end_) result_type(__expr_[__i]);
2758 }
2759 return __r;
2760}
2761
2762// valarray
2763
2764template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002765inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002766valarray<_Tp>::valarray(size_t __n)
2767 : __begin_(0),
2768 __end_(0)
2769{
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002770 if (__n)
2771 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002772 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002773 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002774#ifndef _LIBCPP_NO_EXCEPTIONS
2775 try
2776 {
2777#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002778 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002779 ::new (__end_) value_type();
2780#ifndef _LIBCPP_NO_EXCEPTIONS
2781 }
2782 catch (...)
2783 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002784 __clear(__n);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002785 throw;
2786 }
2787#endif // _LIBCPP_NO_EXCEPTIONS
2788 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002789}
2790
2791template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002792inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002793valarray<_Tp>::valarray(const value_type& __x, size_t __n)
2794 : __begin_(0),
2795 __end_(0)
2796{
2797 resize(__n, __x);
2798}
2799
2800template <class _Tp>
2801valarray<_Tp>::valarray(const value_type* __p, size_t __n)
2802 : __begin_(0),
2803 __end_(0)
2804{
2805 if (__n)
2806 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002807 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002808 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002809#ifndef _LIBCPP_NO_EXCEPTIONS
2810 try
2811 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002812#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002813 for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002814 ::new (__end_) value_type(*__p);
2815#ifndef _LIBCPP_NO_EXCEPTIONS
2816 }
2817 catch (...)
2818 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002819 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002820 throw;
2821 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002822#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002823 }
2824}
2825
2826template <class _Tp>
2827valarray<_Tp>::valarray(const valarray& __v)
2828 : __begin_(0),
2829 __end_(0)
2830{
2831 if (__v.size())
2832 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002833 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002834 _VSTD::__libcpp_allocate(__v.size() * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002835#ifndef _LIBCPP_NO_EXCEPTIONS
2836 try
2837 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002838#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002839 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
2840 ::new (__end_) value_type(*__p);
2841#ifndef _LIBCPP_NO_EXCEPTIONS
2842 }
2843 catch (...)
2844 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002845 __clear(__v.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002846 throw;
2847 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002848#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002849 }
2850}
2851
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002852#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002853
2854template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002855inline
Howard Hinnant298aed92012-07-21 00:51:28 +00002856valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002857 : __begin_(__v.__begin_),
2858 __end_(__v.__end_)
2859{
2860 __v.__begin_ = __v.__end_ = nullptr;
2861}
2862
2863template <class _Tp>
2864valarray<_Tp>::valarray(initializer_list<value_type> __il)
2865 : __begin_(0),
2866 __end_(0)
2867{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002868 const size_t __n = __il.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002869 if (__n)
2870 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002871 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002872_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002873#ifndef _LIBCPP_NO_EXCEPTIONS
2874 try
2875 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002876#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002877 size_t __n_left = __n;
2878 for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002879 ::new (__end_) value_type(*__p);
2880#ifndef _LIBCPP_NO_EXCEPTIONS
2881 }
2882 catch (...)
2883 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002884 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002885 throw;
2886 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002887#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002888 }
2889}
2890
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002891#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002892
2893template <class _Tp>
2894valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
2895 : __begin_(0),
2896 __end_(0)
2897{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002898 const size_t __n = __sa.__size_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002899 if (__n)
2900 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002901 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002902 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002903#ifndef _LIBCPP_NO_EXCEPTIONS
2904 try
2905 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002906#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002907 size_t __n_left = __n;
2908 for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002909 ::new (__end_) value_type(*__p);
2910#ifndef _LIBCPP_NO_EXCEPTIONS
2911 }
2912 catch (...)
2913 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002914 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002915 throw;
2916 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002917#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002918 }
2919}
2920
2921template <class _Tp>
2922valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
2923 : __begin_(0),
2924 __end_(0)
2925{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002926 const size_t __n = __ga.__1d_.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002927 if (__n)
2928 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002929 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002930 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002931#ifndef _LIBCPP_NO_EXCEPTIONS
2932 try
2933 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002934#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002935 typedef const size_t* _Ip;
2936 const value_type* __s = __ga.__vp_;
2937 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2938 __i != __e; ++__i, ++__end_)
2939 ::new (__end_) value_type(__s[*__i]);
2940#ifndef _LIBCPP_NO_EXCEPTIONS
2941 }
2942 catch (...)
2943 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002944 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002945 throw;
2946 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002947#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002948 }
2949}
2950
2951template <class _Tp>
2952valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
2953 : __begin_(0),
2954 __end_(0)
2955{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002956 const size_t __n = __ma.__1d_.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002957 if (__n)
2958 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002959 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002960 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002961#ifndef _LIBCPP_NO_EXCEPTIONS
2962 try
2963 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002964#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002965 typedef const size_t* _Ip;
2966 const value_type* __s = __ma.__vp_;
2967 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2968 __i != __e; ++__i, ++__end_)
2969 ::new (__end_) value_type(__s[*__i]);
2970#ifndef _LIBCPP_NO_EXCEPTIONS
2971 }
2972 catch (...)
2973 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002974 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002975 throw;
2976 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002977#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002978 }
2979}
2980
2981template <class _Tp>
2982valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
2983 : __begin_(0),
2984 __end_(0)
2985{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002986 const size_t __n = __ia.__1d_.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002987 if (__n)
2988 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002989 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002990 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002991#ifndef _LIBCPP_NO_EXCEPTIONS
2992 try
2993 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002994#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002995 typedef const size_t* _Ip;
2996 const value_type* __s = __ia.__vp_;
2997 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2998 __i != __e; ++__i, ++__end_)
2999 ::new (__end_) value_type(__s[*__i]);
3000#ifndef _LIBCPP_NO_EXCEPTIONS
3001 }
3002 catch (...)
3003 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00003004 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003005 throw;
3006 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003007#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00003008 }
3009}
3010
3011template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003012inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003013valarray<_Tp>::~valarray()
3014{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003015 __clear(size());
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003016}
3017
3018template <class _Tp>
3019valarray<_Tp>&
3020valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l)
3021{
3022 size_t __n = __l - __f;
3023 if (size() != __n)
3024 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00003025 __clear(size());
Eric Fiselier06548ab2018-03-22 04:42:56 +00003026 __begin_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003027 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003028 __end_ = __begin_ + __n;
3029 _VSTD::uninitialized_copy(__f, __l, __begin_);
3030 } else {
3031 _VSTD::copy(__f, __l, __begin_);
3032 }
3033 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003034}
3035
3036template <class _Tp>
3037valarray<_Tp>&
3038valarray<_Tp>::operator=(const valarray& __v)
3039{
3040 if (this != &__v)
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003041 return __assign_range(__v.__begin_, __v.__end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003042 return *this;
3043}
3044
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003045#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003046
3047template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003048inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003049valarray<_Tp>&
Howard Hinnant298aed92012-07-21 00:51:28 +00003050valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003051{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003052 __clear(size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003053 __begin_ = __v.__begin_;
3054 __end_ = __v.__end_;
3055 __v.__begin_ = nullptr;
3056 __v.__end_ = nullptr;
3057 return *this;
3058}
3059
3060template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003061inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003062valarray<_Tp>&
3063valarray<_Tp>::operator=(initializer_list<value_type> __il)
3064{
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003065 return __assign_range(__il.begin(), __il.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003066}
3067
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003068#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003069
3070template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003071inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003072valarray<_Tp>&
3073valarray<_Tp>::operator=(const value_type& __x)
3074{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003075 _VSTD::fill(__begin_, __end_, __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003076 return *this;
3077}
3078
3079template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003080inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003081valarray<_Tp>&
3082valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
3083{
3084 value_type* __t = __begin_;
3085 const value_type* __s = __sa.__vp_;
3086 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
3087 *__t = *__s;
3088 return *this;
3089}
3090
3091template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003092inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003093valarray<_Tp>&
3094valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
3095{
3096 typedef const size_t* _Ip;
3097 value_type* __t = __begin_;
3098 const value_type* __s = __ga.__vp_;
3099 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
3100 __i != __e; ++__i, ++__t)
3101 *__t = __s[*__i];
3102 return *this;
3103}
3104
3105template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003106inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003107valarray<_Tp>&
3108valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
3109{
3110 typedef const size_t* _Ip;
3111 value_type* __t = __begin_;
3112 const value_type* __s = __ma.__vp_;
3113 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
3114 __i != __e; ++__i, ++__t)
3115 *__t = __s[*__i];
3116 return *this;
3117}
3118
3119template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003120inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003121valarray<_Tp>&
3122valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
3123{
3124 typedef const size_t* _Ip;
3125 value_type* __t = __begin_;
3126 const value_type* __s = __ia.__vp_;
3127 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
3128 __i != __e; ++__i, ++__t)
3129 *__t = __s[*__i];
3130 return *this;
3131}
3132
3133template <class _Tp>
Howard Hinnant329cd412011-07-27 23:19:59 +00003134template <class _ValExpr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003135inline
Howard Hinnant329cd412011-07-27 23:19:59 +00003136valarray<_Tp>&
3137valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
3138{
3139 size_t __n = __v.size();
3140 if (size() != __n)
3141 resize(__n);
3142 value_type* __t = __begin_;
3143 for (size_t __i = 0; __i != __n; ++__t, ++__i)
3144 *__t = result_type(__v[__i]);
3145 return *this;
3146}
3147
3148template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003149inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003150__val_expr<__slice_expr<const valarray<_Tp>&> >
3151valarray<_Tp>::operator[](slice __s) const
3152{
3153 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
3154}
3155
3156template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003157inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003158slice_array<_Tp>
3159valarray<_Tp>::operator[](slice __s)
3160{
3161 return slice_array<value_type>(__s, *this);
3162}
3163
3164template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003165inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003166__val_expr<__indirect_expr<const valarray<_Tp>&> >
3167valarray<_Tp>::operator[](const gslice& __gs) const
3168{
3169 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
3170}
3171
3172template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003173inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003174gslice_array<_Tp>
3175valarray<_Tp>::operator[](const gslice& __gs)
3176{
3177 return gslice_array<value_type>(__gs, *this);
3178}
3179
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003180#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003181
3182template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003183inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003184__val_expr<__indirect_expr<const valarray<_Tp>&> >
3185valarray<_Tp>::operator[](gslice&& __gs) const
3186{
3187 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
3188}
3189
3190template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003191inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003192gslice_array<_Tp>
3193valarray<_Tp>::operator[](gslice&& __gs)
3194{
3195 return gslice_array<value_type>(move(__gs), *this);
3196}
3197
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003198#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003199
3200template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003201inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003202__val_expr<__mask_expr<const valarray<_Tp>&> >
3203valarray<_Tp>::operator[](const valarray<bool>& __vb) const
3204{
3205 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
3206}
3207
3208template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003209inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003210mask_array<_Tp>
3211valarray<_Tp>::operator[](const valarray<bool>& __vb)
3212{
3213 return mask_array<value_type>(__vb, *this);
3214}
3215
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003216#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003217
3218template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003219inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003220__val_expr<__mask_expr<const valarray<_Tp>&> >
3221valarray<_Tp>::operator[](valarray<bool>&& __vb) const
3222{
3223 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
3224}
3225
3226template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003227inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003228mask_array<_Tp>
3229valarray<_Tp>::operator[](valarray<bool>&& __vb)
3230{
3231 return mask_array<value_type>(move(__vb), *this);
3232}
3233
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003234#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003235
3236template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003237inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003238__val_expr<__indirect_expr<const valarray<_Tp>&> >
3239valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
3240{
3241 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
3242}
3243
3244template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003245inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003246indirect_array<_Tp>
3247valarray<_Tp>::operator[](const valarray<size_t>& __vs)
3248{
3249 return indirect_array<value_type>(__vs, *this);
3250}
3251
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003252#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003253
3254template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003255inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003256__val_expr<__indirect_expr<const valarray<_Tp>&> >
3257valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
3258{
3259 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
3260}
3261
3262template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003263inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003264indirect_array<_Tp>
3265valarray<_Tp>::operator[](valarray<size_t>&& __vs)
3266{
3267 return indirect_array<value_type>(move(__vs), *this);
3268}
3269
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003270#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003271
3272template <class _Tp>
3273valarray<_Tp>
3274valarray<_Tp>::operator+() const
3275{
3276 valarray<value_type> __r;
3277 size_t __n = size();
3278 if (__n)
3279 {
3280 __r.__begin_ =
3281 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003282 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003283 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003284 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3285 ::new (__r.__end_) value_type(+*__p);
3286 }
3287 return __r;
3288}
3289
3290template <class _Tp>
3291valarray<_Tp>
3292valarray<_Tp>::operator-() const
3293{
3294 valarray<value_type> __r;
3295 size_t __n = size();
3296 if (__n)
3297 {
3298 __r.__begin_ =
3299 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003300 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003301 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003302 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3303 ::new (__r.__end_) value_type(-*__p);
3304 }
3305 return __r;
3306}
3307
3308template <class _Tp>
3309valarray<_Tp>
3310valarray<_Tp>::operator~() const
3311{
3312 valarray<value_type> __r;
3313 size_t __n = size();
3314 if (__n)
3315 {
3316 __r.__begin_ =
3317 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003318 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003319 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003320 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3321 ::new (__r.__end_) value_type(~*__p);
3322 }
3323 return __r;
3324}
3325
3326template <class _Tp>
3327valarray<bool>
3328valarray<_Tp>::operator!() const
3329{
3330 valarray<bool> __r;
3331 size_t __n = size();
3332 if (__n)
3333 {
3334 __r.__begin_ =
3335 __r.__end_ =
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003336 static_cast<bool*>(_VSTD::__libcpp_allocate(__n * sizeof(bool), _LIBCPP_ALIGNOF(bool)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003337 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3338 ::new (__r.__end_) bool(!*__p);
3339 }
3340 return __r;
3341}
3342
3343template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003344inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003345valarray<_Tp>&
3346valarray<_Tp>::operator*=(const value_type& __x)
3347{
3348 for (value_type* __p = __begin_; __p != __end_; ++__p)
3349 *__p *= __x;
3350 return *this;
3351}
3352
3353template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003354inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003355valarray<_Tp>&
3356valarray<_Tp>::operator/=(const value_type& __x)
3357{
3358 for (value_type* __p = __begin_; __p != __end_; ++__p)
3359 *__p /= __x;
3360 return *this;
3361}
3362
3363template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003364inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003365valarray<_Tp>&
3366valarray<_Tp>::operator%=(const value_type& __x)
3367{
3368 for (value_type* __p = __begin_; __p != __end_; ++__p)
3369 *__p %= __x;
3370 return *this;
3371}
3372
3373template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003374inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003375valarray<_Tp>&
3376valarray<_Tp>::operator+=(const value_type& __x)
3377{
3378 for (value_type* __p = __begin_; __p != __end_; ++__p)
3379 *__p += __x;
3380 return *this;
3381}
3382
3383template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003384inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003385valarray<_Tp>&
3386valarray<_Tp>::operator-=(const value_type& __x)
3387{
3388 for (value_type* __p = __begin_; __p != __end_; ++__p)
3389 *__p -= __x;
3390 return *this;
3391}
3392
3393template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003394inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003395valarray<_Tp>&
3396valarray<_Tp>::operator^=(const value_type& __x)
3397{
3398 for (value_type* __p = __begin_; __p != __end_; ++__p)
3399 *__p ^= __x;
3400 return *this;
3401}
3402
3403template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003404inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003405valarray<_Tp>&
3406valarray<_Tp>::operator&=(const value_type& __x)
3407{
3408 for (value_type* __p = __begin_; __p != __end_; ++__p)
3409 *__p &= __x;
3410 return *this;
3411}
3412
3413template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003414inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003415valarray<_Tp>&
3416valarray<_Tp>::operator|=(const value_type& __x)
3417{
3418 for (value_type* __p = __begin_; __p != __end_; ++__p)
3419 *__p |= __x;
3420 return *this;
3421}
3422
3423template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003424inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003425valarray<_Tp>&
3426valarray<_Tp>::operator<<=(const value_type& __x)
3427{
3428 for (value_type* __p = __begin_; __p != __end_; ++__p)
3429 *__p <<= __x;
3430 return *this;
3431}
3432
3433template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003434inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003435valarray<_Tp>&
3436valarray<_Tp>::operator>>=(const value_type& __x)
3437{
3438 for (value_type* __p = __begin_; __p != __end_; ++__p)
3439 *__p >>= __x;
3440 return *this;
3441}
3442
3443template <class _Tp>
3444template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003445inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003446typename enable_if
3447<
3448 __is_val_expr<_Expr>::value,
3449 valarray<_Tp>&
3450>::type
3451valarray<_Tp>::operator*=(const _Expr& __v)
3452{
3453 size_t __i = 0;
3454 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3455 *__t *= __v[__i];
3456 return *this;
3457}
3458
3459template <class _Tp>
3460template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003461inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003462typename enable_if
3463<
3464 __is_val_expr<_Expr>::value,
3465 valarray<_Tp>&
3466>::type
3467valarray<_Tp>::operator/=(const _Expr& __v)
3468{
3469 size_t __i = 0;
3470 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3471 *__t /= __v[__i];
3472 return *this;
3473}
3474
3475template <class _Tp>
3476template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003477inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003478typename enable_if
3479<
3480 __is_val_expr<_Expr>::value,
3481 valarray<_Tp>&
3482>::type
3483valarray<_Tp>::operator%=(const _Expr& __v)
3484{
3485 size_t __i = 0;
3486 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3487 *__t %= __v[__i];
3488 return *this;
3489}
3490
3491template <class _Tp>
3492template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003493inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003494typename enable_if
3495<
3496 __is_val_expr<_Expr>::value,
3497 valarray<_Tp>&
3498>::type
3499valarray<_Tp>::operator+=(const _Expr& __v)
3500{
3501 size_t __i = 0;
3502 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3503 *__t += __v[__i];
3504 return *this;
3505}
3506
3507template <class _Tp>
3508template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003509inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003510typename enable_if
3511<
3512 __is_val_expr<_Expr>::value,
3513 valarray<_Tp>&
3514>::type
3515valarray<_Tp>::operator-=(const _Expr& __v)
3516{
3517 size_t __i = 0;
3518 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3519 *__t -= __v[__i];
3520 return *this;
3521}
3522
3523template <class _Tp>
3524template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003525inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003526typename enable_if
3527<
3528 __is_val_expr<_Expr>::value,
3529 valarray<_Tp>&
3530>::type
3531valarray<_Tp>::operator^=(const _Expr& __v)
3532{
3533 size_t __i = 0;
3534 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3535 *__t ^= __v[__i];
3536 return *this;
3537}
3538
3539template <class _Tp>
3540template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003541inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003542typename enable_if
3543<
3544 __is_val_expr<_Expr>::value,
3545 valarray<_Tp>&
3546>::type
3547valarray<_Tp>::operator|=(const _Expr& __v)
3548{
3549 size_t __i = 0;
3550 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3551 *__t |= __v[__i];
3552 return *this;
3553}
3554
3555template <class _Tp>
3556template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003557inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003558typename enable_if
3559<
3560 __is_val_expr<_Expr>::value,
3561 valarray<_Tp>&
3562>::type
3563valarray<_Tp>::operator&=(const _Expr& __v)
3564{
3565 size_t __i = 0;
3566 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3567 *__t &= __v[__i];
3568 return *this;
3569}
3570
3571template <class _Tp>
3572template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003573inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003574typename enable_if
3575<
3576 __is_val_expr<_Expr>::value,
3577 valarray<_Tp>&
3578>::type
3579valarray<_Tp>::operator<<=(const _Expr& __v)
3580{
3581 size_t __i = 0;
3582 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3583 *__t <<= __v[__i];
3584 return *this;
3585}
3586
3587template <class _Tp>
3588template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003589inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003590typename enable_if
3591<
3592 __is_val_expr<_Expr>::value,
3593 valarray<_Tp>&
3594>::type
3595valarray<_Tp>::operator>>=(const _Expr& __v)
3596{
3597 size_t __i = 0;
3598 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3599 *__t >>= __v[__i];
3600 return *this;
3601}
3602
3603template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003604inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003605void
Howard Hinnant298aed92012-07-21 00:51:28 +00003606valarray<_Tp>::swap(valarray& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003607{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003608 _VSTD::swap(__begin_, __v.__begin_);
3609 _VSTD::swap(__end_, __v.__end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003610}
3611
3612template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003613inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003614_Tp
3615valarray<_Tp>::sum() const
3616{
3617 if (__begin_ == __end_)
3618 return value_type();
3619 const value_type* __p = __begin_;
3620 _Tp __r = *__p;
3621 for (++__p; __p != __end_; ++__p)
3622 __r += *__p;
3623 return __r;
3624}
3625
3626template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003627inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003628_Tp
3629valarray<_Tp>::min() const
3630{
3631 if (__begin_ == __end_)
3632 return value_type();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003633 return *_VSTD::min_element(__begin_, __end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003634}
3635
3636template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003637inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003638_Tp
3639valarray<_Tp>::max() const
3640{
3641 if (__begin_ == __end_)
3642 return value_type();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003643 return *_VSTD::max_element(__begin_, __end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003644}
3645
3646template <class _Tp>
3647valarray<_Tp>
3648valarray<_Tp>::shift(int __i) const
3649{
3650 valarray<value_type> __r;
3651 size_t __n = size();
3652 if (__n)
3653 {
3654 __r.__begin_ =
3655 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003656 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003657 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003658 const value_type* __sb;
3659 value_type* __tb;
3660 value_type* __te;
3661 if (__i >= 0)
3662 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003663 __i = _VSTD::min(__i, static_cast<int>(__n));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003664 __sb = __begin_ + __i;
3665 __tb = __r.__begin_;
3666 __te = __r.__begin_ + (__n - __i);
3667 }
3668 else
3669 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003670 __i = _VSTD::min(-__i, static_cast<int>(__n));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003671 __sb = __begin_;
3672 __tb = __r.__begin_ + __i;
3673 __te = __r.__begin_ + __n;
3674 }
3675 for (; __r.__end_ != __tb; ++__r.__end_)
3676 ::new (__r.__end_) value_type();
3677 for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
3678 ::new (__r.__end_) value_type(*__sb);
3679 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
3680 ::new (__r.__end_) value_type();
3681 }
3682 return __r;
3683}
3684
3685template <class _Tp>
3686valarray<_Tp>
3687valarray<_Tp>::cshift(int __i) const
3688{
3689 valarray<value_type> __r;
3690 size_t __n = size();
3691 if (__n)
3692 {
3693 __r.__begin_ =
3694 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003695 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003696 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003697 __i %= static_cast<int>(__n);
3698 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
3699 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
3700 ::new (__r.__end_) value_type(*__s);
3701 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
3702 ::new (__r.__end_) value_type(*__s);
3703 }
3704 return __r;
3705}
3706
3707template <class _Tp>
3708valarray<_Tp>
3709valarray<_Tp>::apply(value_type __f(value_type)) const
3710{
3711 valarray<value_type> __r;
3712 size_t __n = size();
3713 if (__n)
3714 {
3715 __r.__begin_ =
3716 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003717 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003718 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003719 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3720 ::new (__r.__end_) value_type(__f(*__p));
3721 }
3722 return __r;
3723}
3724
3725template <class _Tp>
3726valarray<_Tp>
3727valarray<_Tp>::apply(value_type __f(const value_type&)) const
3728{
3729 valarray<value_type> __r;
3730 size_t __n = size();
3731 if (__n)
3732 {
3733 __r.__begin_ =
3734 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003735 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003736 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003737 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3738 ::new (__r.__end_) value_type(__f(*__p));
3739 }
3740 return __r;
3741}
3742
3743template <class _Tp>
Eric Fiseliera119c322018-10-25 17:43:26 +00003744inline
Eric Fiselier2856ef82018-10-25 17:21:30 +00003745void valarray<_Tp>::__clear(size_t __capacity)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003746{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003747 if (__begin_ != nullptr)
3748 {
3749 while (__end_ != __begin_)
3750 (--__end_)->~value_type();
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003751 _VSTD::__libcpp_deallocate(__begin_, __capacity * sizeof(value_type), _LIBCPP_ALIGNOF(value_type));
Eric Fiselier2856ef82018-10-25 17:21:30 +00003752 __begin_ = __end_ = nullptr;
3753 }
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003754}
3755
3756template <class _Tp>
3757void
3758valarray<_Tp>::resize(size_t __n, value_type __x)
3759{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003760 __clear(size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003761 if (__n)
3762 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00003763 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003764 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003765#ifndef _LIBCPP_NO_EXCEPTIONS
3766 try
3767 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003768#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00003769 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003770 ::new (__end_) value_type(__x);
3771#ifndef _LIBCPP_NO_EXCEPTIONS
3772 }
3773 catch (...)
3774 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00003775 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003776 throw;
3777 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003778#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00003779 }
3780}
3781
3782template<class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003783inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003784void
Howard Hinnant298aed92012-07-21 00:51:28 +00003785swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003786{
3787 __x.swap(__y);
3788}
3789
3790template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003791inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003792typename enable_if
3793<
3794 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3795 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
3796>::type
3797operator*(const _Expr1& __x, const _Expr2& __y)
3798{
3799 typedef typename _Expr1::value_type value_type;
3800 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
3801 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
3802}
3803
3804template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003805inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003806typename enable_if
3807<
3808 __is_val_expr<_Expr>::value,
3809 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3810 _Expr, __scalar_expr<typename _Expr::value_type> > >
3811>::type
3812operator*(const _Expr& __x, const typename _Expr::value_type& __y)
3813{
3814 typedef typename _Expr::value_type value_type;
3815 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3816 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3817 __x, __scalar_expr<value_type>(__y, __x.size())));
3818}
3819
3820template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003821inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003822typename enable_if
3823<
3824 __is_val_expr<_Expr>::value,
3825 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3826 __scalar_expr<typename _Expr::value_type>, _Expr> >
3827>::type
3828operator*(const typename _Expr::value_type& __x, const _Expr& __y)
3829{
3830 typedef typename _Expr::value_type value_type;
3831 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3832 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3833 __scalar_expr<value_type>(__x, __y.size()), __y));
3834}
3835
3836template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003837inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003838typename enable_if
3839<
3840 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3841 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
3842>::type
3843operator/(const _Expr1& __x, const _Expr2& __y)
3844{
3845 typedef typename _Expr1::value_type value_type;
3846 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
3847 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
3848}
3849
3850template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003851inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003852typename enable_if
3853<
3854 __is_val_expr<_Expr>::value,
3855 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3856 _Expr, __scalar_expr<typename _Expr::value_type> > >
3857>::type
3858operator/(const _Expr& __x, const typename _Expr::value_type& __y)
3859{
3860 typedef typename _Expr::value_type value_type;
3861 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3862 return __val_expr<_Op>(_Op(divides<value_type>(),
3863 __x, __scalar_expr<value_type>(__y, __x.size())));
3864}
3865
3866template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003867inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003868typename enable_if
3869<
3870 __is_val_expr<_Expr>::value,
3871 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3872 __scalar_expr<typename _Expr::value_type>, _Expr> >
3873>::type
3874operator/(const typename _Expr::value_type& __x, const _Expr& __y)
3875{
3876 typedef typename _Expr::value_type value_type;
3877 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3878 return __val_expr<_Op>(_Op(divides<value_type>(),
3879 __scalar_expr<value_type>(__x, __y.size()), __y));
3880}
3881
3882template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003883inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003884typename enable_if
3885<
3886 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3887 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3888>::type
3889operator%(const _Expr1& __x, const _Expr2& __y)
3890{
3891 typedef typename _Expr1::value_type value_type;
3892 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
3893 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
3894}
3895
3896template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003897inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003898typename enable_if
3899<
3900 __is_val_expr<_Expr>::value,
3901 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3902 _Expr, __scalar_expr<typename _Expr::value_type> > >
3903>::type
3904operator%(const _Expr& __x, const typename _Expr::value_type& __y)
3905{
3906 typedef typename _Expr::value_type value_type;
3907 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3908 return __val_expr<_Op>(_Op(modulus<value_type>(),
3909 __x, __scalar_expr<value_type>(__y, __x.size())));
3910}
3911
3912template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003913inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003914typename enable_if
3915<
3916 __is_val_expr<_Expr>::value,
3917 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3918 __scalar_expr<typename _Expr::value_type>, _Expr> >
3919>::type
3920operator%(const typename _Expr::value_type& __x, const _Expr& __y)
3921{
3922 typedef typename _Expr::value_type value_type;
3923 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3924 return __val_expr<_Op>(_Op(modulus<value_type>(),
3925 __scalar_expr<value_type>(__x, __y.size()), __y));
3926}
3927
3928template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003929inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003930typename enable_if
3931<
3932 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3933 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3934>::type
3935operator+(const _Expr1& __x, const _Expr2& __y)
3936{
3937 typedef typename _Expr1::value_type value_type;
3938 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
3939 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
3940}
3941
3942template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003943inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003944typename enable_if
3945<
3946 __is_val_expr<_Expr>::value,
3947 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3948 _Expr, __scalar_expr<typename _Expr::value_type> > >
3949>::type
3950operator+(const _Expr& __x, const typename _Expr::value_type& __y)
3951{
3952 typedef typename _Expr::value_type value_type;
3953 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3954 return __val_expr<_Op>(_Op(plus<value_type>(),
3955 __x, __scalar_expr<value_type>(__y, __x.size())));
3956}
3957
3958template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003959inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003960typename enable_if
3961<
3962 __is_val_expr<_Expr>::value,
3963 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3964 __scalar_expr<typename _Expr::value_type>, _Expr> >
3965>::type
3966operator+(const typename _Expr::value_type& __x, const _Expr& __y)
3967{
3968 typedef typename _Expr::value_type value_type;
3969 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3970 return __val_expr<_Op>(_Op(plus<value_type>(),
3971 __scalar_expr<value_type>(__x, __y.size()), __y));
3972}
3973
3974template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003975inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003976typename enable_if
3977<
3978 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3979 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3980>::type
3981operator-(const _Expr1& __x, const _Expr2& __y)
3982{
3983 typedef typename _Expr1::value_type value_type;
3984 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
3985 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
3986}
3987
3988template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003989inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003990typename enable_if
3991<
3992 __is_val_expr<_Expr>::value,
3993 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3994 _Expr, __scalar_expr<typename _Expr::value_type> > >
3995>::type
3996operator-(const _Expr& __x, const typename _Expr::value_type& __y)
3997{
3998 typedef typename _Expr::value_type value_type;
3999 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4000 return __val_expr<_Op>(_Op(minus<value_type>(),
4001 __x, __scalar_expr<value_type>(__y, __x.size())));
4002}
4003
4004template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004005inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004006typename enable_if
4007<
4008 __is_val_expr<_Expr>::value,
4009 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
4010 __scalar_expr<typename _Expr::value_type>, _Expr> >
4011>::type
4012operator-(const typename _Expr::value_type& __x, const _Expr& __y)
4013{
4014 typedef typename _Expr::value_type value_type;
4015 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4016 return __val_expr<_Op>(_Op(minus<value_type>(),
4017 __scalar_expr<value_type>(__x, __y.size()), __y));
4018}
4019
4020template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004021inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004022typename enable_if
4023<
4024 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4025 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
4026>::type
4027operator^(const _Expr1& __x, const _Expr2& __y)
4028{
4029 typedef typename _Expr1::value_type value_type;
4030 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
4031 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
4032}
4033
4034template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004035inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004036typename enable_if
4037<
4038 __is_val_expr<_Expr>::value,
4039 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
4040 _Expr, __scalar_expr<typename _Expr::value_type> > >
4041>::type
4042operator^(const _Expr& __x, const typename _Expr::value_type& __y)
4043{
4044 typedef typename _Expr::value_type value_type;
4045 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4046 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
4047 __x, __scalar_expr<value_type>(__y, __x.size())));
4048}
4049
4050template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004051inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004052typename enable_if
4053<
4054 __is_val_expr<_Expr>::value,
4055 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
4056 __scalar_expr<typename _Expr::value_type>, _Expr> >
4057>::type
4058operator^(const typename _Expr::value_type& __x, const _Expr& __y)
4059{
4060 typedef typename _Expr::value_type value_type;
4061 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4062 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
4063 __scalar_expr<value_type>(__x, __y.size()), __y));
4064}
4065
4066template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004067inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004068typename enable_if
4069<
4070 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4071 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4072>::type
4073operator&(const _Expr1& __x, const _Expr2& __y)
4074{
4075 typedef typename _Expr1::value_type value_type;
4076 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
4077 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
4078}
4079
4080template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004081inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004082typename enable_if
4083<
4084 __is_val_expr<_Expr>::value,
4085 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4086 _Expr, __scalar_expr<typename _Expr::value_type> > >
4087>::type
4088operator&(const _Expr& __x, const typename _Expr::value_type& __y)
4089{
4090 typedef typename _Expr::value_type value_type;
4091 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4092 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4093 __x, __scalar_expr<value_type>(__y, __x.size())));
4094}
4095
4096template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004097inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004098typename enable_if
4099<
4100 __is_val_expr<_Expr>::value,
4101 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4102 __scalar_expr<typename _Expr::value_type>, _Expr> >
4103>::type
4104operator&(const typename _Expr::value_type& __x, const _Expr& __y)
4105{
4106 typedef typename _Expr::value_type value_type;
4107 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4108 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4109 __scalar_expr<value_type>(__x, __y.size()), __y));
4110}
4111
4112template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004113inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004114typename enable_if
4115<
4116 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4117 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4118>::type
4119operator|(const _Expr1& __x, const _Expr2& __y)
4120{
4121 typedef typename _Expr1::value_type value_type;
4122 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
4123 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
4124}
4125
4126template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004127inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004128typename enable_if
4129<
4130 __is_val_expr<_Expr>::value,
4131 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4132 _Expr, __scalar_expr<typename _Expr::value_type> > >
4133>::type
4134operator|(const _Expr& __x, const typename _Expr::value_type& __y)
4135{
4136 typedef typename _Expr::value_type value_type;
4137 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4138 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4139 __x, __scalar_expr<value_type>(__y, __x.size())));
4140}
4141
4142template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004143inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004144typename enable_if
4145<
4146 __is_val_expr<_Expr>::value,
4147 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4148 __scalar_expr<typename _Expr::value_type>, _Expr> >
4149>::type
4150operator|(const typename _Expr::value_type& __x, const _Expr& __y)
4151{
4152 typedef typename _Expr::value_type value_type;
4153 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4154 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4155 __scalar_expr<value_type>(__x, __y.size()), __y));
4156}
4157
4158template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004159inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004160typename enable_if
4161<
4162 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4163 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
4164>::type
4165operator<<(const _Expr1& __x, const _Expr2& __y)
4166{
4167 typedef typename _Expr1::value_type value_type;
4168 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
4169 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
4170}
4171
4172template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004173inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004174typename enable_if
4175<
4176 __is_val_expr<_Expr>::value,
4177 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4178 _Expr, __scalar_expr<typename _Expr::value_type> > >
4179>::type
4180operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
4181{
4182 typedef typename _Expr::value_type value_type;
4183 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4184 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4185 __x, __scalar_expr<value_type>(__y, __x.size())));
4186}
4187
4188template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004189inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004190typename enable_if
4191<
4192 __is_val_expr<_Expr>::value,
4193 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4194 __scalar_expr<typename _Expr::value_type>, _Expr> >
4195>::type
4196operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
4197{
4198 typedef typename _Expr::value_type value_type;
4199 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4200 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4201 __scalar_expr<value_type>(__x, __y.size()), __y));
4202}
4203
4204template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004205inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004206typename enable_if
4207<
4208 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4209 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
4210>::type
4211operator>>(const _Expr1& __x, const _Expr2& __y)
4212{
4213 typedef typename _Expr1::value_type value_type;
4214 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
4215 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
4216}
4217
4218template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004219inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004220typename enable_if
4221<
4222 __is_val_expr<_Expr>::value,
4223 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4224 _Expr, __scalar_expr<typename _Expr::value_type> > >
4225>::type
4226operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
4227{
4228 typedef typename _Expr::value_type value_type;
4229 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4230 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4231 __x, __scalar_expr<value_type>(__y, __x.size())));
4232}
4233
4234template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004235inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004236typename enable_if
4237<
4238 __is_val_expr<_Expr>::value,
4239 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4240 __scalar_expr<typename _Expr::value_type>, _Expr> >
4241>::type
4242operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
4243{
4244 typedef typename _Expr::value_type value_type;
4245 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4246 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4247 __scalar_expr<value_type>(__x, __y.size()), __y));
4248}
4249
4250template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004251inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004252typename enable_if
4253<
4254 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4255 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4256>::type
4257operator&&(const _Expr1& __x, const _Expr2& __y)
4258{
4259 typedef typename _Expr1::value_type value_type;
4260 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
4261 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
4262}
4263
4264template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004265inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004266typename enable_if
4267<
4268 __is_val_expr<_Expr>::value,
4269 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4270 _Expr, __scalar_expr<typename _Expr::value_type> > >
4271>::type
4272operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
4273{
4274 typedef typename _Expr::value_type value_type;
4275 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4276 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4277 __x, __scalar_expr<value_type>(__y, __x.size())));
4278}
4279
4280template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004281inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004282typename enable_if
4283<
4284 __is_val_expr<_Expr>::value,
4285 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4286 __scalar_expr<typename _Expr::value_type>, _Expr> >
4287>::type
4288operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
4289{
4290 typedef typename _Expr::value_type value_type;
4291 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4292 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4293 __scalar_expr<value_type>(__x, __y.size()), __y));
4294}
4295
4296template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004297inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004298typename enable_if
4299<
4300 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4301 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4302>::type
4303operator||(const _Expr1& __x, const _Expr2& __y)
4304{
4305 typedef typename _Expr1::value_type value_type;
4306 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
4307 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
4308}
4309
4310template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004311inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004312typename enable_if
4313<
4314 __is_val_expr<_Expr>::value,
4315 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4316 _Expr, __scalar_expr<typename _Expr::value_type> > >
4317>::type
4318operator||(const _Expr& __x, const typename _Expr::value_type& __y)
4319{
4320 typedef typename _Expr::value_type value_type;
4321 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4322 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4323 __x, __scalar_expr<value_type>(__y, __x.size())));
4324}
4325
4326template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004327inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004328typename enable_if
4329<
4330 __is_val_expr<_Expr>::value,
4331 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4332 __scalar_expr<typename _Expr::value_type>, _Expr> >
4333>::type
4334operator||(const typename _Expr::value_type& __x, const _Expr& __y)
4335{
4336 typedef typename _Expr::value_type value_type;
4337 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4338 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4339 __scalar_expr<value_type>(__x, __y.size()), __y));
4340}
4341
4342template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004343inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004344typename enable_if
4345<
4346 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4347 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4348>::type
4349operator==(const _Expr1& __x, const _Expr2& __y)
4350{
4351 typedef typename _Expr1::value_type value_type;
4352 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
4353 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
4354}
4355
4356template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004357inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004358typename enable_if
4359<
4360 __is_val_expr<_Expr>::value,
4361 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4362 _Expr, __scalar_expr<typename _Expr::value_type> > >
4363>::type
4364operator==(const _Expr& __x, const typename _Expr::value_type& __y)
4365{
4366 typedef typename _Expr::value_type value_type;
4367 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4368 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4369 __x, __scalar_expr<value_type>(__y, __x.size())));
4370}
4371
4372template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004373inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004374typename enable_if
4375<
4376 __is_val_expr<_Expr>::value,
4377 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4378 __scalar_expr<typename _Expr::value_type>, _Expr> >
4379>::type
4380operator==(const typename _Expr::value_type& __x, const _Expr& __y)
4381{
4382 typedef typename _Expr::value_type value_type;
4383 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4384 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4385 __scalar_expr<value_type>(__x, __y.size()), __y));
4386}
4387
4388template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004389inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004390typename enable_if
4391<
4392 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4393 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4394>::type
4395operator!=(const _Expr1& __x, const _Expr2& __y)
4396{
4397 typedef typename _Expr1::value_type value_type;
4398 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
4399 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
4400}
4401
4402template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004403inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004404typename enable_if
4405<
4406 __is_val_expr<_Expr>::value,
4407 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4408 _Expr, __scalar_expr<typename _Expr::value_type> > >
4409>::type
4410operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
4411{
4412 typedef typename _Expr::value_type value_type;
4413 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4414 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4415 __x, __scalar_expr<value_type>(__y, __x.size())));
4416}
4417
4418template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004419inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004420typename enable_if
4421<
4422 __is_val_expr<_Expr>::value,
4423 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4424 __scalar_expr<typename _Expr::value_type>, _Expr> >
4425>::type
4426operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
4427{
4428 typedef typename _Expr::value_type value_type;
4429 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4430 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4431 __scalar_expr<value_type>(__x, __y.size()), __y));
4432}
4433
4434template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004435inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004436typename enable_if
4437<
4438 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4439 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
4440>::type
4441operator<(const _Expr1& __x, const _Expr2& __y)
4442{
4443 typedef typename _Expr1::value_type value_type;
4444 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
4445 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
4446}
4447
4448template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004449inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004450typename enable_if
4451<
4452 __is_val_expr<_Expr>::value,
4453 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4454 _Expr, __scalar_expr<typename _Expr::value_type> > >
4455>::type
4456operator<(const _Expr& __x, const typename _Expr::value_type& __y)
4457{
4458 typedef typename _Expr::value_type value_type;
4459 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4460 return __val_expr<_Op>(_Op(less<value_type>(),
4461 __x, __scalar_expr<value_type>(__y, __x.size())));
4462}
4463
4464template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004465inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004466typename enable_if
4467<
4468 __is_val_expr<_Expr>::value,
4469 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4470 __scalar_expr<typename _Expr::value_type>, _Expr> >
4471>::type
4472operator<(const typename _Expr::value_type& __x, const _Expr& __y)
4473{
4474 typedef typename _Expr::value_type value_type;
4475 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4476 return __val_expr<_Op>(_Op(less<value_type>(),
4477 __scalar_expr<value_type>(__x, __y.size()), __y));
4478}
4479
4480template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004481inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004482typename enable_if
4483<
4484 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4485 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
4486>::type
4487operator>(const _Expr1& __x, const _Expr2& __y)
4488{
4489 typedef typename _Expr1::value_type value_type;
4490 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
4491 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
4492}
4493
4494template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004495inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004496typename enable_if
4497<
4498 __is_val_expr<_Expr>::value,
4499 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4500 _Expr, __scalar_expr<typename _Expr::value_type> > >
4501>::type
4502operator>(const _Expr& __x, const typename _Expr::value_type& __y)
4503{
4504 typedef typename _Expr::value_type value_type;
4505 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4506 return __val_expr<_Op>(_Op(greater<value_type>(),
4507 __x, __scalar_expr<value_type>(__y, __x.size())));
4508}
4509
4510template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004511inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004512typename enable_if
4513<
4514 __is_val_expr<_Expr>::value,
4515 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4516 __scalar_expr<typename _Expr::value_type>, _Expr> >
4517>::type
4518operator>(const typename _Expr::value_type& __x, const _Expr& __y)
4519{
4520 typedef typename _Expr::value_type value_type;
4521 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4522 return __val_expr<_Op>(_Op(greater<value_type>(),
4523 __scalar_expr<value_type>(__x, __y.size()), __y));
4524}
4525
4526template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004527inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004528typename enable_if
4529<
4530 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4531 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4532>::type
4533operator<=(const _Expr1& __x, const _Expr2& __y)
4534{
4535 typedef typename _Expr1::value_type value_type;
4536 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
4537 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
4538}
4539
4540template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004541inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004542typename enable_if
4543<
4544 __is_val_expr<_Expr>::value,
4545 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4546 _Expr, __scalar_expr<typename _Expr::value_type> > >
4547>::type
4548operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
4549{
4550 typedef typename _Expr::value_type value_type;
4551 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4552 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4553 __x, __scalar_expr<value_type>(__y, __x.size())));
4554}
4555
4556template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004557inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004558typename enable_if
4559<
4560 __is_val_expr<_Expr>::value,
4561 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4562 __scalar_expr<typename _Expr::value_type>, _Expr> >
4563>::type
4564operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
4565{
4566 typedef typename _Expr::value_type value_type;
4567 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4568 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4569 __scalar_expr<value_type>(__x, __y.size()), __y));
4570}
4571
4572template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004573inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004574typename enable_if
4575<
4576 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4577 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4578>::type
4579operator>=(const _Expr1& __x, const _Expr2& __y)
4580{
4581 typedef typename _Expr1::value_type value_type;
4582 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
4583 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
4584}
4585
4586template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004587inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004588typename enable_if
4589<
4590 __is_val_expr<_Expr>::value,
4591 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4592 _Expr, __scalar_expr<typename _Expr::value_type> > >
4593>::type
4594operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
4595{
4596 typedef typename _Expr::value_type value_type;
4597 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4598 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4599 __x, __scalar_expr<value_type>(__y, __x.size())));
4600}
4601
4602template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004603inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004604typename enable_if
4605<
4606 __is_val_expr<_Expr>::value,
4607 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4608 __scalar_expr<typename _Expr::value_type>, _Expr> >
4609>::type
4610operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
4611{
4612 typedef typename _Expr::value_type value_type;
4613 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4614 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4615 __scalar_expr<value_type>(__x, __y.size()), __y));
4616}
4617
4618template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004619inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004620typename enable_if
4621<
4622 __is_val_expr<_Expr>::value,
4623 __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
4624>::type
4625abs(const _Expr& __x)
4626{
4627 typedef typename _Expr::value_type value_type;
4628 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
4629 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
4630}
4631
4632template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004633inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004634typename enable_if
4635<
4636 __is_val_expr<_Expr>::value,
4637 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
4638>::type
4639acos(const _Expr& __x)
4640{
4641 typedef typename _Expr::value_type value_type;
4642 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
4643 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
4644}
4645
4646template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004647inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004648typename enable_if
4649<
4650 __is_val_expr<_Expr>::value,
4651 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
4652>::type
4653asin(const _Expr& __x)
4654{
4655 typedef typename _Expr::value_type value_type;
4656 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
4657 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
4658}
4659
4660template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004661inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004662typename enable_if
4663<
4664 __is_val_expr<_Expr>::value,
4665 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
4666>::type
4667atan(const _Expr& __x)
4668{
4669 typedef typename _Expr::value_type value_type;
4670 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
4671 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
4672}
4673
4674template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004675inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004676typename enable_if
4677<
4678 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4679 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4680>::type
4681atan2(const _Expr1& __x, const _Expr2& __y)
4682{
4683 typedef typename _Expr1::value_type value_type;
4684 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
4685 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
4686}
4687
4688template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004689inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004690typename enable_if
4691<
4692 __is_val_expr<_Expr>::value,
4693 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4694 _Expr, __scalar_expr<typename _Expr::value_type> > >
4695>::type
4696atan2(const _Expr& __x, const typename _Expr::value_type& __y)
4697{
4698 typedef typename _Expr::value_type value_type;
4699 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4700 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4701 __x, __scalar_expr<value_type>(__y, __x.size())));
4702}
4703
4704template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004705inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004706typename enable_if
4707<
4708 __is_val_expr<_Expr>::value,
4709 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4710 __scalar_expr<typename _Expr::value_type>, _Expr> >
4711>::type
4712atan2(const typename _Expr::value_type& __x, const _Expr& __y)
4713{
4714 typedef typename _Expr::value_type value_type;
4715 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4716 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4717 __scalar_expr<value_type>(__x, __y.size()), __y));
4718}
4719
4720template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004721inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004722typename enable_if
4723<
4724 __is_val_expr<_Expr>::value,
4725 __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
4726>::type
4727cos(const _Expr& __x)
4728{
4729 typedef typename _Expr::value_type value_type;
4730 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
4731 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
4732}
4733
4734template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004735inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004736typename enable_if
4737<
4738 __is_val_expr<_Expr>::value,
4739 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
4740>::type
4741cosh(const _Expr& __x)
4742{
4743 typedef typename _Expr::value_type value_type;
4744 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
4745 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
4746}
4747
4748template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004749inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004750typename enable_if
4751<
4752 __is_val_expr<_Expr>::value,
4753 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
4754>::type
4755exp(const _Expr& __x)
4756{
4757 typedef typename _Expr::value_type value_type;
4758 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
4759 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
4760}
4761
4762template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004763inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004764typename enable_if
4765<
4766 __is_val_expr<_Expr>::value,
4767 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
4768>::type
4769log(const _Expr& __x)
4770{
4771 typedef typename _Expr::value_type value_type;
4772 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
4773 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
4774}
4775
4776template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004777inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004778typename enable_if
4779<
4780 __is_val_expr<_Expr>::value,
4781 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
4782>::type
4783log10(const _Expr& __x)
4784{
4785 typedef typename _Expr::value_type value_type;
4786 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
4787 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
4788}
4789
4790template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004791inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004792typename enable_if
4793<
4794 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4795 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4796>::type
4797pow(const _Expr1& __x, const _Expr2& __y)
4798{
4799 typedef typename _Expr1::value_type value_type;
4800 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
4801 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
4802}
4803
4804template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004805inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004806typename enable_if
4807<
4808 __is_val_expr<_Expr>::value,
4809 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4810 _Expr, __scalar_expr<typename _Expr::value_type> > >
4811>::type
4812pow(const _Expr& __x, const typename _Expr::value_type& __y)
4813{
4814 typedef typename _Expr::value_type value_type;
4815 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4816 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4817 __x, __scalar_expr<value_type>(__y, __x.size())));
4818}
4819
4820template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004821inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004822typename enable_if
4823<
4824 __is_val_expr<_Expr>::value,
4825 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4826 __scalar_expr<typename _Expr::value_type>, _Expr> >
4827>::type
4828pow(const typename _Expr::value_type& __x, const _Expr& __y)
4829{
4830 typedef typename _Expr::value_type value_type;
4831 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4832 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4833 __scalar_expr<value_type>(__x, __y.size()), __y));
4834}
4835
4836template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004837inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004838typename enable_if
4839<
4840 __is_val_expr<_Expr>::value,
4841 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
4842>::type
4843sin(const _Expr& __x)
4844{
4845 typedef typename _Expr::value_type value_type;
4846 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
4847 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
4848}
4849
4850template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004851inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004852typename enable_if
4853<
4854 __is_val_expr<_Expr>::value,
4855 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
4856>::type
4857sinh(const _Expr& __x)
4858{
4859 typedef typename _Expr::value_type value_type;
4860 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
4861 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
4862}
4863
4864template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004865inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004866typename enable_if
4867<
4868 __is_val_expr<_Expr>::value,
4869 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
4870>::type
4871sqrt(const _Expr& __x)
4872{
4873 typedef typename _Expr::value_type value_type;
4874 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
4875 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
4876}
4877
4878template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004879inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004880typename enable_if
4881<
4882 __is_val_expr<_Expr>::value,
4883 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
4884>::type
4885tan(const _Expr& __x)
4886{
4887 typedef typename _Expr::value_type value_type;
4888 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
4889 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
4890}
4891
4892template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004893inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004894typename enable_if
4895<
4896 __is_val_expr<_Expr>::value,
4897 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
4898>::type
4899tanh(const _Expr& __x)
4900{
4901 typedef typename _Expr::value_type value_type;
4902 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
4903 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
4904}
4905
4906template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004907inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004908_Tp*
4909begin(valarray<_Tp>& __v)
4910{
4911 return __v.__begin_;
4912}
4913
4914template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004915inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004916const _Tp*
4917begin(const valarray<_Tp>& __v)
4918{
4919 return __v.__begin_;
4920}
4921
4922template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004923inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004924_Tp*
4925end(valarray<_Tp>& __v)
4926{
4927 return __v.__end_;
4928}
4929
4930template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004931inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004932const _Tp*
4933end(const valarray<_Tp>& __v)
4934{
4935 return __v.__end_;
4936}
4937
Howard Hinnantc51e1022010-05-11 19:42:16 +00004938_LIBCPP_END_NAMESPACE_STD
4939
Eric Fiselierf4433a32017-05-31 22:07:49 +00004940_LIBCPP_POP_MACROS
4941
Howard Hinnantc51e1022010-05-11 19:42:16 +00004942#endif // _LIBCPP_VALARRAY