blob: d4dbb9b74686385be7f00d267b419d587f2e0486 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- valarray ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_VALARRAY
12#define _LIBCPP_VALARRAY
13
14/*
15 valarray synopsis
16
17namespace std
18{
19
20template<class T>
21class valarray
22{
23public:
24 typedef T value_type;
25
26 // construct/destroy:
27 valarray();
28 explicit valarray(size_t n);
29 valarray(const value_type& x, size_t n);
30 valarray(const value_type* px, size_t n);
31 valarray(const valarray& v);
32 valarray(valarray&& v);
33 valarray(const slice_array<value_type>& sa);
34 valarray(const gslice_array<value_type>& ga);
35 valarray(const mask_array<value_type>& ma);
36 valarray(const indirect_array<value_type>& ia);
37 valarray(initializer_list<value_type> il);
38 ~valarray();
39
40 // assignment:
41 valarray& operator=(const valarray& v);
42 valarray& operator=(valarray&& v);
43 valarray& operator=(initializer_list<value_type> il);
44 valarray& operator=(const value_type& x);
45 valarray& operator=(const slice_array<value_type>& sa);
46 valarray& operator=(const gslice_array<value_type>& ga);
47 valarray& operator=(const mask_array<value_type>& ma);
48 valarray& operator=(const indirect_array<value_type>& ia);
49
50 // element access:
51 const value_type& operator[](size_t i) const;
52 value_type& operator[](size_t i);
53
54 // subset operations:
55 valarray operator[](slice s) const;
56 slice_array<value_type> operator[](slice s);
57 valarray operator[](const gslice& gs) const;
58 gslice_array<value_type> operator[](const gslice& gs);
59 valarray operator[](const valarray<bool>& vb) const;
60 mask_array<value_type> operator[](const valarray<bool>& vb);
61 valarray operator[](const valarray<size_t>& vs) const;
62 indirect_array<value_type> operator[](const valarray<size_t>& vs);
63
64 // unary operators:
65 valarray operator+() const;
66 valarray operator-() const;
67 valarray operator~() const;
68 valarray<bool> operator!() const;
69
70 // computed assignment:
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 valarray& operator>>=(const value_type& x);
81
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 valarray& operator>>=(const valarray& v);
92
93 // member functions:
94 void swap(valarray& v);
95
96 size_t size() const;
97
98 value_type sum() const;
99 value_type min() const;
100 value_type max() const;
101
102 valarray shift (int i) const;
103 valarray cshift(int i) const;
104 valarray apply(value_type f(value_type)) const;
105 valarray apply(value_type f(const value_type&)) const;
106 void resize(size_t n, value_type x = value_type());
107};
108
109class slice
110{
111public:
112 slice();
113 slice(size_t start, size_t size, size_t stride);
114
115 size_t start() const;
116 size_t size() const;
117 size_t stride() const;
118};
119
120template <class T>
121class slice_array
122{
123public:
124 typedef T value_type;
125
126 const slice_array& operator=(const slice_array& sa) 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 void operator>>=(const valarray<value_type>& v) const;
138
139 void operator=(const value_type& x) const;
140
141 slice_array() = delete;
142};
143
144class gslice
145{
146public:
147 gslice();
148 gslice(size_t start, const valarray<size_t>& size,
149 const valarray<size_t>& stride);
150
151 size_t start() const;
152 valarray<size_t> size() const;
153 valarray<size_t> stride() const;
154};
155
156template <class T>
157class gslice_array
158{
159public:
160 typedef T value_type;
161
162 void operator= (const valarray<value_type>& v) const;
163 void operator*= (const valarray<value_type>& v) const;
164 void operator/= (const valarray<value_type>& v) const;
165 void operator%= (const valarray<value_type>& v) const;
166 void operator+= (const valarray<value_type>& v) const;
167 void operator-= (const valarray<value_type>& v) const;
168 void operator^= (const valarray<value_type>& v) const;
169 void operator&= (const valarray<value_type>& v) const;
170 void operator|= (const valarray<value_type>& v) const;
171 void operator<<=(const valarray<value_type>& v) const;
172 void operator>>=(const valarray<value_type>& v) const;
173
174 gslice_array(const gslice_array& ga);
175 ~gslice_array();
176 const gslice_array& operator=(const gslice_array& ga) const;
177 void operator=(const value_type& x) const;
178
179 gslice_array() = delete;
180};
181
182template <class T>
183class mask_array
184{
185public:
186 typedef T value_type;
187
188 void operator= (const valarray<value_type>& v) const;
189 void operator*= (const valarray<value_type>& v) const;
190 void operator/= (const valarray<value_type>& v) const;
191 void operator%= (const valarray<value_type>& v) const;
192 void operator+= (const valarray<value_type>& v) const;
193 void operator-= (const valarray<value_type>& v) const;
194 void operator^= (const valarray<value_type>& v) const;
195 void operator&= (const valarray<value_type>& v) const;
196 void operator|= (const valarray<value_type>& v) const;
197 void operator<<=(const valarray<value_type>& v) const;
198 void operator>>=(const valarray<value_type>& v) const;
199
200 mask_array(const mask_array& ma);
201 ~mask_array();
202 const mask_array& operator=(const mask_array& ma) const;
203 void operator=(const value_type& x) const;
204
205 mask_array() = delete;
206};
207
208template <class T>
209class indirect_array
210{
211public:
212 typedef T value_type;
213
214 void operator= (const valarray<value_type>& v) const;
215 void operator*= (const valarray<value_type>& v) const;
216 void operator/= (const valarray<value_type>& v) const;
217 void operator%= (const valarray<value_type>& v) const;
218 void operator+= (const valarray<value_type>& v) const;
219 void operator-= (const valarray<value_type>& v) const;
220 void operator^= (const valarray<value_type>& v) const;
221 void operator&= (const valarray<value_type>& v) const;
222 void operator|= (const valarray<value_type>& v) const;
223 void operator<<=(const valarray<value_type>& v) const;
224 void operator>>=(const valarray<value_type>& v) const;
225
226 indirect_array(const indirect_array& ia);
227 ~indirect_array();
228 const indirect_array& operator=(const indirect_array& ia) const;
229 void operator=(const value_type& x) const;
230
231 indirect_array() = delete;
232};
233
234template<class T> void swap(valarray<T>& x, valarray<T>& y);
235
236template<class T> valarray<T> operator* (const valarray<T>& x, const valarray<T>& y);
237template<class T> valarray<T> operator* (const valarray<T>& x, const T& y);
238template<class T> valarray<T> operator* (const T& x, const valarray<T>& y);
239
240template<class T> valarray<T> operator/ (const valarray<T>& x, const valarray<T>& y);
241template<class T> valarray<T> operator/ (const valarray<T>& x, const T& y);
242template<class T> valarray<T> operator/ (const T& x, const valarray<T>& y);
243
244template<class T> valarray<T> operator% (const valarray<T>& x, const valarray<T>& y);
245template<class T> valarray<T> operator% (const valarray<T>& x, const T& y);
246template<class T> valarray<T> operator% (const T& x, const valarray<T>& y);
247
248template<class T> valarray<T> operator+ (const valarray<T>& x, const valarray<T>& y);
249template<class T> valarray<T> operator+ (const valarray<T>& x, const T& y);
250template<class T> valarray<T> operator+ (const T& x, const valarray<T>& y);
251
252template<class T> valarray<T> operator- (const valarray<T>& x, const valarray<T>& y);
253template<class T> valarray<T> operator- (const valarray<T>& x, const T& y);
254template<class T> valarray<T> operator- (const T& x, const valarray<T>& y);
255
256template<class T> valarray<T> operator^ (const valarray<T>& x, const valarray<T>& y);
257template<class T> valarray<T> operator^ (const valarray<T>& x, const T& y);
258template<class T> valarray<T> operator^ (const T& x, const valarray<T>& y);
259
260template<class T> valarray<T> operator& (const valarray<T>& x, const valarray<T>& y);
261template<class T> valarray<T> operator& (const valarray<T>& x, const T& y);
262template<class T> valarray<T> operator& (const T& x, const valarray<T>& y);
263
264template<class T> valarray<T> operator| (const valarray<T>& x, const valarray<T>& y);
265template<class T> valarray<T> operator| (const valarray<T>& x, const T& y);
266template<class T> valarray<T> operator| (const T& x, const valarray<T>& y);
267
268template<class T> valarray<T> operator<<(const valarray<T>& x, const valarray<T>& y);
269template<class T> valarray<T> operator<<(const valarray<T>& x, const T& y);
270template<class T> valarray<T> operator<<(const T& x, const valarray<T>& y);
271
272template<class T> valarray<T> operator>>(const valarray<T>& x, const valarray<T>& y);
273template<class T> valarray<T> operator>>(const valarray<T>& x, const T& y);
274template<class T> valarray<T> operator>>(const T& x, const valarray<T>& y);
275
276template<class T> valarray<bool> operator&&(const valarray<T>& x, const valarray<T>& y);
277template<class T> valarray<bool> operator&&(const valarray<T>& x, const T& y);
278template<class T> valarray<bool> operator&&(const T& x, const valarray<T>& y);
279
280template<class T> valarray<bool> operator||(const valarray<T>& x, const valarray<T>& y);
281template<class T> valarray<bool> operator||(const valarray<T>& x, const T& y);
282template<class T> valarray<bool> operator||(const T& x, const valarray<T>& y);
283
284template<class T> valarray<bool> operator==(const valarray<T>& x, const valarray<T>& y);
285template<class T> valarray<bool> operator==(const valarray<T>& x, const T& y);
286template<class T> valarray<bool> operator==(const T& x, const valarray<T>& y);
287
288template<class T> valarray<bool> operator!=(const valarray<T>& x, const valarray<T>& y);
289template<class T> valarray<bool> operator!=(const valarray<T>& x, const T& y);
290template<class T> valarray<bool> operator!=(const T& x, const valarray<T>& y);
291
292template<class T> valarray<bool> operator< (const valarray<T>& x, const valarray<T>& y);
293template<class T> valarray<bool> operator< (const valarray<T>& x, const T& y);
294template<class T> valarray<bool> operator< (const T& x, const valarray<T>& y);
295
296template<class T> valarray<bool> operator> (const valarray<T>& x, const valarray<T>& y);
297template<class T> valarray<bool> operator> (const valarray<T>& x, const T& y);
298template<class T> valarray<bool> operator> (const T& x, const valarray<T>& y);
299
300template<class T> valarray<bool> operator<=(const valarray<T>& x, const valarray<T>& y);
301template<class T> valarray<bool> operator<=(const valarray<T>& x, const T& y);
302template<class T> valarray<bool> operator<=(const T& x, const valarray<T>& y);
303
304template<class T> valarray<bool> operator>=(const valarray<T>& x, const valarray<T>& y);
305template<class T> valarray<bool> operator>=(const valarray<T>& x, const T& y);
306template<class T> valarray<bool> operator>=(const T& x, const valarray<T>& y);
307
308template<class T> valarray<T> abs (const valarray<T>& x);
309template<class T> valarray<T> acos (const valarray<T>& x);
310template<class T> valarray<T> asin (const valarray<T>& x);
311template<class T> valarray<T> atan (const valarray<T>& x);
312
313template<class T> valarray<T> atan2(const valarray<T>& x, const valarray<T>& y);
314template<class T> valarray<T> atan2(const valarray<T>& x, const T& y);
315template<class T> valarray<T> atan2(const T& x, const valarray<T>& y);
316
317template<class T> valarray<T> cos (const valarray<T>& x);
318template<class T> valarray<T> cosh (const valarray<T>& x);
319template<class T> valarray<T> exp (const valarray<T>& x);
320template<class T> valarray<T> log (const valarray<T>& x);
321template<class T> valarray<T> log10(const valarray<T>& x);
322
323template<class T> valarray<T> pow(const valarray<T>& x, const valarray<T>& y);
324template<class T> valarray<T> pow(const valarray<T>& x, const T& y);
325template<class T> valarray<T> pow(const T& x, const valarray<T>& y);
326
327template<class T> valarray<T> sin (const valarray<T>& x);
328template<class T> valarray<T> sinh (const valarray<T>& x);
329template<class T> valarray<T> sqrt (const valarray<T>& x);
330template<class T> valarray<T> tan (const valarray<T>& x);
331template<class T> valarray<T> tanh (const valarray<T>& x);
332
333template <class T> unspecified1 begin(valarray<T>& v);
334template <class T> unspecified2 begin(const valarray<T>& v);
335template <class T> unspecified1 end(valarray<T>& v);
336template <class T> unspecified2 end(const valarray<T>& v);
337
338} // std
339
340*/
341
342#include <__config>
343#include <cstddef>
344#include <cmath>
345#include <initializer_list>
346#include <algorithm>
347#include <functional>
348
Howard Hinnant66c6f972011-11-29 16:45:27 +0000349#include <__undef_min_max>
350
Howard Hinnant08e17472011-10-17 20:05:10 +0000351#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000352#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000353#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000354
355_LIBCPP_BEGIN_NAMESPACE_STD
356
357template<class _Tp> class valarray;
358
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000359class _LIBCPP_VISIBLE slice
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000360{
361 size_t __start_;
362 size_t __size_;
363 size_t __stride_;
364public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000365 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000366 slice()
367 : __start_(0),
368 __size_(0),
369 __stride_(0)
370 {}
371
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000372 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000373 slice(size_t __start, size_t __size, size_t __stride)
374 : __start_(__start),
375 __size_(__size),
376 __stride_(__stride)
377 {}
378
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000379 _LIBCPP_INLINE_VISIBILITY size_t start() const {return __start_;}
380 _LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;}
381 _LIBCPP_INLINE_VISIBILITY size_t stride() const {return __stride_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000382};
383
384template <class _Tp> class slice_array;
385class gslice;
386template <class _Tp> class gslice_array;
387template <class _Tp> class mask_array;
388template <class _Tp> class indirect_array;
389
390template <class _Tp>
391_Tp*
392begin(valarray<_Tp>& __v);
393
394template <class _Tp>
395const _Tp*
396begin(const valarray<_Tp>& __v);
397
398template <class _Tp>
399_Tp*
400end(valarray<_Tp>& __v);
401
402template <class _Tp>
403const _Tp*
404end(const valarray<_Tp>& __v);
405
406template <class _Op, class _A0>
407struct _UnaryOp
408{
409 typedef typename _Op::result_type result_type;
410 typedef typename _A0::value_type value_type;
411
412 _Op __op_;
413 _A0 __a0_;
414
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000415 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416 _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {}
417
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000418 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000419 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
420
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000422 size_t size() const {return __a0_.size();}
423};
424
425template <class _Op, class _A0, class _A1>
426struct _BinaryOp
427{
428 typedef typename _Op::result_type result_type;
429 typedef typename _A0::value_type value_type;
430
431 _Op __op_;
432 _A0 __a0_;
433 _A1 __a1_;
434
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000435 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000436 _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1)
437 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
438
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000439 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000440 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
441
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000442 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000443 size_t size() const {return __a0_.size();}
444};
445
446template <class _Tp>
447class __scalar_expr
448{
449public:
450 typedef _Tp value_type;
451 typedef const _Tp& result_type;
452private:
453 const value_type& __t_;
454 size_t __s_;
455public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000456 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000457 explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {}
458
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000460 result_type operator[](size_t) const {return __t_;}
461
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000463 size_t size() const {return __s_;}
464};
465
466template <class _Tp>
467struct __unary_plus : unary_function<_Tp, _Tp>
468{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470 _Tp operator()(const _Tp& __x) const
471 {return +__x;}
472};
473
474template <class _Tp>
475struct __bit_not : unary_function<_Tp, _Tp>
476{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000478 _Tp operator()(const _Tp& __x) const
479 {return ~__x;}
480};
481
482template <class _Tp>
483struct __bit_shift_left : binary_function<_Tp, _Tp, _Tp>
484{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000485 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000486 _Tp operator()(const _Tp& __x, const _Tp& __y) const
487 {return __x << __y;}
488};
489
490template <class _Tp>
491struct __bit_shift_right : binary_function<_Tp, _Tp, _Tp>
492{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000493 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000494 _Tp operator()(const _Tp& __x, const _Tp& __y) const
495 {return __x >> __y;}
496};
497
Howard Hinnant99968442011-11-29 18:15:50 +0000498template <class _Tp, class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000499struct __apply_expr : unary_function<_Tp, _Tp>
500{
501private:
Howard Hinnant99968442011-11-29 18:15:50 +0000502 _Fp __f_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000503public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000504 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +0000505 explicit __apply_expr(_Fp __f) : __f_(__f) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000506
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000507 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000508 _Tp operator()(const _Tp& __x) const
509 {return __f_(__x);}
510};
511
512template <class _Tp>
513struct __abs_expr : unary_function<_Tp, _Tp>
514{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000516 _Tp operator()(const _Tp& __x) const
517 {return abs(__x);}
518};
519
520template <class _Tp>
521struct __acos_expr : unary_function<_Tp, _Tp>
522{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000523 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000524 _Tp operator()(const _Tp& __x) const
525 {return acos(__x);}
526};
527
528template <class _Tp>
529struct __asin_expr : unary_function<_Tp, _Tp>
530{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000532 _Tp operator()(const _Tp& __x) const
533 {return asin(__x);}
534};
535
536template <class _Tp>
537struct __atan_expr : unary_function<_Tp, _Tp>
538{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000539 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000540 _Tp operator()(const _Tp& __x) const
541 {return atan(__x);}
542};
543
544template <class _Tp>
545struct __atan2_expr : binary_function<_Tp, _Tp, _Tp>
546{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000548 _Tp operator()(const _Tp& __x, const _Tp& __y) const
549 {return atan2(__x, __y);}
550};
551
552template <class _Tp>
553struct __cos_expr : unary_function<_Tp, _Tp>
554{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000555 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000556 _Tp operator()(const _Tp& __x) const
557 {return cos(__x);}
558};
559
560template <class _Tp>
561struct __cosh_expr : unary_function<_Tp, _Tp>
562{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000563 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000564 _Tp operator()(const _Tp& __x) const
565 {return cosh(__x);}
566};
567
568template <class _Tp>
569struct __exp_expr : unary_function<_Tp, _Tp>
570{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000572 _Tp operator()(const _Tp& __x) const
573 {return exp(__x);}
574};
575
576template <class _Tp>
577struct __log_expr : unary_function<_Tp, _Tp>
578{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000579 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000580 _Tp operator()(const _Tp& __x) const
581 {return log(__x);}
582};
583
584template <class _Tp>
585struct __log10_expr : unary_function<_Tp, _Tp>
586{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000588 _Tp operator()(const _Tp& __x) const
589 {return log10(__x);}
590};
591
592template <class _Tp>
593struct __pow_expr : binary_function<_Tp, _Tp, _Tp>
594{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000596 _Tp operator()(const _Tp& __x, const _Tp& __y) const
597 {return pow(__x, __y);}
598};
599
600template <class _Tp>
601struct __sin_expr : unary_function<_Tp, _Tp>
602{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000604 _Tp operator()(const _Tp& __x) const
605 {return sin(__x);}
606};
607
608template <class _Tp>
609struct __sinh_expr : unary_function<_Tp, _Tp>
610{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000612 _Tp operator()(const _Tp& __x) const
613 {return sinh(__x);}
614};
615
616template <class _Tp>
617struct __sqrt_expr : unary_function<_Tp, _Tp>
618{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000619 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000620 _Tp operator()(const _Tp& __x) const
621 {return sqrt(__x);}
622};
623
624template <class _Tp>
625struct __tan_expr : unary_function<_Tp, _Tp>
626{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000628 _Tp operator()(const _Tp& __x) const
629 {return tan(__x);}
630};
631
632template <class _Tp>
633struct __tanh_expr : unary_function<_Tp, _Tp>
634{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000636 _Tp operator()(const _Tp& __x) const
637 {return tanh(__x);}
638};
639
640template <class _ValExpr>
641class __slice_expr
642{
643 typedef typename remove_reference<_ValExpr>::type _RmExpr;
644public:
645 typedef typename _RmExpr::value_type value_type;
646 typedef value_type result_type;
647
648private:
649 _ValExpr __expr_;
650 size_t __start_;
651 size_t __size_;
652 size_t __stride_;
653
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000655 __slice_expr(const slice& __sl, const _RmExpr& __e)
656 : __expr_(__e),
657 __start_(__sl.start()),
658 __size_(__sl.size()),
659 __stride_(__sl.stride())
660 {}
661public:
662
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000663 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000664 result_type operator[](size_t __i) const
665 {return __expr_[__start_ + __i * __stride_];}
666
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000667 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668 size_t size() const {return __size_;}
669
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000670 template <class> friend class _LIBCPP_VISIBLE valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000671};
672
673template <class _ValExpr>
674class __mask_expr;
675
676template <class _ValExpr>
677class __indirect_expr;
678
679template <class _ValExpr>
680class __shift_expr
681{
682 typedef typename remove_reference<_ValExpr>::type _RmExpr;
683public:
684 typedef typename _RmExpr::value_type value_type;
685 typedef value_type result_type;
686
687private:
688 _ValExpr __expr_;
689 size_t __size_;
690 ptrdiff_t __ul_;
691 ptrdiff_t __sn_;
692 ptrdiff_t __n_;
Howard Hinnant99968442011-11-29 18:15:50 +0000693 static const ptrdiff_t _Np = static_cast<ptrdiff_t>(
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000694 sizeof(ptrdiff_t) * __CHAR_BIT__ - 1);
695
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000697 __shift_expr(int __n, const _RmExpr& __e)
698 : __expr_(__e),
699 __size_(__e.size()),
700 __n_(__n)
701 {
Howard Hinnant99968442011-11-29 18:15:50 +0000702 ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _Np);
703 __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _Np);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000704 __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n);
705 }
706public:
707
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000709 result_type operator[](size_t __j) const
710 {
Howard Hinnantec3773c2011-12-01 20:21:04 +0000711 ptrdiff_t __i = static_cast<ptrdiff_t>(__j);
Howard Hinnant99968442011-11-29 18:15:50 +0000712 ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713 return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
714 }
715
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000717 size_t size() const {return __size_;}
718
719 template <class> friend class __val_expr;
720};
721
722template <class _ValExpr>
723class __cshift_expr
724{
725 typedef typename remove_reference<_ValExpr>::type _RmExpr;
726public:
727 typedef typename _RmExpr::value_type value_type;
728 typedef value_type result_type;
729
730private:
731 _ValExpr __expr_;
732 size_t __size_;
733 size_t __m_;
734 size_t __o1_;
735 size_t __o2_;
736
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000737 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000738 __cshift_expr(int __n, const _RmExpr& __e)
739 : __expr_(__e),
740 __size_(__e.size())
741 {
742 __n %= static_cast<int>(__size_);
743 if (__n >= 0)
744 {
745 __m_ = __size_ - __n;
746 __o1_ = __n;
747 __o2_ = __n - __size_;
748 }
749 else
750 {
751 __m_ = -__n;
752 __o1_ = __n + __size_;
753 __o2_ = __n;
754 }
755 }
756public:
757
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000758 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000759 result_type operator[](size_t __i) const
760 {
761 if (__i < __m_)
762 return __expr_[__i + __o1_];
763 return __expr_[__i + __o2_];
764 }
765
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000766 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000767 size_t size() const {return __size_;}
768
769 template <class> friend class __val_expr;
770};
771
772template<class _ValExpr>
773class __val_expr;
774
775template<class _ValExpr>
776struct __is_val_expr : false_type {};
777
778template<class _ValExpr>
779struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
780
781template<class _Tp>
782struct __is_val_expr<valarray<_Tp> > : true_type {};
783
784template<class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000785class _LIBCPP_VISIBLE valarray
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000786{
787public:
788 typedef _Tp value_type;
789 typedef _Tp result_type;
790
791private:
792 value_type* __begin_;
793 value_type* __end_;
794
795public:
796 // construct/destroy:
Douglas Gregore9e4b852012-05-19 04:41:25 +0000797 _LIBCPP_INLINE_VISIBILITY valarray() : __begin_(0), __end_(0) {}
798 _LIBCPP_INLINE_VISIBILITY explicit valarray(size_t __n);
799 _LIBCPP_INLINE_VISIBILITY valarray(const value_type& __x, size_t __n);
800 _LIBCPP_INLINE_VISIBILITY valarray(const value_type* __p, size_t __n);
801 _LIBCPP_INLINE_VISIBILITY valarray(const valarray& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000802#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Douglas Gregore9e4b852012-05-19 04:41:25 +0000803 _LIBCPP_INLINE_VISIBILITY valarray(valarray&& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000804#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000805#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Douglas Gregore9e4b852012-05-19 04:41:25 +0000806 _LIBCPP_INLINE_VISIBILITY valarray(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +0000807#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Douglas Gregore9e4b852012-05-19 04:41:25 +0000808 _LIBCPP_INLINE_VISIBILITY valarray(const slice_array<value_type>& __sa);
809 _LIBCPP_INLINE_VISIBILITY valarray(const gslice_array<value_type>& __ga);
810 _LIBCPP_INLINE_VISIBILITY valarray(const mask_array<value_type>& __ma);
811 _LIBCPP_INLINE_VISIBILITY valarray(const indirect_array<value_type>& __ia);
812 _LIBCPP_INLINE_VISIBILITY ~valarray();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000813
814 // assignment:
Douglas Gregore9e4b852012-05-19 04:41:25 +0000815 _LIBCPP_INLINE_VISIBILITY valarray& operator=(const valarray& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000816#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Douglas Gregore9e4b852012-05-19 04:41:25 +0000817 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000818 valarray& operator=(valarray&& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000819#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000820#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Douglas Gregore9e4b852012-05-19 04:41:25 +0000821 _LIBCPP_INLINE_VISIBILITY valarray& operator=(initializer_list<value_type>);
Howard Hinnante3e32912011-08-12 21:56:02 +0000822#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Douglas Gregore9e4b852012-05-19 04:41:25 +0000823 _LIBCPP_INLINE_VISIBILITY valarray& operator=(const value_type& __x);
824 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000825 valarray& operator=(const slice_array<value_type>& __sa);
Douglas Gregore9e4b852012-05-19 04:41:25 +0000826 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000827 valarray& operator=(const gslice_array<value_type>& __ga);
Douglas Gregore9e4b852012-05-19 04:41:25 +0000828 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000829 valarray& operator=(const mask_array<value_type>& __ma);
Douglas Gregore9e4b852012-05-19 04:41:25 +0000830 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000831 valarray& operator=(const indirect_array<value_type>& __ia);
Howard Hinnantdb866632011-07-27 23:19:59 +0000832 template <class _ValExpr>
Douglas Gregore9e4b852012-05-19 04:41:25 +0000833 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantdb866632011-07-27 23:19:59 +0000834 valarray& operator=(const __val_expr<_ValExpr>& __v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000835
836 // element access:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000837 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000838 const value_type& operator[](size_t __i) const {return __begin_[__i];}
839
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000841 value_type& operator[](size_t __i) {return __begin_[__i];}
842
843 // subset operations:
Douglas Gregore9e4b852012-05-19 04:41:25 +0000844 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000845 __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const;
Douglas Gregore9e4b852012-05-19 04:41:25 +0000846 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000847 slice_array<value_type> operator[](slice __s);
Douglas Gregore9e4b852012-05-19 04:41:25 +0000848 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000849 __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
Douglas Gregore9e4b852012-05-19 04:41:25 +0000850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000851 gslice_array<value_type> operator[](const gslice& __gs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000852#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Douglas Gregore9e4b852012-05-19 04:41:25 +0000853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000854 __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
Douglas Gregore9e4b852012-05-19 04:41:25 +0000855 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000856 gslice_array<value_type> operator[](gslice&& __gs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000857#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Douglas Gregore9e4b852012-05-19 04:41:25 +0000858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000859 __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const;
Douglas Gregore9e4b852012-05-19 04:41:25 +0000860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000861 mask_array<value_type> operator[](const valarray<bool>& __vb);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000862#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Douglas Gregore9e4b852012-05-19 04:41:25 +0000863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000864 __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const;
Douglas Gregore9e4b852012-05-19 04:41:25 +0000865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000866 mask_array<value_type> operator[](valarray<bool>&& __vb);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000867#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Douglas Gregore9e4b852012-05-19 04:41:25 +0000868 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000869 __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
Douglas Gregore9e4b852012-05-19 04:41:25 +0000870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000871 indirect_array<value_type> operator[](const valarray<size_t>& __vs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000872#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Douglas Gregore9e4b852012-05-19 04:41:25 +0000873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000874 __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
Douglas Gregore9e4b852012-05-19 04:41:25 +0000875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000876 indirect_array<value_type> operator[](valarray<size_t>&& __vs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000877#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000878
879 // unary operators:
Douglas Gregore9e4b852012-05-19 04:41:25 +0000880 _LIBCPP_INLINE_VISIBILITY valarray operator+() const;
881 _LIBCPP_INLINE_VISIBILITY valarray operator-() const;
882 _LIBCPP_INLINE_VISIBILITY valarray operator~() const;
883 _LIBCPP_INLINE_VISIBILITY valarray<bool> operator!() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000884
885 // computed assignment:
Douglas Gregore9e4b852012-05-19 04:41:25 +0000886 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000887 valarray& operator*= (const value_type& __x);
Douglas Gregore9e4b852012-05-19 04:41:25 +0000888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000889 valarray& operator/= (const value_type& __x);
Douglas Gregore9e4b852012-05-19 04:41:25 +0000890 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000891 valarray& operator%= (const value_type& __x);
Douglas Gregore9e4b852012-05-19 04:41:25 +0000892 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000893 valarray& operator+= (const value_type& __x);
Douglas Gregore9e4b852012-05-19 04:41:25 +0000894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000895 valarray& operator-= (const value_type& __x);
Douglas Gregore9e4b852012-05-19 04:41:25 +0000896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000897 valarray& operator^= (const value_type& __x);
Douglas Gregore9e4b852012-05-19 04:41:25 +0000898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899 valarray& operator&= (const value_type& __x);
Douglas Gregore9e4b852012-05-19 04:41:25 +0000900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000901 valarray& operator|= (const value_type& __x);
Douglas Gregore9e4b852012-05-19 04:41:25 +0000902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000903 valarray& operator<<=(const value_type& __x);
Douglas Gregore9e4b852012-05-19 04:41:25 +0000904 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000905 valarray& operator>>=(const value_type& __x);
906
907 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +0000908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000909 typename enable_if
910 <
911 __is_val_expr<_Expr>::value,
912 valarray&
913 >::type
914 operator*= (const _Expr& __v);
915
916 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +0000917 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000918 typename enable_if
919 <
920 __is_val_expr<_Expr>::value,
921 valarray&
922 >::type
923 operator/= (const _Expr& __v);
924
925 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +0000926 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000927 typename enable_if
928 <
929 __is_val_expr<_Expr>::value,
930 valarray&
931 >::type
932 operator%= (const _Expr& __v);
933
934 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +0000935 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000936 typename enable_if
937 <
938 __is_val_expr<_Expr>::value,
939 valarray&
940 >::type
941 operator+= (const _Expr& __v);
942
943 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +0000944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000945 typename enable_if
946 <
947 __is_val_expr<_Expr>::value,
948 valarray&
949 >::type
950 operator-= (const _Expr& __v);
951
952 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +0000953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000954 typename enable_if
955 <
956 __is_val_expr<_Expr>::value,
957 valarray&
958 >::type
959 operator^= (const _Expr& __v);
960
961 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +0000962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000963 typename enable_if
964 <
965 __is_val_expr<_Expr>::value,
966 valarray&
967 >::type
968 operator|= (const _Expr& __v);
969
970 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +0000971 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000972 typename enable_if
973 <
974 __is_val_expr<_Expr>::value,
975 valarray&
976 >::type
977 operator&= (const _Expr& __v);
978
979 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +0000980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000981 typename enable_if
982 <
983 __is_val_expr<_Expr>::value,
984 valarray&
985 >::type
986 operator<<= (const _Expr& __v);
987
988 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +0000989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000990 typename enable_if
991 <
992 __is_val_expr<_Expr>::value,
993 valarray&
994 >::type
995 operator>>= (const _Expr& __v);
996
997 // member functions:
Douglas Gregore9e4b852012-05-19 04:41:25 +0000998 _LIBCPP_INLINE_VISIBILITY void swap(valarray& __v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000999
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001000 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001001 size_t size() const {return static_cast<size_t>(__end_ - __begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001002
Douglas Gregore9e4b852012-05-19 04:41:25 +00001003 _LIBCPP_INLINE_VISIBILITY value_type sum() const;
1004 _LIBCPP_INLINE_VISIBILITY value_type min() const;
1005 _LIBCPP_INLINE_VISIBILITY value_type max() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001006
Douglas Gregore9e4b852012-05-19 04:41:25 +00001007 _LIBCPP_INLINE_VISIBILITY valarray shift (int __i) const;
1008 _LIBCPP_INLINE_VISIBILITY valarray cshift(int __i) const;
1009 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001010 valarray apply(value_type __f(value_type)) const;
Douglas Gregore9e4b852012-05-19 04:41:25 +00001011 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001012 valarray apply(value_type __f(const value_type&)) const;
Douglas Gregore9e4b852012-05-19 04:41:25 +00001013 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001014 void resize(size_t __n, value_type __x = value_type());
1015
1016private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001017 template <class> friend class _LIBCPP_VISIBLE valarray;
1018 template <class> friend class _LIBCPP_VISIBLE slice_array;
1019 template <class> friend class _LIBCPP_VISIBLE gslice_array;
1020 template <class> friend class _LIBCPP_VISIBLE mask_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001021 template <class> friend class __mask_expr;
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001022 template <class> friend class _LIBCPP_VISIBLE indirect_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001023 template <class> friend class __indirect_expr;
1024 template <class> friend class __val_expr;
1025
1026 template <class _Up>
1027 friend
1028 _Up*
1029 begin(valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +00001030
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001031 template <class _Up>
1032 friend
1033 const _Up*
1034 begin(const valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +00001035
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001036 template <class _Up>
1037 friend
1038 _Up*
1039 end(valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +00001040
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001041 template <class _Up>
1042 friend
1043 const _Up*
1044 end(const valarray<_Up>& __v);
1045};
1046
1047template <class _Op, class _Tp>
1048struct _UnaryOp<_Op, valarray<_Tp> >
1049{
1050 typedef typename _Op::result_type result_type;
1051 typedef _Tp value_type;
1052
1053 _Op __op_;
1054 const valarray<_Tp>& __a0_;
1055
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001056 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001057 _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
1058
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001059 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001060 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
1061
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001062 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001063 size_t size() const {return __a0_.size();}
1064};
1065
1066template <class _Op, class _Tp, class _A1>
1067struct _BinaryOp<_Op, valarray<_Tp>, _A1>
1068{
1069 typedef typename _Op::result_type result_type;
1070 typedef _Tp value_type;
1071
1072 _Op __op_;
1073 const valarray<_Tp>& __a0_;
1074 _A1 __a1_;
1075
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001076 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001077 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
1078 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1079
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001081 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1082
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001083 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001084 size_t size() const {return __a0_.size();}
1085};
1086
1087template <class _Op, class _A0, class _Tp>
1088struct _BinaryOp<_Op, _A0, valarray<_Tp> >
1089{
1090 typedef typename _Op::result_type result_type;
1091 typedef _Tp value_type;
1092
1093 _Op __op_;
1094 _A0 __a0_;
1095 const valarray<_Tp>& __a1_;
1096
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001098 _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
1099 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1100
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001102 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1103
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001104 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001105 size_t size() const {return __a0_.size();}
1106};
1107
1108template <class _Op, class _Tp>
1109struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> >
1110{
1111 typedef typename _Op::result_type result_type;
1112 typedef _Tp value_type;
1113
1114 _Op __op_;
1115 const valarray<_Tp>& __a0_;
1116 const valarray<_Tp>& __a1_;
1117
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001118 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001119 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
1120 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1121
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001123 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1124
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001125 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001126 size_t size() const {return __a0_.size();}
1127};
1128
1129// slice_array
1130
1131template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001132class _LIBCPP_VISIBLE slice_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001133{
1134public:
1135 typedef _Tp value_type;
1136
1137private:
1138 value_type* __vp_;
1139 size_t __size_;
1140 size_t __stride_;
1141
1142public:
1143 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001144 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001145 typename enable_if
1146 <
1147 __is_val_expr<_Expr>::value,
1148 void
1149 >::type
1150 operator=(const _Expr& __v) const;
1151
1152 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001153 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001154 typename enable_if
1155 <
1156 __is_val_expr<_Expr>::value,
1157 void
1158 >::type
1159 operator*=(const _Expr& __v) const;
1160
1161 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001162 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001163 typename enable_if
1164 <
1165 __is_val_expr<_Expr>::value,
1166 void
1167 >::type
1168 operator/=(const _Expr& __v) const;
1169
1170 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001171 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001172 typename enable_if
1173 <
1174 __is_val_expr<_Expr>::value,
1175 void
1176 >::type
1177 operator%=(const _Expr& __v) const;
1178
1179 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001180 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001181 typename enable_if
1182 <
1183 __is_val_expr<_Expr>::value,
1184 void
1185 >::type
1186 operator+=(const _Expr& __v) const;
1187
1188 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001189 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001190 typename enable_if
1191 <
1192 __is_val_expr<_Expr>::value,
1193 void
1194 >::type
1195 operator-=(const _Expr& __v) const;
1196
1197 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001198 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001199 typename enable_if
1200 <
1201 __is_val_expr<_Expr>::value,
1202 void
1203 >::type
1204 operator^=(const _Expr& __v) const;
1205
1206 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001207 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001208 typename enable_if
1209 <
1210 __is_val_expr<_Expr>::value,
1211 void
1212 >::type
1213 operator&=(const _Expr& __v) const;
1214
1215 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001216 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001217 typename enable_if
1218 <
1219 __is_val_expr<_Expr>::value,
1220 void
1221 >::type
1222 operator|=(const _Expr& __v) const;
1223
1224 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001225 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001226 typename enable_if
1227 <
1228 __is_val_expr<_Expr>::value,
1229 void
1230 >::type
1231 operator<<=(const _Expr& __v) const;
1232
1233 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001234 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001235 typename enable_if
1236 <
1237 __is_val_expr<_Expr>::value,
1238 void
1239 >::type
1240 operator>>=(const _Expr& __v) const;
1241
Douglas Gregore9e4b852012-05-19 04:41:25 +00001242 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001243 const slice_array& operator=(const slice_array& __sa) const;
1244
Douglas Gregore9e4b852012-05-19 04:41:25 +00001245 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001246 void operator=(const value_type& __x) const;
1247
1248private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001249 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001250 slice_array(const slice& __sl, const valarray<value_type>& __v)
1251 : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())),
1252 __size_(__sl.size()),
1253 __stride_(__sl.stride())
1254 {}
1255
1256 template <class> friend class valarray;
1257 template <class> friend class sliceExpr;
1258};
1259
1260template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001261inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001262const slice_array<_Tp>&
1263slice_array<_Tp>::operator=(const slice_array& __sa) const
1264{
1265 value_type* __t = __vp_;
1266 const value_type* __s = __sa.__vp_;
1267 for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
1268 *__t = *__s;
1269}
1270
1271template <class _Tp>
1272template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001273inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001274typename enable_if
1275<
1276 __is_val_expr<_Expr>::value,
1277 void
1278>::type
1279slice_array<_Tp>::operator=(const _Expr& __v) const
1280{
1281 value_type* __t = __vp_;
1282 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1283 *__t = __v[__i];
1284}
1285
1286template <class _Tp>
1287template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001288inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001289typename enable_if
1290<
1291 __is_val_expr<_Expr>::value,
1292 void
1293>::type
1294slice_array<_Tp>::operator*=(const _Expr& __v) const
1295{
1296 value_type* __t = __vp_;
1297 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1298 *__t *= __v[__i];
1299}
1300
1301template <class _Tp>
1302template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001303inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001304typename enable_if
1305<
1306 __is_val_expr<_Expr>::value,
1307 void
1308>::type
1309slice_array<_Tp>::operator/=(const _Expr& __v) const
1310{
1311 value_type* __t = __vp_;
1312 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1313 *__t /= __v[__i];
1314}
1315
1316template <class _Tp>
1317template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001318inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001319typename enable_if
1320<
1321 __is_val_expr<_Expr>::value,
1322 void
1323>::type
1324slice_array<_Tp>::operator%=(const _Expr& __v) const
1325{
1326 value_type* __t = __vp_;
1327 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1328 *__t %= __v[__i];
1329}
1330
1331template <class _Tp>
1332template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001333inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001334typename enable_if
1335<
1336 __is_val_expr<_Expr>::value,
1337 void
1338>::type
1339slice_array<_Tp>::operator+=(const _Expr& __v) const
1340{
1341 value_type* __t = __vp_;
1342 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1343 *__t += __v[__i];
1344}
1345
1346template <class _Tp>
1347template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001348inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001349typename enable_if
1350<
1351 __is_val_expr<_Expr>::value,
1352 void
1353>::type
1354slice_array<_Tp>::operator-=(const _Expr& __v) const
1355{
1356 value_type* __t = __vp_;
1357 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1358 *__t -= __v[__i];
1359}
1360
1361template <class _Tp>
1362template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001363inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001364typename enable_if
1365<
1366 __is_val_expr<_Expr>::value,
1367 void
1368>::type
1369slice_array<_Tp>::operator^=(const _Expr& __v) const
1370{
1371 value_type* __t = __vp_;
1372 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1373 *__t ^= __v[__i];
1374}
1375
1376template <class _Tp>
1377template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001378inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001379typename enable_if
1380<
1381 __is_val_expr<_Expr>::value,
1382 void
1383>::type
1384slice_array<_Tp>::operator&=(const _Expr& __v) const
1385{
1386 value_type* __t = __vp_;
1387 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1388 *__t &= __v[__i];
1389}
1390
1391template <class _Tp>
1392template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001393inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001394typename enable_if
1395<
1396 __is_val_expr<_Expr>::value,
1397 void
1398>::type
1399slice_array<_Tp>::operator|=(const _Expr& __v) const
1400{
1401 value_type* __t = __vp_;
1402 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1403 *__t |= __v[__i];
1404}
1405
1406template <class _Tp>
1407template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001408inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001409typename enable_if
1410<
1411 __is_val_expr<_Expr>::value,
1412 void
1413>::type
1414slice_array<_Tp>::operator<<=(const _Expr& __v) const
1415{
1416 value_type* __t = __vp_;
1417 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1418 *__t <<= __v[__i];
1419}
1420
1421template <class _Tp>
1422template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001423inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001424typename enable_if
1425<
1426 __is_val_expr<_Expr>::value,
1427 void
1428>::type
1429slice_array<_Tp>::operator>>=(const _Expr& __v) const
1430{
1431 value_type* __t = __vp_;
1432 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1433 *__t >>= __v[__i];
1434}
1435
1436template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001437inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001438void
1439slice_array<_Tp>::operator=(const value_type& __x) const
1440{
1441 value_type* __t = __vp_;
1442 for (size_t __n = __size_; __n; --__n, __t += __stride_)
1443 *__t = __x;
1444}
1445
1446// gslice
1447
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001448class _LIBCPP_VISIBLE gslice
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001449{
1450 valarray<size_t> __size_;
1451 valarray<size_t> __stride_;
1452 valarray<size_t> __1d_;
Howard Hinnant324bb032010-08-22 00:02:43 +00001453
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001454public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001456 gslice() {}
Douglas Gregore9e4b852012-05-19 04:41:25 +00001457
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001459 gslice(size_t __start, const valarray<size_t>& __size,
1460 const valarray<size_t>& __stride)
1461 : __size_(__size),
1462 __stride_(__stride)
1463 {__init(__start);}
1464
Howard Hinnant73d21a42010-09-04 23:28:19 +00001465#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001466
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001468 gslice(size_t __start, const valarray<size_t>& __size,
1469 valarray<size_t>&& __stride)
1470 : __size_(__size),
1471 __stride_(move(__stride))
1472 {__init(__start);}
1473
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001475 gslice(size_t __start, valarray<size_t>&& __size,
1476 const valarray<size_t>& __stride)
1477 : __size_(move(__size)),
1478 __stride_(__stride)
1479 {__init(__start);}
1480
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001482 gslice(size_t __start, valarray<size_t>&& __size,
1483 valarray<size_t>&& __stride)
1484 : __size_(move(__size)),
1485 __stride_(move(__stride))
1486 {__init(__start);}
1487
Howard Hinnant73d21a42010-09-04 23:28:19 +00001488#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001489
1490// gslice(const gslice&) = default;
1491// gslice(gslice&&) = default;
1492// gslice& operator=(const gslice&) = default;
1493// gslice& operator=(gslice&&) = default;
1494
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001496 size_t start() const {return __1d_.size() ? __1d_[0] : 0;}
1497
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001499 valarray<size_t> size() const {return __size_;}
1500
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001501 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001502 valarray<size_t> stride() const {return __stride_;}
1503
1504private:
1505 void __init(size_t __start);
1506
1507 template <class> friend class gslice_array;
1508 template <class> friend class valarray;
1509 template <class> friend class __val_expr;
1510};
1511
1512// gslice_array
1513
1514template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001515class _LIBCPP_VISIBLE gslice_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001516{
1517public:
1518 typedef _Tp value_type;
1519
1520private:
1521 value_type* __vp_;
1522 valarray<size_t> __1d_;
1523
1524public:
1525 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001527 typename enable_if
1528 <
1529 __is_val_expr<_Expr>::value,
1530 void
1531 >::type
1532 operator=(const _Expr& __v) const;
1533
1534 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001536 typename enable_if
1537 <
1538 __is_val_expr<_Expr>::value,
1539 void
1540 >::type
1541 operator*=(const _Expr& __v) const;
1542
1543 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001544 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001545 typename enable_if
1546 <
1547 __is_val_expr<_Expr>::value,
1548 void
1549 >::type
1550 operator/=(const _Expr& __v) const;
1551
1552 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001554 typename enable_if
1555 <
1556 __is_val_expr<_Expr>::value,
1557 void
1558 >::type
1559 operator%=(const _Expr& __v) const;
1560
1561 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001563 typename enable_if
1564 <
1565 __is_val_expr<_Expr>::value,
1566 void
1567 >::type
1568 operator+=(const _Expr& __v) const;
1569
1570 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001572 typename enable_if
1573 <
1574 __is_val_expr<_Expr>::value,
1575 void
1576 >::type
1577 operator-=(const _Expr& __v) const;
1578
1579 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001581 typename enable_if
1582 <
1583 __is_val_expr<_Expr>::value,
1584 void
1585 >::type
1586 operator^=(const _Expr& __v) const;
1587
1588 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001590 typename enable_if
1591 <
1592 __is_val_expr<_Expr>::value,
1593 void
1594 >::type
1595 operator&=(const _Expr& __v) const;
1596
1597 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001598 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001599 typename enable_if
1600 <
1601 __is_val_expr<_Expr>::value,
1602 void
1603 >::type
1604 operator|=(const _Expr& __v) const;
1605
1606 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001608 typename enable_if
1609 <
1610 __is_val_expr<_Expr>::value,
1611 void
1612 >::type
1613 operator<<=(const _Expr& __v) const;
1614
1615 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001617 typename enable_if
1618 <
1619 __is_val_expr<_Expr>::value,
1620 void
1621 >::type
1622 operator>>=(const _Expr& __v) const;
1623
Douglas Gregore9e4b852012-05-19 04:41:25 +00001624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001625 const gslice_array& operator=(const gslice_array& __ga) const;
1626
Douglas Gregore9e4b852012-05-19 04:41:25 +00001627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001628 void operator=(const value_type& __x) const;
1629
1630// gslice_array(const gslice_array&) = default;
1631// gslice_array(gslice_array&&) = default;
1632// gslice_array& operator=(const gslice_array&) = default;
1633// gslice_array& operator=(gslice_array&&) = default;
1634
1635private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001637 gslice_array(const gslice& __gs, const valarray<value_type>& __v)
1638 : __vp_(const_cast<value_type*>(__v.__begin_)),
1639 __1d_(__gs.__1d_)
1640 {}
1641
Howard Hinnant73d21a42010-09-04 23:28:19 +00001642#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001643
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001645 gslice_array(gslice&& __gs, const valarray<value_type>& __v)
1646 : __vp_(const_cast<value_type*>(__v.__begin_)),
1647 __1d_(move(__gs.__1d_))
1648 {}
1649
Howard Hinnant73d21a42010-09-04 23:28:19 +00001650#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001651
1652 template <class> friend class valarray;
1653};
1654
1655template <class _Tp>
1656template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001657inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001658typename enable_if
1659<
1660 __is_val_expr<_Expr>::value,
1661 void
1662>::type
1663gslice_array<_Tp>::operator=(const _Expr& __v) const
1664{
1665 typedef const size_t* _Ip;
1666 size_t __j = 0;
1667 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1668 __vp_[*__i] = __v[__j];
1669}
1670
1671template <class _Tp>
1672template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001673inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001674typename enable_if
1675<
1676 __is_val_expr<_Expr>::value,
1677 void
1678>::type
1679gslice_array<_Tp>::operator*=(const _Expr& __v) const
1680{
1681 typedef const size_t* _Ip;
1682 size_t __j = 0;
1683 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1684 __vp_[*__i] *= __v[__j];
1685}
1686
1687template <class _Tp>
1688template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001689inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001690typename enable_if
1691<
1692 __is_val_expr<_Expr>::value,
1693 void
1694>::type
1695gslice_array<_Tp>::operator/=(const _Expr& __v) const
1696{
1697 typedef const size_t* _Ip;
1698 size_t __j = 0;
1699 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1700 __vp_[*__i] /= __v[__j];
1701}
1702
1703template <class _Tp>
1704template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001705inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001706typename enable_if
1707<
1708 __is_val_expr<_Expr>::value,
1709 void
1710>::type
1711gslice_array<_Tp>::operator%=(const _Expr& __v) const
1712{
1713 typedef const size_t* _Ip;
1714 size_t __j = 0;
1715 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1716 __vp_[*__i] %= __v[__j];
1717}
1718
1719template <class _Tp>
1720template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001721inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001722typename enable_if
1723<
1724 __is_val_expr<_Expr>::value,
1725 void
1726>::type
1727gslice_array<_Tp>::operator+=(const _Expr& __v) const
1728{
1729 typedef const size_t* _Ip;
1730 size_t __j = 0;
1731 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1732 __vp_[*__i] += __v[__j];
1733}
1734
1735template <class _Tp>
1736template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001737inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001738typename enable_if
1739<
1740 __is_val_expr<_Expr>::value,
1741 void
1742>::type
1743gslice_array<_Tp>::operator-=(const _Expr& __v) const
1744{
1745 typedef const size_t* _Ip;
1746 size_t __j = 0;
1747 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1748 __vp_[*__i] -= __v[__j];
1749}
1750
1751template <class _Tp>
1752template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001753inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001754typename enable_if
1755<
1756 __is_val_expr<_Expr>::value,
1757 void
1758>::type
1759gslice_array<_Tp>::operator^=(const _Expr& __v) const
1760{
1761 typedef const size_t* _Ip;
1762 size_t __j = 0;
1763 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1764 __vp_[*__i] ^= __v[__j];
1765}
1766
1767template <class _Tp>
1768template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001769inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001770typename enable_if
1771<
1772 __is_val_expr<_Expr>::value,
1773 void
1774>::type
1775gslice_array<_Tp>::operator&=(const _Expr& __v) const
1776{
1777 typedef const size_t* _Ip;
1778 size_t __j = 0;
1779 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1780 __vp_[*__i] &= __v[__j];
1781}
1782
1783template <class _Tp>
1784template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001785inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001786typename enable_if
1787<
1788 __is_val_expr<_Expr>::value,
1789 void
1790>::type
1791gslice_array<_Tp>::operator|=(const _Expr& __v) const
1792{
1793 typedef const size_t* _Ip;
1794 size_t __j = 0;
1795 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1796 __vp_[*__i] |= __v[__j];
1797}
1798
1799template <class _Tp>
1800template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001801inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001802typename enable_if
1803<
1804 __is_val_expr<_Expr>::value,
1805 void
1806>::type
1807gslice_array<_Tp>::operator<<=(const _Expr& __v) const
1808{
1809 typedef const size_t* _Ip;
1810 size_t __j = 0;
1811 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1812 __vp_[*__i] <<= __v[__j];
1813}
1814
1815template <class _Tp>
1816template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001817inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001818typename enable_if
1819<
1820 __is_val_expr<_Expr>::value,
1821 void
1822>::type
1823gslice_array<_Tp>::operator>>=(const _Expr& __v) const
1824{
1825 typedef const size_t* _Ip;
1826 size_t __j = 0;
1827 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1828 __vp_[*__i] >>= __v[__j];
1829}
1830
1831template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001832inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001833const gslice_array<_Tp>&
1834gslice_array<_Tp>::operator=(const gslice_array& __ga) const
1835{
1836 typedef const size_t* _Ip;
1837 const value_type* __s = __ga.__vp_;
1838 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_;
1839 __i != __e; ++__i, ++__j)
1840 __vp_[*__i] = __s[*__j];
1841 return *this;
1842}
1843
1844template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001845inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001846void
1847gslice_array<_Tp>::operator=(const value_type& __x) const
1848{
1849 typedef const size_t* _Ip;
1850 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1851 __vp_[*__i] = __x;
1852}
1853
1854// mask_array
1855
1856template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001857class _LIBCPP_VISIBLE mask_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001858{
1859public:
1860 typedef _Tp value_type;
1861
1862private:
1863 value_type* __vp_;
1864 valarray<size_t> __1d_;
1865
1866public:
1867 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001868 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001869 typename enable_if
1870 <
1871 __is_val_expr<_Expr>::value,
1872 void
1873 >::type
1874 operator=(const _Expr& __v) const;
1875
1876 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001877 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001878 typename enable_if
1879 <
1880 __is_val_expr<_Expr>::value,
1881 void
1882 >::type
1883 operator*=(const _Expr& __v) const;
1884
1885 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001886 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001887 typename enable_if
1888 <
1889 __is_val_expr<_Expr>::value,
1890 void
1891 >::type
1892 operator/=(const _Expr& __v) const;
1893
1894 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001895 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001896 typename enable_if
1897 <
1898 __is_val_expr<_Expr>::value,
1899 void
1900 >::type
1901 operator%=(const _Expr& __v) const;
1902
1903 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001904 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001905 typename enable_if
1906 <
1907 __is_val_expr<_Expr>::value,
1908 void
1909 >::type
1910 operator+=(const _Expr& __v) const;
1911
1912 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001914 typename enable_if
1915 <
1916 __is_val_expr<_Expr>::value,
1917 void
1918 >::type
1919 operator-=(const _Expr& __v) const;
1920
1921 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001922 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001923 typename enable_if
1924 <
1925 __is_val_expr<_Expr>::value,
1926 void
1927 >::type
1928 operator^=(const _Expr& __v) const;
1929
1930 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001931 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001932 typename enable_if
1933 <
1934 __is_val_expr<_Expr>::value,
1935 void
1936 >::type
1937 operator&=(const _Expr& __v) const;
1938
1939 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001940 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001941 typename enable_if
1942 <
1943 __is_val_expr<_Expr>::value,
1944 void
1945 >::type
1946 operator|=(const _Expr& __v) const;
1947
1948 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001949 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001950 typename enable_if
1951 <
1952 __is_val_expr<_Expr>::value,
1953 void
1954 >::type
1955 operator<<=(const _Expr& __v) const;
1956
1957 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001958 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001959 typename enable_if
1960 <
1961 __is_val_expr<_Expr>::value,
1962 void
1963 >::type
1964 operator>>=(const _Expr& __v) const;
1965
Douglas Gregore9e4b852012-05-19 04:41:25 +00001966 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001967 const mask_array& operator=(const mask_array& __ma) const;
1968
Douglas Gregore9e4b852012-05-19 04:41:25 +00001969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001970 void operator=(const value_type& __x) const;
1971
1972// mask_array(const mask_array&) = default;
1973// mask_array(mask_array&&) = default;
1974// mask_array& operator=(const mask_array&) = default;
1975// mask_array& operator=(mask_array&&) = default;
1976
1977private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001979 mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
1980 : __vp_(const_cast<value_type*>(__v.__begin_)),
Howard Hinnantec3773c2011-12-01 20:21:04 +00001981 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001982 {
1983 size_t __j = 0;
1984 for (size_t __i = 0; __i < __vb.size(); ++__i)
1985 if (__vb[__i])
1986 __1d_[__j++] = __i;
1987 }
1988
1989 template <class> friend class valarray;
1990};
1991
1992template <class _Tp>
1993template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001994inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001995typename enable_if
1996<
1997 __is_val_expr<_Expr>::value,
1998 void
1999>::type
2000mask_array<_Tp>::operator=(const _Expr& __v) const
2001{
2002 size_t __n = __1d_.size();
2003 for (size_t __i = 0; __i < __n; ++__i)
2004 __vp_[__1d_[__i]] = __v[__i];
2005}
2006
2007template <class _Tp>
2008template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002009inline
Howard Hinnantbc8d3f92010-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>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002024inline
Howard Hinnantbc8d3f92010-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>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002039inline
Howard Hinnantbc8d3f92010-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>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002054inline
Howard Hinnantbc8d3f92010-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>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002069inline
Howard Hinnantbc8d3f92010-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>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002084inline
Howard Hinnantbc8d3f92010-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>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002099inline
Howard Hinnantbc8d3f92010-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>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002114inline
Howard Hinnantbc8d3f92010-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>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002129inline
Howard Hinnantbc8d3f92010-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>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002144inline
Howard Hinnantbc8d3f92010-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>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002158inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002159const mask_array<_Tp>&
2160mask_array<_Tp>::operator=(const mask_array& __ma) const
2161{
2162 size_t __n = __1d_.size();
2163 for (size_t __i = 0; __i < __n; ++__i)
2164 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
2165}
2166
2167template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002168inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002169void
2170mask_array<_Tp>::operator=(const value_type& __x) const
2171{
2172 size_t __n = __1d_.size();
2173 for (size_t __i = 0; __i < __n; ++__i)
2174 __vp_[__1d_[__i]] = __x;
2175}
2176
2177template <class _ValExpr>
2178class __mask_expr
2179{
2180 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2181public:
2182 typedef typename _RmExpr::value_type value_type;
2183 typedef value_type result_type;
2184
2185private:
2186 _ValExpr __expr_;
2187 valarray<size_t> __1d_;
2188
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002189 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002190 __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
2191 : __expr_(__e),
Howard Hinnantec3773c2011-12-01 20:21:04 +00002192 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002193 {
2194 size_t __j = 0;
2195 for (size_t __i = 0; __i < __vb.size(); ++__i)
2196 if (__vb[__i])
2197 __1d_[__j++] = __i;
2198 }
2199
2200public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002201 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002202 result_type operator[](size_t __i) const
2203 {return __expr_[__1d_[__i]];}
2204
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002205 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002206 size_t size() const {return __1d_.size();}
2207
2208 template <class> friend class valarray;
2209};
2210
2211// indirect_array
2212
2213template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002214class _LIBCPP_VISIBLE indirect_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002215{
2216public:
2217 typedef _Tp value_type;
2218
2219private:
2220 value_type* __vp_;
2221 valarray<size_t> __1d_;
2222
2223public:
2224 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002225 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002226 typename enable_if
2227 <
2228 __is_val_expr<_Expr>::value,
2229 void
2230 >::type
2231 operator=(const _Expr& __v) const;
2232
2233 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002234 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002235 typename enable_if
2236 <
2237 __is_val_expr<_Expr>::value,
2238 void
2239 >::type
2240 operator*=(const _Expr& __v) const;
2241
2242 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002243 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002244 typename enable_if
2245 <
2246 __is_val_expr<_Expr>::value,
2247 void
2248 >::type
2249 operator/=(const _Expr& __v) const;
2250
2251 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002252 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002253 typename enable_if
2254 <
2255 __is_val_expr<_Expr>::value,
2256 void
2257 >::type
2258 operator%=(const _Expr& __v) const;
2259
2260 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002261 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002262 typename enable_if
2263 <
2264 __is_val_expr<_Expr>::value,
2265 void
2266 >::type
2267 operator+=(const _Expr& __v) const;
2268
2269 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002270 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002271 typename enable_if
2272 <
2273 __is_val_expr<_Expr>::value,
2274 void
2275 >::type
2276 operator-=(const _Expr& __v) const;
2277
2278 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002279 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002280 typename enable_if
2281 <
2282 __is_val_expr<_Expr>::value,
2283 void
2284 >::type
2285 operator^=(const _Expr& __v) const;
2286
2287 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002288 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002289 typename enable_if
2290 <
2291 __is_val_expr<_Expr>::value,
2292 void
2293 >::type
2294 operator&=(const _Expr& __v) const;
2295
2296 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002297 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002298 typename enable_if
2299 <
2300 __is_val_expr<_Expr>::value,
2301 void
2302 >::type
2303 operator|=(const _Expr& __v) const;
2304
2305 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002306 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002307 typename enable_if
2308 <
2309 __is_val_expr<_Expr>::value,
2310 void
2311 >::type
2312 operator<<=(const _Expr& __v) const;
2313
2314 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002315 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002316 typename enable_if
2317 <
2318 __is_val_expr<_Expr>::value,
2319 void
2320 >::type
2321 operator>>=(const _Expr& __v) const;
2322
Douglas Gregore9e4b852012-05-19 04:41:25 +00002323 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002324 const indirect_array& operator=(const indirect_array& __ia) const;
2325
Douglas Gregore9e4b852012-05-19 04:41:25 +00002326 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002327 void operator=(const value_type& __x) const;
2328
2329// indirect_array(const indirect_array&) = default;
2330// indirect_array(indirect_array&&) = default;
2331// indirect_array& operator=(const indirect_array&) = default;
2332// indirect_array& operator=(indirect_array&&) = default;
2333
2334private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002335 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002336 indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
2337 : __vp_(const_cast<value_type*>(__v.__begin_)),
2338 __1d_(__ia)
2339 {}
2340
Howard Hinnant73d21a42010-09-04 23:28:19 +00002341#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002342
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002343 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002344 indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
2345 : __vp_(const_cast<value_type*>(__v.__begin_)),
2346 __1d_(move(__ia))
2347 {}
2348
Howard Hinnant73d21a42010-09-04 23:28:19 +00002349#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002350
2351 template <class> friend class valarray;
2352};
2353
2354template <class _Tp>
2355template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002356inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002357typename enable_if
2358<
2359 __is_val_expr<_Expr>::value,
2360 void
2361>::type
2362indirect_array<_Tp>::operator=(const _Expr& __v) const
2363{
2364 size_t __n = __1d_.size();
2365 for (size_t __i = 0; __i < __n; ++__i)
2366 __vp_[__1d_[__i]] = __v[__i];
2367}
2368
2369template <class _Tp>
2370template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002371inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002372typename enable_if
2373<
2374 __is_val_expr<_Expr>::value,
2375 void
2376>::type
2377indirect_array<_Tp>::operator*=(const _Expr& __v) const
2378{
2379 size_t __n = __1d_.size();
2380 for (size_t __i = 0; __i < __n; ++__i)
2381 __vp_[__1d_[__i]] *= __v[__i];
2382}
2383
2384template <class _Tp>
2385template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002386inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002387typename enable_if
2388<
2389 __is_val_expr<_Expr>::value,
2390 void
2391>::type
2392indirect_array<_Tp>::operator/=(const _Expr& __v) const
2393{
2394 size_t __n = __1d_.size();
2395 for (size_t __i = 0; __i < __n; ++__i)
2396 __vp_[__1d_[__i]] /= __v[__i];
2397}
2398
2399template <class _Tp>
2400template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002401inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002402typename enable_if
2403<
2404 __is_val_expr<_Expr>::value,
2405 void
2406>::type
2407indirect_array<_Tp>::operator%=(const _Expr& __v) const
2408{
2409 size_t __n = __1d_.size();
2410 for (size_t __i = 0; __i < __n; ++__i)
2411 __vp_[__1d_[__i]] %= __v[__i];
2412}
2413
2414template <class _Tp>
2415template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002416inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002417typename enable_if
2418<
2419 __is_val_expr<_Expr>::value,
2420 void
2421>::type
2422indirect_array<_Tp>::operator+=(const _Expr& __v) const
2423{
2424 size_t __n = __1d_.size();
2425 for (size_t __i = 0; __i < __n; ++__i)
2426 __vp_[__1d_[__i]] += __v[__i];
2427}
2428
2429template <class _Tp>
2430template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002431inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002432typename enable_if
2433<
2434 __is_val_expr<_Expr>::value,
2435 void
2436>::type
2437indirect_array<_Tp>::operator-=(const _Expr& __v) const
2438{
2439 size_t __n = __1d_.size();
2440 for (size_t __i = 0; __i < __n; ++__i)
2441 __vp_[__1d_[__i]] -= __v[__i];
2442}
2443
2444template <class _Tp>
2445template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002446inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002447typename enable_if
2448<
2449 __is_val_expr<_Expr>::value,
2450 void
2451>::type
2452indirect_array<_Tp>::operator^=(const _Expr& __v) const
2453{
2454 size_t __n = __1d_.size();
2455 for (size_t __i = 0; __i < __n; ++__i)
2456 __vp_[__1d_[__i]] ^= __v[__i];
2457}
2458
2459template <class _Tp>
2460template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002461inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002462typename enable_if
2463<
2464 __is_val_expr<_Expr>::value,
2465 void
2466>::type
2467indirect_array<_Tp>::operator&=(const _Expr& __v) const
2468{
2469 size_t __n = __1d_.size();
2470 for (size_t __i = 0; __i < __n; ++__i)
2471 __vp_[__1d_[__i]] &= __v[__i];
2472}
2473
2474template <class _Tp>
2475template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002476inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002477typename enable_if
2478<
2479 __is_val_expr<_Expr>::value,
2480 void
2481>::type
2482indirect_array<_Tp>::operator|=(const _Expr& __v) const
2483{
2484 size_t __n = __1d_.size();
2485 for (size_t __i = 0; __i < __n; ++__i)
2486 __vp_[__1d_[__i]] |= __v[__i];
2487}
2488
2489template <class _Tp>
2490template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002491inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002492typename enable_if
2493<
2494 __is_val_expr<_Expr>::value,
2495 void
2496>::type
2497indirect_array<_Tp>::operator<<=(const _Expr& __v) const
2498{
2499 size_t __n = __1d_.size();
2500 for (size_t __i = 0; __i < __n; ++__i)
2501 __vp_[__1d_[__i]] <<= __v[__i];
2502}
2503
2504template <class _Tp>
2505template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002506inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002507typename enable_if
2508<
2509 __is_val_expr<_Expr>::value,
2510 void
2511>::type
2512indirect_array<_Tp>::operator>>=(const _Expr& __v) const
2513{
2514 size_t __n = __1d_.size();
2515 for (size_t __i = 0; __i < __n; ++__i)
2516 __vp_[__1d_[__i]] >>= __v[__i];
2517}
2518
2519template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002520inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002521const indirect_array<_Tp>&
2522indirect_array<_Tp>::operator=(const indirect_array& __ia) const
2523{
2524 typedef const size_t* _Ip;
2525 const value_type* __s = __ia.__vp_;
2526 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_;
2527 __i != __e; ++__i, ++__j)
2528 __vp_[*__i] = __s[*__j];
2529 return *this;
2530}
2531
2532template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002533inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002534void
2535indirect_array<_Tp>::operator=(const value_type& __x) const
2536{
2537 typedef const size_t* _Ip;
2538 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
2539 __vp_[*__i] = __x;
2540}
2541
2542template <class _ValExpr>
2543class __indirect_expr
2544{
2545 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2546public:
2547 typedef typename _RmExpr::value_type value_type;
2548 typedef value_type result_type;
2549
2550private:
2551 _ValExpr __expr_;
2552 valarray<size_t> __1d_;
2553
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002555 __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e)
2556 : __expr_(__e),
2557 __1d_(__ia)
2558 {}
2559
Howard Hinnant73d21a42010-09-04 23:28:19 +00002560#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002561
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002563 __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
2564 : __expr_(__e),
2565 __1d_(move(__ia))
2566 {}
2567
Howard Hinnant73d21a42010-09-04 23:28:19 +00002568#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002569
2570public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002572 result_type operator[](size_t __i) const
2573 {return __expr_[__1d_[__i]];}
2574
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002576 size_t size() const {return __1d_.size();}
2577
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002578 template <class> friend class _LIBCPP_VISIBLE valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002579};
2580
2581template<class _ValExpr>
2582class __val_expr
2583{
2584 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2585
2586 _ValExpr __expr_;
2587public:
2588 typedef typename _RmExpr::value_type value_type;
2589 typedef typename _RmExpr::result_type result_type;
2590
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002592 explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
2593
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002595 result_type operator[](size_t __i) const
2596 {return __expr_[__i];}
2597
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002598 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002599 __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
2600 {return __val_expr<__slice_expr<_ValExpr> >(__expr_, __s);}
2601
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002603 __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const
2604 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __gs.__1d_);}
2605
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002606 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002607 __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
2608 {return __val_expr<__mask_expr<_ValExpr> >(__expr_, __vb);}
2609
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002611 __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
2612 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __vs);}
2613
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002614 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002615 __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
2616 operator+() const
2617 {
2618 typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
2619 return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
2620 }
2621
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002623 __val_expr<_UnaryOp<negate<value_type>, _ValExpr> >
2624 operator-() const
2625 {
2626 typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
2627 return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
2628 }
2629
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002631 __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> >
2632 operator~() const
2633 {
2634 typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
2635 return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
2636 }
2637
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002638 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002639 __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> >
2640 operator!() const
2641 {
2642 typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
2643 return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
2644 }
2645
2646 operator valarray<result_type>() const;
2647
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002648 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002649 size_t size() const {return __expr_.size();}
2650
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002651 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002652 result_type sum() const
2653 {
2654 size_t __n = __expr_.size();
2655 result_type __r = __n ? __expr_[0] : result_type();
2656 for (size_t __i = 1; __i < __n; ++__i)
2657 __r += __expr_[__i];
2658 return __r;
2659 }
2660
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002662 result_type min() const
2663 {
2664 size_t __n = size();
2665 result_type __r = __n ? (*this)[0] : result_type();
2666 for (size_t __i = 1; __i < __n; ++__i)
2667 {
2668 result_type __x = __expr_[__i];
2669 if (__x < __r)
2670 __r = __x;
2671 }
2672 return __r;
2673 }
2674
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002676 result_type max() const
2677 {
2678 size_t __n = size();
2679 result_type __r = __n ? (*this)[0] : result_type();
2680 for (size_t __i = 1; __i < __n; ++__i)
2681 {
2682 result_type __x = __expr_[__i];
2683 if (__r < __x)
2684 __r = __x;
2685 }
2686 return __r;
2687 }
2688
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002689 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002690 __val_expr<__shift_expr<_ValExpr> > shift (int __i) const
2691 {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));}
2692
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002694 __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const
2695 {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));}
2696
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002697 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002698 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> >
2699 apply(value_type __f(value_type)) const
2700 {
2701 typedef __apply_expr<value_type, value_type(*)(value_type)> _Op;
2702 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2703 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2704 }
2705
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002707 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> >
2708 apply(value_type __f(const value_type&)) const
2709 {
2710 typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op;
2711 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2712 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2713 }
2714};
2715
2716template<class _ValExpr>
2717__val_expr<_ValExpr>::operator valarray<result_type>() const
2718{
2719 valarray<result_type> __r;
2720 size_t __n = __expr_.size();
2721 if (__n)
2722 {
2723 __r.__begin_ =
2724 __r.__end_ =
2725 static_cast<result_type*>(::operator new(__n * sizeof(result_type)));
2726 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
2727 ::new (__r.__end_) result_type(__expr_[__i]);
2728 }
2729 return __r;
2730}
2731
2732// valarray
2733
2734template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002735inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002736valarray<_Tp>::valarray(size_t __n)
2737 : __begin_(0),
2738 __end_(0)
2739{
2740 resize(__n);
2741}
2742
2743template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002744inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002745valarray<_Tp>::valarray(const value_type& __x, size_t __n)
2746 : __begin_(0),
2747 __end_(0)
2748{
2749 resize(__n, __x);
2750}
2751
2752template <class _Tp>
2753valarray<_Tp>::valarray(const value_type* __p, size_t __n)
2754 : __begin_(0),
2755 __end_(0)
2756{
2757 if (__n)
2758 {
2759 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2760#ifndef _LIBCPP_NO_EXCEPTIONS
2761 try
2762 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002763#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002764 for (; __n; ++__end_, ++__p, --__n)
2765 ::new (__end_) value_type(*__p);
2766#ifndef _LIBCPP_NO_EXCEPTIONS
2767 }
2768 catch (...)
2769 {
2770 resize(0);
2771 throw;
2772 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002773#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002774 }
2775}
2776
2777template <class _Tp>
2778valarray<_Tp>::valarray(const valarray& __v)
2779 : __begin_(0),
2780 __end_(0)
2781{
2782 if (__v.size())
2783 {
2784 __begin_ = __end_ = static_cast<value_type*>(::operator new(__v.size() * sizeof(value_type)));
2785#ifndef _LIBCPP_NO_EXCEPTIONS
2786 try
2787 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002788#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002789 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
2790 ::new (__end_) value_type(*__p);
2791#ifndef _LIBCPP_NO_EXCEPTIONS
2792 }
2793 catch (...)
2794 {
2795 resize(0);
2796 throw;
2797 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002798#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002799 }
2800}
2801
Howard Hinnant73d21a42010-09-04 23:28:19 +00002802#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002803
2804template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002805inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002806valarray<_Tp>::valarray(valarray&& __v)
2807 : __begin_(__v.__begin_),
2808 __end_(__v.__end_)
2809{
2810 __v.__begin_ = __v.__end_ = nullptr;
2811}
2812
Howard Hinnante3e32912011-08-12 21:56:02 +00002813#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2814
2815#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2816
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002817template <class _Tp>
2818valarray<_Tp>::valarray(initializer_list<value_type> __il)
2819 : __begin_(0),
2820 __end_(0)
2821{
2822 size_t __n = __il.size();
2823 if (__n)
2824 {
2825 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2826#ifndef _LIBCPP_NO_EXCEPTIONS
2827 try
2828 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002829#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002830 for (const value_type* __p = __il.begin(); __n; ++__end_, ++__p, --__n)
2831 ::new (__end_) value_type(*__p);
2832#ifndef _LIBCPP_NO_EXCEPTIONS
2833 }
2834 catch (...)
2835 {
2836 resize(0);
2837 throw;
2838 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002839#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002840 }
2841}
2842
Howard Hinnante3e32912011-08-12 21:56:02 +00002843#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002844
2845template <class _Tp>
2846valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
2847 : __begin_(0),
2848 __end_(0)
2849{
2850 size_t __n = __sa.__size_;
2851 if (__n)
2852 {
2853 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2854#ifndef _LIBCPP_NO_EXCEPTIONS
2855 try
2856 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002857#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002858 for (const value_type* __p = __sa.__vp_; __n; ++__end_, __p += __sa.__stride_, --__n)
2859 ::new (__end_) value_type(*__p);
2860#ifndef _LIBCPP_NO_EXCEPTIONS
2861 }
2862 catch (...)
2863 {
2864 resize(0);
2865 throw;
2866 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002867#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002868 }
2869}
2870
2871template <class _Tp>
2872valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
2873 : __begin_(0),
2874 __end_(0)
2875{
2876 size_t __n = __ga.__1d_.size();
2877 if (__n)
2878 {
2879 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2880#ifndef _LIBCPP_NO_EXCEPTIONS
2881 try
2882 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002883#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002884 typedef const size_t* _Ip;
2885 const value_type* __s = __ga.__vp_;
2886 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2887 __i != __e; ++__i, ++__end_)
2888 ::new (__end_) value_type(__s[*__i]);
2889#ifndef _LIBCPP_NO_EXCEPTIONS
2890 }
2891 catch (...)
2892 {
2893 resize(0);
2894 throw;
2895 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002896#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002897 }
2898}
2899
2900template <class _Tp>
2901valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
2902 : __begin_(0),
2903 __end_(0)
2904{
2905 size_t __n = __ma.__1d_.size();
2906 if (__n)
2907 {
2908 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2909#ifndef _LIBCPP_NO_EXCEPTIONS
2910 try
2911 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002912#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002913 typedef const size_t* _Ip;
2914 const value_type* __s = __ma.__vp_;
2915 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2916 __i != __e; ++__i, ++__end_)
2917 ::new (__end_) value_type(__s[*__i]);
2918#ifndef _LIBCPP_NO_EXCEPTIONS
2919 }
2920 catch (...)
2921 {
2922 resize(0);
2923 throw;
2924 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002925#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002926 }
2927}
2928
2929template <class _Tp>
2930valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
2931 : __begin_(0),
2932 __end_(0)
2933{
2934 size_t __n = __ia.__1d_.size();
2935 if (__n)
2936 {
2937 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2938#ifndef _LIBCPP_NO_EXCEPTIONS
2939 try
2940 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002941#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002942 typedef const size_t* _Ip;
2943 const value_type* __s = __ia.__vp_;
2944 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2945 __i != __e; ++__i, ++__end_)
2946 ::new (__end_) value_type(__s[*__i]);
2947#ifndef _LIBCPP_NO_EXCEPTIONS
2948 }
2949 catch (...)
2950 {
2951 resize(0);
2952 throw;
2953 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002954#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002955 }
2956}
2957
2958template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002959inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002960valarray<_Tp>::~valarray()
2961{
2962 resize(0);
2963}
2964
2965template <class _Tp>
2966valarray<_Tp>&
2967valarray<_Tp>::operator=(const valarray& __v)
2968{
2969 if (this != &__v)
2970 {
2971 if (size() != __v.size())
2972 resize(__v.size());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002973 _VSTD::copy(__v.__begin_, __v.__end_, __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002974 }
2975 return *this;
2976}
2977
Howard Hinnant73d21a42010-09-04 23:28:19 +00002978#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002979
2980template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002981inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002982valarray<_Tp>&
2983valarray<_Tp>::operator=(valarray&& __v)
2984{
2985 resize(0);
2986 __begin_ = __v.__begin_;
2987 __end_ = __v.__end_;
2988 __v.__begin_ = nullptr;
2989 __v.__end_ = nullptr;
2990 return *this;
2991}
2992
Howard Hinnante3e32912011-08-12 21:56:02 +00002993#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2994
2995#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2996
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002997template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002998inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002999valarray<_Tp>&
3000valarray<_Tp>::operator=(initializer_list<value_type> __il)
3001{
3002 if (size() != __il.size())
3003 resize(__il.size());
Howard Hinnant0949eed2011-06-30 21:18:19 +00003004 _VSTD::copy(__il.begin(), __il.end(), __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003005 return *this;
3006}
3007
Howard Hinnante3e32912011-08-12 21:56:02 +00003008#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003009
3010template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003011inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003012valarray<_Tp>&
3013valarray<_Tp>::operator=(const value_type& __x)
3014{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003015 _VSTD::fill(__begin_, __end_, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003016 return *this;
3017}
3018
3019template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003020inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003021valarray<_Tp>&
3022valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
3023{
3024 value_type* __t = __begin_;
3025 const value_type* __s = __sa.__vp_;
3026 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
3027 *__t = *__s;
3028 return *this;
3029}
3030
3031template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003032inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003033valarray<_Tp>&
3034valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
3035{
3036 typedef const size_t* _Ip;
3037 value_type* __t = __begin_;
3038 const value_type* __s = __ga.__vp_;
3039 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
3040 __i != __e; ++__i, ++__t)
3041 *__t = __s[*__i];
3042 return *this;
3043}
3044
3045template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003046inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003047valarray<_Tp>&
3048valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
3049{
3050 typedef const size_t* _Ip;
3051 value_type* __t = __begin_;
3052 const value_type* __s = __ma.__vp_;
3053 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
3054 __i != __e; ++__i, ++__t)
3055 *__t = __s[*__i];
3056 return *this;
3057}
3058
3059template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003060inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003061valarray<_Tp>&
3062valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
3063{
3064 typedef const size_t* _Ip;
3065 value_type* __t = __begin_;
3066 const value_type* __s = __ia.__vp_;
3067 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
3068 __i != __e; ++__i, ++__t)
3069 *__t = __s[*__i];
3070 return *this;
3071}
3072
3073template <class _Tp>
Howard Hinnantdb866632011-07-27 23:19:59 +00003074template <class _ValExpr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003075inline
Howard Hinnantdb866632011-07-27 23:19:59 +00003076valarray<_Tp>&
3077valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
3078{
3079 size_t __n = __v.size();
3080 if (size() != __n)
3081 resize(__n);
3082 value_type* __t = __begin_;
3083 for (size_t __i = 0; __i != __n; ++__t, ++__i)
3084 *__t = result_type(__v[__i]);
3085 return *this;
3086}
3087
3088template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003089inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003090__val_expr<__slice_expr<const valarray<_Tp>&> >
3091valarray<_Tp>::operator[](slice __s) const
3092{
3093 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
3094}
3095
3096template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003097inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003098slice_array<_Tp>
3099valarray<_Tp>::operator[](slice __s)
3100{
3101 return slice_array<value_type>(__s, *this);
3102}
3103
3104template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003105inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003106__val_expr<__indirect_expr<const valarray<_Tp>&> >
3107valarray<_Tp>::operator[](const gslice& __gs) const
3108{
3109 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
3110}
3111
3112template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003113inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003114gslice_array<_Tp>
3115valarray<_Tp>::operator[](const gslice& __gs)
3116{
3117 return gslice_array<value_type>(__gs, *this);
3118}
3119
Howard Hinnant73d21a42010-09-04 23:28:19 +00003120#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003121
3122template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003123inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003124__val_expr<__indirect_expr<const valarray<_Tp>&> >
3125valarray<_Tp>::operator[](gslice&& __gs) const
3126{
3127 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
3128}
3129
3130template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003131inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003132gslice_array<_Tp>
3133valarray<_Tp>::operator[](gslice&& __gs)
3134{
3135 return gslice_array<value_type>(move(__gs), *this);
3136}
3137
Howard Hinnant73d21a42010-09-04 23:28:19 +00003138#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003139
3140template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003141inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003142__val_expr<__mask_expr<const valarray<_Tp>&> >
3143valarray<_Tp>::operator[](const valarray<bool>& __vb) const
3144{
3145 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
3146}
3147
3148template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003149inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003150mask_array<_Tp>
3151valarray<_Tp>::operator[](const valarray<bool>& __vb)
3152{
3153 return mask_array<value_type>(__vb, *this);
3154}
3155
Howard Hinnant73d21a42010-09-04 23:28:19 +00003156#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003157
3158template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003159inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003160__val_expr<__mask_expr<const valarray<_Tp>&> >
3161valarray<_Tp>::operator[](valarray<bool>&& __vb) const
3162{
3163 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
3164}
3165
3166template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003167inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003168mask_array<_Tp>
3169valarray<_Tp>::operator[](valarray<bool>&& __vb)
3170{
3171 return mask_array<value_type>(move(__vb), *this);
3172}
3173
Howard Hinnant73d21a42010-09-04 23:28:19 +00003174#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003175
3176template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003177inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003178__val_expr<__indirect_expr<const valarray<_Tp>&> >
3179valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
3180{
3181 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
3182}
3183
3184template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003185inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003186indirect_array<_Tp>
3187valarray<_Tp>::operator[](const valarray<size_t>& __vs)
3188{
3189 return indirect_array<value_type>(__vs, *this);
3190}
3191
Howard Hinnant73d21a42010-09-04 23:28:19 +00003192#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003193
3194template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003195inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003196__val_expr<__indirect_expr<const valarray<_Tp>&> >
3197valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
3198{
3199 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
3200}
3201
3202template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003203inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003204indirect_array<_Tp>
3205valarray<_Tp>::operator[](valarray<size_t>&& __vs)
3206{
3207 return indirect_array<value_type>(move(__vs), *this);
3208}
3209
Howard Hinnant73d21a42010-09-04 23:28:19 +00003210#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003211
3212template <class _Tp>
3213valarray<_Tp>
3214valarray<_Tp>::operator+() const
3215{
3216 valarray<value_type> __r;
3217 size_t __n = size();
3218 if (__n)
3219 {
3220 __r.__begin_ =
3221 __r.__end_ =
3222 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3223 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3224 ::new (__r.__end_) value_type(+*__p);
3225 }
3226 return __r;
3227}
3228
3229template <class _Tp>
3230valarray<_Tp>
3231valarray<_Tp>::operator-() const
3232{
3233 valarray<value_type> __r;
3234 size_t __n = size();
3235 if (__n)
3236 {
3237 __r.__begin_ =
3238 __r.__end_ =
3239 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3240 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3241 ::new (__r.__end_) value_type(-*__p);
3242 }
3243 return __r;
3244}
3245
3246template <class _Tp>
3247valarray<_Tp>
3248valarray<_Tp>::operator~() const
3249{
3250 valarray<value_type> __r;
3251 size_t __n = size();
3252 if (__n)
3253 {
3254 __r.__begin_ =
3255 __r.__end_ =
3256 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3257 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3258 ::new (__r.__end_) value_type(~*__p);
3259 }
3260 return __r;
3261}
3262
3263template <class _Tp>
3264valarray<bool>
3265valarray<_Tp>::operator!() const
3266{
3267 valarray<bool> __r;
3268 size_t __n = size();
3269 if (__n)
3270 {
3271 __r.__begin_ =
3272 __r.__end_ =
3273 static_cast<bool*>(::operator new(__n * sizeof(bool)));
3274 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3275 ::new (__r.__end_) bool(!*__p);
3276 }
3277 return __r;
3278}
3279
3280template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003281inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003282valarray<_Tp>&
3283valarray<_Tp>::operator*=(const value_type& __x)
3284{
3285 for (value_type* __p = __begin_; __p != __end_; ++__p)
3286 *__p *= __x;
3287 return *this;
3288}
3289
3290template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003291inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003292valarray<_Tp>&
3293valarray<_Tp>::operator/=(const value_type& __x)
3294{
3295 for (value_type* __p = __begin_; __p != __end_; ++__p)
3296 *__p /= __x;
3297 return *this;
3298}
3299
3300template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003301inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003302valarray<_Tp>&
3303valarray<_Tp>::operator%=(const value_type& __x)
3304{
3305 for (value_type* __p = __begin_; __p != __end_; ++__p)
3306 *__p %= __x;
3307 return *this;
3308}
3309
3310template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003311inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003312valarray<_Tp>&
3313valarray<_Tp>::operator+=(const value_type& __x)
3314{
3315 for (value_type* __p = __begin_; __p != __end_; ++__p)
3316 *__p += __x;
3317 return *this;
3318}
3319
3320template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003321inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003322valarray<_Tp>&
3323valarray<_Tp>::operator-=(const value_type& __x)
3324{
3325 for (value_type* __p = __begin_; __p != __end_; ++__p)
3326 *__p -= __x;
3327 return *this;
3328}
3329
3330template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003331inline
Howard Hinnantbc8d3f92010-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>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003341inline
Howard Hinnantbc8d3f92010-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>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003351inline
Howard Hinnantbc8d3f92010-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>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003361inline
Howard Hinnantbc8d3f92010-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>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003371inline
Howard Hinnantbc8d3f92010-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>
3381template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003382inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003383typename enable_if
3384<
3385 __is_val_expr<_Expr>::value,
3386 valarray<_Tp>&
3387>::type
3388valarray<_Tp>::operator*=(const _Expr& __v)
3389{
3390 size_t __i = 0;
3391 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3392 *__t *= __v[__i];
3393 return *this;
3394}
3395
3396template <class _Tp>
3397template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003398inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003399typename enable_if
3400<
3401 __is_val_expr<_Expr>::value,
3402 valarray<_Tp>&
3403>::type
3404valarray<_Tp>::operator/=(const _Expr& __v)
3405{
3406 size_t __i = 0;
3407 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3408 *__t /= __v[__i];
3409 return *this;
3410}
3411
3412template <class _Tp>
3413template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003414inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003415typename enable_if
3416<
3417 __is_val_expr<_Expr>::value,
3418 valarray<_Tp>&
3419>::type
3420valarray<_Tp>::operator%=(const _Expr& __v)
3421{
3422 size_t __i = 0;
3423 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3424 *__t %= __v[__i];
3425 return *this;
3426}
3427
3428template <class _Tp>
3429template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003430inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003431typename enable_if
3432<
3433 __is_val_expr<_Expr>::value,
3434 valarray<_Tp>&
3435>::type
3436valarray<_Tp>::operator+=(const _Expr& __v)
3437{
3438 size_t __i = 0;
3439 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3440 *__t += __v[__i];
3441 return *this;
3442}
3443
3444template <class _Tp>
3445template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003446inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003447typename enable_if
3448<
3449 __is_val_expr<_Expr>::value,
3450 valarray<_Tp>&
3451>::type
3452valarray<_Tp>::operator-=(const _Expr& __v)
3453{
3454 size_t __i = 0;
3455 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3456 *__t -= __v[__i];
3457 return *this;
3458}
3459
3460template <class _Tp>
3461template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003462inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003463typename enable_if
3464<
3465 __is_val_expr<_Expr>::value,
3466 valarray<_Tp>&
3467>::type
3468valarray<_Tp>::operator^=(const _Expr& __v)
3469{
3470 size_t __i = 0;
3471 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3472 *__t ^= __v[__i];
3473 return *this;
3474}
3475
3476template <class _Tp>
3477template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003478inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003479typename enable_if
3480<
3481 __is_val_expr<_Expr>::value,
3482 valarray<_Tp>&
3483>::type
3484valarray<_Tp>::operator|=(const _Expr& __v)
3485{
3486 size_t __i = 0;
3487 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3488 *__t |= __v[__i];
3489 return *this;
3490}
3491
3492template <class _Tp>
3493template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003494inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003495typename enable_if
3496<
3497 __is_val_expr<_Expr>::value,
3498 valarray<_Tp>&
3499>::type
3500valarray<_Tp>::operator&=(const _Expr& __v)
3501{
3502 size_t __i = 0;
3503 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3504 *__t &= __v[__i];
3505 return *this;
3506}
3507
3508template <class _Tp>
3509template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003510inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003511typename enable_if
3512<
3513 __is_val_expr<_Expr>::value,
3514 valarray<_Tp>&
3515>::type
3516valarray<_Tp>::operator<<=(const _Expr& __v)
3517{
3518 size_t __i = 0;
3519 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3520 *__t <<= __v[__i];
3521 return *this;
3522}
3523
3524template <class _Tp>
3525template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003526inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003527typename enable_if
3528<
3529 __is_val_expr<_Expr>::value,
3530 valarray<_Tp>&
3531>::type
3532valarray<_Tp>::operator>>=(const _Expr& __v)
3533{
3534 size_t __i = 0;
3535 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3536 *__t >>= __v[__i];
3537 return *this;
3538}
3539
3540template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003541inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003542void
3543valarray<_Tp>::swap(valarray& __v)
3544{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003545 _VSTD::swap(__begin_, __v.__begin_);
3546 _VSTD::swap(__end_, __v.__end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003547}
3548
3549template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003550inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003551_Tp
3552valarray<_Tp>::sum() const
3553{
3554 if (__begin_ == __end_)
3555 return value_type();
3556 const value_type* __p = __begin_;
3557 _Tp __r = *__p;
3558 for (++__p; __p != __end_; ++__p)
3559 __r += *__p;
3560 return __r;
3561}
3562
3563template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003564inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003565_Tp
3566valarray<_Tp>::min() const
3567{
3568 if (__begin_ == __end_)
3569 return value_type();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003570 return *_VSTD::min_element(__begin_, __end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003571}
3572
3573template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003574inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003575_Tp
3576valarray<_Tp>::max() const
3577{
3578 if (__begin_ == __end_)
3579 return value_type();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003580 return *_VSTD::max_element(__begin_, __end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003581}
3582
3583template <class _Tp>
3584valarray<_Tp>
3585valarray<_Tp>::shift(int __i) const
3586{
3587 valarray<value_type> __r;
3588 size_t __n = size();
3589 if (__n)
3590 {
3591 __r.__begin_ =
3592 __r.__end_ =
3593 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3594 const value_type* __sb;
3595 value_type* __tb;
3596 value_type* __te;
3597 if (__i >= 0)
3598 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003599 __i = _VSTD::min(__i, static_cast<int>(__n));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003600 __sb = __begin_ + __i;
3601 __tb = __r.__begin_;
3602 __te = __r.__begin_ + (__n - __i);
3603 }
3604 else
3605 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003606 __i = _VSTD::min(-__i, static_cast<int>(__n));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003607 __sb = __begin_;
3608 __tb = __r.__begin_ + __i;
3609 __te = __r.__begin_ + __n;
3610 }
3611 for (; __r.__end_ != __tb; ++__r.__end_)
3612 ::new (__r.__end_) value_type();
3613 for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
3614 ::new (__r.__end_) value_type(*__sb);
3615 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
3616 ::new (__r.__end_) value_type();
3617 }
3618 return __r;
3619}
3620
3621template <class _Tp>
3622valarray<_Tp>
3623valarray<_Tp>::cshift(int __i) const
3624{
3625 valarray<value_type> __r;
3626 size_t __n = size();
3627 if (__n)
3628 {
3629 __r.__begin_ =
3630 __r.__end_ =
3631 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3632 __i %= static_cast<int>(__n);
3633 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
3634 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
3635 ::new (__r.__end_) value_type(*__s);
3636 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
3637 ::new (__r.__end_) value_type(*__s);
3638 }
3639 return __r;
3640}
3641
3642template <class _Tp>
3643valarray<_Tp>
3644valarray<_Tp>::apply(value_type __f(value_type)) const
3645{
3646 valarray<value_type> __r;
3647 size_t __n = size();
3648 if (__n)
3649 {
3650 __r.__begin_ =
3651 __r.__end_ =
3652 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3653 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3654 ::new (__r.__end_) value_type(__f(*__p));
3655 }
3656 return __r;
3657}
3658
3659template <class _Tp>
3660valarray<_Tp>
3661valarray<_Tp>::apply(value_type __f(const value_type&)) const
3662{
3663 valarray<value_type> __r;
3664 size_t __n = size();
3665 if (__n)
3666 {
3667 __r.__begin_ =
3668 __r.__end_ =
3669 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3670 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3671 ::new (__r.__end_) value_type(__f(*__p));
3672 }
3673 return __r;
3674}
3675
3676template <class _Tp>
3677void
3678valarray<_Tp>::resize(size_t __n, value_type __x)
3679{
3680 if (__begin_ != nullptr)
3681 {
3682 while (__end_ != __begin_)
3683 (--__end_)->~value_type();
3684 ::operator delete(__begin_);
3685 __begin_ = __end_ = nullptr;
3686 }
3687 if (__n)
3688 {
3689 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3690#ifndef _LIBCPP_NO_EXCEPTIONS
3691 try
3692 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003693#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003694 for (; __n; --__n, ++__end_)
3695 ::new (__end_) value_type(__x);
3696#ifndef _LIBCPP_NO_EXCEPTIONS
3697 }
3698 catch (...)
3699 {
3700 resize(0);
3701 throw;
3702 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003703#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003704 }
3705}
3706
3707template<class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003708inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003709void
3710swap(valarray<_Tp>& __x, valarray<_Tp>& __y)
3711{
3712 __x.swap(__y);
3713}
3714
3715template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003716inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003717typename enable_if
3718<
3719 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3720 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
3721>::type
3722operator*(const _Expr1& __x, const _Expr2& __y)
3723{
3724 typedef typename _Expr1::value_type value_type;
3725 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
3726 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
3727}
3728
3729template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003730inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003731typename enable_if
3732<
3733 __is_val_expr<_Expr>::value,
3734 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3735 _Expr, __scalar_expr<typename _Expr::value_type> > >
3736>::type
3737operator*(const _Expr& __x, const typename _Expr::value_type& __y)
3738{
3739 typedef typename _Expr::value_type value_type;
3740 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3741 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3742 __x, __scalar_expr<value_type>(__y, __x.size())));
3743}
3744
3745template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003746inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003747typename enable_if
3748<
3749 __is_val_expr<_Expr>::value,
3750 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3751 __scalar_expr<typename _Expr::value_type>, _Expr> >
3752>::type
3753operator*(const typename _Expr::value_type& __x, const _Expr& __y)
3754{
3755 typedef typename _Expr::value_type value_type;
3756 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3757 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3758 __scalar_expr<value_type>(__x, __y.size()), __y));
3759}
3760
3761template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003762inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003763typename enable_if
3764<
3765 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3766 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
3767>::type
3768operator/(const _Expr1& __x, const _Expr2& __y)
3769{
3770 typedef typename _Expr1::value_type value_type;
3771 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
3772 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
3773}
3774
3775template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003776inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003777typename enable_if
3778<
3779 __is_val_expr<_Expr>::value,
3780 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3781 _Expr, __scalar_expr<typename _Expr::value_type> > >
3782>::type
3783operator/(const _Expr& __x, const typename _Expr::value_type& __y)
3784{
3785 typedef typename _Expr::value_type value_type;
3786 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3787 return __val_expr<_Op>(_Op(divides<value_type>(),
3788 __x, __scalar_expr<value_type>(__y, __x.size())));
3789}
3790
3791template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003792inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003793typename enable_if
3794<
3795 __is_val_expr<_Expr>::value,
3796 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3797 __scalar_expr<typename _Expr::value_type>, _Expr> >
3798>::type
3799operator/(const typename _Expr::value_type& __x, const _Expr& __y)
3800{
3801 typedef typename _Expr::value_type value_type;
3802 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3803 return __val_expr<_Op>(_Op(divides<value_type>(),
3804 __scalar_expr<value_type>(__x, __y.size()), __y));
3805}
3806
3807template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003808inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003809typename enable_if
3810<
3811 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3812 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3813>::type
3814operator%(const _Expr1& __x, const _Expr2& __y)
3815{
3816 typedef typename _Expr1::value_type value_type;
3817 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
3818 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
3819}
3820
3821template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003822inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003823typename enable_if
3824<
3825 __is_val_expr<_Expr>::value,
3826 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3827 _Expr, __scalar_expr<typename _Expr::value_type> > >
3828>::type
3829operator%(const _Expr& __x, const typename _Expr::value_type& __y)
3830{
3831 typedef typename _Expr::value_type value_type;
3832 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3833 return __val_expr<_Op>(_Op(modulus<value_type>(),
3834 __x, __scalar_expr<value_type>(__y, __x.size())));
3835}
3836
3837template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003838inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003839typename enable_if
3840<
3841 __is_val_expr<_Expr>::value,
3842 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3843 __scalar_expr<typename _Expr::value_type>, _Expr> >
3844>::type
3845operator%(const typename _Expr::value_type& __x, const _Expr& __y)
3846{
3847 typedef typename _Expr::value_type value_type;
3848 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3849 return __val_expr<_Op>(_Op(modulus<value_type>(),
3850 __scalar_expr<value_type>(__x, __y.size()), __y));
3851}
3852
3853template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003854inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003855typename enable_if
3856<
3857 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3858 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3859>::type
3860operator+(const _Expr1& __x, const _Expr2& __y)
3861{
3862 typedef typename _Expr1::value_type value_type;
3863 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
3864 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
3865}
3866
3867template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003868inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003869typename enable_if
3870<
3871 __is_val_expr<_Expr>::value,
3872 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3873 _Expr, __scalar_expr<typename _Expr::value_type> > >
3874>::type
3875operator+(const _Expr& __x, const typename _Expr::value_type& __y)
3876{
3877 typedef typename _Expr::value_type value_type;
3878 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3879 return __val_expr<_Op>(_Op(plus<value_type>(),
3880 __x, __scalar_expr<value_type>(__y, __x.size())));
3881}
3882
3883template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003884inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003885typename enable_if
3886<
3887 __is_val_expr<_Expr>::value,
3888 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3889 __scalar_expr<typename _Expr::value_type>, _Expr> >
3890>::type
3891operator+(const typename _Expr::value_type& __x, const _Expr& __y)
3892{
3893 typedef typename _Expr::value_type value_type;
3894 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3895 return __val_expr<_Op>(_Op(plus<value_type>(),
3896 __scalar_expr<value_type>(__x, __y.size()), __y));
3897}
3898
3899template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003900inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003901typename enable_if
3902<
3903 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3904 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3905>::type
3906operator-(const _Expr1& __x, const _Expr2& __y)
3907{
3908 typedef typename _Expr1::value_type value_type;
3909 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
3910 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
3911}
3912
3913template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003914inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003915typename enable_if
3916<
3917 __is_val_expr<_Expr>::value,
3918 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3919 _Expr, __scalar_expr<typename _Expr::value_type> > >
3920>::type
3921operator-(const _Expr& __x, const typename _Expr::value_type& __y)
3922{
3923 typedef typename _Expr::value_type value_type;
3924 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3925 return __val_expr<_Op>(_Op(minus<value_type>(),
3926 __x, __scalar_expr<value_type>(__y, __x.size())));
3927}
3928
3929template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003930inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003931typename enable_if
3932<
3933 __is_val_expr<_Expr>::value,
3934 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3935 __scalar_expr<typename _Expr::value_type>, _Expr> >
3936>::type
3937operator-(const typename _Expr::value_type& __x, const _Expr& __y)
3938{
3939 typedef typename _Expr::value_type value_type;
3940 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3941 return __val_expr<_Op>(_Op(minus<value_type>(),
3942 __scalar_expr<value_type>(__x, __y.size()), __y));
3943}
3944
3945template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003946inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003947typename enable_if
3948<
3949 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3950 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
3951>::type
3952operator^(const _Expr1& __x, const _Expr2& __y)
3953{
3954 typedef typename _Expr1::value_type value_type;
3955 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
3956 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
3957}
3958
3959template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003960inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003961typename enable_if
3962<
3963 __is_val_expr<_Expr>::value,
3964 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
3965 _Expr, __scalar_expr<typename _Expr::value_type> > >
3966>::type
3967operator^(const _Expr& __x, const typename _Expr::value_type& __y)
3968{
3969 typedef typename _Expr::value_type value_type;
3970 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3971 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
3972 __x, __scalar_expr<value_type>(__y, __x.size())));
3973}
3974
3975template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003976inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003977typename enable_if
3978<
3979 __is_val_expr<_Expr>::value,
3980 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
3981 __scalar_expr<typename _Expr::value_type>, _Expr> >
3982>::type
3983operator^(const typename _Expr::value_type& __x, const _Expr& __y)
3984{
3985 typedef typename _Expr::value_type value_type;
3986 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3987 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
3988 __scalar_expr<value_type>(__x, __y.size()), __y));
3989}
3990
3991template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003992inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003993typename enable_if
3994<
3995 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3996 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
3997>::type
3998operator&(const _Expr1& __x, const _Expr2& __y)
3999{
4000 typedef typename _Expr1::value_type value_type;
4001 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
4002 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
4003}
4004
4005template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004006inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004007typename enable_if
4008<
4009 __is_val_expr<_Expr>::value,
4010 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4011 _Expr, __scalar_expr<typename _Expr::value_type> > >
4012>::type
4013operator&(const _Expr& __x, const typename _Expr::value_type& __y)
4014{
4015 typedef typename _Expr::value_type value_type;
4016 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4017 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4018 __x, __scalar_expr<value_type>(__y, __x.size())));
4019}
4020
4021template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004022inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004023typename enable_if
4024<
4025 __is_val_expr<_Expr>::value,
4026 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4027 __scalar_expr<typename _Expr::value_type>, _Expr> >
4028>::type
4029operator&(const typename _Expr::value_type& __x, const _Expr& __y)
4030{
4031 typedef typename _Expr::value_type value_type;
4032 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4033 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4034 __scalar_expr<value_type>(__x, __y.size()), __y));
4035}
4036
4037template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004038inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004039typename enable_if
4040<
4041 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4042 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4043>::type
4044operator|(const _Expr1& __x, const _Expr2& __y)
4045{
4046 typedef typename _Expr1::value_type value_type;
4047 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
4048 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
4049}
4050
4051template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004052inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004053typename enable_if
4054<
4055 __is_val_expr<_Expr>::value,
4056 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4057 _Expr, __scalar_expr<typename _Expr::value_type> > >
4058>::type
4059operator|(const _Expr& __x, const typename _Expr::value_type& __y)
4060{
4061 typedef typename _Expr::value_type value_type;
4062 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4063 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4064 __x, __scalar_expr<value_type>(__y, __x.size())));
4065}
4066
4067template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004068inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004069typename enable_if
4070<
4071 __is_val_expr<_Expr>::value,
4072 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4073 __scalar_expr<typename _Expr::value_type>, _Expr> >
4074>::type
4075operator|(const typename _Expr::value_type& __x, const _Expr& __y)
4076{
4077 typedef typename _Expr::value_type value_type;
4078 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4079 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4080 __scalar_expr<value_type>(__x, __y.size()), __y));
4081}
4082
4083template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004084inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004085typename enable_if
4086<
4087 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4088 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
4089>::type
4090operator<<(const _Expr1& __x, const _Expr2& __y)
4091{
4092 typedef typename _Expr1::value_type value_type;
4093 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
4094 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
4095}
4096
4097template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004098inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004099typename enable_if
4100<
4101 __is_val_expr<_Expr>::value,
4102 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4103 _Expr, __scalar_expr<typename _Expr::value_type> > >
4104>::type
4105operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
4106{
4107 typedef typename _Expr::value_type value_type;
4108 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4109 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4110 __x, __scalar_expr<value_type>(__y, __x.size())));
4111}
4112
4113template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004114inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004115typename enable_if
4116<
4117 __is_val_expr<_Expr>::value,
4118 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4119 __scalar_expr<typename _Expr::value_type>, _Expr> >
4120>::type
4121operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
4122{
4123 typedef typename _Expr::value_type value_type;
4124 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4125 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4126 __scalar_expr<value_type>(__x, __y.size()), __y));
4127}
4128
4129template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004130inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004131typename enable_if
4132<
4133 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4134 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
4135>::type
4136operator>>(const _Expr1& __x, const _Expr2& __y)
4137{
4138 typedef typename _Expr1::value_type value_type;
4139 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
4140 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
4141}
4142
4143template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004144inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004145typename enable_if
4146<
4147 __is_val_expr<_Expr>::value,
4148 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4149 _Expr, __scalar_expr<typename _Expr::value_type> > >
4150>::type
4151operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
4152{
4153 typedef typename _Expr::value_type value_type;
4154 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4155 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4156 __x, __scalar_expr<value_type>(__y, __x.size())));
4157}
4158
4159template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004160inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004161typename enable_if
4162<
4163 __is_val_expr<_Expr>::value,
4164 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4165 __scalar_expr<typename _Expr::value_type>, _Expr> >
4166>::type
4167operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
4168{
4169 typedef typename _Expr::value_type value_type;
4170 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4171 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4172 __scalar_expr<value_type>(__x, __y.size()), __y));
4173}
4174
4175template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004176inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004177typename enable_if
4178<
4179 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4180 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4181>::type
4182operator&&(const _Expr1& __x, const _Expr2& __y)
4183{
4184 typedef typename _Expr1::value_type value_type;
4185 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
4186 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
4187}
4188
4189template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004190inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004191typename enable_if
4192<
4193 __is_val_expr<_Expr>::value,
4194 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4195 _Expr, __scalar_expr<typename _Expr::value_type> > >
4196>::type
4197operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
4198{
4199 typedef typename _Expr::value_type value_type;
4200 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4201 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4202 __x, __scalar_expr<value_type>(__y, __x.size())));
4203}
4204
4205template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004206inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004207typename enable_if
4208<
4209 __is_val_expr<_Expr>::value,
4210 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4211 __scalar_expr<typename _Expr::value_type>, _Expr> >
4212>::type
4213operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
4214{
4215 typedef typename _Expr::value_type value_type;
4216 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4217 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4218 __scalar_expr<value_type>(__x, __y.size()), __y));
4219}
4220
4221template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004222inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004223typename enable_if
4224<
4225 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4226 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4227>::type
4228operator||(const _Expr1& __x, const _Expr2& __y)
4229{
4230 typedef typename _Expr1::value_type value_type;
4231 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
4232 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
4233}
4234
4235template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004236inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004237typename enable_if
4238<
4239 __is_val_expr<_Expr>::value,
4240 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4241 _Expr, __scalar_expr<typename _Expr::value_type> > >
4242>::type
4243operator||(const _Expr& __x, const typename _Expr::value_type& __y)
4244{
4245 typedef typename _Expr::value_type value_type;
4246 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4247 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4248 __x, __scalar_expr<value_type>(__y, __x.size())));
4249}
4250
4251template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004252inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004253typename enable_if
4254<
4255 __is_val_expr<_Expr>::value,
4256 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4257 __scalar_expr<typename _Expr::value_type>, _Expr> >
4258>::type
4259operator||(const typename _Expr::value_type& __x, const _Expr& __y)
4260{
4261 typedef typename _Expr::value_type value_type;
4262 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4263 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4264 __scalar_expr<value_type>(__x, __y.size()), __y));
4265}
4266
4267template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004268inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004269typename enable_if
4270<
4271 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4272 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4273>::type
4274operator==(const _Expr1& __x, const _Expr2& __y)
4275{
4276 typedef typename _Expr1::value_type value_type;
4277 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
4278 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
4279}
4280
4281template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004282inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004283typename enable_if
4284<
4285 __is_val_expr<_Expr>::value,
4286 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4287 _Expr, __scalar_expr<typename _Expr::value_type> > >
4288>::type
4289operator==(const _Expr& __x, const typename _Expr::value_type& __y)
4290{
4291 typedef typename _Expr::value_type value_type;
4292 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4293 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4294 __x, __scalar_expr<value_type>(__y, __x.size())));
4295}
4296
4297template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004298inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004299typename enable_if
4300<
4301 __is_val_expr<_Expr>::value,
4302 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4303 __scalar_expr<typename _Expr::value_type>, _Expr> >
4304>::type
4305operator==(const typename _Expr::value_type& __x, const _Expr& __y)
4306{
4307 typedef typename _Expr::value_type value_type;
4308 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4309 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4310 __scalar_expr<value_type>(__x, __y.size()), __y));
4311}
4312
4313template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004314inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004315typename enable_if
4316<
4317 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4318 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4319>::type
4320operator!=(const _Expr1& __x, const _Expr2& __y)
4321{
4322 typedef typename _Expr1::value_type value_type;
4323 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
4324 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
4325}
4326
4327template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004328inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004329typename enable_if
4330<
4331 __is_val_expr<_Expr>::value,
4332 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4333 _Expr, __scalar_expr<typename _Expr::value_type> > >
4334>::type
4335operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
4336{
4337 typedef typename _Expr::value_type value_type;
4338 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4339 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4340 __x, __scalar_expr<value_type>(__y, __x.size())));
4341}
4342
4343template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004344inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004345typename enable_if
4346<
4347 __is_val_expr<_Expr>::value,
4348 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4349 __scalar_expr<typename _Expr::value_type>, _Expr> >
4350>::type
4351operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
4352{
4353 typedef typename _Expr::value_type value_type;
4354 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4355 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4356 __scalar_expr<value_type>(__x, __y.size()), __y));
4357}
4358
4359template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004360inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004361typename enable_if
4362<
4363 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4364 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
4365>::type
4366operator<(const _Expr1& __x, const _Expr2& __y)
4367{
4368 typedef typename _Expr1::value_type value_type;
4369 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
4370 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
4371}
4372
4373template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004374inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004375typename enable_if
4376<
4377 __is_val_expr<_Expr>::value,
4378 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4379 _Expr, __scalar_expr<typename _Expr::value_type> > >
4380>::type
4381operator<(const _Expr& __x, const typename _Expr::value_type& __y)
4382{
4383 typedef typename _Expr::value_type value_type;
4384 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4385 return __val_expr<_Op>(_Op(less<value_type>(),
4386 __x, __scalar_expr<value_type>(__y, __x.size())));
4387}
4388
4389template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004390inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004391typename enable_if
4392<
4393 __is_val_expr<_Expr>::value,
4394 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4395 __scalar_expr<typename _Expr::value_type>, _Expr> >
4396>::type
4397operator<(const typename _Expr::value_type& __x, const _Expr& __y)
4398{
4399 typedef typename _Expr::value_type value_type;
4400 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4401 return __val_expr<_Op>(_Op(less<value_type>(),
4402 __scalar_expr<value_type>(__x, __y.size()), __y));
4403}
4404
4405template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004406inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004407typename enable_if
4408<
4409 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4410 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
4411>::type
4412operator>(const _Expr1& __x, const _Expr2& __y)
4413{
4414 typedef typename _Expr1::value_type value_type;
4415 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
4416 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
4417}
4418
4419template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004420inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004421typename enable_if
4422<
4423 __is_val_expr<_Expr>::value,
4424 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4425 _Expr, __scalar_expr<typename _Expr::value_type> > >
4426>::type
4427operator>(const _Expr& __x, const typename _Expr::value_type& __y)
4428{
4429 typedef typename _Expr::value_type value_type;
4430 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4431 return __val_expr<_Op>(_Op(greater<value_type>(),
4432 __x, __scalar_expr<value_type>(__y, __x.size())));
4433}
4434
4435template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004436inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004437typename enable_if
4438<
4439 __is_val_expr<_Expr>::value,
4440 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4441 __scalar_expr<typename _Expr::value_type>, _Expr> >
4442>::type
4443operator>(const typename _Expr::value_type& __x, const _Expr& __y)
4444{
4445 typedef typename _Expr::value_type value_type;
4446 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4447 return __val_expr<_Op>(_Op(greater<value_type>(),
4448 __scalar_expr<value_type>(__x, __y.size()), __y));
4449}
4450
4451template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004452inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004453typename enable_if
4454<
4455 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4456 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4457>::type
4458operator<=(const _Expr1& __x, const _Expr2& __y)
4459{
4460 typedef typename _Expr1::value_type value_type;
4461 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
4462 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
4463}
4464
4465template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004466inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004467typename enable_if
4468<
4469 __is_val_expr<_Expr>::value,
4470 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4471 _Expr, __scalar_expr<typename _Expr::value_type> > >
4472>::type
4473operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
4474{
4475 typedef typename _Expr::value_type value_type;
4476 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4477 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4478 __x, __scalar_expr<value_type>(__y, __x.size())));
4479}
4480
4481template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004482inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004483typename enable_if
4484<
4485 __is_val_expr<_Expr>::value,
4486 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4487 __scalar_expr<typename _Expr::value_type>, _Expr> >
4488>::type
4489operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
4490{
4491 typedef typename _Expr::value_type value_type;
4492 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4493 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4494 __scalar_expr<value_type>(__x, __y.size()), __y));
4495}
4496
4497template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004498inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004499typename enable_if
4500<
4501 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4502 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4503>::type
4504operator>=(const _Expr1& __x, const _Expr2& __y)
4505{
4506 typedef typename _Expr1::value_type value_type;
4507 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
4508 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
4509}
4510
4511template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004512inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004513typename enable_if
4514<
4515 __is_val_expr<_Expr>::value,
4516 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4517 _Expr, __scalar_expr<typename _Expr::value_type> > >
4518>::type
4519operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
4520{
4521 typedef typename _Expr::value_type value_type;
4522 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4523 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4524 __x, __scalar_expr<value_type>(__y, __x.size())));
4525}
4526
4527template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004528inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004529typename enable_if
4530<
4531 __is_val_expr<_Expr>::value,
4532 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4533 __scalar_expr<typename _Expr::value_type>, _Expr> >
4534>::type
4535operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
4536{
4537 typedef typename _Expr::value_type value_type;
4538 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4539 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4540 __scalar_expr<value_type>(__x, __y.size()), __y));
4541}
4542
4543template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004544inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004545typename enable_if
4546<
4547 __is_val_expr<_Expr>::value,
4548 __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
4549>::type
4550abs(const _Expr& __x)
4551{
4552 typedef typename _Expr::value_type value_type;
4553 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
4554 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
4555}
4556
4557template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004558inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004559typename enable_if
4560<
4561 __is_val_expr<_Expr>::value,
4562 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
4563>::type
4564acos(const _Expr& __x)
4565{
4566 typedef typename _Expr::value_type value_type;
4567 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
4568 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
4569}
4570
4571template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004572inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004573typename enable_if
4574<
4575 __is_val_expr<_Expr>::value,
4576 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
4577>::type
4578asin(const _Expr& __x)
4579{
4580 typedef typename _Expr::value_type value_type;
4581 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
4582 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
4583}
4584
4585template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004586inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004587typename enable_if
4588<
4589 __is_val_expr<_Expr>::value,
4590 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
4591>::type
4592atan(const _Expr& __x)
4593{
4594 typedef typename _Expr::value_type value_type;
4595 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
4596 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
4597}
4598
4599template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004600inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004601typename enable_if
4602<
4603 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4604 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4605>::type
4606atan2(const _Expr1& __x, const _Expr2& __y)
4607{
4608 typedef typename _Expr1::value_type value_type;
4609 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
4610 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
4611}
4612
4613template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004614inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004615typename enable_if
4616<
4617 __is_val_expr<_Expr>::value,
4618 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4619 _Expr, __scalar_expr<typename _Expr::value_type> > >
4620>::type
4621atan2(const _Expr& __x, const typename _Expr::value_type& __y)
4622{
4623 typedef typename _Expr::value_type value_type;
4624 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4625 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4626 __x, __scalar_expr<value_type>(__y, __x.size())));
4627}
4628
4629template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004630inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004631typename enable_if
4632<
4633 __is_val_expr<_Expr>::value,
4634 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4635 __scalar_expr<typename _Expr::value_type>, _Expr> >
4636>::type
4637atan2(const typename _Expr::value_type& __x, const _Expr& __y)
4638{
4639 typedef typename _Expr::value_type value_type;
4640 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4641 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4642 __scalar_expr<value_type>(__x, __y.size()), __y));
4643}
4644
4645template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004646inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004647typename enable_if
4648<
4649 __is_val_expr<_Expr>::value,
4650 __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
4651>::type
4652cos(const _Expr& __x)
4653{
4654 typedef typename _Expr::value_type value_type;
4655 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
4656 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
4657}
4658
4659template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004660inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004661typename enable_if
4662<
4663 __is_val_expr<_Expr>::value,
4664 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
4665>::type
4666cosh(const _Expr& __x)
4667{
4668 typedef typename _Expr::value_type value_type;
4669 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
4670 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
4671}
4672
4673template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004674inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004675typename enable_if
4676<
4677 __is_val_expr<_Expr>::value,
4678 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
4679>::type
4680exp(const _Expr& __x)
4681{
4682 typedef typename _Expr::value_type value_type;
4683 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
4684 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
4685}
4686
4687template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004688inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004689typename enable_if
4690<
4691 __is_val_expr<_Expr>::value,
4692 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
4693>::type
4694log(const _Expr& __x)
4695{
4696 typedef typename _Expr::value_type value_type;
4697 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
4698 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
4699}
4700
4701template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004702inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004703typename enable_if
4704<
4705 __is_val_expr<_Expr>::value,
4706 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
4707>::type
4708log10(const _Expr& __x)
4709{
4710 typedef typename _Expr::value_type value_type;
4711 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
4712 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
4713}
4714
4715template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004716inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004717typename enable_if
4718<
4719 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4720 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4721>::type
4722pow(const _Expr1& __x, const _Expr2& __y)
4723{
4724 typedef typename _Expr1::value_type value_type;
4725 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
4726 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
4727}
4728
4729template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004730inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004731typename enable_if
4732<
4733 __is_val_expr<_Expr>::value,
4734 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4735 _Expr, __scalar_expr<typename _Expr::value_type> > >
4736>::type
4737pow(const _Expr& __x, const typename _Expr::value_type& __y)
4738{
4739 typedef typename _Expr::value_type value_type;
4740 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4741 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4742 __x, __scalar_expr<value_type>(__y, __x.size())));
4743}
4744
4745template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004746inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004747typename enable_if
4748<
4749 __is_val_expr<_Expr>::value,
4750 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4751 __scalar_expr<typename _Expr::value_type>, _Expr> >
4752>::type
4753pow(const typename _Expr::value_type& __x, const _Expr& __y)
4754{
4755 typedef typename _Expr::value_type value_type;
4756 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4757 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4758 __scalar_expr<value_type>(__x, __y.size()), __y));
4759}
4760
4761template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004762inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004763typename enable_if
4764<
4765 __is_val_expr<_Expr>::value,
4766 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
4767>::type
4768sin(const _Expr& __x)
4769{
4770 typedef typename _Expr::value_type value_type;
4771 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
4772 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
4773}
4774
4775template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004776inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004777typename enable_if
4778<
4779 __is_val_expr<_Expr>::value,
4780 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
4781>::type
4782sinh(const _Expr& __x)
4783{
4784 typedef typename _Expr::value_type value_type;
4785 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
4786 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
4787}
4788
4789template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004790inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004791typename enable_if
4792<
4793 __is_val_expr<_Expr>::value,
4794 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
4795>::type
4796sqrt(const _Expr& __x)
4797{
4798 typedef typename _Expr::value_type value_type;
4799 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
4800 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
4801}
4802
4803template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004804inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004805typename enable_if
4806<
4807 __is_val_expr<_Expr>::value,
4808 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
4809>::type
4810tan(const _Expr& __x)
4811{
4812 typedef typename _Expr::value_type value_type;
4813 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
4814 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
4815}
4816
4817template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004818inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004819typename enable_if
4820<
4821 __is_val_expr<_Expr>::value,
4822 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
4823>::type
4824tanh(const _Expr& __x)
4825{
4826 typedef typename _Expr::value_type value_type;
4827 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
4828 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
4829}
4830
4831template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004832inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004833_Tp*
4834begin(valarray<_Tp>& __v)
4835{
4836 return __v.__begin_;
4837}
4838
4839template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004840inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004841const _Tp*
4842begin(const valarray<_Tp>& __v)
4843{
4844 return __v.__begin_;
4845}
4846
4847template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004848inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004849_Tp*
4850end(valarray<_Tp>& __v)
4851{
4852 return __v.__end_;
4853}
4854
4855template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004856inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004857const _Tp*
4858end(const valarray<_Tp>& __v)
4859{
4860 return __v.__end_;
4861}
4862
4863extern template valarray<size_t>::valarray(size_t);
4864extern template valarray<size_t>::~valarray();
4865extern template void valarray<size_t>::resize(size_t, size_t);
4866
4867_LIBCPP_END_NAMESPACE_STD
4868
4869#endif // _LIBCPP_VALARRAY