blob: c9ca08c618bcadd2caa63de0dcd23063fc9d8e8b [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 Fiselierb5eb1bf2017-01-04 23:56:00 +0000676 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000677};
678
679template <class _ValExpr>
680class __mask_expr;
681
682template <class _ValExpr>
683class __indirect_expr;
684
685template <class _ValExpr>
686class __shift_expr
687{
688 typedef typename remove_reference<_ValExpr>::type _RmExpr;
689public:
690 typedef typename _RmExpr::value_type value_type;
691 typedef value_type result_type;
692
693private:
694 _ValExpr __expr_;
695 size_t __size_;
696 ptrdiff_t __ul_;
697 ptrdiff_t __sn_;
698 ptrdiff_t __n_;
Howard Hinnantc834c512011-11-29 18:15:50 +0000699 static const ptrdiff_t _Np = static_cast<ptrdiff_t>(
Howard Hinnantc51e1022010-05-11 19:42:16 +0000700 sizeof(ptrdiff_t) * __CHAR_BIT__ - 1);
701
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000702 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000703 __shift_expr(int __n, const _RmExpr& __e)
704 : __expr_(__e),
705 __size_(__e.size()),
706 __n_(__n)
707 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000708 ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _Np);
709 __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _Np);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000710 __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n);
711 }
712public:
713
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000715 result_type operator[](size_t __j) const
716 {
Howard Hinnant28b24882011-12-01 20:21:04 +0000717 ptrdiff_t __i = static_cast<ptrdiff_t>(__j);
Howard Hinnantc834c512011-11-29 18:15:50 +0000718 ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000719 return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
720 }
721
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000723 size_t size() const {return __size_;}
724
725 template <class> friend class __val_expr;
726};
727
728template <class _ValExpr>
729class __cshift_expr
730{
731 typedef typename remove_reference<_ValExpr>::type _RmExpr;
732public:
733 typedef typename _RmExpr::value_type value_type;
734 typedef value_type result_type;
735
736private:
737 _ValExpr __expr_;
738 size_t __size_;
739 size_t __m_;
740 size_t __o1_;
741 size_t __o2_;
742
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000743 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000744 __cshift_expr(int __n, const _RmExpr& __e)
745 : __expr_(__e),
746 __size_(__e.size())
747 {
748 __n %= static_cast<int>(__size_);
749 if (__n >= 0)
750 {
751 __m_ = __size_ - __n;
752 __o1_ = __n;
753 __o2_ = __n - __size_;
754 }
755 else
756 {
757 __m_ = -__n;
758 __o1_ = __n + __size_;
759 __o2_ = __n;
760 }
761 }
762public:
763
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000764 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000765 result_type operator[](size_t __i) const
766 {
767 if (__i < __m_)
768 return __expr_[__i + __o1_];
769 return __expr_[__i + __o2_];
770 }
771
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000772 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000773 size_t size() const {return __size_;}
774
775 template <class> friend class __val_expr;
776};
777
778template<class _ValExpr>
779class __val_expr;
780
781template<class _ValExpr>
782struct __is_val_expr : false_type {};
783
784template<class _ValExpr>
785struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
786
787template<class _Tp>
788struct __is_val_expr<valarray<_Tp> > : true_type {};
789
790template<class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000791class _LIBCPP_TEMPLATE_VIS valarray
Howard Hinnantc51e1022010-05-11 19:42:16 +0000792{
793public:
794 typedef _Tp value_type;
795 typedef _Tp result_type;
796
797private:
798 value_type* __begin_;
799 value_type* __end_;
800
801public:
802 // construct/destroy:
Douglas Gregor68902322012-05-19 07:14:17 +0000803 _LIBCPP_INLINE_VISIBILITY
804 valarray() : __begin_(0), __end_(0) {}
Louis Dionneb4d05d72018-10-16 19:26:23 +0000805 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Eric Fiseliere529a802016-09-16 00:13:55 +0000806 explicit valarray(size_t __n);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000807 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +0000808 valarray(const value_type& __x, size_t __n);
809 valarray(const value_type* __p, size_t __n);
810 valarray(const valarray& __v);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000811#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000812 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant298aed92012-07-21 00:51:28 +0000813 valarray(valarray&& __v) _NOEXCEPT;
Douglas Gregor68902322012-05-19 07:14:17 +0000814 valarray(initializer_list<value_type> __il);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000815#endif // _LIBCPP_CXX03_LANG
Douglas Gregor68902322012-05-19 07:14:17 +0000816 valarray(const slice_array<value_type>& __sa);
817 valarray(const gslice_array<value_type>& __ga);
818 valarray(const mask_array<value_type>& __ma);
819 valarray(const indirect_array<value_type>& __ia);
Louis Dionneb4d05d72018-10-16 19:26:23 +0000820 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Douglas Gregor68902322012-05-19 07:14:17 +0000821 ~valarray();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000822
823 // assignment:
Douglas Gregor68902322012-05-19 07:14:17 +0000824 valarray& operator=(const valarray& __v);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000825#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000826 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant298aed92012-07-21 00:51:28 +0000827 valarray& operator=(valarray&& __v) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000828 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +0000829 valarray& operator=(initializer_list<value_type>);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000830#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000831 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +0000832 valarray& operator=(const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000833 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000834 valarray& operator=(const slice_array<value_type>& __sa);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000835 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000836 valarray& operator=(const gslice_array<value_type>& __ga);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000837 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000838 valarray& operator=(const mask_array<value_type>& __ma);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000839 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000840 valarray& operator=(const indirect_array<value_type>& __ia);
Howard Hinnant329cd412011-07-27 23:19:59 +0000841 template <class _ValExpr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000842 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant329cd412011-07-27 23:19:59 +0000843 valarray& operator=(const __val_expr<_ValExpr>& __v);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000844
845 // element access:
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000846 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000847 const value_type& operator[](size_t __i) const {return __begin_[__i];}
848
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000849 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000850 value_type& operator[](size_t __i) {return __begin_[__i];}
851
852 // subset operations:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000854 __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000855 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000856 slice_array<value_type> operator[](slice __s);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000858 __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000859 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860 gslice_array<value_type> operator[](const gslice& __gs);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000861#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000862 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000863 __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000864 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000865 gslice_array<value_type> operator[](gslice&& __gs);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000866#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000868 __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000870 mask_array<value_type> operator[](const valarray<bool>& __vb);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000871#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000872 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000873 __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000874 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000875 mask_array<value_type> operator[](valarray<bool>&& __vb);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000876#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000877 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000878 __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000879 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000880 indirect_array<value_type> operator[](const valarray<size_t>& __vs);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000881#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000882 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000883 __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000884 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000885 indirect_array<value_type> operator[](valarray<size_t>&& __vs);
Eric Fiselier3b0b81f2017-04-19 00:23:45 +0000886#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000887
888 // unary operators:
Douglas Gregor68902322012-05-19 07:14:17 +0000889 valarray operator+() const;
890 valarray operator-() const;
891 valarray operator~() const;
892 valarray<bool> operator!() const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000893
894 // computed assignment:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000895 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000896 valarray& operator*= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000898 valarray& operator/= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000899 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000900 valarray& operator%= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000902 valarray& operator+= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000904 valarray& operator-= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000906 valarray& operator^= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000908 valarray& operator&= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000910 valarray& operator|= (const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000912 valarray& operator<<=(const value_type& __x);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000914 valarray& operator>>=(const value_type& __x);
915
916 template <class _Expr>
917 typename enable_if
918 <
919 __is_val_expr<_Expr>::value,
920 valarray&
921 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000922 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000923 operator*= (const _Expr& __v);
924
925 template <class _Expr>
926 typename enable_if
927 <
928 __is_val_expr<_Expr>::value,
929 valarray&
930 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000931 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000932 operator/= (const _Expr& __v);
933
934 template <class _Expr>
935 typename enable_if
936 <
937 __is_val_expr<_Expr>::value,
938 valarray&
939 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000940 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000941 operator%= (const _Expr& __v);
942
943 template <class _Expr>
944 typename enable_if
945 <
946 __is_val_expr<_Expr>::value,
947 valarray&
948 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000949 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000950 operator+= (const _Expr& __v);
951
952 template <class _Expr>
953 typename enable_if
954 <
955 __is_val_expr<_Expr>::value,
956 valarray&
957 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000958 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000959 operator-= (const _Expr& __v);
960
961 template <class _Expr>
962 typename enable_if
963 <
964 __is_val_expr<_Expr>::value,
965 valarray&
966 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000968 operator^= (const _Expr& __v);
969
970 template <class _Expr>
971 typename enable_if
972 <
973 __is_val_expr<_Expr>::value,
974 valarray&
975 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000976 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000977 operator|= (const _Expr& __v);
978
979 template <class _Expr>
980 typename enable_if
981 <
982 __is_val_expr<_Expr>::value,
983 valarray&
984 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000985 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000986 operator&= (const _Expr& __v);
987
988 template <class _Expr>
989 typename enable_if
990 <
991 __is_val_expr<_Expr>::value,
992 valarray&
993 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000994 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000995 operator<<= (const _Expr& __v);
996
997 template <class _Expr>
998 typename enable_if
999 <
1000 __is_val_expr<_Expr>::value,
1001 valarray&
1002 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001003 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001004 operator>>= (const _Expr& __v);
1005
1006 // member functions:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001007 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant298aed92012-07-21 00:51:28 +00001008 void swap(valarray& __v) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001009
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001010 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant28b24882011-12-01 20:21:04 +00001011 size_t size() const {return static_cast<size_t>(__end_ - __begin_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001012
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001013 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +00001014 value_type sum() const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001015 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +00001016 value_type min() const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001017 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor68902322012-05-19 07:14:17 +00001018 value_type max() const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001019
Douglas Gregor68902322012-05-19 07:14:17 +00001020 valarray shift (int __i) const;
1021 valarray cshift(int __i) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001022 valarray apply(value_type __f(value_type)) const;
1023 valarray apply(value_type __f(const value_type&)) const;
1024 void resize(size_t __n, value_type __x = value_type());
1025
1026private:
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001027 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
1028 template <class> friend class _LIBCPP_TEMPLATE_VIS slice_array;
1029 template <class> friend class _LIBCPP_TEMPLATE_VIS gslice_array;
1030 template <class> friend class _LIBCPP_TEMPLATE_VIS mask_array;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001031 template <class> friend class __mask_expr;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001032 template <class> friend class _LIBCPP_TEMPLATE_VIS indirect_array;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001033 template <class> friend class __indirect_expr;
1034 template <class> friend class __val_expr;
1035
1036 template <class _Up>
1037 friend
1038 _Up*
1039 begin(valarray<_Up>& __v);
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001040
Howard Hinnantc51e1022010-05-11 19:42:16 +00001041 template <class _Up>
1042 friend
1043 const _Up*
1044 begin(const valarray<_Up>& __v);
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001045
Howard Hinnantc51e1022010-05-11 19:42:16 +00001046 template <class _Up>
1047 friend
1048 _Up*
1049 end(valarray<_Up>& __v);
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001050
Howard Hinnantc51e1022010-05-11 19:42:16 +00001051 template <class _Up>
1052 friend
1053 const _Up*
1054 end(const valarray<_Up>& __v);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00001055
Eric Fiseliera119c322018-10-25 17:43:26 +00001056 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2856ef82018-10-25 17:21:30 +00001057 void __clear(size_t __capacity);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00001058 valarray& __assign_range(const value_type* __f, const value_type* __l);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001059};
1060
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001061_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::valarray(size_t))
1062_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::~valarray())
1063_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void valarray<size_t>::resize(size_t, size_t))
1064
Howard Hinnantc51e1022010-05-11 19:42:16 +00001065template <class _Op, class _Tp>
1066struct _UnaryOp<_Op, valarray<_Tp> >
1067{
1068 typedef typename _Op::result_type result_type;
1069 typedef _Tp value_type;
1070
1071 _Op __op_;
1072 const valarray<_Tp>& __a0_;
1073
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001074 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001075 _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
1076
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001077 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001078 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
1079
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081 size_t size() const {return __a0_.size();}
1082};
1083
1084template <class _Op, class _Tp, class _A1>
1085struct _BinaryOp<_Op, valarray<_Tp>, _A1>
1086{
1087 typedef typename _Op::result_type result_type;
1088 typedef _Tp value_type;
1089
1090 _Op __op_;
1091 const valarray<_Tp>& __a0_;
1092 _A1 __a1_;
1093
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001094 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001095 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
1096 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1097
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001099 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1100
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001102 size_t size() const {return __a0_.size();}
1103};
1104
1105template <class _Op, class _A0, class _Tp>
1106struct _BinaryOp<_Op, _A0, valarray<_Tp> >
1107{
1108 typedef typename _Op::result_type result_type;
1109 typedef _Tp value_type;
1110
1111 _Op __op_;
1112 _A0 __a0_;
1113 const valarray<_Tp>& __a1_;
1114
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001116 _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
1117 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1118
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001119 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001120 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1121
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001123 size_t size() const {return __a0_.size();}
1124};
1125
1126template <class _Op, class _Tp>
1127struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> >
1128{
1129 typedef typename _Op::result_type result_type;
1130 typedef _Tp value_type;
1131
1132 _Op __op_;
1133 const valarray<_Tp>& __a0_;
1134 const valarray<_Tp>& __a1_;
1135
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001136 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001137 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
1138 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1139
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001141 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1142
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001143 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001144 size_t size() const {return __a0_.size();}
1145};
1146
1147// slice_array
1148
1149template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001150class _LIBCPP_TEMPLATE_VIS slice_array
Howard Hinnantc51e1022010-05-11 19:42:16 +00001151{
1152public:
1153 typedef _Tp value_type;
1154
1155private:
1156 value_type* __vp_;
1157 size_t __size_;
1158 size_t __stride_;
1159
1160public:
1161 template <class _Expr>
1162 typename enable_if
1163 <
1164 __is_val_expr<_Expr>::value,
1165 void
1166 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001168 operator=(const _Expr& __v) const;
1169
1170 template <class _Expr>
1171 typename enable_if
1172 <
1173 __is_val_expr<_Expr>::value,
1174 void
1175 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001176 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001177 operator*=(const _Expr& __v) const;
1178
1179 template <class _Expr>
1180 typename enable_if
1181 <
1182 __is_val_expr<_Expr>::value,
1183 void
1184 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001186 operator/=(const _Expr& __v) const;
1187
1188 template <class _Expr>
1189 typename enable_if
1190 <
1191 __is_val_expr<_Expr>::value,
1192 void
1193 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001194 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001195 operator%=(const _Expr& __v) const;
1196
1197 template <class _Expr>
1198 typename enable_if
1199 <
1200 __is_val_expr<_Expr>::value,
1201 void
1202 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001203 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001204 operator+=(const _Expr& __v) const;
1205
1206 template <class _Expr>
1207 typename enable_if
1208 <
1209 __is_val_expr<_Expr>::value,
1210 void
1211 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001212 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001213 operator-=(const _Expr& __v) const;
1214
1215 template <class _Expr>
1216 typename enable_if
1217 <
1218 __is_val_expr<_Expr>::value,
1219 void
1220 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001221 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001222 operator^=(const _Expr& __v) const;
1223
1224 template <class _Expr>
1225 typename enable_if
1226 <
1227 __is_val_expr<_Expr>::value,
1228 void
1229 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001230 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001231 operator&=(const _Expr& __v) const;
1232
1233 template <class _Expr>
1234 typename enable_if
1235 <
1236 __is_val_expr<_Expr>::value,
1237 void
1238 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001239 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001240 operator|=(const _Expr& __v) const;
1241
1242 template <class _Expr>
1243 typename enable_if
1244 <
1245 __is_val_expr<_Expr>::value,
1246 void
1247 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001248 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001249 operator<<=(const _Expr& __v) const;
1250
1251 template <class _Expr>
1252 typename enable_if
1253 <
1254 __is_val_expr<_Expr>::value,
1255 void
1256 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001257 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001258 operator>>=(const _Expr& __v) const;
1259
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001260 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001261 const slice_array& operator=(const slice_array& __sa) const;
1262
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001263 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001264 void operator=(const value_type& __x) const;
1265
1266private:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001267 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001268 slice_array(const slice& __sl, const valarray<value_type>& __v)
1269 : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())),
1270 __size_(__sl.size()),
1271 __stride_(__sl.stride())
1272 {}
1273
1274 template <class> friend class valarray;
1275 template <class> friend class sliceExpr;
1276};
1277
1278template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001279inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001280const slice_array<_Tp>&
1281slice_array<_Tp>::operator=(const slice_array& __sa) const
1282{
1283 value_type* __t = __vp_;
1284 const value_type* __s = __sa.__vp_;
1285 for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
1286 *__t = *__s;
Eric Fiselier3b80ce92014-08-12 00:06:58 +00001287 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001288}
1289
1290template <class _Tp>
1291template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001292inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001293typename enable_if
1294<
1295 __is_val_expr<_Expr>::value,
1296 void
1297>::type
1298slice_array<_Tp>::operator=(const _Expr& __v) const
1299{
1300 value_type* __t = __vp_;
1301 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1302 *__t = __v[__i];
1303}
1304
1305template <class _Tp>
1306template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001307inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001308typename enable_if
1309<
1310 __is_val_expr<_Expr>::value,
1311 void
1312>::type
1313slice_array<_Tp>::operator*=(const _Expr& __v) const
1314{
1315 value_type* __t = __vp_;
1316 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1317 *__t *= __v[__i];
1318}
1319
1320template <class _Tp>
1321template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001322inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001323typename enable_if
1324<
1325 __is_val_expr<_Expr>::value,
1326 void
1327>::type
1328slice_array<_Tp>::operator/=(const _Expr& __v) const
1329{
1330 value_type* __t = __vp_;
1331 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1332 *__t /= __v[__i];
1333}
1334
1335template <class _Tp>
1336template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001337inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001338typename enable_if
1339<
1340 __is_val_expr<_Expr>::value,
1341 void
1342>::type
1343slice_array<_Tp>::operator%=(const _Expr& __v) const
1344{
1345 value_type* __t = __vp_;
1346 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1347 *__t %= __v[__i];
1348}
1349
1350template <class _Tp>
1351template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001352inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001353typename enable_if
1354<
1355 __is_val_expr<_Expr>::value,
1356 void
1357>::type
1358slice_array<_Tp>::operator+=(const _Expr& __v) const
1359{
1360 value_type* __t = __vp_;
1361 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1362 *__t += __v[__i];
1363}
1364
1365template <class _Tp>
1366template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001367inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001368typename enable_if
1369<
1370 __is_val_expr<_Expr>::value,
1371 void
1372>::type
1373slice_array<_Tp>::operator-=(const _Expr& __v) const
1374{
1375 value_type* __t = __vp_;
1376 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1377 *__t -= __v[__i];
1378}
1379
1380template <class _Tp>
1381template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001382inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001383typename enable_if
1384<
1385 __is_val_expr<_Expr>::value,
1386 void
1387>::type
1388slice_array<_Tp>::operator^=(const _Expr& __v) const
1389{
1390 value_type* __t = __vp_;
1391 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1392 *__t ^= __v[__i];
1393}
1394
1395template <class _Tp>
1396template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001397inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001398typename enable_if
1399<
1400 __is_val_expr<_Expr>::value,
1401 void
1402>::type
1403slice_array<_Tp>::operator&=(const _Expr& __v) const
1404{
1405 value_type* __t = __vp_;
1406 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1407 *__t &= __v[__i];
1408}
1409
1410template <class _Tp>
1411template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001412inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001413typename enable_if
1414<
1415 __is_val_expr<_Expr>::value,
1416 void
1417>::type
1418slice_array<_Tp>::operator|=(const _Expr& __v) const
1419{
1420 value_type* __t = __vp_;
1421 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1422 *__t |= __v[__i];
1423}
1424
1425template <class _Tp>
1426template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001427inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001428typename enable_if
1429<
1430 __is_val_expr<_Expr>::value,
1431 void
1432>::type
1433slice_array<_Tp>::operator<<=(const _Expr& __v) const
1434{
1435 value_type* __t = __vp_;
1436 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1437 *__t <<= __v[__i];
1438}
1439
1440template <class _Tp>
1441template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001442inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001443typename enable_if
1444<
1445 __is_val_expr<_Expr>::value,
1446 void
1447>::type
1448slice_array<_Tp>::operator>>=(const _Expr& __v) const
1449{
1450 value_type* __t = __vp_;
1451 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1452 *__t >>= __v[__i];
1453}
1454
1455template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001456inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001457void
1458slice_array<_Tp>::operator=(const value_type& __x) const
1459{
1460 value_type* __t = __vp_;
1461 for (size_t __n = __size_; __n; --__n, __t += __stride_)
1462 *__t = __x;
1463}
1464
1465// gslice
1466
Howard Hinnant8331b762013-03-06 23:30:19 +00001467class _LIBCPP_TYPE_VIS gslice
Howard Hinnantc51e1022010-05-11 19:42:16 +00001468{
1469 valarray<size_t> __size_;
1470 valarray<size_t> __stride_;
1471 valarray<size_t> __1d_;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001472
Howard Hinnantc51e1022010-05-11 19:42:16 +00001473public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001475 gslice() {}
Douglas Gregor68902322012-05-19 07:14:17 +00001476
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001478 gslice(size_t __start, const valarray<size_t>& __size,
1479 const valarray<size_t>& __stride)
1480 : __size_(__size),
1481 __stride_(__stride)
1482 {__init(__start);}
1483
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00001484#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001485
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001486 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001487 gslice(size_t __start, const valarray<size_t>& __size,
1488 valarray<size_t>&& __stride)
1489 : __size_(__size),
1490 __stride_(move(__stride))
1491 {__init(__start);}
1492
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001493 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001494 gslice(size_t __start, valarray<size_t>&& __size,
1495 const valarray<size_t>& __stride)
1496 : __size_(move(__size)),
1497 __stride_(__stride)
1498 {__init(__start);}
1499
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001501 gslice(size_t __start, valarray<size_t>&& __size,
1502 valarray<size_t>&& __stride)
1503 : __size_(move(__size)),
1504 __stride_(move(__stride))
1505 {__init(__start);}
1506
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00001507#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001508
1509// gslice(const gslice&) = default;
1510// gslice(gslice&&) = default;
1511// gslice& operator=(const gslice&) = default;
1512// gslice& operator=(gslice&&) = default;
1513
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001515 size_t start() const {return __1d_.size() ? __1d_[0] : 0;}
1516
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001518 valarray<size_t> size() const {return __size_;}
1519
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001521 valarray<size_t> stride() const {return __stride_;}
1522
1523private:
1524 void __init(size_t __start);
1525
1526 template <class> friend class gslice_array;
1527 template <class> friend class valarray;
1528 template <class> friend class __val_expr;
1529};
1530
1531// gslice_array
1532
1533template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001534class _LIBCPP_TEMPLATE_VIS gslice_array
Howard Hinnantc51e1022010-05-11 19:42:16 +00001535{
1536public:
1537 typedef _Tp value_type;
1538
1539private:
1540 value_type* __vp_;
1541 valarray<size_t> __1d_;
1542
1543public:
1544 template <class _Expr>
1545 typename enable_if
1546 <
1547 __is_val_expr<_Expr>::value,
1548 void
1549 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001551 operator=(const _Expr& __v) const;
1552
1553 template <class _Expr>
1554 typename enable_if
1555 <
1556 __is_val_expr<_Expr>::value,
1557 void
1558 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001560 operator*=(const _Expr& __v) const;
1561
1562 template <class _Expr>
1563 typename enable_if
1564 <
1565 __is_val_expr<_Expr>::value,
1566 void
1567 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001569 operator/=(const _Expr& __v) const;
1570
1571 template <class _Expr>
1572 typename enable_if
1573 <
1574 __is_val_expr<_Expr>::value,
1575 void
1576 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001578 operator%=(const _Expr& __v) const;
1579
1580 template <class _Expr>
1581 typename enable_if
1582 <
1583 __is_val_expr<_Expr>::value,
1584 void
1585 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001587 operator+=(const _Expr& __v) const;
1588
1589 template <class _Expr>
1590 typename enable_if
1591 <
1592 __is_val_expr<_Expr>::value,
1593 void
1594 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001596 operator-=(const _Expr& __v) const;
1597
1598 template <class _Expr>
1599 typename enable_if
1600 <
1601 __is_val_expr<_Expr>::value,
1602 void
1603 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001605 operator^=(const _Expr& __v) const;
1606
1607 template <class _Expr>
1608 typename enable_if
1609 <
1610 __is_val_expr<_Expr>::value,
1611 void
1612 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001613 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001614 operator&=(const _Expr& __v) const;
1615
1616 template <class _Expr>
1617 typename enable_if
1618 <
1619 __is_val_expr<_Expr>::value,
1620 void
1621 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001623 operator|=(const _Expr& __v) const;
1624
1625 template <class _Expr>
1626 typename enable_if
1627 <
1628 __is_val_expr<_Expr>::value,
1629 void
1630 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001632 operator<<=(const _Expr& __v) const;
1633
1634 template <class _Expr>
1635 typename enable_if
1636 <
1637 __is_val_expr<_Expr>::value,
1638 void
1639 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001640 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001641 operator>>=(const _Expr& __v) const;
1642
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001644 const gslice_array& operator=(const gslice_array& __ga) const;
1645
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001646 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001647 void operator=(const value_type& __x) const;
1648
1649// gslice_array(const gslice_array&) = default;
1650// gslice_array(gslice_array&&) = default;
1651// gslice_array& operator=(const gslice_array&) = default;
1652// gslice_array& operator=(gslice_array&&) = default;
1653
1654private:
Howard Hinnantc51e1022010-05-11 19:42:16 +00001655 gslice_array(const gslice& __gs, const valarray<value_type>& __v)
1656 : __vp_(const_cast<value_type*>(__v.__begin_)),
1657 __1d_(__gs.__1d_)
1658 {}
1659
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00001660#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001661 gslice_array(gslice&& __gs, const valarray<value_type>& __v)
1662 : __vp_(const_cast<value_type*>(__v.__begin_)),
1663 __1d_(move(__gs.__1d_))
1664 {}
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00001665#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001666
1667 template <class> friend class valarray;
1668};
1669
1670template <class _Tp>
1671template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001672inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001673typename enable_if
1674<
1675 __is_val_expr<_Expr>::value,
1676 void
1677>::type
1678gslice_array<_Tp>::operator=(const _Expr& __v) const
1679{
1680 typedef const size_t* _Ip;
1681 size_t __j = 0;
1682 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1683 __vp_[*__i] = __v[__j];
1684}
1685
1686template <class _Tp>
1687template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001688inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001689typename enable_if
1690<
1691 __is_val_expr<_Expr>::value,
1692 void
1693>::type
1694gslice_array<_Tp>::operator*=(const _Expr& __v) const
1695{
1696 typedef const size_t* _Ip;
1697 size_t __j = 0;
1698 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1699 __vp_[*__i] *= __v[__j];
1700}
1701
1702template <class _Tp>
1703template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001704inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001705typename enable_if
1706<
1707 __is_val_expr<_Expr>::value,
1708 void
1709>::type
1710gslice_array<_Tp>::operator/=(const _Expr& __v) const
1711{
1712 typedef const size_t* _Ip;
1713 size_t __j = 0;
1714 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1715 __vp_[*__i] /= __v[__j];
1716}
1717
1718template <class _Tp>
1719template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001720inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001721typename enable_if
1722<
1723 __is_val_expr<_Expr>::value,
1724 void
1725>::type
1726gslice_array<_Tp>::operator%=(const _Expr& __v) const
1727{
1728 typedef const size_t* _Ip;
1729 size_t __j = 0;
1730 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1731 __vp_[*__i] %= __v[__j];
1732}
1733
1734template <class _Tp>
1735template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001736inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001737typename enable_if
1738<
1739 __is_val_expr<_Expr>::value,
1740 void
1741>::type
1742gslice_array<_Tp>::operator+=(const _Expr& __v) const
1743{
1744 typedef const size_t* _Ip;
1745 size_t __j = 0;
1746 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1747 __vp_[*__i] += __v[__j];
1748}
1749
1750template <class _Tp>
1751template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001752inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001753typename enable_if
1754<
1755 __is_val_expr<_Expr>::value,
1756 void
1757>::type
1758gslice_array<_Tp>::operator-=(const _Expr& __v) const
1759{
1760 typedef const size_t* _Ip;
1761 size_t __j = 0;
1762 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1763 __vp_[*__i] -= __v[__j];
1764}
1765
1766template <class _Tp>
1767template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001768inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001769typename enable_if
1770<
1771 __is_val_expr<_Expr>::value,
1772 void
1773>::type
1774gslice_array<_Tp>::operator^=(const _Expr& __v) const
1775{
1776 typedef const size_t* _Ip;
1777 size_t __j = 0;
1778 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1779 __vp_[*__i] ^= __v[__j];
1780}
1781
1782template <class _Tp>
1783template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001784inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001785typename enable_if
1786<
1787 __is_val_expr<_Expr>::value,
1788 void
1789>::type
1790gslice_array<_Tp>::operator&=(const _Expr& __v) const
1791{
1792 typedef const size_t* _Ip;
1793 size_t __j = 0;
1794 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1795 __vp_[*__i] &= __v[__j];
1796}
1797
1798template <class _Tp>
1799template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001800inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001801typename enable_if
1802<
1803 __is_val_expr<_Expr>::value,
1804 void
1805>::type
1806gslice_array<_Tp>::operator|=(const _Expr& __v) const
1807{
1808 typedef const size_t* _Ip;
1809 size_t __j = 0;
1810 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1811 __vp_[*__i] |= __v[__j];
1812}
1813
1814template <class _Tp>
1815template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001816inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001817typename enable_if
1818<
1819 __is_val_expr<_Expr>::value,
1820 void
1821>::type
1822gslice_array<_Tp>::operator<<=(const _Expr& __v) const
1823{
1824 typedef const size_t* _Ip;
1825 size_t __j = 0;
1826 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1827 __vp_[*__i] <<= __v[__j];
1828}
1829
1830template <class _Tp>
1831template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001832inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001833typename enable_if
1834<
1835 __is_val_expr<_Expr>::value,
1836 void
1837>::type
1838gslice_array<_Tp>::operator>>=(const _Expr& __v) const
1839{
1840 typedef const size_t* _Ip;
1841 size_t __j = 0;
1842 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1843 __vp_[*__i] >>= __v[__j];
1844}
1845
1846template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001847inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001848const gslice_array<_Tp>&
1849gslice_array<_Tp>::operator=(const gslice_array& __ga) const
1850{
1851 typedef const size_t* _Ip;
1852 const value_type* __s = __ga.__vp_;
1853 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_;
1854 __i != __e; ++__i, ++__j)
1855 __vp_[*__i] = __s[*__j];
1856 return *this;
1857}
1858
1859template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001860inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001861void
1862gslice_array<_Tp>::operator=(const value_type& __x) const
1863{
1864 typedef const size_t* _Ip;
1865 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1866 __vp_[*__i] = __x;
1867}
1868
1869// mask_array
1870
1871template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001872class _LIBCPP_TEMPLATE_VIS mask_array
Howard Hinnantc51e1022010-05-11 19:42:16 +00001873{
1874public:
1875 typedef _Tp value_type;
1876
1877private:
1878 value_type* __vp_;
1879 valarray<size_t> __1d_;
1880
1881public:
1882 template <class _Expr>
1883 typename enable_if
1884 <
1885 __is_val_expr<_Expr>::value,
1886 void
1887 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001889 operator=(const _Expr& __v) const;
1890
1891 template <class _Expr>
1892 typename enable_if
1893 <
1894 __is_val_expr<_Expr>::value,
1895 void
1896 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001898 operator*=(const _Expr& __v) const;
1899
1900 template <class _Expr>
1901 typename enable_if
1902 <
1903 __is_val_expr<_Expr>::value,
1904 void
1905 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001907 operator/=(const _Expr& __v) const;
1908
1909 template <class _Expr>
1910 typename enable_if
1911 <
1912 __is_val_expr<_Expr>::value,
1913 void
1914 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001915 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001916 operator%=(const _Expr& __v) const;
1917
1918 template <class _Expr>
1919 typename enable_if
1920 <
1921 __is_val_expr<_Expr>::value,
1922 void
1923 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001924 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001925 operator+=(const _Expr& __v) const;
1926
1927 template <class _Expr>
1928 typename enable_if
1929 <
1930 __is_val_expr<_Expr>::value,
1931 void
1932 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001934 operator-=(const _Expr& __v) const;
1935
1936 template <class _Expr>
1937 typename enable_if
1938 <
1939 __is_val_expr<_Expr>::value,
1940 void
1941 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001942 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001943 operator^=(const _Expr& __v) const;
1944
1945 template <class _Expr>
1946 typename enable_if
1947 <
1948 __is_val_expr<_Expr>::value,
1949 void
1950 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001951 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001952 operator&=(const _Expr& __v) const;
1953
1954 template <class _Expr>
1955 typename enable_if
1956 <
1957 __is_val_expr<_Expr>::value,
1958 void
1959 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001960 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001961 operator|=(const _Expr& __v) const;
1962
1963 template <class _Expr>
1964 typename enable_if
1965 <
1966 __is_val_expr<_Expr>::value,
1967 void
1968 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001970 operator<<=(const _Expr& __v) const;
1971
1972 template <class _Expr>
1973 typename enable_if
1974 <
1975 __is_val_expr<_Expr>::value,
1976 void
1977 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001979 operator>>=(const _Expr& __v) const;
1980
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001981 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001982 const mask_array& operator=(const mask_array& __ma) const;
1983
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001984 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001985 void operator=(const value_type& __x) const;
1986
1987// mask_array(const mask_array&) = default;
1988// mask_array(mask_array&&) = default;
1989// mask_array& operator=(const mask_array&) = default;
1990// mask_array& operator=(mask_array&&) = default;
1991
1992private:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00001993 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001994 mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
1995 : __vp_(const_cast<value_type*>(__v.__begin_)),
Howard Hinnant28b24882011-12-01 20:21:04 +00001996 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001997 {
1998 size_t __j = 0;
1999 for (size_t __i = 0; __i < __vb.size(); ++__i)
2000 if (__vb[__i])
2001 __1d_[__j++] = __i;
2002 }
2003
2004 template <class> friend class valarray;
2005};
2006
2007template <class _Tp>
2008template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002009inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002010typename enable_if
2011<
2012 __is_val_expr<_Expr>::value,
2013 void
2014>::type
2015mask_array<_Tp>::operator=(const _Expr& __v) const
2016{
2017 size_t __n = __1d_.size();
2018 for (size_t __i = 0; __i < __n; ++__i)
2019 __vp_[__1d_[__i]] = __v[__i];
2020}
2021
2022template <class _Tp>
2023template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002024inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002025typename enable_if
2026<
2027 __is_val_expr<_Expr>::value,
2028 void
2029>::type
2030mask_array<_Tp>::operator*=(const _Expr& __v) const
2031{
2032 size_t __n = __1d_.size();
2033 for (size_t __i = 0; __i < __n; ++__i)
2034 __vp_[__1d_[__i]] *= __v[__i];
2035}
2036
2037template <class _Tp>
2038template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002039inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002040typename enable_if
2041<
2042 __is_val_expr<_Expr>::value,
2043 void
2044>::type
2045mask_array<_Tp>::operator/=(const _Expr& __v) const
2046{
2047 size_t __n = __1d_.size();
2048 for (size_t __i = 0; __i < __n; ++__i)
2049 __vp_[__1d_[__i]] /= __v[__i];
2050}
2051
2052template <class _Tp>
2053template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002054inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002055typename enable_if
2056<
2057 __is_val_expr<_Expr>::value,
2058 void
2059>::type
2060mask_array<_Tp>::operator%=(const _Expr& __v) const
2061{
2062 size_t __n = __1d_.size();
2063 for (size_t __i = 0; __i < __n; ++__i)
2064 __vp_[__1d_[__i]] %= __v[__i];
2065}
2066
2067template <class _Tp>
2068template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002069inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002070typename enable_if
2071<
2072 __is_val_expr<_Expr>::value,
2073 void
2074>::type
2075mask_array<_Tp>::operator+=(const _Expr& __v) const
2076{
2077 size_t __n = __1d_.size();
2078 for (size_t __i = 0; __i < __n; ++__i)
2079 __vp_[__1d_[__i]] += __v[__i];
2080}
2081
2082template <class _Tp>
2083template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002084inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002085typename enable_if
2086<
2087 __is_val_expr<_Expr>::value,
2088 void
2089>::type
2090mask_array<_Tp>::operator-=(const _Expr& __v) const
2091{
2092 size_t __n = __1d_.size();
2093 for (size_t __i = 0; __i < __n; ++__i)
2094 __vp_[__1d_[__i]] -= __v[__i];
2095}
2096
2097template <class _Tp>
2098template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002099inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002100typename enable_if
2101<
2102 __is_val_expr<_Expr>::value,
2103 void
2104>::type
2105mask_array<_Tp>::operator^=(const _Expr& __v) const
2106{
2107 size_t __n = __1d_.size();
2108 for (size_t __i = 0; __i < __n; ++__i)
2109 __vp_[__1d_[__i]] ^= __v[__i];
2110}
2111
2112template <class _Tp>
2113template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002114inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002115typename enable_if
2116<
2117 __is_val_expr<_Expr>::value,
2118 void
2119>::type
2120mask_array<_Tp>::operator&=(const _Expr& __v) const
2121{
2122 size_t __n = __1d_.size();
2123 for (size_t __i = 0; __i < __n; ++__i)
2124 __vp_[__1d_[__i]] &= __v[__i];
2125}
2126
2127template <class _Tp>
2128template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002129inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002130typename enable_if
2131<
2132 __is_val_expr<_Expr>::value,
2133 void
2134>::type
2135mask_array<_Tp>::operator|=(const _Expr& __v) const
2136{
2137 size_t __n = __1d_.size();
2138 for (size_t __i = 0; __i < __n; ++__i)
2139 __vp_[__1d_[__i]] |= __v[__i];
2140}
2141
2142template <class _Tp>
2143template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002144inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002145typename enable_if
2146<
2147 __is_val_expr<_Expr>::value,
2148 void
2149>::type
2150mask_array<_Tp>::operator<<=(const _Expr& __v) const
2151{
2152 size_t __n = __1d_.size();
2153 for (size_t __i = 0; __i < __n; ++__i)
2154 __vp_[__1d_[__i]] <<= __v[__i];
2155}
2156
2157template <class _Tp>
2158template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002159inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002160typename enable_if
2161<
2162 __is_val_expr<_Expr>::value,
2163 void
2164>::type
2165mask_array<_Tp>::operator>>=(const _Expr& __v) const
2166{
2167 size_t __n = __1d_.size();
2168 for (size_t __i = 0; __i < __n; ++__i)
2169 __vp_[__1d_[__i]] >>= __v[__i];
2170}
2171
2172template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002173inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002174const mask_array<_Tp>&
2175mask_array<_Tp>::operator=(const mask_array& __ma) const
2176{
2177 size_t __n = __1d_.size();
2178 for (size_t __i = 0; __i < __n; ++__i)
2179 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
Eric Fiselier3b80ce92014-08-12 00:06:58 +00002180 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002181}
2182
2183template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002184inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002185void
2186mask_array<_Tp>::operator=(const value_type& __x) const
2187{
2188 size_t __n = __1d_.size();
2189 for (size_t __i = 0; __i < __n; ++__i)
2190 __vp_[__1d_[__i]] = __x;
2191}
2192
2193template <class _ValExpr>
2194class __mask_expr
2195{
2196 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2197public:
2198 typedef typename _RmExpr::value_type value_type;
2199 typedef value_type result_type;
2200
2201private:
2202 _ValExpr __expr_;
2203 valarray<size_t> __1d_;
2204
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002205 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002206 __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
2207 : __expr_(__e),
Howard Hinnant28b24882011-12-01 20:21:04 +00002208 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002209 {
2210 size_t __j = 0;
2211 for (size_t __i = 0; __i < __vb.size(); ++__i)
2212 if (__vb[__i])
2213 __1d_[__j++] = __i;
2214 }
2215
2216public:
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002217 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002218 result_type operator[](size_t __i) const
2219 {return __expr_[__1d_[__i]];}
2220
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002221 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002222 size_t size() const {return __1d_.size();}
2223
2224 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 Fiselierb5eb1bf2017-01-04 23:56:00 +00002594 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002595};
2596
2597template<class _ValExpr>
2598class __val_expr
2599{
2600 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2601
2602 _ValExpr __expr_;
2603public:
2604 typedef typename _RmExpr::value_type value_type;
2605 typedef typename _RmExpr::result_type result_type;
2606
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002608 explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
2609
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002611 result_type operator[](size_t __i) const
2612 {return __expr_[__i];}
2613
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002614 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002615 __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
2616 {return __val_expr<__slice_expr<_ValExpr> >(__expr_, __s);}
2617
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002619 __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const
2620 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __gs.__1d_);}
2621
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002623 __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
2624 {return __val_expr<__mask_expr<_ValExpr> >(__expr_, __vb);}
2625
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002627 __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
2628 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __vs);}
2629
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002631 __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
2632 operator+() const
2633 {
2634 typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
2635 return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
2636 }
2637
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002638 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002639 __val_expr<_UnaryOp<negate<value_type>, _ValExpr> >
2640 operator-() const
2641 {
2642 typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
2643 return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
2644 }
2645
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002646 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002647 __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> >
2648 operator~() const
2649 {
2650 typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
2651 return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
2652 }
2653
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002655 __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> >
2656 operator!() const
2657 {
2658 typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
2659 return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
2660 }
2661
2662 operator valarray<result_type>() const;
2663
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002664 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002665 size_t size() const {return __expr_.size();}
2666
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002667 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002668 result_type sum() const
2669 {
2670 size_t __n = __expr_.size();
2671 result_type __r = __n ? __expr_[0] : result_type();
2672 for (size_t __i = 1; __i < __n; ++__i)
2673 __r += __expr_[__i];
2674 return __r;
2675 }
2676
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002678 result_type min() const
2679 {
2680 size_t __n = size();
2681 result_type __r = __n ? (*this)[0] : result_type();
2682 for (size_t __i = 1; __i < __n; ++__i)
2683 {
2684 result_type __x = __expr_[__i];
2685 if (__x < __r)
2686 __r = __x;
2687 }
2688 return __r;
2689 }
2690
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002691 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002692 result_type max() const
2693 {
2694 size_t __n = size();
2695 result_type __r = __n ? (*this)[0] : result_type();
2696 for (size_t __i = 1; __i < __n; ++__i)
2697 {
2698 result_type __x = __expr_[__i];
2699 if (__r < __x)
2700 __r = __x;
2701 }
2702 return __r;
2703 }
2704
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002706 __val_expr<__shift_expr<_ValExpr> > shift (int __i) const
2707 {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));}
2708
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002709 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002710 __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const
2711 {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));}
2712
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002713 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002714 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> >
2715 apply(value_type __f(value_type)) const
2716 {
2717 typedef __apply_expr<value_type, value_type(*)(value_type)> _Op;
2718 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2719 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2720 }
2721
Howard Hinnant1c265cd2010-09-23 18:58:28 +00002722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002723 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> >
2724 apply(value_type __f(const value_type&)) const
2725 {
2726 typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op;
2727 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2728 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2729 }
2730};
2731
2732template<class _ValExpr>
Howard Hinnanta77b71b2013-09-13 23:27:42 +00002733__val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00002734{
2735 valarray<result_type> __r;
2736 size_t __n = __expr_.size();
2737 if (__n)
2738 {
2739 __r.__begin_ =
2740 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00002741 static_cast<result_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002742 _VSTD::__libcpp_allocate(__n * sizeof(result_type), _LIBCPP_ALIGNOF(result_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002743 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
2744 ::new (__r.__end_) result_type(__expr_[__i]);
2745 }
2746 return __r;
2747}
2748
2749// valarray
2750
2751template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002752inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002753valarray<_Tp>::valarray(size_t __n)
2754 : __begin_(0),
2755 __end_(0)
2756{
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002757 if (__n)
2758 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002759 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002760 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002761#ifndef _LIBCPP_NO_EXCEPTIONS
2762 try
2763 {
2764#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002765 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002766 ::new (__end_) value_type();
2767#ifndef _LIBCPP_NO_EXCEPTIONS
2768 }
2769 catch (...)
2770 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002771 __clear(__n);
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00002772 throw;
2773 }
2774#endif // _LIBCPP_NO_EXCEPTIONS
2775 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002776}
2777
2778template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002779inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002780valarray<_Tp>::valarray(const value_type& __x, size_t __n)
2781 : __begin_(0),
2782 __end_(0)
2783{
2784 resize(__n, __x);
2785}
2786
2787template <class _Tp>
2788valarray<_Tp>::valarray(const value_type* __p, size_t __n)
2789 : __begin_(0),
2790 __end_(0)
2791{
2792 if (__n)
2793 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002794 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002795 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002796#ifndef _LIBCPP_NO_EXCEPTIONS
2797 try
2798 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002799#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002800 for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002801 ::new (__end_) value_type(*__p);
2802#ifndef _LIBCPP_NO_EXCEPTIONS
2803 }
2804 catch (...)
2805 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002806 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002807 throw;
2808 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002809#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002810 }
2811}
2812
2813template <class _Tp>
2814valarray<_Tp>::valarray(const valarray& __v)
2815 : __begin_(0),
2816 __end_(0)
2817{
2818 if (__v.size())
2819 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002820 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002821 _VSTD::__libcpp_allocate(__v.size() * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002822#ifndef _LIBCPP_NO_EXCEPTIONS
2823 try
2824 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002825#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002826 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
2827 ::new (__end_) value_type(*__p);
2828#ifndef _LIBCPP_NO_EXCEPTIONS
2829 }
2830 catch (...)
2831 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002832 __clear(__v.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002833 throw;
2834 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002835#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002836 }
2837}
2838
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002839#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002840
2841template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002842inline
Howard Hinnant298aed92012-07-21 00:51:28 +00002843valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002844 : __begin_(__v.__begin_),
2845 __end_(__v.__end_)
2846{
2847 __v.__begin_ = __v.__end_ = nullptr;
2848}
2849
2850template <class _Tp>
2851valarray<_Tp>::valarray(initializer_list<value_type> __il)
2852 : __begin_(0),
2853 __end_(0)
2854{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002855 const size_t __n = __il.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002856 if (__n)
2857 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002858 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002859_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002860#ifndef _LIBCPP_NO_EXCEPTIONS
2861 try
2862 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002863#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002864 size_t __n_left = __n;
2865 for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002866 ::new (__end_) value_type(*__p);
2867#ifndef _LIBCPP_NO_EXCEPTIONS
2868 }
2869 catch (...)
2870 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002871 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002872 throw;
2873 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002874#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002875 }
2876}
2877
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00002878#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002879
2880template <class _Tp>
2881valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
2882 : __begin_(0),
2883 __end_(0)
2884{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002885 const size_t __n = __sa.__size_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002886 if (__n)
2887 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002888 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002889 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002890#ifndef _LIBCPP_NO_EXCEPTIONS
2891 try
2892 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002893#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00002894 size_t __n_left = __n;
2895 for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002896 ::new (__end_) value_type(*__p);
2897#ifndef _LIBCPP_NO_EXCEPTIONS
2898 }
2899 catch (...)
2900 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002901 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002902 throw;
2903 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002904#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002905 }
2906}
2907
2908template <class _Tp>
2909valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
2910 : __begin_(0),
2911 __end_(0)
2912{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002913 const size_t __n = __ga.__1d_.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002914 if (__n)
2915 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002916 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002917 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002918#ifndef _LIBCPP_NO_EXCEPTIONS
2919 try
2920 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002921#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002922 typedef const size_t* _Ip;
2923 const value_type* __s = __ga.__vp_;
2924 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2925 __i != __e; ++__i, ++__end_)
2926 ::new (__end_) value_type(__s[*__i]);
2927#ifndef _LIBCPP_NO_EXCEPTIONS
2928 }
2929 catch (...)
2930 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002931 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002932 throw;
2933 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002934#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002935 }
2936}
2937
2938template <class _Tp>
2939valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
2940 : __begin_(0),
2941 __end_(0)
2942{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002943 const size_t __n = __ma.__1d_.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002944 if (__n)
2945 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002946 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002947 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002948#ifndef _LIBCPP_NO_EXCEPTIONS
2949 try
2950 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002951#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002952 typedef const size_t* _Ip;
2953 const value_type* __s = __ma.__vp_;
2954 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2955 __i != __e; ++__i, ++__end_)
2956 ::new (__end_) value_type(__s[*__i]);
2957#ifndef _LIBCPP_NO_EXCEPTIONS
2958 }
2959 catch (...)
2960 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002961 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002962 throw;
2963 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002964#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002965 }
2966}
2967
2968template <class _Tp>
2969valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
2970 : __begin_(0),
2971 __end_(0)
2972{
Eric Fiselier2856ef82018-10-25 17:21:30 +00002973 const size_t __n = __ia.__1d_.size();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002974 if (__n)
2975 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00002976 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002977 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002978#ifndef _LIBCPP_NO_EXCEPTIONS
2979 try
2980 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002981#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002982 typedef const size_t* _Ip;
2983 const value_type* __s = __ia.__vp_;
2984 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2985 __i != __e; ++__i, ++__end_)
2986 ::new (__end_) value_type(__s[*__i]);
2987#ifndef _LIBCPP_NO_EXCEPTIONS
2988 }
2989 catch (...)
2990 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00002991 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002992 throw;
2993 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002994#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002995 }
2996}
2997
2998template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00002999inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003000valarray<_Tp>::~valarray()
3001{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003002 __clear(size());
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003003}
3004
3005template <class _Tp>
3006valarray<_Tp>&
3007valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l)
3008{
3009 size_t __n = __l - __f;
3010 if (size() != __n)
3011 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00003012 __clear(size());
Eric Fiselier06548ab2018-03-22 04:42:56 +00003013 __begin_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003014 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003015 __end_ = __begin_ + __n;
3016 _VSTD::uninitialized_copy(__f, __l, __begin_);
3017 } else {
3018 _VSTD::copy(__f, __l, __begin_);
3019 }
3020 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003021}
3022
3023template <class _Tp>
3024valarray<_Tp>&
3025valarray<_Tp>::operator=(const valarray& __v)
3026{
3027 if (this != &__v)
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003028 return __assign_range(__v.__begin_, __v.__end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003029 return *this;
3030}
3031
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003032#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003033
3034template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003035inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003036valarray<_Tp>&
Howard Hinnant298aed92012-07-21 00:51:28 +00003037valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003038{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003039 __clear(size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003040 __begin_ = __v.__begin_;
3041 __end_ = __v.__end_;
3042 __v.__begin_ = nullptr;
3043 __v.__end_ = nullptr;
3044 return *this;
3045}
3046
3047template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003048inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003049valarray<_Tp>&
3050valarray<_Tp>::operator=(initializer_list<value_type> __il)
3051{
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003052 return __assign_range(__il.begin(), __il.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003053}
3054
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003055#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003056
3057template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003058inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003059valarray<_Tp>&
3060valarray<_Tp>::operator=(const value_type& __x)
3061{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003062 _VSTD::fill(__begin_, __end_, __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003063 return *this;
3064}
3065
3066template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003067inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003068valarray<_Tp>&
3069valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
3070{
3071 value_type* __t = __begin_;
3072 const value_type* __s = __sa.__vp_;
3073 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
3074 *__t = *__s;
3075 return *this;
3076}
3077
3078template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003079inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003080valarray<_Tp>&
3081valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
3082{
3083 typedef const size_t* _Ip;
3084 value_type* __t = __begin_;
3085 const value_type* __s = __ga.__vp_;
3086 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
3087 __i != __e; ++__i, ++__t)
3088 *__t = __s[*__i];
3089 return *this;
3090}
3091
3092template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003093inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003094valarray<_Tp>&
3095valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
3096{
3097 typedef const size_t* _Ip;
3098 value_type* __t = __begin_;
3099 const value_type* __s = __ma.__vp_;
3100 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
3101 __i != __e; ++__i, ++__t)
3102 *__t = __s[*__i];
3103 return *this;
3104}
3105
3106template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003107inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003108valarray<_Tp>&
3109valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
3110{
3111 typedef const size_t* _Ip;
3112 value_type* __t = __begin_;
3113 const value_type* __s = __ia.__vp_;
3114 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
3115 __i != __e; ++__i, ++__t)
3116 *__t = __s[*__i];
3117 return *this;
3118}
3119
3120template <class _Tp>
Howard Hinnant329cd412011-07-27 23:19:59 +00003121template <class _ValExpr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003122inline
Howard Hinnant329cd412011-07-27 23:19:59 +00003123valarray<_Tp>&
3124valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
3125{
3126 size_t __n = __v.size();
3127 if (size() != __n)
3128 resize(__n);
3129 value_type* __t = __begin_;
3130 for (size_t __i = 0; __i != __n; ++__t, ++__i)
3131 *__t = result_type(__v[__i]);
3132 return *this;
3133}
3134
3135template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003136inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003137__val_expr<__slice_expr<const valarray<_Tp>&> >
3138valarray<_Tp>::operator[](slice __s) const
3139{
3140 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
3141}
3142
3143template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003144inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003145slice_array<_Tp>
3146valarray<_Tp>::operator[](slice __s)
3147{
3148 return slice_array<value_type>(__s, *this);
3149}
3150
3151template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003152inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003153__val_expr<__indirect_expr<const valarray<_Tp>&> >
3154valarray<_Tp>::operator[](const gslice& __gs) const
3155{
3156 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
3157}
3158
3159template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003160inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003161gslice_array<_Tp>
3162valarray<_Tp>::operator[](const gslice& __gs)
3163{
3164 return gslice_array<value_type>(__gs, *this);
3165}
3166
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003167#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003168
3169template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003170inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003171__val_expr<__indirect_expr<const valarray<_Tp>&> >
3172valarray<_Tp>::operator[](gslice&& __gs) const
3173{
3174 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
3175}
3176
3177template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003178inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003179gslice_array<_Tp>
3180valarray<_Tp>::operator[](gslice&& __gs)
3181{
3182 return gslice_array<value_type>(move(__gs), *this);
3183}
3184
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003185#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003186
3187template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003188inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003189__val_expr<__mask_expr<const valarray<_Tp>&> >
3190valarray<_Tp>::operator[](const valarray<bool>& __vb) const
3191{
3192 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
3193}
3194
3195template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003196inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003197mask_array<_Tp>
3198valarray<_Tp>::operator[](const valarray<bool>& __vb)
3199{
3200 return mask_array<value_type>(__vb, *this);
3201}
3202
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003203#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003204
3205template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003206inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003207__val_expr<__mask_expr<const valarray<_Tp>&> >
3208valarray<_Tp>::operator[](valarray<bool>&& __vb) const
3209{
3210 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
3211}
3212
3213template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003214inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003215mask_array<_Tp>
3216valarray<_Tp>::operator[](valarray<bool>&& __vb)
3217{
3218 return mask_array<value_type>(move(__vb), *this);
3219}
3220
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003221#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003222
3223template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003224inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003225__val_expr<__indirect_expr<const valarray<_Tp>&> >
3226valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
3227{
3228 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
3229}
3230
3231template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003232inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003233indirect_array<_Tp>
3234valarray<_Tp>::operator[](const valarray<size_t>& __vs)
3235{
3236 return indirect_array<value_type>(__vs, *this);
3237}
3238
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003239#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003240
3241template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003242inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003243__val_expr<__indirect_expr<const valarray<_Tp>&> >
3244valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
3245{
3246 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
3247}
3248
3249template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003250inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003251indirect_array<_Tp>
3252valarray<_Tp>::operator[](valarray<size_t>&& __vs)
3253{
3254 return indirect_array<value_type>(move(__vs), *this);
3255}
3256
Eric Fiselier3b0b81f2017-04-19 00:23:45 +00003257#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003258
3259template <class _Tp>
3260valarray<_Tp>
3261valarray<_Tp>::operator+() const
3262{
3263 valarray<value_type> __r;
3264 size_t __n = size();
3265 if (__n)
3266 {
3267 __r.__begin_ =
3268 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003269 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003270 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003271 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3272 ::new (__r.__end_) value_type(+*__p);
3273 }
3274 return __r;
3275}
3276
3277template <class _Tp>
3278valarray<_Tp>
3279valarray<_Tp>::operator-() const
3280{
3281 valarray<value_type> __r;
3282 size_t __n = size();
3283 if (__n)
3284 {
3285 __r.__begin_ =
3286 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003287 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003288 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003289 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3290 ::new (__r.__end_) value_type(-*__p);
3291 }
3292 return __r;
3293}
3294
3295template <class _Tp>
3296valarray<_Tp>
3297valarray<_Tp>::operator~() const
3298{
3299 valarray<value_type> __r;
3300 size_t __n = size();
3301 if (__n)
3302 {
3303 __r.__begin_ =
3304 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003305 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003306 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003307 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3308 ::new (__r.__end_) value_type(~*__p);
3309 }
3310 return __r;
3311}
3312
3313template <class _Tp>
3314valarray<bool>
3315valarray<_Tp>::operator!() const
3316{
3317 valarray<bool> __r;
3318 size_t __n = size();
3319 if (__n)
3320 {
3321 __r.__begin_ =
3322 __r.__end_ =
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003323 static_cast<bool*>(_VSTD::__libcpp_allocate(__n * sizeof(bool), _LIBCPP_ALIGNOF(bool)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003324 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3325 ::new (__r.__end_) bool(!*__p);
3326 }
3327 return __r;
3328}
3329
3330template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003331inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003332valarray<_Tp>&
3333valarray<_Tp>::operator*=(const value_type& __x)
3334{
3335 for (value_type* __p = __begin_; __p != __end_; ++__p)
3336 *__p *= __x;
3337 return *this;
3338}
3339
3340template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003341inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003342valarray<_Tp>&
3343valarray<_Tp>::operator/=(const value_type& __x)
3344{
3345 for (value_type* __p = __begin_; __p != __end_; ++__p)
3346 *__p /= __x;
3347 return *this;
3348}
3349
3350template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003351inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003352valarray<_Tp>&
3353valarray<_Tp>::operator%=(const value_type& __x)
3354{
3355 for (value_type* __p = __begin_; __p != __end_; ++__p)
3356 *__p %= __x;
3357 return *this;
3358}
3359
3360template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003361inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003362valarray<_Tp>&
3363valarray<_Tp>::operator+=(const value_type& __x)
3364{
3365 for (value_type* __p = __begin_; __p != __end_; ++__p)
3366 *__p += __x;
3367 return *this;
3368}
3369
3370template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003371inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003372valarray<_Tp>&
3373valarray<_Tp>::operator-=(const value_type& __x)
3374{
3375 for (value_type* __p = __begin_; __p != __end_; ++__p)
3376 *__p -= __x;
3377 return *this;
3378}
3379
3380template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003381inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003382valarray<_Tp>&
3383valarray<_Tp>::operator^=(const value_type& __x)
3384{
3385 for (value_type* __p = __begin_; __p != __end_; ++__p)
3386 *__p ^= __x;
3387 return *this;
3388}
3389
3390template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003391inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003392valarray<_Tp>&
3393valarray<_Tp>::operator&=(const value_type& __x)
3394{
3395 for (value_type* __p = __begin_; __p != __end_; ++__p)
3396 *__p &= __x;
3397 return *this;
3398}
3399
3400template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003401inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003402valarray<_Tp>&
3403valarray<_Tp>::operator|=(const value_type& __x)
3404{
3405 for (value_type* __p = __begin_; __p != __end_; ++__p)
3406 *__p |= __x;
3407 return *this;
3408}
3409
3410template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003411inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003412valarray<_Tp>&
3413valarray<_Tp>::operator<<=(const value_type& __x)
3414{
3415 for (value_type* __p = __begin_; __p != __end_; ++__p)
3416 *__p <<= __x;
3417 return *this;
3418}
3419
3420template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003421inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003422valarray<_Tp>&
3423valarray<_Tp>::operator>>=(const value_type& __x)
3424{
3425 for (value_type* __p = __begin_; __p != __end_; ++__p)
3426 *__p >>= __x;
3427 return *this;
3428}
3429
3430template <class _Tp>
3431template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003432inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003433typename enable_if
3434<
3435 __is_val_expr<_Expr>::value,
3436 valarray<_Tp>&
3437>::type
3438valarray<_Tp>::operator*=(const _Expr& __v)
3439{
3440 size_t __i = 0;
3441 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3442 *__t *= __v[__i];
3443 return *this;
3444}
3445
3446template <class _Tp>
3447template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003448inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003449typename enable_if
3450<
3451 __is_val_expr<_Expr>::value,
3452 valarray<_Tp>&
3453>::type
3454valarray<_Tp>::operator/=(const _Expr& __v)
3455{
3456 size_t __i = 0;
3457 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3458 *__t /= __v[__i];
3459 return *this;
3460}
3461
3462template <class _Tp>
3463template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003464inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003465typename enable_if
3466<
3467 __is_val_expr<_Expr>::value,
3468 valarray<_Tp>&
3469>::type
3470valarray<_Tp>::operator%=(const _Expr& __v)
3471{
3472 size_t __i = 0;
3473 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3474 *__t %= __v[__i];
3475 return *this;
3476}
3477
3478template <class _Tp>
3479template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003480inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003481typename enable_if
3482<
3483 __is_val_expr<_Expr>::value,
3484 valarray<_Tp>&
3485>::type
3486valarray<_Tp>::operator+=(const _Expr& __v)
3487{
3488 size_t __i = 0;
3489 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3490 *__t += __v[__i];
3491 return *this;
3492}
3493
3494template <class _Tp>
3495template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003496inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003497typename enable_if
3498<
3499 __is_val_expr<_Expr>::value,
3500 valarray<_Tp>&
3501>::type
3502valarray<_Tp>::operator-=(const _Expr& __v)
3503{
3504 size_t __i = 0;
3505 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3506 *__t -= __v[__i];
3507 return *this;
3508}
3509
3510template <class _Tp>
3511template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003512inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003513typename enable_if
3514<
3515 __is_val_expr<_Expr>::value,
3516 valarray<_Tp>&
3517>::type
3518valarray<_Tp>::operator^=(const _Expr& __v)
3519{
3520 size_t __i = 0;
3521 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3522 *__t ^= __v[__i];
3523 return *this;
3524}
3525
3526template <class _Tp>
3527template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003528inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003529typename enable_if
3530<
3531 __is_val_expr<_Expr>::value,
3532 valarray<_Tp>&
3533>::type
3534valarray<_Tp>::operator|=(const _Expr& __v)
3535{
3536 size_t __i = 0;
3537 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3538 *__t |= __v[__i];
3539 return *this;
3540}
3541
3542template <class _Tp>
3543template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003544inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003545typename enable_if
3546<
3547 __is_val_expr<_Expr>::value,
3548 valarray<_Tp>&
3549>::type
3550valarray<_Tp>::operator&=(const _Expr& __v)
3551{
3552 size_t __i = 0;
3553 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3554 *__t &= __v[__i];
3555 return *this;
3556}
3557
3558template <class _Tp>
3559template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003560inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003561typename enable_if
3562<
3563 __is_val_expr<_Expr>::value,
3564 valarray<_Tp>&
3565>::type
3566valarray<_Tp>::operator<<=(const _Expr& __v)
3567{
3568 size_t __i = 0;
3569 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3570 *__t <<= __v[__i];
3571 return *this;
3572}
3573
3574template <class _Tp>
3575template <class _Expr>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003576inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003577typename enable_if
3578<
3579 __is_val_expr<_Expr>::value,
3580 valarray<_Tp>&
3581>::type
3582valarray<_Tp>::operator>>=(const _Expr& __v)
3583{
3584 size_t __i = 0;
3585 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3586 *__t >>= __v[__i];
3587 return *this;
3588}
3589
3590template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003591inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003592void
Howard Hinnant298aed92012-07-21 00:51:28 +00003593valarray<_Tp>::swap(valarray& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003594{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003595 _VSTD::swap(__begin_, __v.__begin_);
3596 _VSTD::swap(__end_, __v.__end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003597}
3598
3599template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003600inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003601_Tp
3602valarray<_Tp>::sum() const
3603{
3604 if (__begin_ == __end_)
3605 return value_type();
3606 const value_type* __p = __begin_;
3607 _Tp __r = *__p;
3608 for (++__p; __p != __end_; ++__p)
3609 __r += *__p;
3610 return __r;
3611}
3612
3613template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003614inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003615_Tp
3616valarray<_Tp>::min() const
3617{
3618 if (__begin_ == __end_)
3619 return value_type();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003620 return *_VSTD::min_element(__begin_, __end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003621}
3622
3623template <class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003624inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003625_Tp
3626valarray<_Tp>::max() const
3627{
3628 if (__begin_ == __end_)
3629 return value_type();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003630 return *_VSTD::max_element(__begin_, __end_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003631}
3632
3633template <class _Tp>
3634valarray<_Tp>
3635valarray<_Tp>::shift(int __i) const
3636{
3637 valarray<value_type> __r;
3638 size_t __n = size();
3639 if (__n)
3640 {
3641 __r.__begin_ =
3642 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003643 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003644 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003645 const value_type* __sb;
3646 value_type* __tb;
3647 value_type* __te;
3648 if (__i >= 0)
3649 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003650 __i = _VSTD::min(__i, static_cast<int>(__n));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003651 __sb = __begin_ + __i;
3652 __tb = __r.__begin_;
3653 __te = __r.__begin_ + (__n - __i);
3654 }
3655 else
3656 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003657 __i = _VSTD::min(-__i, static_cast<int>(__n));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003658 __sb = __begin_;
3659 __tb = __r.__begin_ + __i;
3660 __te = __r.__begin_ + __n;
3661 }
3662 for (; __r.__end_ != __tb; ++__r.__end_)
3663 ::new (__r.__end_) value_type();
3664 for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
3665 ::new (__r.__end_) value_type(*__sb);
3666 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
3667 ::new (__r.__end_) value_type();
3668 }
3669 return __r;
3670}
3671
3672template <class _Tp>
3673valarray<_Tp>
3674valarray<_Tp>::cshift(int __i) const
3675{
3676 valarray<value_type> __r;
3677 size_t __n = size();
3678 if (__n)
3679 {
3680 __r.__begin_ =
3681 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003682 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003683 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003684 __i %= static_cast<int>(__n);
3685 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
3686 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
3687 ::new (__r.__end_) value_type(*__s);
3688 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
3689 ::new (__r.__end_) value_type(*__s);
3690 }
3691 return __r;
3692}
3693
3694template <class _Tp>
3695valarray<_Tp>
3696valarray<_Tp>::apply(value_type __f(value_type)) const
3697{
3698 valarray<value_type> __r;
3699 size_t __n = size();
3700 if (__n)
3701 {
3702 __r.__begin_ =
3703 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003704 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003705 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003706 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3707 ::new (__r.__end_) value_type(__f(*__p));
3708 }
3709 return __r;
3710}
3711
3712template <class _Tp>
3713valarray<_Tp>
3714valarray<_Tp>::apply(value_type __f(const value_type&)) const
3715{
3716 valarray<value_type> __r;
3717 size_t __n = size();
3718 if (__n)
3719 {
3720 __r.__begin_ =
3721 __r.__end_ =
Eric Fiselier06548ab2018-03-22 04:42:56 +00003722 static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003723 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003724 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3725 ::new (__r.__end_) value_type(__f(*__p));
3726 }
3727 return __r;
3728}
3729
3730template <class _Tp>
Eric Fiseliera119c322018-10-25 17:43:26 +00003731inline
Eric Fiselier2856ef82018-10-25 17:21:30 +00003732void valarray<_Tp>::__clear(size_t __capacity)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003733{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003734 if (__begin_ != nullptr)
3735 {
3736 while (__end_ != __begin_)
3737 (--__end_)->~value_type();
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003738 _VSTD::__libcpp_deallocate(__begin_, __capacity * sizeof(value_type), _LIBCPP_ALIGNOF(value_type));
Eric Fiselier2856ef82018-10-25 17:21:30 +00003739 __begin_ = __end_ = nullptr;
3740 }
Mikhail Maltsev59de6f82018-02-08 11:33:48 +00003741}
3742
3743template <class _Tp>
3744void
3745valarray<_Tp>::resize(size_t __n, value_type __x)
3746{
Eric Fiselier2856ef82018-10-25 17:21:30 +00003747 __clear(size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003748 if (__n)
3749 {
Eric Fiselier06548ab2018-03-22 04:42:56 +00003750 __begin_ = __end_ = static_cast<value_type*>(
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00003751 _VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003752#ifndef _LIBCPP_NO_EXCEPTIONS
3753 try
3754 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003755#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier2856ef82018-10-25 17:21:30 +00003756 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003757 ::new (__end_) value_type(__x);
3758#ifndef _LIBCPP_NO_EXCEPTIONS
3759 }
3760 catch (...)
3761 {
Eric Fiselier2856ef82018-10-25 17:21:30 +00003762 __clear(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003763 throw;
3764 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003765#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00003766 }
3767}
3768
3769template<class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003770inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003771void
Howard Hinnant298aed92012-07-21 00:51:28 +00003772swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003773{
3774 __x.swap(__y);
3775}
3776
3777template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003778inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003779typename enable_if
3780<
3781 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3782 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
3783>::type
3784operator*(const _Expr1& __x, const _Expr2& __y)
3785{
3786 typedef typename _Expr1::value_type value_type;
3787 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
3788 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
3789}
3790
3791template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003792inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003793typename enable_if
3794<
3795 __is_val_expr<_Expr>::value,
3796 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3797 _Expr, __scalar_expr<typename _Expr::value_type> > >
3798>::type
3799operator*(const _Expr& __x, const typename _Expr::value_type& __y)
3800{
3801 typedef typename _Expr::value_type value_type;
3802 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3803 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3804 __x, __scalar_expr<value_type>(__y, __x.size())));
3805}
3806
3807template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003808inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003809typename enable_if
3810<
3811 __is_val_expr<_Expr>::value,
3812 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3813 __scalar_expr<typename _Expr::value_type>, _Expr> >
3814>::type
3815operator*(const typename _Expr::value_type& __x, const _Expr& __y)
3816{
3817 typedef typename _Expr::value_type value_type;
3818 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3819 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3820 __scalar_expr<value_type>(__x, __y.size()), __y));
3821}
3822
3823template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003824inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003825typename enable_if
3826<
3827 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3828 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
3829>::type
3830operator/(const _Expr1& __x, const _Expr2& __y)
3831{
3832 typedef typename _Expr1::value_type value_type;
3833 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
3834 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
3835}
3836
3837template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003838inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003839typename enable_if
3840<
3841 __is_val_expr<_Expr>::value,
3842 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3843 _Expr, __scalar_expr<typename _Expr::value_type> > >
3844>::type
3845operator/(const _Expr& __x, const typename _Expr::value_type& __y)
3846{
3847 typedef typename _Expr::value_type value_type;
3848 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3849 return __val_expr<_Op>(_Op(divides<value_type>(),
3850 __x, __scalar_expr<value_type>(__y, __x.size())));
3851}
3852
3853template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003854inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003855typename enable_if
3856<
3857 __is_val_expr<_Expr>::value,
3858 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3859 __scalar_expr<typename _Expr::value_type>, _Expr> >
3860>::type
3861operator/(const typename _Expr::value_type& __x, const _Expr& __y)
3862{
3863 typedef typename _Expr::value_type value_type;
3864 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3865 return __val_expr<_Op>(_Op(divides<value_type>(),
3866 __scalar_expr<value_type>(__x, __y.size()), __y));
3867}
3868
3869template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003870inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003871typename enable_if
3872<
3873 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3874 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3875>::type
3876operator%(const _Expr1& __x, const _Expr2& __y)
3877{
3878 typedef typename _Expr1::value_type value_type;
3879 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
3880 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
3881}
3882
3883template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003884inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003885typename enable_if
3886<
3887 __is_val_expr<_Expr>::value,
3888 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3889 _Expr, __scalar_expr<typename _Expr::value_type> > >
3890>::type
3891operator%(const _Expr& __x, const typename _Expr::value_type& __y)
3892{
3893 typedef typename _Expr::value_type value_type;
3894 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3895 return __val_expr<_Op>(_Op(modulus<value_type>(),
3896 __x, __scalar_expr<value_type>(__y, __x.size())));
3897}
3898
3899template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003900inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003901typename enable_if
3902<
3903 __is_val_expr<_Expr>::value,
3904 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3905 __scalar_expr<typename _Expr::value_type>, _Expr> >
3906>::type
3907operator%(const typename _Expr::value_type& __x, const _Expr& __y)
3908{
3909 typedef typename _Expr::value_type value_type;
3910 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3911 return __val_expr<_Op>(_Op(modulus<value_type>(),
3912 __scalar_expr<value_type>(__x, __y.size()), __y));
3913}
3914
3915template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003916inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003917typename enable_if
3918<
3919 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3920 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3921>::type
3922operator+(const _Expr1& __x, const _Expr2& __y)
3923{
3924 typedef typename _Expr1::value_type value_type;
3925 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
3926 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
3927}
3928
3929template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003930inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003931typename enable_if
3932<
3933 __is_val_expr<_Expr>::value,
3934 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3935 _Expr, __scalar_expr<typename _Expr::value_type> > >
3936>::type
3937operator+(const _Expr& __x, const typename _Expr::value_type& __y)
3938{
3939 typedef typename _Expr::value_type value_type;
3940 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3941 return __val_expr<_Op>(_Op(plus<value_type>(),
3942 __x, __scalar_expr<value_type>(__y, __x.size())));
3943}
3944
3945template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003946inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003947typename enable_if
3948<
3949 __is_val_expr<_Expr>::value,
3950 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3951 __scalar_expr<typename _Expr::value_type>, _Expr> >
3952>::type
3953operator+(const typename _Expr::value_type& __x, const _Expr& __y)
3954{
3955 typedef typename _Expr::value_type value_type;
3956 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3957 return __val_expr<_Op>(_Op(plus<value_type>(),
3958 __scalar_expr<value_type>(__x, __y.size()), __y));
3959}
3960
3961template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003962inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003963typename enable_if
3964<
3965 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3966 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3967>::type
3968operator-(const _Expr1& __x, const _Expr2& __y)
3969{
3970 typedef typename _Expr1::value_type value_type;
3971 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
3972 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
3973}
3974
3975template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003976inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003977typename enable_if
3978<
3979 __is_val_expr<_Expr>::value,
3980 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3981 _Expr, __scalar_expr<typename _Expr::value_type> > >
3982>::type
3983operator-(const _Expr& __x, const typename _Expr::value_type& __y)
3984{
3985 typedef typename _Expr::value_type value_type;
3986 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3987 return __val_expr<_Op>(_Op(minus<value_type>(),
3988 __x, __scalar_expr<value_type>(__y, __x.size())));
3989}
3990
3991template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00003992inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003993typename enable_if
3994<
3995 __is_val_expr<_Expr>::value,
3996 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3997 __scalar_expr<typename _Expr::value_type>, _Expr> >
3998>::type
3999operator-(const typename _Expr::value_type& __x, const _Expr& __y)
4000{
4001 typedef typename _Expr::value_type value_type;
4002 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4003 return __val_expr<_Op>(_Op(minus<value_type>(),
4004 __scalar_expr<value_type>(__x, __y.size()), __y));
4005}
4006
4007template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004008inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004009typename enable_if
4010<
4011 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4012 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
4013>::type
4014operator^(const _Expr1& __x, const _Expr2& __y)
4015{
4016 typedef typename _Expr1::value_type value_type;
4017 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
4018 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
4019}
4020
4021template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004022inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004023typename enable_if
4024<
4025 __is_val_expr<_Expr>::value,
4026 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
4027 _Expr, __scalar_expr<typename _Expr::value_type> > >
4028>::type
4029operator^(const _Expr& __x, const typename _Expr::value_type& __y)
4030{
4031 typedef typename _Expr::value_type value_type;
4032 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4033 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
4034 __x, __scalar_expr<value_type>(__y, __x.size())));
4035}
4036
4037template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004038inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004039typename enable_if
4040<
4041 __is_val_expr<_Expr>::value,
4042 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
4043 __scalar_expr<typename _Expr::value_type>, _Expr> >
4044>::type
4045operator^(const typename _Expr::value_type& __x, const _Expr& __y)
4046{
4047 typedef typename _Expr::value_type value_type;
4048 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4049 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
4050 __scalar_expr<value_type>(__x, __y.size()), __y));
4051}
4052
4053template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004054inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004055typename enable_if
4056<
4057 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4058 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4059>::type
4060operator&(const _Expr1& __x, const _Expr2& __y)
4061{
4062 typedef typename _Expr1::value_type value_type;
4063 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
4064 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
4065}
4066
4067template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004068inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004069typename enable_if
4070<
4071 __is_val_expr<_Expr>::value,
4072 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4073 _Expr, __scalar_expr<typename _Expr::value_type> > >
4074>::type
4075operator&(const _Expr& __x, const typename _Expr::value_type& __y)
4076{
4077 typedef typename _Expr::value_type value_type;
4078 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4079 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4080 __x, __scalar_expr<value_type>(__y, __x.size())));
4081}
4082
4083template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004084inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004085typename enable_if
4086<
4087 __is_val_expr<_Expr>::value,
4088 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4089 __scalar_expr<typename _Expr::value_type>, _Expr> >
4090>::type
4091operator&(const typename _Expr::value_type& __x, const _Expr& __y)
4092{
4093 typedef typename _Expr::value_type value_type;
4094 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4095 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4096 __scalar_expr<value_type>(__x, __y.size()), __y));
4097}
4098
4099template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004100inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004101typename enable_if
4102<
4103 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4104 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4105>::type
4106operator|(const _Expr1& __x, const _Expr2& __y)
4107{
4108 typedef typename _Expr1::value_type value_type;
4109 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
4110 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
4111}
4112
4113template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004114inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004115typename enable_if
4116<
4117 __is_val_expr<_Expr>::value,
4118 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4119 _Expr, __scalar_expr<typename _Expr::value_type> > >
4120>::type
4121operator|(const _Expr& __x, const typename _Expr::value_type& __y)
4122{
4123 typedef typename _Expr::value_type value_type;
4124 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4125 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4126 __x, __scalar_expr<value_type>(__y, __x.size())));
4127}
4128
4129template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004130inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004131typename enable_if
4132<
4133 __is_val_expr<_Expr>::value,
4134 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4135 __scalar_expr<typename _Expr::value_type>, _Expr> >
4136>::type
4137operator|(const typename _Expr::value_type& __x, const _Expr& __y)
4138{
4139 typedef typename _Expr::value_type value_type;
4140 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4141 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4142 __scalar_expr<value_type>(__x, __y.size()), __y));
4143}
4144
4145template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004146inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004147typename enable_if
4148<
4149 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4150 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
4151>::type
4152operator<<(const _Expr1& __x, const _Expr2& __y)
4153{
4154 typedef typename _Expr1::value_type value_type;
4155 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
4156 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
4157}
4158
4159template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004160inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004161typename enable_if
4162<
4163 __is_val_expr<_Expr>::value,
4164 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4165 _Expr, __scalar_expr<typename _Expr::value_type> > >
4166>::type
4167operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
4168{
4169 typedef typename _Expr::value_type value_type;
4170 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4171 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4172 __x, __scalar_expr<value_type>(__y, __x.size())));
4173}
4174
4175template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004176inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004177typename enable_if
4178<
4179 __is_val_expr<_Expr>::value,
4180 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4181 __scalar_expr<typename _Expr::value_type>, _Expr> >
4182>::type
4183operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
4184{
4185 typedef typename _Expr::value_type value_type;
4186 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4187 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4188 __scalar_expr<value_type>(__x, __y.size()), __y));
4189}
4190
4191template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004192inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004193typename enable_if
4194<
4195 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4196 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
4197>::type
4198operator>>(const _Expr1& __x, const _Expr2& __y)
4199{
4200 typedef typename _Expr1::value_type value_type;
4201 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
4202 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
4203}
4204
4205template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004206inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004207typename enable_if
4208<
4209 __is_val_expr<_Expr>::value,
4210 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4211 _Expr, __scalar_expr<typename _Expr::value_type> > >
4212>::type
4213operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
4214{
4215 typedef typename _Expr::value_type value_type;
4216 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4217 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4218 __x, __scalar_expr<value_type>(__y, __x.size())));
4219}
4220
4221template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004222inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004223typename enable_if
4224<
4225 __is_val_expr<_Expr>::value,
4226 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4227 __scalar_expr<typename _Expr::value_type>, _Expr> >
4228>::type
4229operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
4230{
4231 typedef typename _Expr::value_type value_type;
4232 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4233 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4234 __scalar_expr<value_type>(__x, __y.size()), __y));
4235}
4236
4237template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004238inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004239typename enable_if
4240<
4241 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4242 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4243>::type
4244operator&&(const _Expr1& __x, const _Expr2& __y)
4245{
4246 typedef typename _Expr1::value_type value_type;
4247 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
4248 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
4249}
4250
4251template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004252inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004253typename enable_if
4254<
4255 __is_val_expr<_Expr>::value,
4256 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4257 _Expr, __scalar_expr<typename _Expr::value_type> > >
4258>::type
4259operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
4260{
4261 typedef typename _Expr::value_type value_type;
4262 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4263 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4264 __x, __scalar_expr<value_type>(__y, __x.size())));
4265}
4266
4267template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004268inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004269typename enable_if
4270<
4271 __is_val_expr<_Expr>::value,
4272 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4273 __scalar_expr<typename _Expr::value_type>, _Expr> >
4274>::type
4275operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
4276{
4277 typedef typename _Expr::value_type value_type;
4278 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4279 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4280 __scalar_expr<value_type>(__x, __y.size()), __y));
4281}
4282
4283template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004284inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004285typename enable_if
4286<
4287 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4288 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4289>::type
4290operator||(const _Expr1& __x, const _Expr2& __y)
4291{
4292 typedef typename _Expr1::value_type value_type;
4293 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
4294 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
4295}
4296
4297template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004298inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004299typename enable_if
4300<
4301 __is_val_expr<_Expr>::value,
4302 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4303 _Expr, __scalar_expr<typename _Expr::value_type> > >
4304>::type
4305operator||(const _Expr& __x, const typename _Expr::value_type& __y)
4306{
4307 typedef typename _Expr::value_type value_type;
4308 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4309 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4310 __x, __scalar_expr<value_type>(__y, __x.size())));
4311}
4312
4313template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004314inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004315typename enable_if
4316<
4317 __is_val_expr<_Expr>::value,
4318 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4319 __scalar_expr<typename _Expr::value_type>, _Expr> >
4320>::type
4321operator||(const typename _Expr::value_type& __x, const _Expr& __y)
4322{
4323 typedef typename _Expr::value_type value_type;
4324 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4325 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4326 __scalar_expr<value_type>(__x, __y.size()), __y));
4327}
4328
4329template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004330inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004331typename enable_if
4332<
4333 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4334 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4335>::type
4336operator==(const _Expr1& __x, const _Expr2& __y)
4337{
4338 typedef typename _Expr1::value_type value_type;
4339 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
4340 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
4341}
4342
4343template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004344inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004345typename enable_if
4346<
4347 __is_val_expr<_Expr>::value,
4348 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4349 _Expr, __scalar_expr<typename _Expr::value_type> > >
4350>::type
4351operator==(const _Expr& __x, const typename _Expr::value_type& __y)
4352{
4353 typedef typename _Expr::value_type value_type;
4354 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4355 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4356 __x, __scalar_expr<value_type>(__y, __x.size())));
4357}
4358
4359template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004360inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004361typename enable_if
4362<
4363 __is_val_expr<_Expr>::value,
4364 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4365 __scalar_expr<typename _Expr::value_type>, _Expr> >
4366>::type
4367operator==(const typename _Expr::value_type& __x, const _Expr& __y)
4368{
4369 typedef typename _Expr::value_type value_type;
4370 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4371 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4372 __scalar_expr<value_type>(__x, __y.size()), __y));
4373}
4374
4375template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004376inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004377typename enable_if
4378<
4379 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4380 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4381>::type
4382operator!=(const _Expr1& __x, const _Expr2& __y)
4383{
4384 typedef typename _Expr1::value_type value_type;
4385 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
4386 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
4387}
4388
4389template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004390inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004391typename enable_if
4392<
4393 __is_val_expr<_Expr>::value,
4394 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4395 _Expr, __scalar_expr<typename _Expr::value_type> > >
4396>::type
4397operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
4398{
4399 typedef typename _Expr::value_type value_type;
4400 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4401 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4402 __x, __scalar_expr<value_type>(__y, __x.size())));
4403}
4404
4405template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004406inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004407typename enable_if
4408<
4409 __is_val_expr<_Expr>::value,
4410 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4411 __scalar_expr<typename _Expr::value_type>, _Expr> >
4412>::type
4413operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
4414{
4415 typedef typename _Expr::value_type value_type;
4416 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4417 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4418 __scalar_expr<value_type>(__x, __y.size()), __y));
4419}
4420
4421template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004422inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004423typename enable_if
4424<
4425 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4426 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
4427>::type
4428operator<(const _Expr1& __x, const _Expr2& __y)
4429{
4430 typedef typename _Expr1::value_type value_type;
4431 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
4432 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
4433}
4434
4435template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004436inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004437typename enable_if
4438<
4439 __is_val_expr<_Expr>::value,
4440 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4441 _Expr, __scalar_expr<typename _Expr::value_type> > >
4442>::type
4443operator<(const _Expr& __x, const typename _Expr::value_type& __y)
4444{
4445 typedef typename _Expr::value_type value_type;
4446 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4447 return __val_expr<_Op>(_Op(less<value_type>(),
4448 __x, __scalar_expr<value_type>(__y, __x.size())));
4449}
4450
4451template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004452inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004453typename enable_if
4454<
4455 __is_val_expr<_Expr>::value,
4456 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4457 __scalar_expr<typename _Expr::value_type>, _Expr> >
4458>::type
4459operator<(const typename _Expr::value_type& __x, const _Expr& __y)
4460{
4461 typedef typename _Expr::value_type value_type;
4462 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4463 return __val_expr<_Op>(_Op(less<value_type>(),
4464 __scalar_expr<value_type>(__x, __y.size()), __y));
4465}
4466
4467template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004468inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004469typename enable_if
4470<
4471 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4472 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
4473>::type
4474operator>(const _Expr1& __x, const _Expr2& __y)
4475{
4476 typedef typename _Expr1::value_type value_type;
4477 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
4478 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
4479}
4480
4481template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004482inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004483typename enable_if
4484<
4485 __is_val_expr<_Expr>::value,
4486 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4487 _Expr, __scalar_expr<typename _Expr::value_type> > >
4488>::type
4489operator>(const _Expr& __x, const typename _Expr::value_type& __y)
4490{
4491 typedef typename _Expr::value_type value_type;
4492 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4493 return __val_expr<_Op>(_Op(greater<value_type>(),
4494 __x, __scalar_expr<value_type>(__y, __x.size())));
4495}
4496
4497template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004498inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004499typename enable_if
4500<
4501 __is_val_expr<_Expr>::value,
4502 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4503 __scalar_expr<typename _Expr::value_type>, _Expr> >
4504>::type
4505operator>(const typename _Expr::value_type& __x, const _Expr& __y)
4506{
4507 typedef typename _Expr::value_type value_type;
4508 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4509 return __val_expr<_Op>(_Op(greater<value_type>(),
4510 __scalar_expr<value_type>(__x, __y.size()), __y));
4511}
4512
4513template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004514inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004515typename enable_if
4516<
4517 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4518 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4519>::type
4520operator<=(const _Expr1& __x, const _Expr2& __y)
4521{
4522 typedef typename _Expr1::value_type value_type;
4523 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
4524 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
4525}
4526
4527template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004528inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004529typename enable_if
4530<
4531 __is_val_expr<_Expr>::value,
4532 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4533 _Expr, __scalar_expr<typename _Expr::value_type> > >
4534>::type
4535operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
4536{
4537 typedef typename _Expr::value_type value_type;
4538 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4539 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4540 __x, __scalar_expr<value_type>(__y, __x.size())));
4541}
4542
4543template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004544inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004545typename enable_if
4546<
4547 __is_val_expr<_Expr>::value,
4548 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4549 __scalar_expr<typename _Expr::value_type>, _Expr> >
4550>::type
4551operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
4552{
4553 typedef typename _Expr::value_type value_type;
4554 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4555 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4556 __scalar_expr<value_type>(__x, __y.size()), __y));
4557}
4558
4559template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004560inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004561typename enable_if
4562<
4563 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4564 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4565>::type
4566operator>=(const _Expr1& __x, const _Expr2& __y)
4567{
4568 typedef typename _Expr1::value_type value_type;
4569 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
4570 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
4571}
4572
4573template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004574inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004575typename enable_if
4576<
4577 __is_val_expr<_Expr>::value,
4578 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4579 _Expr, __scalar_expr<typename _Expr::value_type> > >
4580>::type
4581operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
4582{
4583 typedef typename _Expr::value_type value_type;
4584 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4585 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4586 __x, __scalar_expr<value_type>(__y, __x.size())));
4587}
4588
4589template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004590inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004591typename enable_if
4592<
4593 __is_val_expr<_Expr>::value,
4594 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4595 __scalar_expr<typename _Expr::value_type>, _Expr> >
4596>::type
4597operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
4598{
4599 typedef typename _Expr::value_type value_type;
4600 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4601 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4602 __scalar_expr<value_type>(__x, __y.size()), __y));
4603}
4604
4605template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004606inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004607typename enable_if
4608<
4609 __is_val_expr<_Expr>::value,
4610 __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
4611>::type
4612abs(const _Expr& __x)
4613{
4614 typedef typename _Expr::value_type value_type;
4615 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
4616 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
4617}
4618
4619template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004620inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004621typename enable_if
4622<
4623 __is_val_expr<_Expr>::value,
4624 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
4625>::type
4626acos(const _Expr& __x)
4627{
4628 typedef typename _Expr::value_type value_type;
4629 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
4630 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
4631}
4632
4633template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004634inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004635typename enable_if
4636<
4637 __is_val_expr<_Expr>::value,
4638 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
4639>::type
4640asin(const _Expr& __x)
4641{
4642 typedef typename _Expr::value_type value_type;
4643 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
4644 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
4645}
4646
4647template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004648inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004649typename enable_if
4650<
4651 __is_val_expr<_Expr>::value,
4652 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
4653>::type
4654atan(const _Expr& __x)
4655{
4656 typedef typename _Expr::value_type value_type;
4657 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
4658 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
4659}
4660
4661template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004662inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004663typename enable_if
4664<
4665 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4666 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4667>::type
4668atan2(const _Expr1& __x, const _Expr2& __y)
4669{
4670 typedef typename _Expr1::value_type value_type;
4671 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
4672 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
4673}
4674
4675template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004676inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004677typename enable_if
4678<
4679 __is_val_expr<_Expr>::value,
4680 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4681 _Expr, __scalar_expr<typename _Expr::value_type> > >
4682>::type
4683atan2(const _Expr& __x, const typename _Expr::value_type& __y)
4684{
4685 typedef typename _Expr::value_type value_type;
4686 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4687 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4688 __x, __scalar_expr<value_type>(__y, __x.size())));
4689}
4690
4691template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004692inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004693typename enable_if
4694<
4695 __is_val_expr<_Expr>::value,
4696 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4697 __scalar_expr<typename _Expr::value_type>, _Expr> >
4698>::type
4699atan2(const typename _Expr::value_type& __x, const _Expr& __y)
4700{
4701 typedef typename _Expr::value_type value_type;
4702 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4703 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4704 __scalar_expr<value_type>(__x, __y.size()), __y));
4705}
4706
4707template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004708inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004709typename enable_if
4710<
4711 __is_val_expr<_Expr>::value,
4712 __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
4713>::type
4714cos(const _Expr& __x)
4715{
4716 typedef typename _Expr::value_type value_type;
4717 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
4718 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
4719}
4720
4721template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004722inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004723typename enable_if
4724<
4725 __is_val_expr<_Expr>::value,
4726 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
4727>::type
4728cosh(const _Expr& __x)
4729{
4730 typedef typename _Expr::value_type value_type;
4731 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
4732 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
4733}
4734
4735template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004736inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004737typename enable_if
4738<
4739 __is_val_expr<_Expr>::value,
4740 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
4741>::type
4742exp(const _Expr& __x)
4743{
4744 typedef typename _Expr::value_type value_type;
4745 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
4746 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
4747}
4748
4749template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004750inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004751typename enable_if
4752<
4753 __is_val_expr<_Expr>::value,
4754 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
4755>::type
4756log(const _Expr& __x)
4757{
4758 typedef typename _Expr::value_type value_type;
4759 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
4760 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
4761}
4762
4763template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004764inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004765typename enable_if
4766<
4767 __is_val_expr<_Expr>::value,
4768 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
4769>::type
4770log10(const _Expr& __x)
4771{
4772 typedef typename _Expr::value_type value_type;
4773 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
4774 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
4775}
4776
4777template<class _Expr1, class _Expr2>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004778inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004779typename enable_if
4780<
4781 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4782 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4783>::type
4784pow(const _Expr1& __x, const _Expr2& __y)
4785{
4786 typedef typename _Expr1::value_type value_type;
4787 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
4788 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
4789}
4790
4791template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004792inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004793typename enable_if
4794<
4795 __is_val_expr<_Expr>::value,
4796 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4797 _Expr, __scalar_expr<typename _Expr::value_type> > >
4798>::type
4799pow(const _Expr& __x, const typename _Expr::value_type& __y)
4800{
4801 typedef typename _Expr::value_type value_type;
4802 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4803 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4804 __x, __scalar_expr<value_type>(__y, __x.size())));
4805}
4806
4807template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004808inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004809typename enable_if
4810<
4811 __is_val_expr<_Expr>::value,
4812 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4813 __scalar_expr<typename _Expr::value_type>, _Expr> >
4814>::type
4815pow(const typename _Expr::value_type& __x, const _Expr& __y)
4816{
4817 typedef typename _Expr::value_type value_type;
4818 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4819 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4820 __scalar_expr<value_type>(__x, __y.size()), __y));
4821}
4822
4823template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004824inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004825typename enable_if
4826<
4827 __is_val_expr<_Expr>::value,
4828 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
4829>::type
4830sin(const _Expr& __x)
4831{
4832 typedef typename _Expr::value_type value_type;
4833 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
4834 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
4835}
4836
4837template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004838inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004839typename enable_if
4840<
4841 __is_val_expr<_Expr>::value,
4842 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
4843>::type
4844sinh(const _Expr& __x)
4845{
4846 typedef typename _Expr::value_type value_type;
4847 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
4848 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
4849}
4850
4851template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004852inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004853typename enable_if
4854<
4855 __is_val_expr<_Expr>::value,
4856 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
4857>::type
4858sqrt(const _Expr& __x)
4859{
4860 typedef typename _Expr::value_type value_type;
4861 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
4862 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
4863}
4864
4865template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004866inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004867typename enable_if
4868<
4869 __is_val_expr<_Expr>::value,
4870 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
4871>::type
4872tan(const _Expr& __x)
4873{
4874 typedef typename _Expr::value_type value_type;
4875 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
4876 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
4877}
4878
4879template<class _Expr>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004880inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004881typename enable_if
4882<
4883 __is_val_expr<_Expr>::value,
4884 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
4885>::type
4886tanh(const _Expr& __x)
4887{
4888 typedef typename _Expr::value_type value_type;
4889 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
4890 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
4891}
4892
4893template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004894inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004895_Tp*
4896begin(valarray<_Tp>& __v)
4897{
4898 return __v.__begin_;
4899}
4900
4901template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004902inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004903const _Tp*
4904begin(const valarray<_Tp>& __v)
4905{
4906 return __v.__begin_;
4907}
4908
4909template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004910inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004911_Tp*
4912end(valarray<_Tp>& __v)
4913{
4914 return __v.__end_;
4915}
4916
4917template <class _Tp>
Howard Hinnant1c265cd2010-09-23 18:58:28 +00004918inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004919const _Tp*
4920end(const valarray<_Tp>& __v)
4921{
4922 return __v.__end_;
4923}
4924
Howard Hinnantc51e1022010-05-11 19:42:16 +00004925_LIBCPP_END_NAMESPACE_STD
4926
Eric Fiselierf4433a32017-05-31 22:07:49 +00004927_LIBCPP_POP_MACROS
4928
Howard Hinnantc51e1022010-05-11 19:42:16 +00004929#endif // _LIBCPP_VALARRAY