blob: 72e9cae296af98ef32253b57863193411e25e4a4 [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;
1013 void resize(size_t __n, value_type __x = value_type());
1014
1015private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001016 template <class> friend class _LIBCPP_VISIBLE valarray;
1017 template <class> friend class _LIBCPP_VISIBLE slice_array;
1018 template <class> friend class _LIBCPP_VISIBLE gslice_array;
1019 template <class> friend class _LIBCPP_VISIBLE mask_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001020 template <class> friend class __mask_expr;
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001021 template <class> friend class _LIBCPP_VISIBLE indirect_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001022 template <class> friend class __indirect_expr;
1023 template <class> friend class __val_expr;
1024
1025 template <class _Up>
1026 friend
1027 _Up*
1028 begin(valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +00001029
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001030 template <class _Up>
1031 friend
1032 const _Up*
1033 begin(const valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +00001034
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001035 template <class _Up>
1036 friend
1037 _Up*
1038 end(valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +00001039
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001040 template <class _Up>
1041 friend
1042 const _Up*
1043 end(const valarray<_Up>& __v);
1044};
1045
1046template <class _Op, class _Tp>
1047struct _UnaryOp<_Op, valarray<_Tp> >
1048{
1049 typedef typename _Op::result_type result_type;
1050 typedef _Tp value_type;
1051
1052 _Op __op_;
1053 const valarray<_Tp>& __a0_;
1054
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001055 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001056 _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
1057
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001058 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001059 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
1060
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001061 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001062 size_t size() const {return __a0_.size();}
1063};
1064
1065template <class _Op, class _Tp, class _A1>
1066struct _BinaryOp<_Op, valarray<_Tp>, _A1>
1067{
1068 typedef typename _Op::result_type result_type;
1069 typedef _Tp value_type;
1070
1071 _Op __op_;
1072 const valarray<_Tp>& __a0_;
1073 _A1 __a1_;
1074
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001075 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001076 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
1077 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1078
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001079 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001080 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1081
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001082 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001083 size_t size() const {return __a0_.size();}
1084};
1085
1086template <class _Op, class _A0, class _Tp>
1087struct _BinaryOp<_Op, _A0, valarray<_Tp> >
1088{
1089 typedef typename _Op::result_type result_type;
1090 typedef _Tp value_type;
1091
1092 _Op __op_;
1093 _A0 __a0_;
1094 const valarray<_Tp>& __a1_;
1095
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001096 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001097 _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
1098 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1099
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001101 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1102
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001103 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001104 size_t size() const {return __a0_.size();}
1105};
1106
1107template <class _Op, class _Tp>
1108struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> >
1109{
1110 typedef typename _Op::result_type result_type;
1111 typedef _Tp value_type;
1112
1113 _Op __op_;
1114 const valarray<_Tp>& __a0_;
1115 const valarray<_Tp>& __a1_;
1116
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001117 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001118 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
1119 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1120
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001121 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001122 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1123
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001124 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001125 size_t size() const {return __a0_.size();}
1126};
1127
1128// slice_array
1129
1130template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001131class _LIBCPP_VISIBLE slice_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001132{
1133public:
1134 typedef _Tp value_type;
1135
1136private:
1137 value_type* __vp_;
1138 size_t __size_;
1139 size_t __stride_;
1140
1141public:
1142 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001143 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001144 typename enable_if
1145 <
1146 __is_val_expr<_Expr>::value,
1147 void
1148 >::type
1149 operator=(const _Expr& __v) const;
1150
1151 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001153 typename enable_if
1154 <
1155 __is_val_expr<_Expr>::value,
1156 void
1157 >::type
1158 operator*=(const _Expr& __v) const;
1159
1160 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001161 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001162 typename enable_if
1163 <
1164 __is_val_expr<_Expr>::value,
1165 void
1166 >::type
1167 operator/=(const _Expr& __v) const;
1168
1169 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001170 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001171 typename enable_if
1172 <
1173 __is_val_expr<_Expr>::value,
1174 void
1175 >::type
1176 operator%=(const _Expr& __v) const;
1177
1178 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001179 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001180 typename enable_if
1181 <
1182 __is_val_expr<_Expr>::value,
1183 void
1184 >::type
1185 operator+=(const _Expr& __v) const;
1186
1187 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001188 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001189 typename enable_if
1190 <
1191 __is_val_expr<_Expr>::value,
1192 void
1193 >::type
1194 operator-=(const _Expr& __v) const;
1195
1196 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001197 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198 typename enable_if
1199 <
1200 __is_val_expr<_Expr>::value,
1201 void
1202 >::type
1203 operator^=(const _Expr& __v) const;
1204
1205 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001206 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001207 typename enable_if
1208 <
1209 __is_val_expr<_Expr>::value,
1210 void
1211 >::type
1212 operator&=(const _Expr& __v) const;
1213
1214 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001215 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001216 typename enable_if
1217 <
1218 __is_val_expr<_Expr>::value,
1219 void
1220 >::type
1221 operator|=(const _Expr& __v) const;
1222
1223 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001224 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001225 typename enable_if
1226 <
1227 __is_val_expr<_Expr>::value,
1228 void
1229 >::type
1230 operator<<=(const _Expr& __v) const;
1231
1232 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001233 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001234 typename enable_if
1235 <
1236 __is_val_expr<_Expr>::value,
1237 void
1238 >::type
1239 operator>>=(const _Expr& __v) const;
1240
Douglas Gregore9e4b852012-05-19 04:41:25 +00001241 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001242 const slice_array& operator=(const slice_array& __sa) const;
1243
Douglas Gregore9e4b852012-05-19 04:41:25 +00001244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001245 void operator=(const value_type& __x) const;
1246
1247private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001248 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001249 slice_array(const slice& __sl, const valarray<value_type>& __v)
1250 : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())),
1251 __size_(__sl.size()),
1252 __stride_(__sl.stride())
1253 {}
1254
1255 template <class> friend class valarray;
1256 template <class> friend class sliceExpr;
1257};
1258
1259template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001260inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001261const slice_array<_Tp>&
1262slice_array<_Tp>::operator=(const slice_array& __sa) const
1263{
1264 value_type* __t = __vp_;
1265 const value_type* __s = __sa.__vp_;
1266 for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
1267 *__t = *__s;
1268}
1269
1270template <class _Tp>
1271template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001272inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001273typename enable_if
1274<
1275 __is_val_expr<_Expr>::value,
1276 void
1277>::type
1278slice_array<_Tp>::operator=(const _Expr& __v) const
1279{
1280 value_type* __t = __vp_;
1281 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1282 *__t = __v[__i];
1283}
1284
1285template <class _Tp>
1286template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001287inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001288typename enable_if
1289<
1290 __is_val_expr<_Expr>::value,
1291 void
1292>::type
1293slice_array<_Tp>::operator*=(const _Expr& __v) const
1294{
1295 value_type* __t = __vp_;
1296 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1297 *__t *= __v[__i];
1298}
1299
1300template <class _Tp>
1301template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001302inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001303typename enable_if
1304<
1305 __is_val_expr<_Expr>::value,
1306 void
1307>::type
1308slice_array<_Tp>::operator/=(const _Expr& __v) const
1309{
1310 value_type* __t = __vp_;
1311 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1312 *__t /= __v[__i];
1313}
1314
1315template <class _Tp>
1316template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001317inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001318typename enable_if
1319<
1320 __is_val_expr<_Expr>::value,
1321 void
1322>::type
1323slice_array<_Tp>::operator%=(const _Expr& __v) const
1324{
1325 value_type* __t = __vp_;
1326 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1327 *__t %= __v[__i];
1328}
1329
1330template <class _Tp>
1331template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001332inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001333typename enable_if
1334<
1335 __is_val_expr<_Expr>::value,
1336 void
1337>::type
1338slice_array<_Tp>::operator+=(const _Expr& __v) const
1339{
1340 value_type* __t = __vp_;
1341 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1342 *__t += __v[__i];
1343}
1344
1345template <class _Tp>
1346template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001347inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001348typename enable_if
1349<
1350 __is_val_expr<_Expr>::value,
1351 void
1352>::type
1353slice_array<_Tp>::operator-=(const _Expr& __v) const
1354{
1355 value_type* __t = __vp_;
1356 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1357 *__t -= __v[__i];
1358}
1359
1360template <class _Tp>
1361template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001362inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001363typename enable_if
1364<
1365 __is_val_expr<_Expr>::value,
1366 void
1367>::type
1368slice_array<_Tp>::operator^=(const _Expr& __v) const
1369{
1370 value_type* __t = __vp_;
1371 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1372 *__t ^= __v[__i];
1373}
1374
1375template <class _Tp>
1376template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001377inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001378typename enable_if
1379<
1380 __is_val_expr<_Expr>::value,
1381 void
1382>::type
1383slice_array<_Tp>::operator&=(const _Expr& __v) const
1384{
1385 value_type* __t = __vp_;
1386 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1387 *__t &= __v[__i];
1388}
1389
1390template <class _Tp>
1391template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001392inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001393typename enable_if
1394<
1395 __is_val_expr<_Expr>::value,
1396 void
1397>::type
1398slice_array<_Tp>::operator|=(const _Expr& __v) const
1399{
1400 value_type* __t = __vp_;
1401 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1402 *__t |= __v[__i];
1403}
1404
1405template <class _Tp>
1406template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001407inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001408typename enable_if
1409<
1410 __is_val_expr<_Expr>::value,
1411 void
1412>::type
1413slice_array<_Tp>::operator<<=(const _Expr& __v) const
1414{
1415 value_type* __t = __vp_;
1416 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1417 *__t <<= __v[__i];
1418}
1419
1420template <class _Tp>
1421template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001422inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001423typename enable_if
1424<
1425 __is_val_expr<_Expr>::value,
1426 void
1427>::type
1428slice_array<_Tp>::operator>>=(const _Expr& __v) const
1429{
1430 value_type* __t = __vp_;
1431 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1432 *__t >>= __v[__i];
1433}
1434
1435template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001436inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001437void
1438slice_array<_Tp>::operator=(const value_type& __x) const
1439{
1440 value_type* __t = __vp_;
1441 for (size_t __n = __size_; __n; --__n, __t += __stride_)
1442 *__t = __x;
1443}
1444
1445// gslice
1446
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001447class _LIBCPP_VISIBLE gslice
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001448{
1449 valarray<size_t> __size_;
1450 valarray<size_t> __stride_;
1451 valarray<size_t> __1d_;
Howard Hinnant324bb032010-08-22 00:02:43 +00001452
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001453public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001454 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001455 gslice() {}
Douglas Gregore9e4b852012-05-19 04:41:25 +00001456
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001457 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001458 gslice(size_t __start, const valarray<size_t>& __size,
1459 const valarray<size_t>& __stride)
1460 : __size_(__size),
1461 __stride_(__stride)
1462 {__init(__start);}
1463
Howard Hinnant73d21a42010-09-04 23:28:19 +00001464#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001465
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001467 gslice(size_t __start, const valarray<size_t>& __size,
1468 valarray<size_t>&& __stride)
1469 : __size_(__size),
1470 __stride_(move(__stride))
1471 {__init(__start);}
1472
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001474 gslice(size_t __start, valarray<size_t>&& __size,
1475 const valarray<size_t>& __stride)
1476 : __size_(move(__size)),
1477 __stride_(__stride)
1478 {__init(__start);}
1479
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001481 gslice(size_t __start, valarray<size_t>&& __size,
1482 valarray<size_t>&& __stride)
1483 : __size_(move(__size)),
1484 __stride_(move(__stride))
1485 {__init(__start);}
1486
Howard Hinnant73d21a42010-09-04 23:28:19 +00001487#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001488
1489// gslice(const gslice&) = default;
1490// gslice(gslice&&) = default;
1491// gslice& operator=(const gslice&) = default;
1492// gslice& operator=(gslice&&) = default;
1493
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001495 size_t start() const {return __1d_.size() ? __1d_[0] : 0;}
1496
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001498 valarray<size_t> size() const {return __size_;}
1499
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001501 valarray<size_t> stride() const {return __stride_;}
1502
1503private:
1504 void __init(size_t __start);
1505
1506 template <class> friend class gslice_array;
1507 template <class> friend class valarray;
1508 template <class> friend class __val_expr;
1509};
1510
1511// gslice_array
1512
1513template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001514class _LIBCPP_VISIBLE gslice_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001515{
1516public:
1517 typedef _Tp value_type;
1518
1519private:
1520 value_type* __vp_;
1521 valarray<size_t> __1d_;
1522
1523public:
1524 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001526 typename enable_if
1527 <
1528 __is_val_expr<_Expr>::value,
1529 void
1530 >::type
1531 operator=(const _Expr& __v) const;
1532
1533 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001534 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001535 typename enable_if
1536 <
1537 __is_val_expr<_Expr>::value,
1538 void
1539 >::type
1540 operator*=(const _Expr& __v) const;
1541
1542 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001544 typename enable_if
1545 <
1546 __is_val_expr<_Expr>::value,
1547 void
1548 >::type
1549 operator/=(const _Expr& __v) const;
1550
1551 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001553 typename enable_if
1554 <
1555 __is_val_expr<_Expr>::value,
1556 void
1557 >::type
1558 operator%=(const _Expr& __v) const;
1559
1560 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001562 typename enable_if
1563 <
1564 __is_val_expr<_Expr>::value,
1565 void
1566 >::type
1567 operator+=(const _Expr& __v) const;
1568
1569 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001571 typename enable_if
1572 <
1573 __is_val_expr<_Expr>::value,
1574 void
1575 >::type
1576 operator-=(const _Expr& __v) const;
1577
1578 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001579 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001580 typename enable_if
1581 <
1582 __is_val_expr<_Expr>::value,
1583 void
1584 >::type
1585 operator^=(const _Expr& __v) const;
1586
1587 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001588 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001589 typename enable_if
1590 <
1591 __is_val_expr<_Expr>::value,
1592 void
1593 >::type
1594 operator&=(const _Expr& __v) const;
1595
1596 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001597 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001598 typename enable_if
1599 <
1600 __is_val_expr<_Expr>::value,
1601 void
1602 >::type
1603 operator|=(const _Expr& __v) const;
1604
1605 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001606 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001607 typename enable_if
1608 <
1609 __is_val_expr<_Expr>::value,
1610 void
1611 >::type
1612 operator<<=(const _Expr& __v) const;
1613
1614 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001615 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001616 typename enable_if
1617 <
1618 __is_val_expr<_Expr>::value,
1619 void
1620 >::type
1621 operator>>=(const _Expr& __v) const;
1622
Douglas Gregore9e4b852012-05-19 04:41:25 +00001623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001624 const gslice_array& operator=(const gslice_array& __ga) const;
1625
Douglas Gregore9e4b852012-05-19 04:41:25 +00001626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001627 void operator=(const value_type& __x) const;
1628
1629// gslice_array(const gslice_array&) = default;
1630// gslice_array(gslice_array&&) = default;
1631// gslice_array& operator=(const gslice_array&) = default;
1632// gslice_array& operator=(gslice_array&&) = default;
1633
1634private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001636 gslice_array(const gslice& __gs, const valarray<value_type>& __v)
1637 : __vp_(const_cast<value_type*>(__v.__begin_)),
1638 __1d_(__gs.__1d_)
1639 {}
1640
Howard Hinnant73d21a42010-09-04 23:28:19 +00001641#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001642
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001644 gslice_array(gslice&& __gs, const valarray<value_type>& __v)
1645 : __vp_(const_cast<value_type*>(__v.__begin_)),
1646 __1d_(move(__gs.__1d_))
1647 {}
1648
Howard Hinnant73d21a42010-09-04 23:28:19 +00001649#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001650
1651 template <class> friend class valarray;
1652};
1653
1654template <class _Tp>
1655template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001656inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001657typename enable_if
1658<
1659 __is_val_expr<_Expr>::value,
1660 void
1661>::type
1662gslice_array<_Tp>::operator=(const _Expr& __v) const
1663{
1664 typedef const size_t* _Ip;
1665 size_t __j = 0;
1666 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1667 __vp_[*__i] = __v[__j];
1668}
1669
1670template <class _Tp>
1671template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001672inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001673typename enable_if
1674<
1675 __is_val_expr<_Expr>::value,
1676 void
1677>::type
1678gslice_array<_Tp>::operator*=(const _Expr& __v) const
1679{
1680 typedef const size_t* _Ip;
1681 size_t __j = 0;
1682 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1683 __vp_[*__i] *= __v[__j];
1684}
1685
1686template <class _Tp>
1687template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001688inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001689typename enable_if
1690<
1691 __is_val_expr<_Expr>::value,
1692 void
1693>::type
1694gslice_array<_Tp>::operator/=(const _Expr& __v) const
1695{
1696 typedef const size_t* _Ip;
1697 size_t __j = 0;
1698 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1699 __vp_[*__i] /= __v[__j];
1700}
1701
1702template <class _Tp>
1703template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001704inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001705typename enable_if
1706<
1707 __is_val_expr<_Expr>::value,
1708 void
1709>::type
1710gslice_array<_Tp>::operator%=(const _Expr& __v) const
1711{
1712 typedef const size_t* _Ip;
1713 size_t __j = 0;
1714 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1715 __vp_[*__i] %= __v[__j];
1716}
1717
1718template <class _Tp>
1719template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001720inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001721typename enable_if
1722<
1723 __is_val_expr<_Expr>::value,
1724 void
1725>::type
1726gslice_array<_Tp>::operator+=(const _Expr& __v) const
1727{
1728 typedef const size_t* _Ip;
1729 size_t __j = 0;
1730 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1731 __vp_[*__i] += __v[__j];
1732}
1733
1734template <class _Tp>
1735template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001736inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001737typename enable_if
1738<
1739 __is_val_expr<_Expr>::value,
1740 void
1741>::type
1742gslice_array<_Tp>::operator-=(const _Expr& __v) const
1743{
1744 typedef const size_t* _Ip;
1745 size_t __j = 0;
1746 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1747 __vp_[*__i] -= __v[__j];
1748}
1749
1750template <class _Tp>
1751template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001752inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001753typename enable_if
1754<
1755 __is_val_expr<_Expr>::value,
1756 void
1757>::type
1758gslice_array<_Tp>::operator^=(const _Expr& __v) const
1759{
1760 typedef const size_t* _Ip;
1761 size_t __j = 0;
1762 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1763 __vp_[*__i] ^= __v[__j];
1764}
1765
1766template <class _Tp>
1767template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001768inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001769typename enable_if
1770<
1771 __is_val_expr<_Expr>::value,
1772 void
1773>::type
1774gslice_array<_Tp>::operator&=(const _Expr& __v) const
1775{
1776 typedef const size_t* _Ip;
1777 size_t __j = 0;
1778 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1779 __vp_[*__i] &= __v[__j];
1780}
1781
1782template <class _Tp>
1783template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001784inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001785typename enable_if
1786<
1787 __is_val_expr<_Expr>::value,
1788 void
1789>::type
1790gslice_array<_Tp>::operator|=(const _Expr& __v) const
1791{
1792 typedef const size_t* _Ip;
1793 size_t __j = 0;
1794 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1795 __vp_[*__i] |= __v[__j];
1796}
1797
1798template <class _Tp>
1799template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001800inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001801typename enable_if
1802<
1803 __is_val_expr<_Expr>::value,
1804 void
1805>::type
1806gslice_array<_Tp>::operator<<=(const _Expr& __v) const
1807{
1808 typedef const size_t* _Ip;
1809 size_t __j = 0;
1810 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1811 __vp_[*__i] <<= __v[__j];
1812}
1813
1814template <class _Tp>
1815template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001816inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001817typename enable_if
1818<
1819 __is_val_expr<_Expr>::value,
1820 void
1821>::type
1822gslice_array<_Tp>::operator>>=(const _Expr& __v) const
1823{
1824 typedef const size_t* _Ip;
1825 size_t __j = 0;
1826 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1827 __vp_[*__i] >>= __v[__j];
1828}
1829
1830template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001831inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001832const gslice_array<_Tp>&
1833gslice_array<_Tp>::operator=(const gslice_array& __ga) const
1834{
1835 typedef const size_t* _Ip;
1836 const value_type* __s = __ga.__vp_;
1837 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_;
1838 __i != __e; ++__i, ++__j)
1839 __vp_[*__i] = __s[*__j];
1840 return *this;
1841}
1842
1843template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001844inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001845void
1846gslice_array<_Tp>::operator=(const value_type& __x) const
1847{
1848 typedef const size_t* _Ip;
1849 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1850 __vp_[*__i] = __x;
1851}
1852
1853// mask_array
1854
1855template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001856class _LIBCPP_VISIBLE mask_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001857{
1858public:
1859 typedef _Tp value_type;
1860
1861private:
1862 value_type* __vp_;
1863 valarray<size_t> __1d_;
1864
1865public:
1866 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001868 typename enable_if
1869 <
1870 __is_val_expr<_Expr>::value,
1871 void
1872 >::type
1873 operator=(const _Expr& __v) const;
1874
1875 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001877 typename enable_if
1878 <
1879 __is_val_expr<_Expr>::value,
1880 void
1881 >::type
1882 operator*=(const _Expr& __v) const;
1883
1884 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001886 typename enable_if
1887 <
1888 __is_val_expr<_Expr>::value,
1889 void
1890 >::type
1891 operator/=(const _Expr& __v) const;
1892
1893 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001895 typename enable_if
1896 <
1897 __is_val_expr<_Expr>::value,
1898 void
1899 >::type
1900 operator%=(const _Expr& __v) const;
1901
1902 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001904 typename enable_if
1905 <
1906 __is_val_expr<_Expr>::value,
1907 void
1908 >::type
1909 operator+=(const _Expr& __v) const;
1910
1911 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001912 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001913 typename enable_if
1914 <
1915 __is_val_expr<_Expr>::value,
1916 void
1917 >::type
1918 operator-=(const _Expr& __v) const;
1919
1920 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001922 typename enable_if
1923 <
1924 __is_val_expr<_Expr>::value,
1925 void
1926 >::type
1927 operator^=(const _Expr& __v) const;
1928
1929 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001930 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001931 typename enable_if
1932 <
1933 __is_val_expr<_Expr>::value,
1934 void
1935 >::type
1936 operator&=(const _Expr& __v) const;
1937
1938 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001940 typename enable_if
1941 <
1942 __is_val_expr<_Expr>::value,
1943 void
1944 >::type
1945 operator|=(const _Expr& __v) const;
1946
1947 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001948 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001949 typename enable_if
1950 <
1951 __is_val_expr<_Expr>::value,
1952 void
1953 >::type
1954 operator<<=(const _Expr& __v) const;
1955
1956 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001957 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001958 typename enable_if
1959 <
1960 __is_val_expr<_Expr>::value,
1961 void
1962 >::type
1963 operator>>=(const _Expr& __v) const;
1964
Douglas Gregore9e4b852012-05-19 04:41:25 +00001965 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001966 const mask_array& operator=(const mask_array& __ma) const;
1967
Douglas Gregore9e4b852012-05-19 04:41:25 +00001968 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001969 void operator=(const value_type& __x) const;
1970
1971// mask_array(const mask_array&) = default;
1972// mask_array(mask_array&&) = default;
1973// mask_array& operator=(const mask_array&) = default;
1974// mask_array& operator=(mask_array&&) = default;
1975
1976private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001977 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001978 mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
1979 : __vp_(const_cast<value_type*>(__v.__begin_)),
Howard Hinnantec3773c2011-12-01 20:21:04 +00001980 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001981 {
1982 size_t __j = 0;
1983 for (size_t __i = 0; __i < __vb.size(); ++__i)
1984 if (__vb[__i])
1985 __1d_[__j++] = __i;
1986 }
1987
1988 template <class> friend class valarray;
1989};
1990
1991template <class _Tp>
1992template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00001993inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001994typename enable_if
1995<
1996 __is_val_expr<_Expr>::value,
1997 void
1998>::type
1999mask_array<_Tp>::operator=(const _Expr& __v) const
2000{
2001 size_t __n = __1d_.size();
2002 for (size_t __i = 0; __i < __n; ++__i)
2003 __vp_[__1d_[__i]] = __v[__i];
2004}
2005
2006template <class _Tp>
2007template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002008inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002009typename enable_if
2010<
2011 __is_val_expr<_Expr>::value,
2012 void
2013>::type
2014mask_array<_Tp>::operator*=(const _Expr& __v) const
2015{
2016 size_t __n = __1d_.size();
2017 for (size_t __i = 0; __i < __n; ++__i)
2018 __vp_[__1d_[__i]] *= __v[__i];
2019}
2020
2021template <class _Tp>
2022template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002023inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002024typename enable_if
2025<
2026 __is_val_expr<_Expr>::value,
2027 void
2028>::type
2029mask_array<_Tp>::operator/=(const _Expr& __v) const
2030{
2031 size_t __n = __1d_.size();
2032 for (size_t __i = 0; __i < __n; ++__i)
2033 __vp_[__1d_[__i]] /= __v[__i];
2034}
2035
2036template <class _Tp>
2037template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002038inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002039typename enable_if
2040<
2041 __is_val_expr<_Expr>::value,
2042 void
2043>::type
2044mask_array<_Tp>::operator%=(const _Expr& __v) const
2045{
2046 size_t __n = __1d_.size();
2047 for (size_t __i = 0; __i < __n; ++__i)
2048 __vp_[__1d_[__i]] %= __v[__i];
2049}
2050
2051template <class _Tp>
2052template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002053inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002054typename enable_if
2055<
2056 __is_val_expr<_Expr>::value,
2057 void
2058>::type
2059mask_array<_Tp>::operator+=(const _Expr& __v) const
2060{
2061 size_t __n = __1d_.size();
2062 for (size_t __i = 0; __i < __n; ++__i)
2063 __vp_[__1d_[__i]] += __v[__i];
2064}
2065
2066template <class _Tp>
2067template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002068inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002069typename enable_if
2070<
2071 __is_val_expr<_Expr>::value,
2072 void
2073>::type
2074mask_array<_Tp>::operator-=(const _Expr& __v) const
2075{
2076 size_t __n = __1d_.size();
2077 for (size_t __i = 0; __i < __n; ++__i)
2078 __vp_[__1d_[__i]] -= __v[__i];
2079}
2080
2081template <class _Tp>
2082template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002083inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002084typename enable_if
2085<
2086 __is_val_expr<_Expr>::value,
2087 void
2088>::type
2089mask_array<_Tp>::operator^=(const _Expr& __v) const
2090{
2091 size_t __n = __1d_.size();
2092 for (size_t __i = 0; __i < __n; ++__i)
2093 __vp_[__1d_[__i]] ^= __v[__i];
2094}
2095
2096template <class _Tp>
2097template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002098inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002099typename enable_if
2100<
2101 __is_val_expr<_Expr>::value,
2102 void
2103>::type
2104mask_array<_Tp>::operator&=(const _Expr& __v) const
2105{
2106 size_t __n = __1d_.size();
2107 for (size_t __i = 0; __i < __n; ++__i)
2108 __vp_[__1d_[__i]] &= __v[__i];
2109}
2110
2111template <class _Tp>
2112template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002113inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002114typename enable_if
2115<
2116 __is_val_expr<_Expr>::value,
2117 void
2118>::type
2119mask_array<_Tp>::operator|=(const _Expr& __v) const
2120{
2121 size_t __n = __1d_.size();
2122 for (size_t __i = 0; __i < __n; ++__i)
2123 __vp_[__1d_[__i]] |= __v[__i];
2124}
2125
2126template <class _Tp>
2127template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002128inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002129typename enable_if
2130<
2131 __is_val_expr<_Expr>::value,
2132 void
2133>::type
2134mask_array<_Tp>::operator<<=(const _Expr& __v) const
2135{
2136 size_t __n = __1d_.size();
2137 for (size_t __i = 0; __i < __n; ++__i)
2138 __vp_[__1d_[__i]] <<= __v[__i];
2139}
2140
2141template <class _Tp>
2142template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002143inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002144typename enable_if
2145<
2146 __is_val_expr<_Expr>::value,
2147 void
2148>::type
2149mask_array<_Tp>::operator>>=(const _Expr& __v) const
2150{
2151 size_t __n = __1d_.size();
2152 for (size_t __i = 0; __i < __n; ++__i)
2153 __vp_[__1d_[__i]] >>= __v[__i];
2154}
2155
2156template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002157inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002158const mask_array<_Tp>&
2159mask_array<_Tp>::operator=(const mask_array& __ma) const
2160{
2161 size_t __n = __1d_.size();
2162 for (size_t __i = 0; __i < __n; ++__i)
2163 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
2164}
2165
2166template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002167inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002168void
2169mask_array<_Tp>::operator=(const value_type& __x) const
2170{
2171 size_t __n = __1d_.size();
2172 for (size_t __i = 0; __i < __n; ++__i)
2173 __vp_[__1d_[__i]] = __x;
2174}
2175
2176template <class _ValExpr>
2177class __mask_expr
2178{
2179 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2180public:
2181 typedef typename _RmExpr::value_type value_type;
2182 typedef value_type result_type;
2183
2184private:
2185 _ValExpr __expr_;
2186 valarray<size_t> __1d_;
2187
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002188 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002189 __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
2190 : __expr_(__e),
Howard Hinnantec3773c2011-12-01 20:21:04 +00002191 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002192 {
2193 size_t __j = 0;
2194 for (size_t __i = 0; __i < __vb.size(); ++__i)
2195 if (__vb[__i])
2196 __1d_[__j++] = __i;
2197 }
2198
2199public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002200 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002201 result_type operator[](size_t __i) const
2202 {return __expr_[__1d_[__i]];}
2203
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002204 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002205 size_t size() const {return __1d_.size();}
2206
2207 template <class> friend class valarray;
2208};
2209
2210// indirect_array
2211
2212template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002213class _LIBCPP_VISIBLE indirect_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002214{
2215public:
2216 typedef _Tp value_type;
2217
2218private:
2219 value_type* __vp_;
2220 valarray<size_t> __1d_;
2221
2222public:
2223 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002224 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002225 typename enable_if
2226 <
2227 __is_val_expr<_Expr>::value,
2228 void
2229 >::type
2230 operator=(const _Expr& __v) const;
2231
2232 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002233 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002234 typename enable_if
2235 <
2236 __is_val_expr<_Expr>::value,
2237 void
2238 >::type
2239 operator*=(const _Expr& __v) const;
2240
2241 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002242 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002243 typename enable_if
2244 <
2245 __is_val_expr<_Expr>::value,
2246 void
2247 >::type
2248 operator/=(const _Expr& __v) const;
2249
2250 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002251 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002252 typename enable_if
2253 <
2254 __is_val_expr<_Expr>::value,
2255 void
2256 >::type
2257 operator%=(const _Expr& __v) const;
2258
2259 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002260 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002261 typename enable_if
2262 <
2263 __is_val_expr<_Expr>::value,
2264 void
2265 >::type
2266 operator+=(const _Expr& __v) const;
2267
2268 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002270 typename enable_if
2271 <
2272 __is_val_expr<_Expr>::value,
2273 void
2274 >::type
2275 operator-=(const _Expr& __v) const;
2276
2277 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002278 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002279 typename enable_if
2280 <
2281 __is_val_expr<_Expr>::value,
2282 void
2283 >::type
2284 operator^=(const _Expr& __v) const;
2285
2286 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002287 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002288 typename enable_if
2289 <
2290 __is_val_expr<_Expr>::value,
2291 void
2292 >::type
2293 operator&=(const _Expr& __v) const;
2294
2295 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002296 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002297 typename enable_if
2298 <
2299 __is_val_expr<_Expr>::value,
2300 void
2301 >::type
2302 operator|=(const _Expr& __v) const;
2303
2304 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002305 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002306 typename enable_if
2307 <
2308 __is_val_expr<_Expr>::value,
2309 void
2310 >::type
2311 operator<<=(const _Expr& __v) const;
2312
2313 template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002314 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002315 typename enable_if
2316 <
2317 __is_val_expr<_Expr>::value,
2318 void
2319 >::type
2320 operator>>=(const _Expr& __v) const;
2321
Douglas Gregore9e4b852012-05-19 04:41:25 +00002322 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002323 const indirect_array& operator=(const indirect_array& __ia) const;
2324
Douglas Gregore9e4b852012-05-19 04:41:25 +00002325 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002326 void operator=(const value_type& __x) const;
2327
2328// indirect_array(const indirect_array&) = default;
2329// indirect_array(indirect_array&&) = default;
2330// indirect_array& operator=(const indirect_array&) = default;
2331// indirect_array& operator=(indirect_array&&) = default;
2332
2333private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002334 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002335 indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
2336 : __vp_(const_cast<value_type*>(__v.__begin_)),
2337 __1d_(__ia)
2338 {}
2339
Howard Hinnant73d21a42010-09-04 23:28:19 +00002340#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002341
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002342 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002343 indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
2344 : __vp_(const_cast<value_type*>(__v.__begin_)),
2345 __1d_(move(__ia))
2346 {}
2347
Howard Hinnant73d21a42010-09-04 23:28:19 +00002348#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002349
2350 template <class> friend class valarray;
2351};
2352
2353template <class _Tp>
2354template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002355inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002356typename enable_if
2357<
2358 __is_val_expr<_Expr>::value,
2359 void
2360>::type
2361indirect_array<_Tp>::operator=(const _Expr& __v) const
2362{
2363 size_t __n = __1d_.size();
2364 for (size_t __i = 0; __i < __n; ++__i)
2365 __vp_[__1d_[__i]] = __v[__i];
2366}
2367
2368template <class _Tp>
2369template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002370inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002371typename enable_if
2372<
2373 __is_val_expr<_Expr>::value,
2374 void
2375>::type
2376indirect_array<_Tp>::operator*=(const _Expr& __v) const
2377{
2378 size_t __n = __1d_.size();
2379 for (size_t __i = 0; __i < __n; ++__i)
2380 __vp_[__1d_[__i]] *= __v[__i];
2381}
2382
2383template <class _Tp>
2384template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002385inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002386typename enable_if
2387<
2388 __is_val_expr<_Expr>::value,
2389 void
2390>::type
2391indirect_array<_Tp>::operator/=(const _Expr& __v) const
2392{
2393 size_t __n = __1d_.size();
2394 for (size_t __i = 0; __i < __n; ++__i)
2395 __vp_[__1d_[__i]] /= __v[__i];
2396}
2397
2398template <class _Tp>
2399template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002400inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002401typename enable_if
2402<
2403 __is_val_expr<_Expr>::value,
2404 void
2405>::type
2406indirect_array<_Tp>::operator%=(const _Expr& __v) const
2407{
2408 size_t __n = __1d_.size();
2409 for (size_t __i = 0; __i < __n; ++__i)
2410 __vp_[__1d_[__i]] %= __v[__i];
2411}
2412
2413template <class _Tp>
2414template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002415inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002416typename enable_if
2417<
2418 __is_val_expr<_Expr>::value,
2419 void
2420>::type
2421indirect_array<_Tp>::operator+=(const _Expr& __v) const
2422{
2423 size_t __n = __1d_.size();
2424 for (size_t __i = 0; __i < __n; ++__i)
2425 __vp_[__1d_[__i]] += __v[__i];
2426}
2427
2428template <class _Tp>
2429template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002430inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002431typename enable_if
2432<
2433 __is_val_expr<_Expr>::value,
2434 void
2435>::type
2436indirect_array<_Tp>::operator-=(const _Expr& __v) const
2437{
2438 size_t __n = __1d_.size();
2439 for (size_t __i = 0; __i < __n; ++__i)
2440 __vp_[__1d_[__i]] -= __v[__i];
2441}
2442
2443template <class _Tp>
2444template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002445inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002446typename enable_if
2447<
2448 __is_val_expr<_Expr>::value,
2449 void
2450>::type
2451indirect_array<_Tp>::operator^=(const _Expr& __v) const
2452{
2453 size_t __n = __1d_.size();
2454 for (size_t __i = 0; __i < __n; ++__i)
2455 __vp_[__1d_[__i]] ^= __v[__i];
2456}
2457
2458template <class _Tp>
2459template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002460inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002461typename enable_if
2462<
2463 __is_val_expr<_Expr>::value,
2464 void
2465>::type
2466indirect_array<_Tp>::operator&=(const _Expr& __v) const
2467{
2468 size_t __n = __1d_.size();
2469 for (size_t __i = 0; __i < __n; ++__i)
2470 __vp_[__1d_[__i]] &= __v[__i];
2471}
2472
2473template <class _Tp>
2474template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002475inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002476typename enable_if
2477<
2478 __is_val_expr<_Expr>::value,
2479 void
2480>::type
2481indirect_array<_Tp>::operator|=(const _Expr& __v) const
2482{
2483 size_t __n = __1d_.size();
2484 for (size_t __i = 0; __i < __n; ++__i)
2485 __vp_[__1d_[__i]] |= __v[__i];
2486}
2487
2488template <class _Tp>
2489template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002490inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002491typename enable_if
2492<
2493 __is_val_expr<_Expr>::value,
2494 void
2495>::type
2496indirect_array<_Tp>::operator<<=(const _Expr& __v) const
2497{
2498 size_t __n = __1d_.size();
2499 for (size_t __i = 0; __i < __n; ++__i)
2500 __vp_[__1d_[__i]] <<= __v[__i];
2501}
2502
2503template <class _Tp>
2504template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002505inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002506typename enable_if
2507<
2508 __is_val_expr<_Expr>::value,
2509 void
2510>::type
2511indirect_array<_Tp>::operator>>=(const _Expr& __v) const
2512{
2513 size_t __n = __1d_.size();
2514 for (size_t __i = 0; __i < __n; ++__i)
2515 __vp_[__1d_[__i]] >>= __v[__i];
2516}
2517
2518template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002519inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002520const indirect_array<_Tp>&
2521indirect_array<_Tp>::operator=(const indirect_array& __ia) const
2522{
2523 typedef const size_t* _Ip;
2524 const value_type* __s = __ia.__vp_;
2525 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_;
2526 __i != __e; ++__i, ++__j)
2527 __vp_[*__i] = __s[*__j];
2528 return *this;
2529}
2530
2531template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002532inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002533void
2534indirect_array<_Tp>::operator=(const value_type& __x) const
2535{
2536 typedef const size_t* _Ip;
2537 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
2538 __vp_[*__i] = __x;
2539}
2540
2541template <class _ValExpr>
2542class __indirect_expr
2543{
2544 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2545public:
2546 typedef typename _RmExpr::value_type value_type;
2547 typedef value_type result_type;
2548
2549private:
2550 _ValExpr __expr_;
2551 valarray<size_t> __1d_;
2552
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002554 __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e)
2555 : __expr_(__e),
2556 __1d_(__ia)
2557 {}
2558
Howard Hinnant73d21a42010-09-04 23:28:19 +00002559#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002560
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002562 __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
2563 : __expr_(__e),
2564 __1d_(move(__ia))
2565 {}
2566
Howard Hinnant73d21a42010-09-04 23:28:19 +00002567#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002568
2569public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002571 result_type operator[](size_t __i) const
2572 {return __expr_[__1d_[__i]];}
2573
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002574 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002575 size_t size() const {return __1d_.size();}
2576
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002577 template <class> friend class _LIBCPP_VISIBLE valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002578};
2579
2580template<class _ValExpr>
2581class __val_expr
2582{
2583 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2584
2585 _ValExpr __expr_;
2586public:
2587 typedef typename _RmExpr::value_type value_type;
2588 typedef typename _RmExpr::result_type result_type;
2589
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002590 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002591 explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
2592
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002594 result_type operator[](size_t __i) const
2595 {return __expr_[__i];}
2596
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002597 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002598 __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
2599 {return __val_expr<__slice_expr<_ValExpr> >(__expr_, __s);}
2600
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002601 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002602 __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const
2603 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __gs.__1d_);}
2604
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002605 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002606 __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
2607 {return __val_expr<__mask_expr<_ValExpr> >(__expr_, __vb);}
2608
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002610 __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
2611 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __vs);}
2612
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002613 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002614 __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
2615 operator+() const
2616 {
2617 typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
2618 return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
2619 }
2620
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002622 __val_expr<_UnaryOp<negate<value_type>, _ValExpr> >
2623 operator-() const
2624 {
2625 typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
2626 return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
2627 }
2628
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002629 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002630 __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> >
2631 operator~() const
2632 {
2633 typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
2634 return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
2635 }
2636
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002637 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002638 __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> >
2639 operator!() const
2640 {
2641 typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
2642 return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
2643 }
2644
2645 operator valarray<result_type>() const;
2646
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002647 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002648 size_t size() const {return __expr_.size();}
2649
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002651 result_type sum() const
2652 {
2653 size_t __n = __expr_.size();
2654 result_type __r = __n ? __expr_[0] : result_type();
2655 for (size_t __i = 1; __i < __n; ++__i)
2656 __r += __expr_[__i];
2657 return __r;
2658 }
2659
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002661 result_type min() const
2662 {
2663 size_t __n = size();
2664 result_type __r = __n ? (*this)[0] : result_type();
2665 for (size_t __i = 1; __i < __n; ++__i)
2666 {
2667 result_type __x = __expr_[__i];
2668 if (__x < __r)
2669 __r = __x;
2670 }
2671 return __r;
2672 }
2673
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002675 result_type max() const
2676 {
2677 size_t __n = size();
2678 result_type __r = __n ? (*this)[0] : result_type();
2679 for (size_t __i = 1; __i < __n; ++__i)
2680 {
2681 result_type __x = __expr_[__i];
2682 if (__r < __x)
2683 __r = __x;
2684 }
2685 return __r;
2686 }
2687
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002688 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002689 __val_expr<__shift_expr<_ValExpr> > shift (int __i) const
2690 {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));}
2691
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002693 __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const
2694 {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));}
2695
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002697 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> >
2698 apply(value_type __f(value_type)) const
2699 {
2700 typedef __apply_expr<value_type, value_type(*)(value_type)> _Op;
2701 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2702 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2703 }
2704
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002706 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> >
2707 apply(value_type __f(const value_type&)) const
2708 {
2709 typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op;
2710 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2711 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2712 }
2713};
2714
2715template<class _ValExpr>
2716__val_expr<_ValExpr>::operator valarray<result_type>() const
2717{
2718 valarray<result_type> __r;
2719 size_t __n = __expr_.size();
2720 if (__n)
2721 {
2722 __r.__begin_ =
2723 __r.__end_ =
2724 static_cast<result_type*>(::operator new(__n * sizeof(result_type)));
2725 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
2726 ::new (__r.__end_) result_type(__expr_[__i]);
2727 }
2728 return __r;
2729}
2730
2731// valarray
2732
2733template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002734inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002735valarray<_Tp>::valarray(size_t __n)
2736 : __begin_(0),
2737 __end_(0)
2738{
2739 resize(__n);
2740}
2741
2742template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002743inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002744valarray<_Tp>::valarray(const value_type& __x, size_t __n)
2745 : __begin_(0),
2746 __end_(0)
2747{
2748 resize(__n, __x);
2749}
2750
2751template <class _Tp>
2752valarray<_Tp>::valarray(const value_type* __p, size_t __n)
2753 : __begin_(0),
2754 __end_(0)
2755{
2756 if (__n)
2757 {
2758 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2759#ifndef _LIBCPP_NO_EXCEPTIONS
2760 try
2761 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002762#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002763 for (; __n; ++__end_, ++__p, --__n)
2764 ::new (__end_) value_type(*__p);
2765#ifndef _LIBCPP_NO_EXCEPTIONS
2766 }
2767 catch (...)
2768 {
2769 resize(0);
2770 throw;
2771 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002772#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002773 }
2774}
2775
2776template <class _Tp>
2777valarray<_Tp>::valarray(const valarray& __v)
2778 : __begin_(0),
2779 __end_(0)
2780{
2781 if (__v.size())
2782 {
2783 __begin_ = __end_ = static_cast<value_type*>(::operator new(__v.size() * sizeof(value_type)));
2784#ifndef _LIBCPP_NO_EXCEPTIONS
2785 try
2786 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002787#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002788 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
2789 ::new (__end_) value_type(*__p);
2790#ifndef _LIBCPP_NO_EXCEPTIONS
2791 }
2792 catch (...)
2793 {
2794 resize(0);
2795 throw;
2796 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002797#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002798 }
2799}
2800
Howard Hinnant73d21a42010-09-04 23:28:19 +00002801#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002802
2803template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002804inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002805valarray<_Tp>::valarray(valarray&& __v)
2806 : __begin_(__v.__begin_),
2807 __end_(__v.__end_)
2808{
2809 __v.__begin_ = __v.__end_ = nullptr;
2810}
2811
Howard Hinnante3e32912011-08-12 21:56:02 +00002812#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2813
2814#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2815
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002816template <class _Tp>
2817valarray<_Tp>::valarray(initializer_list<value_type> __il)
2818 : __begin_(0),
2819 __end_(0)
2820{
2821 size_t __n = __il.size();
2822 if (__n)
2823 {
2824 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2825#ifndef _LIBCPP_NO_EXCEPTIONS
2826 try
2827 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002828#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002829 for (const value_type* __p = __il.begin(); __n; ++__end_, ++__p, --__n)
2830 ::new (__end_) value_type(*__p);
2831#ifndef _LIBCPP_NO_EXCEPTIONS
2832 }
2833 catch (...)
2834 {
2835 resize(0);
2836 throw;
2837 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002838#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002839 }
2840}
2841
Howard Hinnante3e32912011-08-12 21:56:02 +00002842#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002843
2844template <class _Tp>
2845valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
2846 : __begin_(0),
2847 __end_(0)
2848{
2849 size_t __n = __sa.__size_;
2850 if (__n)
2851 {
2852 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2853#ifndef _LIBCPP_NO_EXCEPTIONS
2854 try
2855 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002856#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002857 for (const value_type* __p = __sa.__vp_; __n; ++__end_, __p += __sa.__stride_, --__n)
2858 ::new (__end_) value_type(*__p);
2859#ifndef _LIBCPP_NO_EXCEPTIONS
2860 }
2861 catch (...)
2862 {
2863 resize(0);
2864 throw;
2865 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002866#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002867 }
2868}
2869
2870template <class _Tp>
2871valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
2872 : __begin_(0),
2873 __end_(0)
2874{
2875 size_t __n = __ga.__1d_.size();
2876 if (__n)
2877 {
2878 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2879#ifndef _LIBCPP_NO_EXCEPTIONS
2880 try
2881 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002882#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002883 typedef const size_t* _Ip;
2884 const value_type* __s = __ga.__vp_;
2885 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2886 __i != __e; ++__i, ++__end_)
2887 ::new (__end_) value_type(__s[*__i]);
2888#ifndef _LIBCPP_NO_EXCEPTIONS
2889 }
2890 catch (...)
2891 {
2892 resize(0);
2893 throw;
2894 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002895#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002896 }
2897}
2898
2899template <class _Tp>
2900valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
2901 : __begin_(0),
2902 __end_(0)
2903{
2904 size_t __n = __ma.__1d_.size();
2905 if (__n)
2906 {
2907 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2908#ifndef _LIBCPP_NO_EXCEPTIONS
2909 try
2910 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002911#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002912 typedef const size_t* _Ip;
2913 const value_type* __s = __ma.__vp_;
2914 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2915 __i != __e; ++__i, ++__end_)
2916 ::new (__end_) value_type(__s[*__i]);
2917#ifndef _LIBCPP_NO_EXCEPTIONS
2918 }
2919 catch (...)
2920 {
2921 resize(0);
2922 throw;
2923 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002924#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002925 }
2926}
2927
2928template <class _Tp>
2929valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
2930 : __begin_(0),
2931 __end_(0)
2932{
2933 size_t __n = __ia.__1d_.size();
2934 if (__n)
2935 {
2936 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2937#ifndef _LIBCPP_NO_EXCEPTIONS
2938 try
2939 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002940#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002941 typedef const size_t* _Ip;
2942 const value_type* __s = __ia.__vp_;
2943 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2944 __i != __e; ++__i, ++__end_)
2945 ::new (__end_) value_type(__s[*__i]);
2946#ifndef _LIBCPP_NO_EXCEPTIONS
2947 }
2948 catch (...)
2949 {
2950 resize(0);
2951 throw;
2952 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002953#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002954 }
2955}
2956
2957template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002958inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002959valarray<_Tp>::~valarray()
2960{
2961 resize(0);
2962}
2963
2964template <class _Tp>
2965valarray<_Tp>&
2966valarray<_Tp>::operator=(const valarray& __v)
2967{
2968 if (this != &__v)
2969 {
2970 if (size() != __v.size())
2971 resize(__v.size());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002972 _VSTD::copy(__v.__begin_, __v.__end_, __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002973 }
2974 return *this;
2975}
2976
Howard Hinnant73d21a42010-09-04 23:28:19 +00002977#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002978
2979template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002980inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002981valarray<_Tp>&
2982valarray<_Tp>::operator=(valarray&& __v)
2983{
2984 resize(0);
2985 __begin_ = __v.__begin_;
2986 __end_ = __v.__end_;
2987 __v.__begin_ = nullptr;
2988 __v.__end_ = nullptr;
2989 return *this;
2990}
2991
Howard Hinnante3e32912011-08-12 21:56:02 +00002992#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2993
2994#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2995
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002996template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00002997inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002998valarray<_Tp>&
2999valarray<_Tp>::operator=(initializer_list<value_type> __il)
3000{
3001 if (size() != __il.size())
3002 resize(__il.size());
Howard Hinnant0949eed2011-06-30 21:18:19 +00003003 _VSTD::copy(__il.begin(), __il.end(), __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003004 return *this;
3005}
3006
Howard Hinnante3e32912011-08-12 21:56:02 +00003007#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003008
3009template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003010inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003011valarray<_Tp>&
3012valarray<_Tp>::operator=(const value_type& __x)
3013{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003014 _VSTD::fill(__begin_, __end_, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003015 return *this;
3016}
3017
3018template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003019inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003020valarray<_Tp>&
3021valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
3022{
3023 value_type* __t = __begin_;
3024 const value_type* __s = __sa.__vp_;
3025 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
3026 *__t = *__s;
3027 return *this;
3028}
3029
3030template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003031inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003032valarray<_Tp>&
3033valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
3034{
3035 typedef const size_t* _Ip;
3036 value_type* __t = __begin_;
3037 const value_type* __s = __ga.__vp_;
3038 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
3039 __i != __e; ++__i, ++__t)
3040 *__t = __s[*__i];
3041 return *this;
3042}
3043
3044template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003045inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003046valarray<_Tp>&
3047valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
3048{
3049 typedef const size_t* _Ip;
3050 value_type* __t = __begin_;
3051 const value_type* __s = __ma.__vp_;
3052 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
3053 __i != __e; ++__i, ++__t)
3054 *__t = __s[*__i];
3055 return *this;
3056}
3057
3058template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003059inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003060valarray<_Tp>&
3061valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
3062{
3063 typedef const size_t* _Ip;
3064 value_type* __t = __begin_;
3065 const value_type* __s = __ia.__vp_;
3066 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
3067 __i != __e; ++__i, ++__t)
3068 *__t = __s[*__i];
3069 return *this;
3070}
3071
3072template <class _Tp>
Howard Hinnantdb866632011-07-27 23:19:59 +00003073template <class _ValExpr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003074inline
Howard Hinnantdb866632011-07-27 23:19:59 +00003075valarray<_Tp>&
3076valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
3077{
3078 size_t __n = __v.size();
3079 if (size() != __n)
3080 resize(__n);
3081 value_type* __t = __begin_;
3082 for (size_t __i = 0; __i != __n; ++__t, ++__i)
3083 *__t = result_type(__v[__i]);
3084 return *this;
3085}
3086
3087template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003088inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003089__val_expr<__slice_expr<const valarray<_Tp>&> >
3090valarray<_Tp>::operator[](slice __s) const
3091{
3092 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
3093}
3094
3095template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003096inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003097slice_array<_Tp>
3098valarray<_Tp>::operator[](slice __s)
3099{
3100 return slice_array<value_type>(__s, *this);
3101}
3102
3103template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003104inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003105__val_expr<__indirect_expr<const valarray<_Tp>&> >
3106valarray<_Tp>::operator[](const gslice& __gs) const
3107{
3108 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
3109}
3110
3111template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003112inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003113gslice_array<_Tp>
3114valarray<_Tp>::operator[](const gslice& __gs)
3115{
3116 return gslice_array<value_type>(__gs, *this);
3117}
3118
Howard Hinnant73d21a42010-09-04 23:28:19 +00003119#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003120
3121template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003122inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003123__val_expr<__indirect_expr<const valarray<_Tp>&> >
3124valarray<_Tp>::operator[](gslice&& __gs) const
3125{
3126 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
3127}
3128
3129template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003130inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003131gslice_array<_Tp>
3132valarray<_Tp>::operator[](gslice&& __gs)
3133{
3134 return gslice_array<value_type>(move(__gs), *this);
3135}
3136
Howard Hinnant73d21a42010-09-04 23:28:19 +00003137#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003138
3139template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003140inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003141__val_expr<__mask_expr<const valarray<_Tp>&> >
3142valarray<_Tp>::operator[](const valarray<bool>& __vb) const
3143{
3144 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
3145}
3146
3147template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003148inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003149mask_array<_Tp>
3150valarray<_Tp>::operator[](const valarray<bool>& __vb)
3151{
3152 return mask_array<value_type>(__vb, *this);
3153}
3154
Howard Hinnant73d21a42010-09-04 23:28:19 +00003155#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003156
3157template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003158inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003159__val_expr<__mask_expr<const valarray<_Tp>&> >
3160valarray<_Tp>::operator[](valarray<bool>&& __vb) const
3161{
3162 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
3163}
3164
3165template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003166inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003167mask_array<_Tp>
3168valarray<_Tp>::operator[](valarray<bool>&& __vb)
3169{
3170 return mask_array<value_type>(move(__vb), *this);
3171}
3172
Howard Hinnant73d21a42010-09-04 23:28:19 +00003173#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003174
3175template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003176inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003177__val_expr<__indirect_expr<const valarray<_Tp>&> >
3178valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
3179{
3180 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
3181}
3182
3183template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003184inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003185indirect_array<_Tp>
3186valarray<_Tp>::operator[](const valarray<size_t>& __vs)
3187{
3188 return indirect_array<value_type>(__vs, *this);
3189}
3190
Howard Hinnant73d21a42010-09-04 23:28:19 +00003191#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003192
3193template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003194inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003195__val_expr<__indirect_expr<const valarray<_Tp>&> >
3196valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
3197{
3198 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
3199}
3200
3201template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003202inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003203indirect_array<_Tp>
3204valarray<_Tp>::operator[](valarray<size_t>&& __vs)
3205{
3206 return indirect_array<value_type>(move(__vs), *this);
3207}
3208
Howard Hinnant73d21a42010-09-04 23:28:19 +00003209#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003210
3211template <class _Tp>
3212valarray<_Tp>
3213valarray<_Tp>::operator+() const
3214{
3215 valarray<value_type> __r;
3216 size_t __n = size();
3217 if (__n)
3218 {
3219 __r.__begin_ =
3220 __r.__end_ =
3221 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3222 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3223 ::new (__r.__end_) value_type(+*__p);
3224 }
3225 return __r;
3226}
3227
3228template <class _Tp>
3229valarray<_Tp>
3230valarray<_Tp>::operator-() const
3231{
3232 valarray<value_type> __r;
3233 size_t __n = size();
3234 if (__n)
3235 {
3236 __r.__begin_ =
3237 __r.__end_ =
3238 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3239 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3240 ::new (__r.__end_) value_type(-*__p);
3241 }
3242 return __r;
3243}
3244
3245template <class _Tp>
3246valarray<_Tp>
3247valarray<_Tp>::operator~() const
3248{
3249 valarray<value_type> __r;
3250 size_t __n = size();
3251 if (__n)
3252 {
3253 __r.__begin_ =
3254 __r.__end_ =
3255 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3256 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3257 ::new (__r.__end_) value_type(~*__p);
3258 }
3259 return __r;
3260}
3261
3262template <class _Tp>
3263valarray<bool>
3264valarray<_Tp>::operator!() const
3265{
3266 valarray<bool> __r;
3267 size_t __n = size();
3268 if (__n)
3269 {
3270 __r.__begin_ =
3271 __r.__end_ =
3272 static_cast<bool*>(::operator new(__n * sizeof(bool)));
3273 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3274 ::new (__r.__end_) bool(!*__p);
3275 }
3276 return __r;
3277}
3278
3279template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003280inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003281valarray<_Tp>&
3282valarray<_Tp>::operator*=(const value_type& __x)
3283{
3284 for (value_type* __p = __begin_; __p != __end_; ++__p)
3285 *__p *= __x;
3286 return *this;
3287}
3288
3289template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003290inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003291valarray<_Tp>&
3292valarray<_Tp>::operator/=(const value_type& __x)
3293{
3294 for (value_type* __p = __begin_; __p != __end_; ++__p)
3295 *__p /= __x;
3296 return *this;
3297}
3298
3299template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003300inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003301valarray<_Tp>&
3302valarray<_Tp>::operator%=(const value_type& __x)
3303{
3304 for (value_type* __p = __begin_; __p != __end_; ++__p)
3305 *__p %= __x;
3306 return *this;
3307}
3308
3309template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003310inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003311valarray<_Tp>&
3312valarray<_Tp>::operator+=(const value_type& __x)
3313{
3314 for (value_type* __p = __begin_; __p != __end_; ++__p)
3315 *__p += __x;
3316 return *this;
3317}
3318
3319template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003320inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003321valarray<_Tp>&
3322valarray<_Tp>::operator-=(const value_type& __x)
3323{
3324 for (value_type* __p = __begin_; __p != __end_; ++__p)
3325 *__p -= __x;
3326 return *this;
3327}
3328
3329template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003330inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003331valarray<_Tp>&
3332valarray<_Tp>::operator^=(const value_type& __x)
3333{
3334 for (value_type* __p = __begin_; __p != __end_; ++__p)
3335 *__p ^= __x;
3336 return *this;
3337}
3338
3339template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003340inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003341valarray<_Tp>&
3342valarray<_Tp>::operator&=(const value_type& __x)
3343{
3344 for (value_type* __p = __begin_; __p != __end_; ++__p)
3345 *__p &= __x;
3346 return *this;
3347}
3348
3349template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003350inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003351valarray<_Tp>&
3352valarray<_Tp>::operator|=(const value_type& __x)
3353{
3354 for (value_type* __p = __begin_; __p != __end_; ++__p)
3355 *__p |= __x;
3356 return *this;
3357}
3358
3359template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003360inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003361valarray<_Tp>&
3362valarray<_Tp>::operator<<=(const value_type& __x)
3363{
3364 for (value_type* __p = __begin_; __p != __end_; ++__p)
3365 *__p <<= __x;
3366 return *this;
3367}
3368
3369template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003370inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003371valarray<_Tp>&
3372valarray<_Tp>::operator>>=(const value_type& __x)
3373{
3374 for (value_type* __p = __begin_; __p != __end_; ++__p)
3375 *__p >>= __x;
3376 return *this;
3377}
3378
3379template <class _Tp>
3380template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003381inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003382typename enable_if
3383<
3384 __is_val_expr<_Expr>::value,
3385 valarray<_Tp>&
3386>::type
3387valarray<_Tp>::operator*=(const _Expr& __v)
3388{
3389 size_t __i = 0;
3390 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3391 *__t *= __v[__i];
3392 return *this;
3393}
3394
3395template <class _Tp>
3396template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003397inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003398typename enable_if
3399<
3400 __is_val_expr<_Expr>::value,
3401 valarray<_Tp>&
3402>::type
3403valarray<_Tp>::operator/=(const _Expr& __v)
3404{
3405 size_t __i = 0;
3406 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3407 *__t /= __v[__i];
3408 return *this;
3409}
3410
3411template <class _Tp>
3412template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003413inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003414typename enable_if
3415<
3416 __is_val_expr<_Expr>::value,
3417 valarray<_Tp>&
3418>::type
3419valarray<_Tp>::operator%=(const _Expr& __v)
3420{
3421 size_t __i = 0;
3422 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3423 *__t %= __v[__i];
3424 return *this;
3425}
3426
3427template <class _Tp>
3428template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003429inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003430typename enable_if
3431<
3432 __is_val_expr<_Expr>::value,
3433 valarray<_Tp>&
3434>::type
3435valarray<_Tp>::operator+=(const _Expr& __v)
3436{
3437 size_t __i = 0;
3438 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3439 *__t += __v[__i];
3440 return *this;
3441}
3442
3443template <class _Tp>
3444template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003445inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003446typename enable_if
3447<
3448 __is_val_expr<_Expr>::value,
3449 valarray<_Tp>&
3450>::type
3451valarray<_Tp>::operator-=(const _Expr& __v)
3452{
3453 size_t __i = 0;
3454 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3455 *__t -= __v[__i];
3456 return *this;
3457}
3458
3459template <class _Tp>
3460template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003461inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003462typename enable_if
3463<
3464 __is_val_expr<_Expr>::value,
3465 valarray<_Tp>&
3466>::type
3467valarray<_Tp>::operator^=(const _Expr& __v)
3468{
3469 size_t __i = 0;
3470 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3471 *__t ^= __v[__i];
3472 return *this;
3473}
3474
3475template <class _Tp>
3476template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003477inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003478typename enable_if
3479<
3480 __is_val_expr<_Expr>::value,
3481 valarray<_Tp>&
3482>::type
3483valarray<_Tp>::operator|=(const _Expr& __v)
3484{
3485 size_t __i = 0;
3486 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3487 *__t |= __v[__i];
3488 return *this;
3489}
3490
3491template <class _Tp>
3492template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003493inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003494typename enable_if
3495<
3496 __is_val_expr<_Expr>::value,
3497 valarray<_Tp>&
3498>::type
3499valarray<_Tp>::operator&=(const _Expr& __v)
3500{
3501 size_t __i = 0;
3502 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3503 *__t &= __v[__i];
3504 return *this;
3505}
3506
3507template <class _Tp>
3508template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003509inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003510typename enable_if
3511<
3512 __is_val_expr<_Expr>::value,
3513 valarray<_Tp>&
3514>::type
3515valarray<_Tp>::operator<<=(const _Expr& __v)
3516{
3517 size_t __i = 0;
3518 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3519 *__t <<= __v[__i];
3520 return *this;
3521}
3522
3523template <class _Tp>
3524template <class _Expr>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003525inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003526typename enable_if
3527<
3528 __is_val_expr<_Expr>::value,
3529 valarray<_Tp>&
3530>::type
3531valarray<_Tp>::operator>>=(const _Expr& __v)
3532{
3533 size_t __i = 0;
3534 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3535 *__t >>= __v[__i];
3536 return *this;
3537}
3538
3539template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003540inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003541void
3542valarray<_Tp>::swap(valarray& __v)
3543{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003544 _VSTD::swap(__begin_, __v.__begin_);
3545 _VSTD::swap(__end_, __v.__end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003546}
3547
3548template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003549inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003550_Tp
3551valarray<_Tp>::sum() const
3552{
3553 if (__begin_ == __end_)
3554 return value_type();
3555 const value_type* __p = __begin_;
3556 _Tp __r = *__p;
3557 for (++__p; __p != __end_; ++__p)
3558 __r += *__p;
3559 return __r;
3560}
3561
3562template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003563inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003564_Tp
3565valarray<_Tp>::min() const
3566{
3567 if (__begin_ == __end_)
3568 return value_type();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003569 return *_VSTD::min_element(__begin_, __end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003570}
3571
3572template <class _Tp>
Douglas Gregore9e4b852012-05-19 04:41:25 +00003573inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003574_Tp
3575valarray<_Tp>::max() const
3576{
3577 if (__begin_ == __end_)
3578 return value_type();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003579 return *_VSTD::max_element(__begin_, __end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003580}
3581
3582template <class _Tp>
3583valarray<_Tp>
3584valarray<_Tp>::shift(int __i) const
3585{
3586 valarray<value_type> __r;
3587 size_t __n = size();
3588 if (__n)
3589 {
3590 __r.__begin_ =
3591 __r.__end_ =
3592 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3593 const value_type* __sb;
3594 value_type* __tb;
3595 value_type* __te;
3596 if (__i >= 0)
3597 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003598 __i = _VSTD::min(__i, static_cast<int>(__n));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003599 __sb = __begin_ + __i;
3600 __tb = __r.__begin_;
3601 __te = __r.__begin_ + (__n - __i);
3602 }
3603 else
3604 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003605 __i = _VSTD::min(-__i, static_cast<int>(__n));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003606 __sb = __begin_;
3607 __tb = __r.__begin_ + __i;
3608 __te = __r.__begin_ + __n;
3609 }
3610 for (; __r.__end_ != __tb; ++__r.__end_)
3611 ::new (__r.__end_) value_type();
3612 for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
3613 ::new (__r.__end_) value_type(*__sb);
3614 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
3615 ::new (__r.__end_) value_type();
3616 }
3617 return __r;
3618}
3619
3620template <class _Tp>
3621valarray<_Tp>
3622valarray<_Tp>::cshift(int __i) const
3623{
3624 valarray<value_type> __r;
3625 size_t __n = size();
3626 if (__n)
3627 {
3628 __r.__begin_ =
3629 __r.__end_ =
3630 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3631 __i %= static_cast<int>(__n);
3632 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
3633 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
3634 ::new (__r.__end_) value_type(*__s);
3635 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
3636 ::new (__r.__end_) value_type(*__s);
3637 }
3638 return __r;
3639}
3640
3641template <class _Tp>
3642valarray<_Tp>
3643valarray<_Tp>::apply(value_type __f(value_type)) const
3644{
3645 valarray<value_type> __r;
3646 size_t __n = size();
3647 if (__n)
3648 {
3649 __r.__begin_ =
3650 __r.__end_ =
3651 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3652 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3653 ::new (__r.__end_) value_type(__f(*__p));
3654 }
3655 return __r;
3656}
3657
3658template <class _Tp>
3659valarray<_Tp>
3660valarray<_Tp>::apply(value_type __f(const value_type&)) const
3661{
3662 valarray<value_type> __r;
3663 size_t __n = size();
3664 if (__n)
3665 {
3666 __r.__begin_ =
3667 __r.__end_ =
3668 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3669 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3670 ::new (__r.__end_) value_type(__f(*__p));
3671 }
3672 return __r;
3673}
3674
3675template <class _Tp>
3676void
3677valarray<_Tp>::resize(size_t __n, value_type __x)
3678{
3679 if (__begin_ != nullptr)
3680 {
3681 while (__end_ != __begin_)
3682 (--__end_)->~value_type();
3683 ::operator delete(__begin_);
3684 __begin_ = __end_ = nullptr;
3685 }
3686 if (__n)
3687 {
3688 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3689#ifndef _LIBCPP_NO_EXCEPTIONS
3690 try
3691 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003692#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003693 for (; __n; --__n, ++__end_)
3694 ::new (__end_) value_type(__x);
3695#ifndef _LIBCPP_NO_EXCEPTIONS
3696 }
3697 catch (...)
3698 {
3699 resize(0);
3700 throw;
3701 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003702#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003703 }
3704}
3705
3706template<class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003707inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003708void
3709swap(valarray<_Tp>& __x, valarray<_Tp>& __y)
3710{
3711 __x.swap(__y);
3712}
3713
3714template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003715inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003716typename enable_if
3717<
3718 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3719 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
3720>::type
3721operator*(const _Expr1& __x, const _Expr2& __y)
3722{
3723 typedef typename _Expr1::value_type value_type;
3724 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
3725 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
3726}
3727
3728template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003729inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003730typename enable_if
3731<
3732 __is_val_expr<_Expr>::value,
3733 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3734 _Expr, __scalar_expr<typename _Expr::value_type> > >
3735>::type
3736operator*(const _Expr& __x, const typename _Expr::value_type& __y)
3737{
3738 typedef typename _Expr::value_type value_type;
3739 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3740 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3741 __x, __scalar_expr<value_type>(__y, __x.size())));
3742}
3743
3744template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003745inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003746typename enable_if
3747<
3748 __is_val_expr<_Expr>::value,
3749 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3750 __scalar_expr<typename _Expr::value_type>, _Expr> >
3751>::type
3752operator*(const typename _Expr::value_type& __x, const _Expr& __y)
3753{
3754 typedef typename _Expr::value_type value_type;
3755 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3756 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3757 __scalar_expr<value_type>(__x, __y.size()), __y));
3758}
3759
3760template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003761inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003762typename enable_if
3763<
3764 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3765 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
3766>::type
3767operator/(const _Expr1& __x, const _Expr2& __y)
3768{
3769 typedef typename _Expr1::value_type value_type;
3770 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
3771 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
3772}
3773
3774template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003775inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003776typename enable_if
3777<
3778 __is_val_expr<_Expr>::value,
3779 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3780 _Expr, __scalar_expr<typename _Expr::value_type> > >
3781>::type
3782operator/(const _Expr& __x, const typename _Expr::value_type& __y)
3783{
3784 typedef typename _Expr::value_type value_type;
3785 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3786 return __val_expr<_Op>(_Op(divides<value_type>(),
3787 __x, __scalar_expr<value_type>(__y, __x.size())));
3788}
3789
3790template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003791inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003792typename enable_if
3793<
3794 __is_val_expr<_Expr>::value,
3795 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3796 __scalar_expr<typename _Expr::value_type>, _Expr> >
3797>::type
3798operator/(const typename _Expr::value_type& __x, const _Expr& __y)
3799{
3800 typedef typename _Expr::value_type value_type;
3801 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3802 return __val_expr<_Op>(_Op(divides<value_type>(),
3803 __scalar_expr<value_type>(__x, __y.size()), __y));
3804}
3805
3806template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003807inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003808typename enable_if
3809<
3810 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3811 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3812>::type
3813operator%(const _Expr1& __x, const _Expr2& __y)
3814{
3815 typedef typename _Expr1::value_type value_type;
3816 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
3817 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
3818}
3819
3820template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003821inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003822typename enable_if
3823<
3824 __is_val_expr<_Expr>::value,
3825 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3826 _Expr, __scalar_expr<typename _Expr::value_type> > >
3827>::type
3828operator%(const _Expr& __x, const typename _Expr::value_type& __y)
3829{
3830 typedef typename _Expr::value_type value_type;
3831 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3832 return __val_expr<_Op>(_Op(modulus<value_type>(),
3833 __x, __scalar_expr<value_type>(__y, __x.size())));
3834}
3835
3836template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003837inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003838typename enable_if
3839<
3840 __is_val_expr<_Expr>::value,
3841 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3842 __scalar_expr<typename _Expr::value_type>, _Expr> >
3843>::type
3844operator%(const typename _Expr::value_type& __x, const _Expr& __y)
3845{
3846 typedef typename _Expr::value_type value_type;
3847 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3848 return __val_expr<_Op>(_Op(modulus<value_type>(),
3849 __scalar_expr<value_type>(__x, __y.size()), __y));
3850}
3851
3852template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003853inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003854typename enable_if
3855<
3856 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3857 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3858>::type
3859operator+(const _Expr1& __x, const _Expr2& __y)
3860{
3861 typedef typename _Expr1::value_type value_type;
3862 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
3863 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
3864}
3865
3866template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003867inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003868typename enable_if
3869<
3870 __is_val_expr<_Expr>::value,
3871 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3872 _Expr, __scalar_expr<typename _Expr::value_type> > >
3873>::type
3874operator+(const _Expr& __x, const typename _Expr::value_type& __y)
3875{
3876 typedef typename _Expr::value_type value_type;
3877 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3878 return __val_expr<_Op>(_Op(plus<value_type>(),
3879 __x, __scalar_expr<value_type>(__y, __x.size())));
3880}
3881
3882template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003883inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003884typename enable_if
3885<
3886 __is_val_expr<_Expr>::value,
3887 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3888 __scalar_expr<typename _Expr::value_type>, _Expr> >
3889>::type
3890operator+(const typename _Expr::value_type& __x, const _Expr& __y)
3891{
3892 typedef typename _Expr::value_type value_type;
3893 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3894 return __val_expr<_Op>(_Op(plus<value_type>(),
3895 __scalar_expr<value_type>(__x, __y.size()), __y));
3896}
3897
3898template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003899inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003900typename enable_if
3901<
3902 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3903 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3904>::type
3905operator-(const _Expr1& __x, const _Expr2& __y)
3906{
3907 typedef typename _Expr1::value_type value_type;
3908 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
3909 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
3910}
3911
3912template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003913inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003914typename enable_if
3915<
3916 __is_val_expr<_Expr>::value,
3917 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3918 _Expr, __scalar_expr<typename _Expr::value_type> > >
3919>::type
3920operator-(const _Expr& __x, const typename _Expr::value_type& __y)
3921{
3922 typedef typename _Expr::value_type value_type;
3923 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3924 return __val_expr<_Op>(_Op(minus<value_type>(),
3925 __x, __scalar_expr<value_type>(__y, __x.size())));
3926}
3927
3928template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003929inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003930typename enable_if
3931<
3932 __is_val_expr<_Expr>::value,
3933 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3934 __scalar_expr<typename _Expr::value_type>, _Expr> >
3935>::type
3936operator-(const typename _Expr::value_type& __x, const _Expr& __y)
3937{
3938 typedef typename _Expr::value_type value_type;
3939 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3940 return __val_expr<_Op>(_Op(minus<value_type>(),
3941 __scalar_expr<value_type>(__x, __y.size()), __y));
3942}
3943
3944template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003945inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003946typename enable_if
3947<
3948 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3949 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
3950>::type
3951operator^(const _Expr1& __x, const _Expr2& __y)
3952{
3953 typedef typename _Expr1::value_type value_type;
3954 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
3955 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
3956}
3957
3958template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003959inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003960typename enable_if
3961<
3962 __is_val_expr<_Expr>::value,
3963 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
3964 _Expr, __scalar_expr<typename _Expr::value_type> > >
3965>::type
3966operator^(const _Expr& __x, const typename _Expr::value_type& __y)
3967{
3968 typedef typename _Expr::value_type value_type;
3969 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3970 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
3971 __x, __scalar_expr<value_type>(__y, __x.size())));
3972}
3973
3974template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003975inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003976typename enable_if
3977<
3978 __is_val_expr<_Expr>::value,
3979 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
3980 __scalar_expr<typename _Expr::value_type>, _Expr> >
3981>::type
3982operator^(const typename _Expr::value_type& __x, const _Expr& __y)
3983{
3984 typedef typename _Expr::value_type value_type;
3985 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3986 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
3987 __scalar_expr<value_type>(__x, __y.size()), __y));
3988}
3989
3990template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003991inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003992typename enable_if
3993<
3994 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3995 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
3996>::type
3997operator&(const _Expr1& __x, const _Expr2& __y)
3998{
3999 typedef typename _Expr1::value_type value_type;
4000 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
4001 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
4002}
4003
4004template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004005inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004006typename enable_if
4007<
4008 __is_val_expr<_Expr>::value,
4009 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4010 _Expr, __scalar_expr<typename _Expr::value_type> > >
4011>::type
4012operator&(const _Expr& __x, const typename _Expr::value_type& __y)
4013{
4014 typedef typename _Expr::value_type value_type;
4015 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4016 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4017 __x, __scalar_expr<value_type>(__y, __x.size())));
4018}
4019
4020template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004021inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004022typename enable_if
4023<
4024 __is_val_expr<_Expr>::value,
4025 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4026 __scalar_expr<typename _Expr::value_type>, _Expr> >
4027>::type
4028operator&(const typename _Expr::value_type& __x, const _Expr& __y)
4029{
4030 typedef typename _Expr::value_type value_type;
4031 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4032 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4033 __scalar_expr<value_type>(__x, __y.size()), __y));
4034}
4035
4036template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004037inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004038typename enable_if
4039<
4040 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4041 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4042>::type
4043operator|(const _Expr1& __x, const _Expr2& __y)
4044{
4045 typedef typename _Expr1::value_type value_type;
4046 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
4047 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
4048}
4049
4050template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004051inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004052typename enable_if
4053<
4054 __is_val_expr<_Expr>::value,
4055 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4056 _Expr, __scalar_expr<typename _Expr::value_type> > >
4057>::type
4058operator|(const _Expr& __x, const typename _Expr::value_type& __y)
4059{
4060 typedef typename _Expr::value_type value_type;
4061 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4062 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4063 __x, __scalar_expr<value_type>(__y, __x.size())));
4064}
4065
4066template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004067inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004068typename enable_if
4069<
4070 __is_val_expr<_Expr>::value,
4071 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4072 __scalar_expr<typename _Expr::value_type>, _Expr> >
4073>::type
4074operator|(const typename _Expr::value_type& __x, const _Expr& __y)
4075{
4076 typedef typename _Expr::value_type value_type;
4077 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4078 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4079 __scalar_expr<value_type>(__x, __y.size()), __y));
4080}
4081
4082template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004083inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004084typename enable_if
4085<
4086 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4087 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
4088>::type
4089operator<<(const _Expr1& __x, const _Expr2& __y)
4090{
4091 typedef typename _Expr1::value_type value_type;
4092 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
4093 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
4094}
4095
4096template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004097inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004098typename enable_if
4099<
4100 __is_val_expr<_Expr>::value,
4101 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4102 _Expr, __scalar_expr<typename _Expr::value_type> > >
4103>::type
4104operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
4105{
4106 typedef typename _Expr::value_type value_type;
4107 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4108 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4109 __x, __scalar_expr<value_type>(__y, __x.size())));
4110}
4111
4112template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004113inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004114typename enable_if
4115<
4116 __is_val_expr<_Expr>::value,
4117 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4118 __scalar_expr<typename _Expr::value_type>, _Expr> >
4119>::type
4120operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
4121{
4122 typedef typename _Expr::value_type value_type;
4123 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4124 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4125 __scalar_expr<value_type>(__x, __y.size()), __y));
4126}
4127
4128template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004129inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004130typename enable_if
4131<
4132 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4133 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
4134>::type
4135operator>>(const _Expr1& __x, const _Expr2& __y)
4136{
4137 typedef typename _Expr1::value_type value_type;
4138 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
4139 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
4140}
4141
4142template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004143inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004144typename enable_if
4145<
4146 __is_val_expr<_Expr>::value,
4147 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4148 _Expr, __scalar_expr<typename _Expr::value_type> > >
4149>::type
4150operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
4151{
4152 typedef typename _Expr::value_type value_type;
4153 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4154 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4155 __x, __scalar_expr<value_type>(__y, __x.size())));
4156}
4157
4158template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004159inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004160typename enable_if
4161<
4162 __is_val_expr<_Expr>::value,
4163 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4164 __scalar_expr<typename _Expr::value_type>, _Expr> >
4165>::type
4166operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
4167{
4168 typedef typename _Expr::value_type value_type;
4169 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4170 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4171 __scalar_expr<value_type>(__x, __y.size()), __y));
4172}
4173
4174template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004175inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004176typename enable_if
4177<
4178 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4179 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4180>::type
4181operator&&(const _Expr1& __x, const _Expr2& __y)
4182{
4183 typedef typename _Expr1::value_type value_type;
4184 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
4185 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
4186}
4187
4188template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004189inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004190typename enable_if
4191<
4192 __is_val_expr<_Expr>::value,
4193 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4194 _Expr, __scalar_expr<typename _Expr::value_type> > >
4195>::type
4196operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
4197{
4198 typedef typename _Expr::value_type value_type;
4199 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4200 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4201 __x, __scalar_expr<value_type>(__y, __x.size())));
4202}
4203
4204template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004205inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004206typename enable_if
4207<
4208 __is_val_expr<_Expr>::value,
4209 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4210 __scalar_expr<typename _Expr::value_type>, _Expr> >
4211>::type
4212operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
4213{
4214 typedef typename _Expr::value_type value_type;
4215 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4216 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4217 __scalar_expr<value_type>(__x, __y.size()), __y));
4218}
4219
4220template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004221inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004222typename enable_if
4223<
4224 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4225 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4226>::type
4227operator||(const _Expr1& __x, const _Expr2& __y)
4228{
4229 typedef typename _Expr1::value_type value_type;
4230 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
4231 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
4232}
4233
4234template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004235inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004236typename enable_if
4237<
4238 __is_val_expr<_Expr>::value,
4239 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4240 _Expr, __scalar_expr<typename _Expr::value_type> > >
4241>::type
4242operator||(const _Expr& __x, const typename _Expr::value_type& __y)
4243{
4244 typedef typename _Expr::value_type value_type;
4245 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4246 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4247 __x, __scalar_expr<value_type>(__y, __x.size())));
4248}
4249
4250template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004251inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004252typename enable_if
4253<
4254 __is_val_expr<_Expr>::value,
4255 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4256 __scalar_expr<typename _Expr::value_type>, _Expr> >
4257>::type
4258operator||(const typename _Expr::value_type& __x, const _Expr& __y)
4259{
4260 typedef typename _Expr::value_type value_type;
4261 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4262 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4263 __scalar_expr<value_type>(__x, __y.size()), __y));
4264}
4265
4266template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004267inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004268typename enable_if
4269<
4270 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4271 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4272>::type
4273operator==(const _Expr1& __x, const _Expr2& __y)
4274{
4275 typedef typename _Expr1::value_type value_type;
4276 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
4277 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
4278}
4279
4280template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004281inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004282typename enable_if
4283<
4284 __is_val_expr<_Expr>::value,
4285 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4286 _Expr, __scalar_expr<typename _Expr::value_type> > >
4287>::type
4288operator==(const _Expr& __x, const typename _Expr::value_type& __y)
4289{
4290 typedef typename _Expr::value_type value_type;
4291 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4292 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4293 __x, __scalar_expr<value_type>(__y, __x.size())));
4294}
4295
4296template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004297inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004298typename enable_if
4299<
4300 __is_val_expr<_Expr>::value,
4301 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4302 __scalar_expr<typename _Expr::value_type>, _Expr> >
4303>::type
4304operator==(const typename _Expr::value_type& __x, const _Expr& __y)
4305{
4306 typedef typename _Expr::value_type value_type;
4307 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4308 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4309 __scalar_expr<value_type>(__x, __y.size()), __y));
4310}
4311
4312template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004313inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004314typename enable_if
4315<
4316 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4317 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4318>::type
4319operator!=(const _Expr1& __x, const _Expr2& __y)
4320{
4321 typedef typename _Expr1::value_type value_type;
4322 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
4323 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
4324}
4325
4326template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004327inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004328typename enable_if
4329<
4330 __is_val_expr<_Expr>::value,
4331 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4332 _Expr, __scalar_expr<typename _Expr::value_type> > >
4333>::type
4334operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
4335{
4336 typedef typename _Expr::value_type value_type;
4337 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4338 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4339 __x, __scalar_expr<value_type>(__y, __x.size())));
4340}
4341
4342template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004343inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004344typename enable_if
4345<
4346 __is_val_expr<_Expr>::value,
4347 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4348 __scalar_expr<typename _Expr::value_type>, _Expr> >
4349>::type
4350operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
4351{
4352 typedef typename _Expr::value_type value_type;
4353 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4354 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4355 __scalar_expr<value_type>(__x, __y.size()), __y));
4356}
4357
4358template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004359inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004360typename enable_if
4361<
4362 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4363 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
4364>::type
4365operator<(const _Expr1& __x, const _Expr2& __y)
4366{
4367 typedef typename _Expr1::value_type value_type;
4368 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
4369 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
4370}
4371
4372template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004373inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004374typename enable_if
4375<
4376 __is_val_expr<_Expr>::value,
4377 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4378 _Expr, __scalar_expr<typename _Expr::value_type> > >
4379>::type
4380operator<(const _Expr& __x, const typename _Expr::value_type& __y)
4381{
4382 typedef typename _Expr::value_type value_type;
4383 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4384 return __val_expr<_Op>(_Op(less<value_type>(),
4385 __x, __scalar_expr<value_type>(__y, __x.size())));
4386}
4387
4388template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004389inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004390typename enable_if
4391<
4392 __is_val_expr<_Expr>::value,
4393 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4394 __scalar_expr<typename _Expr::value_type>, _Expr> >
4395>::type
4396operator<(const typename _Expr::value_type& __x, const _Expr& __y)
4397{
4398 typedef typename _Expr::value_type value_type;
4399 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4400 return __val_expr<_Op>(_Op(less<value_type>(),
4401 __scalar_expr<value_type>(__x, __y.size()), __y));
4402}
4403
4404template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004405inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004406typename enable_if
4407<
4408 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4409 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
4410>::type
4411operator>(const _Expr1& __x, const _Expr2& __y)
4412{
4413 typedef typename _Expr1::value_type value_type;
4414 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
4415 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
4416}
4417
4418template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004419inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004420typename enable_if
4421<
4422 __is_val_expr<_Expr>::value,
4423 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4424 _Expr, __scalar_expr<typename _Expr::value_type> > >
4425>::type
4426operator>(const _Expr& __x, const typename _Expr::value_type& __y)
4427{
4428 typedef typename _Expr::value_type value_type;
4429 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4430 return __val_expr<_Op>(_Op(greater<value_type>(),
4431 __x, __scalar_expr<value_type>(__y, __x.size())));
4432}
4433
4434template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004435inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004436typename enable_if
4437<
4438 __is_val_expr<_Expr>::value,
4439 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4440 __scalar_expr<typename _Expr::value_type>, _Expr> >
4441>::type
4442operator>(const typename _Expr::value_type& __x, const _Expr& __y)
4443{
4444 typedef typename _Expr::value_type value_type;
4445 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4446 return __val_expr<_Op>(_Op(greater<value_type>(),
4447 __scalar_expr<value_type>(__x, __y.size()), __y));
4448}
4449
4450template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004451inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004452typename enable_if
4453<
4454 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4455 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4456>::type
4457operator<=(const _Expr1& __x, const _Expr2& __y)
4458{
4459 typedef typename _Expr1::value_type value_type;
4460 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
4461 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
4462}
4463
4464template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004465inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004466typename enable_if
4467<
4468 __is_val_expr<_Expr>::value,
4469 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4470 _Expr, __scalar_expr<typename _Expr::value_type> > >
4471>::type
4472operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
4473{
4474 typedef typename _Expr::value_type value_type;
4475 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4476 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4477 __x, __scalar_expr<value_type>(__y, __x.size())));
4478}
4479
4480template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004481inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004482typename enable_if
4483<
4484 __is_val_expr<_Expr>::value,
4485 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4486 __scalar_expr<typename _Expr::value_type>, _Expr> >
4487>::type
4488operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
4489{
4490 typedef typename _Expr::value_type value_type;
4491 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4492 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4493 __scalar_expr<value_type>(__x, __y.size()), __y));
4494}
4495
4496template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004497inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004498typename enable_if
4499<
4500 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4501 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4502>::type
4503operator>=(const _Expr1& __x, const _Expr2& __y)
4504{
4505 typedef typename _Expr1::value_type value_type;
4506 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
4507 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
4508}
4509
4510template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004511inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004512typename enable_if
4513<
4514 __is_val_expr<_Expr>::value,
4515 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4516 _Expr, __scalar_expr<typename _Expr::value_type> > >
4517>::type
4518operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
4519{
4520 typedef typename _Expr::value_type value_type;
4521 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4522 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4523 __x, __scalar_expr<value_type>(__y, __x.size())));
4524}
4525
4526template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004527inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004528typename enable_if
4529<
4530 __is_val_expr<_Expr>::value,
4531 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4532 __scalar_expr<typename _Expr::value_type>, _Expr> >
4533>::type
4534operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
4535{
4536 typedef typename _Expr::value_type value_type;
4537 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4538 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4539 __scalar_expr<value_type>(__x, __y.size()), __y));
4540}
4541
4542template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004543inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004544typename enable_if
4545<
4546 __is_val_expr<_Expr>::value,
4547 __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
4548>::type
4549abs(const _Expr& __x)
4550{
4551 typedef typename _Expr::value_type value_type;
4552 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
4553 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
4554}
4555
4556template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004557inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004558typename enable_if
4559<
4560 __is_val_expr<_Expr>::value,
4561 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
4562>::type
4563acos(const _Expr& __x)
4564{
4565 typedef typename _Expr::value_type value_type;
4566 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
4567 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
4568}
4569
4570template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004571inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004572typename enable_if
4573<
4574 __is_val_expr<_Expr>::value,
4575 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
4576>::type
4577asin(const _Expr& __x)
4578{
4579 typedef typename _Expr::value_type value_type;
4580 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
4581 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
4582}
4583
4584template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004585inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004586typename enable_if
4587<
4588 __is_val_expr<_Expr>::value,
4589 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
4590>::type
4591atan(const _Expr& __x)
4592{
4593 typedef typename _Expr::value_type value_type;
4594 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
4595 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
4596}
4597
4598template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004599inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004600typename enable_if
4601<
4602 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4603 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4604>::type
4605atan2(const _Expr1& __x, const _Expr2& __y)
4606{
4607 typedef typename _Expr1::value_type value_type;
4608 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
4609 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
4610}
4611
4612template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004613inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004614typename enable_if
4615<
4616 __is_val_expr<_Expr>::value,
4617 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4618 _Expr, __scalar_expr<typename _Expr::value_type> > >
4619>::type
4620atan2(const _Expr& __x, const typename _Expr::value_type& __y)
4621{
4622 typedef typename _Expr::value_type value_type;
4623 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4624 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4625 __x, __scalar_expr<value_type>(__y, __x.size())));
4626}
4627
4628template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004629inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004630typename enable_if
4631<
4632 __is_val_expr<_Expr>::value,
4633 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4634 __scalar_expr<typename _Expr::value_type>, _Expr> >
4635>::type
4636atan2(const typename _Expr::value_type& __x, const _Expr& __y)
4637{
4638 typedef typename _Expr::value_type value_type;
4639 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4640 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4641 __scalar_expr<value_type>(__x, __y.size()), __y));
4642}
4643
4644template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004645inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004646typename enable_if
4647<
4648 __is_val_expr<_Expr>::value,
4649 __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
4650>::type
4651cos(const _Expr& __x)
4652{
4653 typedef typename _Expr::value_type value_type;
4654 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
4655 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
4656}
4657
4658template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004659inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004660typename enable_if
4661<
4662 __is_val_expr<_Expr>::value,
4663 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
4664>::type
4665cosh(const _Expr& __x)
4666{
4667 typedef typename _Expr::value_type value_type;
4668 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
4669 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
4670}
4671
4672template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004673inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004674typename enable_if
4675<
4676 __is_val_expr<_Expr>::value,
4677 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
4678>::type
4679exp(const _Expr& __x)
4680{
4681 typedef typename _Expr::value_type value_type;
4682 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
4683 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
4684}
4685
4686template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004687inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004688typename enable_if
4689<
4690 __is_val_expr<_Expr>::value,
4691 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
4692>::type
4693log(const _Expr& __x)
4694{
4695 typedef typename _Expr::value_type value_type;
4696 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
4697 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
4698}
4699
4700template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004701inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004702typename enable_if
4703<
4704 __is_val_expr<_Expr>::value,
4705 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
4706>::type
4707log10(const _Expr& __x)
4708{
4709 typedef typename _Expr::value_type value_type;
4710 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
4711 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
4712}
4713
4714template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004715inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004716typename enable_if
4717<
4718 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4719 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4720>::type
4721pow(const _Expr1& __x, const _Expr2& __y)
4722{
4723 typedef typename _Expr1::value_type value_type;
4724 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
4725 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
4726}
4727
4728template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004729inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004730typename enable_if
4731<
4732 __is_val_expr<_Expr>::value,
4733 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4734 _Expr, __scalar_expr<typename _Expr::value_type> > >
4735>::type
4736pow(const _Expr& __x, const typename _Expr::value_type& __y)
4737{
4738 typedef typename _Expr::value_type value_type;
4739 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4740 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4741 __x, __scalar_expr<value_type>(__y, __x.size())));
4742}
4743
4744template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004745inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004746typename enable_if
4747<
4748 __is_val_expr<_Expr>::value,
4749 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4750 __scalar_expr<typename _Expr::value_type>, _Expr> >
4751>::type
4752pow(const typename _Expr::value_type& __x, const _Expr& __y)
4753{
4754 typedef typename _Expr::value_type value_type;
4755 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4756 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4757 __scalar_expr<value_type>(__x, __y.size()), __y));
4758}
4759
4760template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004761inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004762typename enable_if
4763<
4764 __is_val_expr<_Expr>::value,
4765 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
4766>::type
4767sin(const _Expr& __x)
4768{
4769 typedef typename _Expr::value_type value_type;
4770 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
4771 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
4772}
4773
4774template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004775inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004776typename enable_if
4777<
4778 __is_val_expr<_Expr>::value,
4779 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
4780>::type
4781sinh(const _Expr& __x)
4782{
4783 typedef typename _Expr::value_type value_type;
4784 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
4785 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
4786}
4787
4788template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004789inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004790typename enable_if
4791<
4792 __is_val_expr<_Expr>::value,
4793 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
4794>::type
4795sqrt(const _Expr& __x)
4796{
4797 typedef typename _Expr::value_type value_type;
4798 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
4799 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
4800}
4801
4802template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004803inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004804typename enable_if
4805<
4806 __is_val_expr<_Expr>::value,
4807 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
4808>::type
4809tan(const _Expr& __x)
4810{
4811 typedef typename _Expr::value_type value_type;
4812 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
4813 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
4814}
4815
4816template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004817inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004818typename enable_if
4819<
4820 __is_val_expr<_Expr>::value,
4821 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
4822>::type
4823tanh(const _Expr& __x)
4824{
4825 typedef typename _Expr::value_type value_type;
4826 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
4827 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
4828}
4829
4830template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004831inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004832_Tp*
4833begin(valarray<_Tp>& __v)
4834{
4835 return __v.__begin_;
4836}
4837
4838template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004839inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004840const _Tp*
4841begin(const valarray<_Tp>& __v)
4842{
4843 return __v.__begin_;
4844}
4845
4846template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004847inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004848_Tp*
4849end(valarray<_Tp>& __v)
4850{
4851 return __v.__end_;
4852}
4853
4854template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004855inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004856const _Tp*
4857end(const valarray<_Tp>& __v)
4858{
4859 return __v.__end_;
4860}
4861
4862extern template valarray<size_t>::valarray(size_t);
4863extern template valarray<size_t>::~valarray();
4864extern template void valarray<size_t>::resize(size_t, size_t);
4865
4866_LIBCPP_END_NAMESPACE_STD
4867
4868#endif // _LIBCPP_VALARRAY