blob: c56dd125d6a526dd581538fc110cc78f75fcfca2 [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);
Howard Hinnantbd143082012-07-21 00:51:28 +000032 valarray(valarray&& v) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000033 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);
Howard Hinnantbd143082012-07-21 00:51:28 +000042 valarray& operator=(valarray&& v) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000043 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:
Howard Hinnantbd143082012-07-21 00:51:28 +000094 void swap(valarray& v) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000095
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
Howard Hinnantbd143082012-07-21 00:51:28 +0000234template<class T> void swap(valarray<T>& x, valarray<T>& y) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000235
236template<class T> valarray<T> operator* (const valarray<T>& x, const valarray<T>& y);
237template<class T> valarray<T> operator* (const valarray<T>& x, const T& y);
238template<class T> valarray<T> operator* (const T& x, const valarray<T>& y);
239
240template<class T> valarray<T> operator/ (const valarray<T>& x, const valarray<T>& y);
241template<class T> valarray<T> operator/ (const valarray<T>& x, const T& y);
242template<class T> valarray<T> operator/ (const T& x, const valarray<T>& y);
243
244template<class T> valarray<T> operator% (const valarray<T>& x, const valarray<T>& y);
245template<class T> valarray<T> operator% (const valarray<T>& x, const T& y);
246template<class T> valarray<T> operator% (const T& x, const valarray<T>& y);
247
248template<class T> valarray<T> operator+ (const valarray<T>& x, const valarray<T>& y);
249template<class T> valarray<T> operator+ (const valarray<T>& x, const T& y);
250template<class T> valarray<T> operator+ (const T& x, const valarray<T>& y);
251
252template<class T> valarray<T> operator- (const valarray<T>& x, const valarray<T>& y);
253template<class T> valarray<T> operator- (const valarray<T>& x, const T& y);
254template<class T> valarray<T> operator- (const T& x, const valarray<T>& y);
255
256template<class T> valarray<T> operator^ (const valarray<T>& x, const valarray<T>& y);
257template<class T> valarray<T> operator^ (const valarray<T>& x, const T& y);
258template<class T> valarray<T> operator^ (const T& x, const valarray<T>& y);
259
260template<class T> valarray<T> operator& (const valarray<T>& x, const valarray<T>& y);
261template<class T> valarray<T> operator& (const valarray<T>& x, const T& y);
262template<class T> valarray<T> operator& (const T& x, const valarray<T>& y);
263
264template<class T> valarray<T> operator| (const valarray<T>& x, const valarray<T>& y);
265template<class T> valarray<T> operator| (const valarray<T>& x, const T& y);
266template<class T> valarray<T> operator| (const T& x, const valarray<T>& y);
267
268template<class T> valarray<T> operator<<(const valarray<T>& x, const valarray<T>& y);
269template<class T> valarray<T> operator<<(const valarray<T>& x, const T& y);
270template<class T> valarray<T> operator<<(const T& x, const valarray<T>& y);
271
272template<class T> valarray<T> operator>>(const valarray<T>& x, const valarray<T>& y);
273template<class T> valarray<T> operator>>(const valarray<T>& x, const T& y);
274template<class T> valarray<T> operator>>(const T& x, const valarray<T>& y);
275
276template<class T> valarray<bool> operator&&(const valarray<T>& x, const valarray<T>& y);
277template<class T> valarray<bool> operator&&(const valarray<T>& x, const T& y);
278template<class T> valarray<bool> operator&&(const T& x, const valarray<T>& y);
279
280template<class T> valarray<bool> operator||(const valarray<T>& x, const valarray<T>& y);
281template<class T> valarray<bool> operator||(const valarray<T>& x, const T& y);
282template<class T> valarray<bool> operator||(const T& x, const valarray<T>& y);
283
284template<class T> valarray<bool> operator==(const valarray<T>& x, const valarray<T>& y);
285template<class T> valarray<bool> operator==(const valarray<T>& x, const T& y);
286template<class T> valarray<bool> operator==(const T& x, const valarray<T>& y);
287
288template<class T> valarray<bool> operator!=(const valarray<T>& x, const valarray<T>& y);
289template<class T> valarray<bool> operator!=(const valarray<T>& x, const T& y);
290template<class T> valarray<bool> operator!=(const T& x, const valarray<T>& y);
291
292template<class T> valarray<bool> operator< (const valarray<T>& x, const valarray<T>& y);
293template<class T> valarray<bool> operator< (const valarray<T>& x, const T& y);
294template<class T> valarray<bool> operator< (const T& x, const valarray<T>& y);
295
296template<class T> valarray<bool> operator> (const valarray<T>& x, const valarray<T>& y);
297template<class T> valarray<bool> operator> (const valarray<T>& x, const T& y);
298template<class T> valarray<bool> operator> (const T& x, const valarray<T>& y);
299
300template<class T> valarray<bool> operator<=(const valarray<T>& x, const valarray<T>& y);
301template<class T> valarray<bool> operator<=(const valarray<T>& x, const T& y);
302template<class T> valarray<bool> operator<=(const T& x, const valarray<T>& y);
303
304template<class T> valarray<bool> operator>=(const valarray<T>& x, const valarray<T>& y);
305template<class T> valarray<bool> operator>=(const valarray<T>& x, const T& y);
306template<class T> valarray<bool> operator>=(const T& x, const valarray<T>& y);
307
308template<class T> valarray<T> abs (const valarray<T>& x);
309template<class T> valarray<T> acos (const valarray<T>& x);
310template<class T> valarray<T> asin (const valarray<T>& x);
311template<class T> valarray<T> atan (const valarray<T>& x);
312
313template<class T> valarray<T> atan2(const valarray<T>& x, const valarray<T>& y);
314template<class T> valarray<T> atan2(const valarray<T>& x, const T& y);
315template<class T> valarray<T> atan2(const T& x, const valarray<T>& y);
316
317template<class T> valarray<T> cos (const valarray<T>& x);
318template<class T> valarray<T> cosh (const valarray<T>& x);
319template<class T> valarray<T> exp (const valarray<T>& x);
320template<class T> valarray<T> log (const valarray<T>& x);
321template<class T> valarray<T> log10(const valarray<T>& x);
322
323template<class T> valarray<T> pow(const valarray<T>& x, const valarray<T>& y);
324template<class T> valarray<T> pow(const valarray<T>& x, const T& y);
325template<class T> valarray<T> pow(const T& x, const valarray<T>& y);
326
327template<class T> valarray<T> sin (const valarray<T>& x);
328template<class T> valarray<T> sinh (const valarray<T>& x);
329template<class T> valarray<T> sqrt (const valarray<T>& x);
330template<class T> valarray<T> tan (const valarray<T>& x);
331template<class T> valarray<T> tanh (const valarray<T>& x);
332
333template <class T> unspecified1 begin(valarray<T>& v);
334template <class T> unspecified2 begin(const valarray<T>& v);
335template <class T> unspecified1 end(valarray<T>& v);
336template <class T> unspecified2 end(const valarray<T>& v);
337
338} // std
339
340*/
341
342#include <__config>
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
Howard Hinnant33be35e2012-09-14 00:39:16 +0000357template<class _Tp> class _LIBCPP_VISIBLE valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000358
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
Howard Hinnant33be35e2012-09-14 00:39:16 +0000384template <class _Tp> class _LIBCPP_VISIBLE slice_array;
385class _LIBCPP_VISIBLE gslice;
386template <class _Tp> class _LIBCPP_VISIBLE gslice_array;
387template <class _Tp> class _LIBCPP_VISIBLE mask_array;
388template <class _Tp> class _LIBCPP_VISIBLE indirect_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000389
390template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000391_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000392_Tp*
393begin(valarray<_Tp>& __v);
394
395template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000396_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397const _Tp*
398begin(const valarray<_Tp>& __v);
399
400template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000401_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402_Tp*
403end(valarray<_Tp>& __v);
404
405template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000406_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000407const _Tp*
408end(const valarray<_Tp>& __v);
409
410template <class _Op, class _A0>
411struct _UnaryOp
412{
413 typedef typename _Op::result_type result_type;
414 typedef typename _A0::value_type value_type;
415
416 _Op __op_;
417 _A0 __a0_;
418
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000419 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000420 _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {}
421
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000423 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
424
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000425 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000426 size_t size() const {return __a0_.size();}
427};
428
429template <class _Op, class _A0, class _A1>
430struct _BinaryOp
431{
432 typedef typename _Op::result_type result_type;
433 typedef typename _A0::value_type value_type;
434
435 _Op __op_;
436 _A0 __a0_;
437 _A1 __a1_;
438
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000439 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000440 _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1)
441 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
442
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000444 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
445
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000446 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000447 size_t size() const {return __a0_.size();}
448};
449
450template <class _Tp>
451class __scalar_expr
452{
453public:
454 typedef _Tp value_type;
455 typedef const _Tp& result_type;
456private:
457 const value_type& __t_;
458 size_t __s_;
459public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000460 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000461 explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {}
462
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000464 result_type operator[](size_t) const {return __t_;}
465
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000467 size_t size() const {return __s_;}
468};
469
470template <class _Tp>
471struct __unary_plus : unary_function<_Tp, _Tp>
472{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000474 _Tp operator()(const _Tp& __x) const
475 {return +__x;}
476};
477
478template <class _Tp>
479struct __bit_not : unary_function<_Tp, _Tp>
480{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000482 _Tp operator()(const _Tp& __x) const
483 {return ~__x;}
484};
485
486template <class _Tp>
487struct __bit_shift_left : binary_function<_Tp, _Tp, _Tp>
488{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000489 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000490 _Tp operator()(const _Tp& __x, const _Tp& __y) const
491 {return __x << __y;}
492};
493
494template <class _Tp>
495struct __bit_shift_right : binary_function<_Tp, _Tp, _Tp>
496{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000498 _Tp operator()(const _Tp& __x, const _Tp& __y) const
499 {return __x >> __y;}
500};
501
Howard Hinnant99968442011-11-29 18:15:50 +0000502template <class _Tp, class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000503struct __apply_expr : unary_function<_Tp, _Tp>
504{
505private:
Howard Hinnant99968442011-11-29 18:15:50 +0000506 _Fp __f_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000507public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +0000509 explicit __apply_expr(_Fp __f) : __f_(__f) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000510
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000512 _Tp operator()(const _Tp& __x) const
513 {return __f_(__x);}
514};
515
516template <class _Tp>
517struct __abs_expr : unary_function<_Tp, _Tp>
518{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000520 _Tp operator()(const _Tp& __x) const
521 {return abs(__x);}
522};
523
524template <class _Tp>
525struct __acos_expr : unary_function<_Tp, _Tp>
526{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528 _Tp operator()(const _Tp& __x) const
529 {return acos(__x);}
530};
531
532template <class _Tp>
533struct __asin_expr : unary_function<_Tp, _Tp>
534{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000536 _Tp operator()(const _Tp& __x) const
537 {return asin(__x);}
538};
539
540template <class _Tp>
541struct __atan_expr : unary_function<_Tp, _Tp>
542{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000544 _Tp operator()(const _Tp& __x) const
545 {return atan(__x);}
546};
547
548template <class _Tp>
549struct __atan2_expr : binary_function<_Tp, _Tp, _Tp>
550{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000552 _Tp operator()(const _Tp& __x, const _Tp& __y) const
553 {return atan2(__x, __y);}
554};
555
556template <class _Tp>
557struct __cos_expr : unary_function<_Tp, _Tp>
558{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000560 _Tp operator()(const _Tp& __x) const
561 {return cos(__x);}
562};
563
564template <class _Tp>
565struct __cosh_expr : unary_function<_Tp, _Tp>
566{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000568 _Tp operator()(const _Tp& __x) const
569 {return cosh(__x);}
570};
571
572template <class _Tp>
573struct __exp_expr : unary_function<_Tp, _Tp>
574{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000576 _Tp operator()(const _Tp& __x) const
577 {return exp(__x);}
578};
579
580template <class _Tp>
581struct __log_expr : unary_function<_Tp, _Tp>
582{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000584 _Tp operator()(const _Tp& __x) const
585 {return log(__x);}
586};
587
588template <class _Tp>
589struct __log10_expr : unary_function<_Tp, _Tp>
590{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000592 _Tp operator()(const _Tp& __x) const
593 {return log10(__x);}
594};
595
596template <class _Tp>
597struct __pow_expr : binary_function<_Tp, _Tp, _Tp>
598{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000600 _Tp operator()(const _Tp& __x, const _Tp& __y) const
601 {return pow(__x, __y);}
602};
603
604template <class _Tp>
605struct __sin_expr : unary_function<_Tp, _Tp>
606{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000608 _Tp operator()(const _Tp& __x) const
609 {return sin(__x);}
610};
611
612template <class _Tp>
613struct __sinh_expr : unary_function<_Tp, _Tp>
614{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000615 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000616 _Tp operator()(const _Tp& __x) const
617 {return sinh(__x);}
618};
619
620template <class _Tp>
621struct __sqrt_expr : unary_function<_Tp, _Tp>
622{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000624 _Tp operator()(const _Tp& __x) const
625 {return sqrt(__x);}
626};
627
628template <class _Tp>
629struct __tan_expr : unary_function<_Tp, _Tp>
630{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000632 _Tp operator()(const _Tp& __x) const
633 {return tan(__x);}
634};
635
636template <class _Tp>
637struct __tanh_expr : unary_function<_Tp, _Tp>
638{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000640 _Tp operator()(const _Tp& __x) const
641 {return tanh(__x);}
642};
643
644template <class _ValExpr>
645class __slice_expr
646{
647 typedef typename remove_reference<_ValExpr>::type _RmExpr;
648public:
649 typedef typename _RmExpr::value_type value_type;
650 typedef value_type result_type;
651
652private:
653 _ValExpr __expr_;
654 size_t __start_;
655 size_t __size_;
656 size_t __stride_;
657
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000658 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000659 __slice_expr(const slice& __sl, const _RmExpr& __e)
660 : __expr_(__e),
661 __start_(__sl.start()),
662 __size_(__sl.size()),
663 __stride_(__sl.stride())
664 {}
665public:
666
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000667 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668 result_type operator[](size_t __i) const
669 {return __expr_[__start_ + __i * __stride_];}
670
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000671 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000672 size_t size() const {return __size_;}
673
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000674 template <class> friend class _LIBCPP_VISIBLE valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000675};
676
677template <class _ValExpr>
678class __mask_expr;
679
680template <class _ValExpr>
681class __indirect_expr;
682
683template <class _ValExpr>
684class __shift_expr
685{
686 typedef typename remove_reference<_ValExpr>::type _RmExpr;
687public:
688 typedef typename _RmExpr::value_type value_type;
689 typedef value_type result_type;
690
691private:
692 _ValExpr __expr_;
693 size_t __size_;
694 ptrdiff_t __ul_;
695 ptrdiff_t __sn_;
696 ptrdiff_t __n_;
Howard Hinnant99968442011-11-29 18:15:50 +0000697 static const ptrdiff_t _Np = static_cast<ptrdiff_t>(
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000698 sizeof(ptrdiff_t) * __CHAR_BIT__ - 1);
699
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000700 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000701 __shift_expr(int __n, const _RmExpr& __e)
702 : __expr_(__e),
703 __size_(__e.size()),
704 __n_(__n)
705 {
Howard Hinnant99968442011-11-29 18:15:50 +0000706 ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _Np);
707 __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _Np);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708 __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n);
709 }
710public:
711
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713 result_type operator[](size_t __j) const
714 {
Howard Hinnantec3773c2011-12-01 20:21:04 +0000715 ptrdiff_t __i = static_cast<ptrdiff_t>(__j);
Howard Hinnant99968442011-11-29 18:15:50 +0000716 ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000717 return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
718 }
719
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000720 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000721 size_t size() const {return __size_;}
722
723 template <class> friend class __val_expr;
724};
725
726template <class _ValExpr>
727class __cshift_expr
728{
729 typedef typename remove_reference<_ValExpr>::type _RmExpr;
730public:
731 typedef typename _RmExpr::value_type value_type;
732 typedef value_type result_type;
733
734private:
735 _ValExpr __expr_;
736 size_t __size_;
737 size_t __m_;
738 size_t __o1_;
739 size_t __o2_;
740
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000741 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000742 __cshift_expr(int __n, const _RmExpr& __e)
743 : __expr_(__e),
744 __size_(__e.size())
745 {
746 __n %= static_cast<int>(__size_);
747 if (__n >= 0)
748 {
749 __m_ = __size_ - __n;
750 __o1_ = __n;
751 __o2_ = __n - __size_;
752 }
753 else
754 {
755 __m_ = -__n;
756 __o1_ = __n + __size_;
757 __o2_ = __n;
758 }
759 }
760public:
761
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000762 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000763 result_type operator[](size_t __i) const
764 {
765 if (__i < __m_)
766 return __expr_[__i + __o1_];
767 return __expr_[__i + __o2_];
768 }
769
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000770 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000771 size_t size() const {return __size_;}
772
773 template <class> friend class __val_expr;
774};
775
776template<class _ValExpr>
777class __val_expr;
778
779template<class _ValExpr>
780struct __is_val_expr : false_type {};
781
782template<class _ValExpr>
783struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
784
785template<class _Tp>
786struct __is_val_expr<valarray<_Tp> > : true_type {};
787
788template<class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000789class _LIBCPP_VISIBLE valarray
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000790{
791public:
792 typedef _Tp value_type;
793 typedef _Tp result_type;
794
795private:
796 value_type* __begin_;
797 value_type* __end_;
798
799public:
800 // construct/destroy:
Douglas Gregor0855dde2012-05-19 07:14:17 +0000801 _LIBCPP_INLINE_VISIBILITY
802 valarray() : __begin_(0), __end_(0) {}
803 explicit valarray(size_t __n);
804 valarray(const value_type& __x, size_t __n);
805 valarray(const value_type* __p, size_t __n);
806 valarray(const valarray& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000807#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbd143082012-07-21 00:51:28 +0000808 valarray(valarray&& __v) _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000809#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000810#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Douglas Gregor0855dde2012-05-19 07:14:17 +0000811 valarray(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +0000812#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Douglas Gregor0855dde2012-05-19 07:14:17 +0000813 valarray(const slice_array<value_type>& __sa);
814 valarray(const gslice_array<value_type>& __ga);
815 valarray(const mask_array<value_type>& __ma);
816 valarray(const indirect_array<value_type>& __ia);
817 ~valarray();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000818
819 // assignment:
Douglas Gregor0855dde2012-05-19 07:14:17 +0000820 valarray& operator=(const valarray& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000821#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbd143082012-07-21 00:51:28 +0000822 valarray& operator=(valarray&& __v) _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000823#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000824#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Douglas Gregor0855dde2012-05-19 07:14:17 +0000825 valarray& operator=(initializer_list<value_type>);
Howard Hinnante3e32912011-08-12 21:56:02 +0000826#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Douglas Gregor0855dde2012-05-19 07:14:17 +0000827 valarray& operator=(const value_type& __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000828 valarray& operator=(const slice_array<value_type>& __sa);
829 valarray& operator=(const gslice_array<value_type>& __ga);
830 valarray& operator=(const mask_array<value_type>& __ma);
831 valarray& operator=(const indirect_array<value_type>& __ia);
Howard Hinnantdb866632011-07-27 23:19:59 +0000832 template <class _ValExpr>
833 valarray& operator=(const __val_expr<_ValExpr>& __v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000834
835 // element access:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000837 const value_type& operator[](size_t __i) const {return __begin_[__i];}
838
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000839 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000840 value_type& operator[](size_t __i) {return __begin_[__i];}
841
842 // subset operations:
843 __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const;
844 slice_array<value_type> operator[](slice __s);
845 __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
846 gslice_array<value_type> operator[](const gslice& __gs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000847#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000848 __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
849 gslice_array<value_type> operator[](gslice&& __gs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000850#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000851 __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const;
852 mask_array<value_type> operator[](const valarray<bool>& __vb);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000853#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000854 __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const;
855 mask_array<value_type> operator[](valarray<bool>&& __vb);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000856#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000857 __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
858 indirect_array<value_type> operator[](const valarray<size_t>& __vs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000859#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000860 __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
861 indirect_array<value_type> operator[](valarray<size_t>&& __vs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000862#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000863
864 // unary operators:
Douglas Gregor0855dde2012-05-19 07:14:17 +0000865 valarray operator+() const;
866 valarray operator-() const;
867 valarray operator~() const;
868 valarray<bool> operator!() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000869
870 // computed assignment:
871 valarray& operator*= (const value_type& __x);
872 valarray& operator/= (const value_type& __x);
873 valarray& operator%= (const value_type& __x);
874 valarray& operator+= (const value_type& __x);
875 valarray& operator-= (const value_type& __x);
876 valarray& operator^= (const value_type& __x);
877 valarray& operator&= (const value_type& __x);
878 valarray& operator|= (const value_type& __x);
879 valarray& operator<<=(const value_type& __x);
880 valarray& operator>>=(const value_type& __x);
881
882 template <class _Expr>
883 typename enable_if
884 <
885 __is_val_expr<_Expr>::value,
886 valarray&
887 >::type
888 operator*= (const _Expr& __v);
889
890 template <class _Expr>
891 typename enable_if
892 <
893 __is_val_expr<_Expr>::value,
894 valarray&
895 >::type
896 operator/= (const _Expr& __v);
897
898 template <class _Expr>
899 typename enable_if
900 <
901 __is_val_expr<_Expr>::value,
902 valarray&
903 >::type
904 operator%= (const _Expr& __v);
905
906 template <class _Expr>
907 typename enable_if
908 <
909 __is_val_expr<_Expr>::value,
910 valarray&
911 >::type
912 operator+= (const _Expr& __v);
913
914 template <class _Expr>
915 typename enable_if
916 <
917 __is_val_expr<_Expr>::value,
918 valarray&
919 >::type
920 operator-= (const _Expr& __v);
921
922 template <class _Expr>
923 typename enable_if
924 <
925 __is_val_expr<_Expr>::value,
926 valarray&
927 >::type
928 operator^= (const _Expr& __v);
929
930 template <class _Expr>
931 typename enable_if
932 <
933 __is_val_expr<_Expr>::value,
934 valarray&
935 >::type
936 operator|= (const _Expr& __v);
937
938 template <class _Expr>
939 typename enable_if
940 <
941 __is_val_expr<_Expr>::value,
942 valarray&
943 >::type
944 operator&= (const _Expr& __v);
945
946 template <class _Expr>
947 typename enable_if
948 <
949 __is_val_expr<_Expr>::value,
950 valarray&
951 >::type
952 operator<<= (const _Expr& __v);
953
954 template <class _Expr>
955 typename enable_if
956 <
957 __is_val_expr<_Expr>::value,
958 valarray&
959 >::type
960 operator>>= (const _Expr& __v);
961
962 // member functions:
Howard Hinnantbd143082012-07-21 00:51:28 +0000963 void swap(valarray& __v) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000964
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000965 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +0000966 size_t size() const {return static_cast<size_t>(__end_ - __begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000967
Douglas Gregor0855dde2012-05-19 07:14:17 +0000968 value_type sum() const;
969 value_type min() const;
970 value_type max() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000971
Douglas Gregor0855dde2012-05-19 07:14:17 +0000972 valarray shift (int __i) const;
973 valarray cshift(int __i) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000974 valarray apply(value_type __f(value_type)) const;
975 valarray apply(value_type __f(const value_type&)) const;
976 void resize(size_t __n, value_type __x = value_type());
977
978private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000979 template <class> friend class _LIBCPP_VISIBLE valarray;
980 template <class> friend class _LIBCPP_VISIBLE slice_array;
981 template <class> friend class _LIBCPP_VISIBLE gslice_array;
982 template <class> friend class _LIBCPP_VISIBLE mask_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000983 template <class> friend class __mask_expr;
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000984 template <class> friend class _LIBCPP_VISIBLE indirect_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000985 template <class> friend class __indirect_expr;
986 template <class> friend class __val_expr;
987
988 template <class _Up>
989 friend
990 _Up*
991 begin(valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +0000992
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000993 template <class _Up>
994 friend
995 const _Up*
996 begin(const valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +0000997
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000998 template <class _Up>
999 friend
1000 _Up*
1001 end(valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +00001002
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001003 template <class _Up>
1004 friend
1005 const _Up*
1006 end(const valarray<_Up>& __v);
1007};
1008
1009template <class _Op, class _Tp>
1010struct _UnaryOp<_Op, valarray<_Tp> >
1011{
1012 typedef typename _Op::result_type result_type;
1013 typedef _Tp value_type;
1014
1015 _Op __op_;
1016 const valarray<_Tp>& __a0_;
1017
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001018 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001019 _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
1020
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001021 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001022 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
1023
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001024 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001025 size_t size() const {return __a0_.size();}
1026};
1027
1028template <class _Op, class _Tp, class _A1>
1029struct _BinaryOp<_Op, valarray<_Tp>, _A1>
1030{
1031 typedef typename _Op::result_type result_type;
1032 typedef _Tp value_type;
1033
1034 _Op __op_;
1035 const valarray<_Tp>& __a0_;
1036 _A1 __a1_;
1037
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001038 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001039 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
1040 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1041
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001042 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001043 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1044
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001045 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001046 size_t size() const {return __a0_.size();}
1047};
1048
1049template <class _Op, class _A0, class _Tp>
1050struct _BinaryOp<_Op, _A0, valarray<_Tp> >
1051{
1052 typedef typename _Op::result_type result_type;
1053 typedef _Tp value_type;
1054
1055 _Op __op_;
1056 _A0 __a0_;
1057 const valarray<_Tp>& __a1_;
1058
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001059 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001060 _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
1061 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1062
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001063 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001064 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1065
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001066 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001067 size_t size() const {return __a0_.size();}
1068};
1069
1070template <class _Op, class _Tp>
1071struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> >
1072{
1073 typedef typename _Op::result_type result_type;
1074 typedef _Tp value_type;
1075
1076 _Op __op_;
1077 const valarray<_Tp>& __a0_;
1078 const valarray<_Tp>& __a1_;
1079
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001081 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
1082 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1083
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001084 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001085 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1086
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001087 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001088 size_t size() const {return __a0_.size();}
1089};
1090
1091// slice_array
1092
1093template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001094class _LIBCPP_VISIBLE slice_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001095{
1096public:
1097 typedef _Tp value_type;
1098
1099private:
1100 value_type* __vp_;
1101 size_t __size_;
1102 size_t __stride_;
1103
1104public:
1105 template <class _Expr>
1106 typename enable_if
1107 <
1108 __is_val_expr<_Expr>::value,
1109 void
1110 >::type
1111 operator=(const _Expr& __v) const;
1112
1113 template <class _Expr>
1114 typename enable_if
1115 <
1116 __is_val_expr<_Expr>::value,
1117 void
1118 >::type
1119 operator*=(const _Expr& __v) const;
1120
1121 template <class _Expr>
1122 typename enable_if
1123 <
1124 __is_val_expr<_Expr>::value,
1125 void
1126 >::type
1127 operator/=(const _Expr& __v) const;
1128
1129 template <class _Expr>
1130 typename enable_if
1131 <
1132 __is_val_expr<_Expr>::value,
1133 void
1134 >::type
1135 operator%=(const _Expr& __v) const;
1136
1137 template <class _Expr>
1138 typename enable_if
1139 <
1140 __is_val_expr<_Expr>::value,
1141 void
1142 >::type
1143 operator+=(const _Expr& __v) const;
1144
1145 template <class _Expr>
1146 typename enable_if
1147 <
1148 __is_val_expr<_Expr>::value,
1149 void
1150 >::type
1151 operator-=(const _Expr& __v) const;
1152
1153 template <class _Expr>
1154 typename enable_if
1155 <
1156 __is_val_expr<_Expr>::value,
1157 void
1158 >::type
1159 operator^=(const _Expr& __v) const;
1160
1161 template <class _Expr>
1162 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>
1170 typename enable_if
1171 <
1172 __is_val_expr<_Expr>::value,
1173 void
1174 >::type
1175 operator|=(const _Expr& __v) const;
1176
1177 template <class _Expr>
1178 typename enable_if
1179 <
1180 __is_val_expr<_Expr>::value,
1181 void
1182 >::type
1183 operator<<=(const _Expr& __v) const;
1184
1185 template <class _Expr>
1186 typename enable_if
1187 <
1188 __is_val_expr<_Expr>::value,
1189 void
1190 >::type
1191 operator>>=(const _Expr& __v) const;
1192
1193 const slice_array& operator=(const slice_array& __sa) const;
1194
1195 void operator=(const value_type& __x) const;
1196
1197private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001198 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001199 slice_array(const slice& __sl, const valarray<value_type>& __v)
1200 : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())),
1201 __size_(__sl.size()),
1202 __stride_(__sl.stride())
1203 {}
1204
1205 template <class> friend class valarray;
1206 template <class> friend class sliceExpr;
1207};
1208
1209template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001210inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001211const slice_array<_Tp>&
1212slice_array<_Tp>::operator=(const slice_array& __sa) const
1213{
1214 value_type* __t = __vp_;
1215 const value_type* __s = __sa.__vp_;
1216 for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
1217 *__t = *__s;
1218}
1219
1220template <class _Tp>
1221template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001222inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001223typename enable_if
1224<
1225 __is_val_expr<_Expr>::value,
1226 void
1227>::type
1228slice_array<_Tp>::operator=(const _Expr& __v) const
1229{
1230 value_type* __t = __vp_;
1231 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1232 *__t = __v[__i];
1233}
1234
1235template <class _Tp>
1236template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001237inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001238typename enable_if
1239<
1240 __is_val_expr<_Expr>::value,
1241 void
1242>::type
1243slice_array<_Tp>::operator*=(const _Expr& __v) const
1244{
1245 value_type* __t = __vp_;
1246 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1247 *__t *= __v[__i];
1248}
1249
1250template <class _Tp>
1251template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001252inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001253typename enable_if
1254<
1255 __is_val_expr<_Expr>::value,
1256 void
1257>::type
1258slice_array<_Tp>::operator/=(const _Expr& __v) const
1259{
1260 value_type* __t = __vp_;
1261 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1262 *__t /= __v[__i];
1263}
1264
1265template <class _Tp>
1266template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001267inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001268typename enable_if
1269<
1270 __is_val_expr<_Expr>::value,
1271 void
1272>::type
1273slice_array<_Tp>::operator%=(const _Expr& __v) const
1274{
1275 value_type* __t = __vp_;
1276 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1277 *__t %= __v[__i];
1278}
1279
1280template <class _Tp>
1281template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001282inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001283typename enable_if
1284<
1285 __is_val_expr<_Expr>::value,
1286 void
1287>::type
1288slice_array<_Tp>::operator+=(const _Expr& __v) const
1289{
1290 value_type* __t = __vp_;
1291 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1292 *__t += __v[__i];
1293}
1294
1295template <class _Tp>
1296template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001297inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001298typename enable_if
1299<
1300 __is_val_expr<_Expr>::value,
1301 void
1302>::type
1303slice_array<_Tp>::operator-=(const _Expr& __v) const
1304{
1305 value_type* __t = __vp_;
1306 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1307 *__t -= __v[__i];
1308}
1309
1310template <class _Tp>
1311template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001312inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001313typename enable_if
1314<
1315 __is_val_expr<_Expr>::value,
1316 void
1317>::type
1318slice_array<_Tp>::operator^=(const _Expr& __v) const
1319{
1320 value_type* __t = __vp_;
1321 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1322 *__t ^= __v[__i];
1323}
1324
1325template <class _Tp>
1326template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001327inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001328typename enable_if
1329<
1330 __is_val_expr<_Expr>::value,
1331 void
1332>::type
1333slice_array<_Tp>::operator&=(const _Expr& __v) const
1334{
1335 value_type* __t = __vp_;
1336 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1337 *__t &= __v[__i];
1338}
1339
1340template <class _Tp>
1341template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001342inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001343typename enable_if
1344<
1345 __is_val_expr<_Expr>::value,
1346 void
1347>::type
1348slice_array<_Tp>::operator|=(const _Expr& __v) const
1349{
1350 value_type* __t = __vp_;
1351 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1352 *__t |= __v[__i];
1353}
1354
1355template <class _Tp>
1356template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001357inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001358typename enable_if
1359<
1360 __is_val_expr<_Expr>::value,
1361 void
1362>::type
1363slice_array<_Tp>::operator<<=(const _Expr& __v) const
1364{
1365 value_type* __t = __vp_;
1366 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1367 *__t <<= __v[__i];
1368}
1369
1370template <class _Tp>
1371template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001372inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001373typename enable_if
1374<
1375 __is_val_expr<_Expr>::value,
1376 void
1377>::type
1378slice_array<_Tp>::operator>>=(const _Expr& __v) const
1379{
1380 value_type* __t = __vp_;
1381 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1382 *__t >>= __v[__i];
1383}
1384
1385template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001386inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001387void
1388slice_array<_Tp>::operator=(const value_type& __x) const
1389{
1390 value_type* __t = __vp_;
1391 for (size_t __n = __size_; __n; --__n, __t += __stride_)
1392 *__t = __x;
1393}
1394
1395// gslice
1396
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001397class _LIBCPP_VISIBLE gslice
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001398{
1399 valarray<size_t> __size_;
1400 valarray<size_t> __stride_;
1401 valarray<size_t> __1d_;
Howard Hinnant324bb032010-08-22 00:02:43 +00001402
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001403public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001404 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001405 gslice() {}
Douglas Gregor0855dde2012-05-19 07:14:17 +00001406
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001407 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001408 gslice(size_t __start, const valarray<size_t>& __size,
1409 const valarray<size_t>& __stride)
1410 : __size_(__size),
1411 __stride_(__stride)
1412 {__init(__start);}
1413
Howard Hinnant73d21a42010-09-04 23:28:19 +00001414#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001415
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001416 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001417 gslice(size_t __start, const valarray<size_t>& __size,
1418 valarray<size_t>&& __stride)
1419 : __size_(__size),
1420 __stride_(move(__stride))
1421 {__init(__start);}
1422
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001423 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001424 gslice(size_t __start, valarray<size_t>&& __size,
1425 const valarray<size_t>& __stride)
1426 : __size_(move(__size)),
1427 __stride_(__stride)
1428 {__init(__start);}
1429
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001430 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001431 gslice(size_t __start, valarray<size_t>&& __size,
1432 valarray<size_t>&& __stride)
1433 : __size_(move(__size)),
1434 __stride_(move(__stride))
1435 {__init(__start);}
1436
Howard Hinnant73d21a42010-09-04 23:28:19 +00001437#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001438
1439// gslice(const gslice&) = default;
1440// gslice(gslice&&) = default;
1441// gslice& operator=(const gslice&) = default;
1442// gslice& operator=(gslice&&) = default;
1443
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001444 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001445 size_t start() const {return __1d_.size() ? __1d_[0] : 0;}
1446
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001447 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001448 valarray<size_t> size() const {return __size_;}
1449
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001451 valarray<size_t> stride() const {return __stride_;}
1452
1453private:
1454 void __init(size_t __start);
1455
1456 template <class> friend class gslice_array;
1457 template <class> friend class valarray;
1458 template <class> friend class __val_expr;
1459};
1460
1461// gslice_array
1462
1463template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001464class _LIBCPP_VISIBLE gslice_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001465{
1466public:
1467 typedef _Tp value_type;
1468
1469private:
1470 value_type* __vp_;
1471 valarray<size_t> __1d_;
1472
1473public:
1474 template <class _Expr>
1475 typename enable_if
1476 <
1477 __is_val_expr<_Expr>::value,
1478 void
1479 >::type
1480 operator=(const _Expr& __v) const;
1481
1482 template <class _Expr>
1483 typename enable_if
1484 <
1485 __is_val_expr<_Expr>::value,
1486 void
1487 >::type
1488 operator*=(const _Expr& __v) const;
1489
1490 template <class _Expr>
1491 typename enable_if
1492 <
1493 __is_val_expr<_Expr>::value,
1494 void
1495 >::type
1496 operator/=(const _Expr& __v) const;
1497
1498 template <class _Expr>
1499 typename enable_if
1500 <
1501 __is_val_expr<_Expr>::value,
1502 void
1503 >::type
1504 operator%=(const _Expr& __v) const;
1505
1506 template <class _Expr>
1507 typename enable_if
1508 <
1509 __is_val_expr<_Expr>::value,
1510 void
1511 >::type
1512 operator+=(const _Expr& __v) const;
1513
1514 template <class _Expr>
1515 typename enable_if
1516 <
1517 __is_val_expr<_Expr>::value,
1518 void
1519 >::type
1520 operator-=(const _Expr& __v) const;
1521
1522 template <class _Expr>
1523 typename enable_if
1524 <
1525 __is_val_expr<_Expr>::value,
1526 void
1527 >::type
1528 operator^=(const _Expr& __v) const;
1529
1530 template <class _Expr>
1531 typename enable_if
1532 <
1533 __is_val_expr<_Expr>::value,
1534 void
1535 >::type
1536 operator&=(const _Expr& __v) const;
1537
1538 template <class _Expr>
1539 typename enable_if
1540 <
1541 __is_val_expr<_Expr>::value,
1542 void
1543 >::type
1544 operator|=(const _Expr& __v) const;
1545
1546 template <class _Expr>
1547 typename enable_if
1548 <
1549 __is_val_expr<_Expr>::value,
1550 void
1551 >::type
1552 operator<<=(const _Expr& __v) const;
1553
1554 template <class _Expr>
1555 typename enable_if
1556 <
1557 __is_val_expr<_Expr>::value,
1558 void
1559 >::type
1560 operator>>=(const _Expr& __v) const;
1561
1562 const gslice_array& operator=(const gslice_array& __ga) const;
1563
1564 void operator=(const value_type& __x) const;
1565
1566// gslice_array(const gslice_array&) = default;
1567// gslice_array(gslice_array&&) = default;
1568// gslice_array& operator=(const gslice_array&) = default;
1569// gslice_array& operator=(gslice_array&&) = default;
1570
1571private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001572 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001573 gslice_array(const gslice& __gs, const valarray<value_type>& __v)
1574 : __vp_(const_cast<value_type*>(__v.__begin_)),
1575 __1d_(__gs.__1d_)
1576 {}
1577
Howard Hinnant73d21a42010-09-04 23:28:19 +00001578#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001579
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001581 gslice_array(gslice&& __gs, const valarray<value_type>& __v)
1582 : __vp_(const_cast<value_type*>(__v.__begin_)),
1583 __1d_(move(__gs.__1d_))
1584 {}
1585
Howard Hinnant73d21a42010-09-04 23:28:19 +00001586#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001587
1588 template <class> friend class valarray;
1589};
1590
1591template <class _Tp>
1592template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001593inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001594typename enable_if
1595<
1596 __is_val_expr<_Expr>::value,
1597 void
1598>::type
1599gslice_array<_Tp>::operator=(const _Expr& __v) const
1600{
1601 typedef const size_t* _Ip;
1602 size_t __j = 0;
1603 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1604 __vp_[*__i] = __v[__j];
1605}
1606
1607template <class _Tp>
1608template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001609inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001610typename enable_if
1611<
1612 __is_val_expr<_Expr>::value,
1613 void
1614>::type
1615gslice_array<_Tp>::operator*=(const _Expr& __v) const
1616{
1617 typedef const size_t* _Ip;
1618 size_t __j = 0;
1619 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1620 __vp_[*__i] *= __v[__j];
1621}
1622
1623template <class _Tp>
1624template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001625inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001626typename enable_if
1627<
1628 __is_val_expr<_Expr>::value,
1629 void
1630>::type
1631gslice_array<_Tp>::operator/=(const _Expr& __v) const
1632{
1633 typedef const size_t* _Ip;
1634 size_t __j = 0;
1635 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1636 __vp_[*__i] /= __v[__j];
1637}
1638
1639template <class _Tp>
1640template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001641inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001642typename enable_if
1643<
1644 __is_val_expr<_Expr>::value,
1645 void
1646>::type
1647gslice_array<_Tp>::operator%=(const _Expr& __v) const
1648{
1649 typedef const size_t* _Ip;
1650 size_t __j = 0;
1651 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1652 __vp_[*__i] %= __v[__j];
1653}
1654
1655template <class _Tp>
1656template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001657inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001658typename enable_if
1659<
1660 __is_val_expr<_Expr>::value,
1661 void
1662>::type
1663gslice_array<_Tp>::operator+=(const _Expr& __v) const
1664{
1665 typedef const size_t* _Ip;
1666 size_t __j = 0;
1667 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1668 __vp_[*__i] += __v[__j];
1669}
1670
1671template <class _Tp>
1672template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001673inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001674typename enable_if
1675<
1676 __is_val_expr<_Expr>::value,
1677 void
1678>::type
1679gslice_array<_Tp>::operator-=(const _Expr& __v) const
1680{
1681 typedef const size_t* _Ip;
1682 size_t __j = 0;
1683 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1684 __vp_[*__i] -= __v[__j];
1685}
1686
1687template <class _Tp>
1688template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001689inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001690typename enable_if
1691<
1692 __is_val_expr<_Expr>::value,
1693 void
1694>::type
1695gslice_array<_Tp>::operator^=(const _Expr& __v) const
1696{
1697 typedef const size_t* _Ip;
1698 size_t __j = 0;
1699 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1700 __vp_[*__i] ^= __v[__j];
1701}
1702
1703template <class _Tp>
1704template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001705inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001706typename enable_if
1707<
1708 __is_val_expr<_Expr>::value,
1709 void
1710>::type
1711gslice_array<_Tp>::operator&=(const _Expr& __v) const
1712{
1713 typedef const size_t* _Ip;
1714 size_t __j = 0;
1715 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1716 __vp_[*__i] &= __v[__j];
1717}
1718
1719template <class _Tp>
1720template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001721inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001722typename enable_if
1723<
1724 __is_val_expr<_Expr>::value,
1725 void
1726>::type
1727gslice_array<_Tp>::operator|=(const _Expr& __v) const
1728{
1729 typedef const size_t* _Ip;
1730 size_t __j = 0;
1731 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1732 __vp_[*__i] |= __v[__j];
1733}
1734
1735template <class _Tp>
1736template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001737inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001738typename enable_if
1739<
1740 __is_val_expr<_Expr>::value,
1741 void
1742>::type
1743gslice_array<_Tp>::operator<<=(const _Expr& __v) const
1744{
1745 typedef const size_t* _Ip;
1746 size_t __j = 0;
1747 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1748 __vp_[*__i] <<= __v[__j];
1749}
1750
1751template <class _Tp>
1752template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001753inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001754typename enable_if
1755<
1756 __is_val_expr<_Expr>::value,
1757 void
1758>::type
1759gslice_array<_Tp>::operator>>=(const _Expr& __v) const
1760{
1761 typedef const size_t* _Ip;
1762 size_t __j = 0;
1763 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1764 __vp_[*__i] >>= __v[__j];
1765}
1766
1767template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001768inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001769const gslice_array<_Tp>&
1770gslice_array<_Tp>::operator=(const gslice_array& __ga) const
1771{
1772 typedef const size_t* _Ip;
1773 const value_type* __s = __ga.__vp_;
1774 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_;
1775 __i != __e; ++__i, ++__j)
1776 __vp_[*__i] = __s[*__j];
1777 return *this;
1778}
1779
1780template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001781inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001782void
1783gslice_array<_Tp>::operator=(const value_type& __x) const
1784{
1785 typedef const size_t* _Ip;
1786 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1787 __vp_[*__i] = __x;
1788}
1789
1790// mask_array
1791
1792template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001793class _LIBCPP_VISIBLE mask_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001794{
1795public:
1796 typedef _Tp value_type;
1797
1798private:
1799 value_type* __vp_;
1800 valarray<size_t> __1d_;
1801
1802public:
1803 template <class _Expr>
1804 typename enable_if
1805 <
1806 __is_val_expr<_Expr>::value,
1807 void
1808 >::type
1809 operator=(const _Expr& __v) const;
1810
1811 template <class _Expr>
1812 typename enable_if
1813 <
1814 __is_val_expr<_Expr>::value,
1815 void
1816 >::type
1817 operator*=(const _Expr& __v) const;
1818
1819 template <class _Expr>
1820 typename enable_if
1821 <
1822 __is_val_expr<_Expr>::value,
1823 void
1824 >::type
1825 operator/=(const _Expr& __v) const;
1826
1827 template <class _Expr>
1828 typename enable_if
1829 <
1830 __is_val_expr<_Expr>::value,
1831 void
1832 >::type
1833 operator%=(const _Expr& __v) const;
1834
1835 template <class _Expr>
1836 typename enable_if
1837 <
1838 __is_val_expr<_Expr>::value,
1839 void
1840 >::type
1841 operator+=(const _Expr& __v) const;
1842
1843 template <class _Expr>
1844 typename enable_if
1845 <
1846 __is_val_expr<_Expr>::value,
1847 void
1848 >::type
1849 operator-=(const _Expr& __v) const;
1850
1851 template <class _Expr>
1852 typename enable_if
1853 <
1854 __is_val_expr<_Expr>::value,
1855 void
1856 >::type
1857 operator^=(const _Expr& __v) const;
1858
1859 template <class _Expr>
1860 typename enable_if
1861 <
1862 __is_val_expr<_Expr>::value,
1863 void
1864 >::type
1865 operator&=(const _Expr& __v) const;
1866
1867 template <class _Expr>
1868 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>
1876 typename enable_if
1877 <
1878 __is_val_expr<_Expr>::value,
1879 void
1880 >::type
1881 operator<<=(const _Expr& __v) const;
1882
1883 template <class _Expr>
1884 typename enable_if
1885 <
1886 __is_val_expr<_Expr>::value,
1887 void
1888 >::type
1889 operator>>=(const _Expr& __v) const;
1890
1891 const mask_array& operator=(const mask_array& __ma) const;
1892
1893 void operator=(const value_type& __x) const;
1894
1895// mask_array(const mask_array&) = default;
1896// mask_array(mask_array&&) = default;
1897// mask_array& operator=(const mask_array&) = default;
1898// mask_array& operator=(mask_array&&) = default;
1899
1900private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001902 mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
1903 : __vp_(const_cast<value_type*>(__v.__begin_)),
Howard Hinnantec3773c2011-12-01 20:21:04 +00001904 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001905 {
1906 size_t __j = 0;
1907 for (size_t __i = 0; __i < __vb.size(); ++__i)
1908 if (__vb[__i])
1909 __1d_[__j++] = __i;
1910 }
1911
1912 template <class> friend class valarray;
1913};
1914
1915template <class _Tp>
1916template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001917inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001918typename enable_if
1919<
1920 __is_val_expr<_Expr>::value,
1921 void
1922>::type
1923mask_array<_Tp>::operator=(const _Expr& __v) const
1924{
1925 size_t __n = __1d_.size();
1926 for (size_t __i = 0; __i < __n; ++__i)
1927 __vp_[__1d_[__i]] = __v[__i];
1928}
1929
1930template <class _Tp>
1931template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001932inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001933typename enable_if
1934<
1935 __is_val_expr<_Expr>::value,
1936 void
1937>::type
1938mask_array<_Tp>::operator*=(const _Expr& __v) const
1939{
1940 size_t __n = __1d_.size();
1941 for (size_t __i = 0; __i < __n; ++__i)
1942 __vp_[__1d_[__i]] *= __v[__i];
1943}
1944
1945template <class _Tp>
1946template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001947inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001948typename enable_if
1949<
1950 __is_val_expr<_Expr>::value,
1951 void
1952>::type
1953mask_array<_Tp>::operator/=(const _Expr& __v) const
1954{
1955 size_t __n = __1d_.size();
1956 for (size_t __i = 0; __i < __n; ++__i)
1957 __vp_[__1d_[__i]] /= __v[__i];
1958}
1959
1960template <class _Tp>
1961template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001962inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001963typename enable_if
1964<
1965 __is_val_expr<_Expr>::value,
1966 void
1967>::type
1968mask_array<_Tp>::operator%=(const _Expr& __v) const
1969{
1970 size_t __n = __1d_.size();
1971 for (size_t __i = 0; __i < __n; ++__i)
1972 __vp_[__1d_[__i]] %= __v[__i];
1973}
1974
1975template <class _Tp>
1976template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001977inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001978typename enable_if
1979<
1980 __is_val_expr<_Expr>::value,
1981 void
1982>::type
1983mask_array<_Tp>::operator+=(const _Expr& __v) const
1984{
1985 size_t __n = __1d_.size();
1986 for (size_t __i = 0; __i < __n; ++__i)
1987 __vp_[__1d_[__i]] += __v[__i];
1988}
1989
1990template <class _Tp>
1991template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001992inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001993typename enable_if
1994<
1995 __is_val_expr<_Expr>::value,
1996 void
1997>::type
1998mask_array<_Tp>::operator-=(const _Expr& __v) const
1999{
2000 size_t __n = __1d_.size();
2001 for (size_t __i = 0; __i < __n; ++__i)
2002 __vp_[__1d_[__i]] -= __v[__i];
2003}
2004
2005template <class _Tp>
2006template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002007inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002008typename enable_if
2009<
2010 __is_val_expr<_Expr>::value,
2011 void
2012>::type
2013mask_array<_Tp>::operator^=(const _Expr& __v) const
2014{
2015 size_t __n = __1d_.size();
2016 for (size_t __i = 0; __i < __n; ++__i)
2017 __vp_[__1d_[__i]] ^= __v[__i];
2018}
2019
2020template <class _Tp>
2021template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002022inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002023typename enable_if
2024<
2025 __is_val_expr<_Expr>::value,
2026 void
2027>::type
2028mask_array<_Tp>::operator&=(const _Expr& __v) const
2029{
2030 size_t __n = __1d_.size();
2031 for (size_t __i = 0; __i < __n; ++__i)
2032 __vp_[__1d_[__i]] &= __v[__i];
2033}
2034
2035template <class _Tp>
2036template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002037inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002038typename enable_if
2039<
2040 __is_val_expr<_Expr>::value,
2041 void
2042>::type
2043mask_array<_Tp>::operator|=(const _Expr& __v) const
2044{
2045 size_t __n = __1d_.size();
2046 for (size_t __i = 0; __i < __n; ++__i)
2047 __vp_[__1d_[__i]] |= __v[__i];
2048}
2049
2050template <class _Tp>
2051template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002052inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002053typename enable_if
2054<
2055 __is_val_expr<_Expr>::value,
2056 void
2057>::type
2058mask_array<_Tp>::operator<<=(const _Expr& __v) const
2059{
2060 size_t __n = __1d_.size();
2061 for (size_t __i = 0; __i < __n; ++__i)
2062 __vp_[__1d_[__i]] <<= __v[__i];
2063}
2064
2065template <class _Tp>
2066template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002067inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002068typename enable_if
2069<
2070 __is_val_expr<_Expr>::value,
2071 void
2072>::type
2073mask_array<_Tp>::operator>>=(const _Expr& __v) const
2074{
2075 size_t __n = __1d_.size();
2076 for (size_t __i = 0; __i < __n; ++__i)
2077 __vp_[__1d_[__i]] >>= __v[__i];
2078}
2079
2080template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002081inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002082const mask_array<_Tp>&
2083mask_array<_Tp>::operator=(const mask_array& __ma) const
2084{
2085 size_t __n = __1d_.size();
2086 for (size_t __i = 0; __i < __n; ++__i)
2087 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
2088}
2089
2090template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002091inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002092void
2093mask_array<_Tp>::operator=(const value_type& __x) const
2094{
2095 size_t __n = __1d_.size();
2096 for (size_t __i = 0; __i < __n; ++__i)
2097 __vp_[__1d_[__i]] = __x;
2098}
2099
2100template <class _ValExpr>
2101class __mask_expr
2102{
2103 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2104public:
2105 typedef typename _RmExpr::value_type value_type;
2106 typedef value_type result_type;
2107
2108private:
2109 _ValExpr __expr_;
2110 valarray<size_t> __1d_;
2111
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002112 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002113 __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
2114 : __expr_(__e),
Howard Hinnantec3773c2011-12-01 20:21:04 +00002115 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002116 {
2117 size_t __j = 0;
2118 for (size_t __i = 0; __i < __vb.size(); ++__i)
2119 if (__vb[__i])
2120 __1d_[__j++] = __i;
2121 }
2122
2123public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002124 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002125 result_type operator[](size_t __i) const
2126 {return __expr_[__1d_[__i]];}
2127
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002128 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002129 size_t size() const {return __1d_.size();}
2130
2131 template <class> friend class valarray;
2132};
2133
2134// indirect_array
2135
2136template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002137class _LIBCPP_VISIBLE indirect_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002138{
2139public:
2140 typedef _Tp value_type;
2141
2142private:
2143 value_type* __vp_;
2144 valarray<size_t> __1d_;
2145
2146public:
2147 template <class _Expr>
2148 typename enable_if
2149 <
2150 __is_val_expr<_Expr>::value,
2151 void
2152 >::type
2153 operator=(const _Expr& __v) const;
2154
2155 template <class _Expr>
2156 typename enable_if
2157 <
2158 __is_val_expr<_Expr>::value,
2159 void
2160 >::type
2161 operator*=(const _Expr& __v) const;
2162
2163 template <class _Expr>
2164 typename enable_if
2165 <
2166 __is_val_expr<_Expr>::value,
2167 void
2168 >::type
2169 operator/=(const _Expr& __v) const;
2170
2171 template <class _Expr>
2172 typename enable_if
2173 <
2174 __is_val_expr<_Expr>::value,
2175 void
2176 >::type
2177 operator%=(const _Expr& __v) const;
2178
2179 template <class _Expr>
2180 typename enable_if
2181 <
2182 __is_val_expr<_Expr>::value,
2183 void
2184 >::type
2185 operator+=(const _Expr& __v) const;
2186
2187 template <class _Expr>
2188 typename enable_if
2189 <
2190 __is_val_expr<_Expr>::value,
2191 void
2192 >::type
2193 operator-=(const _Expr& __v) const;
2194
2195 template <class _Expr>
2196 typename enable_if
2197 <
2198 __is_val_expr<_Expr>::value,
2199 void
2200 >::type
2201 operator^=(const _Expr& __v) const;
2202
2203 template <class _Expr>
2204 typename enable_if
2205 <
2206 __is_val_expr<_Expr>::value,
2207 void
2208 >::type
2209 operator&=(const _Expr& __v) const;
2210
2211 template <class _Expr>
2212 typename enable_if
2213 <
2214 __is_val_expr<_Expr>::value,
2215 void
2216 >::type
2217 operator|=(const _Expr& __v) const;
2218
2219 template <class _Expr>
2220 typename enable_if
2221 <
2222 __is_val_expr<_Expr>::value,
2223 void
2224 >::type
2225 operator<<=(const _Expr& __v) const;
2226
2227 template <class _Expr>
2228 typename enable_if
2229 <
2230 __is_val_expr<_Expr>::value,
2231 void
2232 >::type
2233 operator>>=(const _Expr& __v) const;
2234
2235 const indirect_array& operator=(const indirect_array& __ia) const;
2236
2237 void operator=(const value_type& __x) const;
2238
2239// indirect_array(const indirect_array&) = default;
2240// indirect_array(indirect_array&&) = default;
2241// indirect_array& operator=(const indirect_array&) = default;
2242// indirect_array& operator=(indirect_array&&) = default;
2243
2244private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002245 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002246 indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
2247 : __vp_(const_cast<value_type*>(__v.__begin_)),
2248 __1d_(__ia)
2249 {}
2250
Howard Hinnant73d21a42010-09-04 23:28:19 +00002251#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002252
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002254 indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
2255 : __vp_(const_cast<value_type*>(__v.__begin_)),
2256 __1d_(move(__ia))
2257 {}
2258
Howard Hinnant73d21a42010-09-04 23:28:19 +00002259#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002260
2261 template <class> friend class valarray;
2262};
2263
2264template <class _Tp>
2265template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002266inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002267typename enable_if
2268<
2269 __is_val_expr<_Expr>::value,
2270 void
2271>::type
2272indirect_array<_Tp>::operator=(const _Expr& __v) const
2273{
2274 size_t __n = __1d_.size();
2275 for (size_t __i = 0; __i < __n; ++__i)
2276 __vp_[__1d_[__i]] = __v[__i];
2277}
2278
2279template <class _Tp>
2280template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002281inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002282typename enable_if
2283<
2284 __is_val_expr<_Expr>::value,
2285 void
2286>::type
2287indirect_array<_Tp>::operator*=(const _Expr& __v) const
2288{
2289 size_t __n = __1d_.size();
2290 for (size_t __i = 0; __i < __n; ++__i)
2291 __vp_[__1d_[__i]] *= __v[__i];
2292}
2293
2294template <class _Tp>
2295template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002296inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002297typename enable_if
2298<
2299 __is_val_expr<_Expr>::value,
2300 void
2301>::type
2302indirect_array<_Tp>::operator/=(const _Expr& __v) const
2303{
2304 size_t __n = __1d_.size();
2305 for (size_t __i = 0; __i < __n; ++__i)
2306 __vp_[__1d_[__i]] /= __v[__i];
2307}
2308
2309template <class _Tp>
2310template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002311inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002312typename enable_if
2313<
2314 __is_val_expr<_Expr>::value,
2315 void
2316>::type
2317indirect_array<_Tp>::operator%=(const _Expr& __v) const
2318{
2319 size_t __n = __1d_.size();
2320 for (size_t __i = 0; __i < __n; ++__i)
2321 __vp_[__1d_[__i]] %= __v[__i];
2322}
2323
2324template <class _Tp>
2325template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002326inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002327typename enable_if
2328<
2329 __is_val_expr<_Expr>::value,
2330 void
2331>::type
2332indirect_array<_Tp>::operator+=(const _Expr& __v) const
2333{
2334 size_t __n = __1d_.size();
2335 for (size_t __i = 0; __i < __n; ++__i)
2336 __vp_[__1d_[__i]] += __v[__i];
2337}
2338
2339template <class _Tp>
2340template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002341inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002342typename enable_if
2343<
2344 __is_val_expr<_Expr>::value,
2345 void
2346>::type
2347indirect_array<_Tp>::operator-=(const _Expr& __v) const
2348{
2349 size_t __n = __1d_.size();
2350 for (size_t __i = 0; __i < __n; ++__i)
2351 __vp_[__1d_[__i]] -= __v[__i];
2352}
2353
2354template <class _Tp>
2355template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002356inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002357typename enable_if
2358<
2359 __is_val_expr<_Expr>::value,
2360 void
2361>::type
2362indirect_array<_Tp>::operator^=(const _Expr& __v) const
2363{
2364 size_t __n = __1d_.size();
2365 for (size_t __i = 0; __i < __n; ++__i)
2366 __vp_[__1d_[__i]] ^= __v[__i];
2367}
2368
2369template <class _Tp>
2370template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002371inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002372typename enable_if
2373<
2374 __is_val_expr<_Expr>::value,
2375 void
2376>::type
2377indirect_array<_Tp>::operator&=(const _Expr& __v) const
2378{
2379 size_t __n = __1d_.size();
2380 for (size_t __i = 0; __i < __n; ++__i)
2381 __vp_[__1d_[__i]] &= __v[__i];
2382}
2383
2384template <class _Tp>
2385template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002386inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002387typename enable_if
2388<
2389 __is_val_expr<_Expr>::value,
2390 void
2391>::type
2392indirect_array<_Tp>::operator|=(const _Expr& __v) const
2393{
2394 size_t __n = __1d_.size();
2395 for (size_t __i = 0; __i < __n; ++__i)
2396 __vp_[__1d_[__i]] |= __v[__i];
2397}
2398
2399template <class _Tp>
2400template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002401inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002402typename enable_if
2403<
2404 __is_val_expr<_Expr>::value,
2405 void
2406>::type
2407indirect_array<_Tp>::operator<<=(const _Expr& __v) const
2408{
2409 size_t __n = __1d_.size();
2410 for (size_t __i = 0; __i < __n; ++__i)
2411 __vp_[__1d_[__i]] <<= __v[__i];
2412}
2413
2414template <class _Tp>
2415template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002416inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002417typename enable_if
2418<
2419 __is_val_expr<_Expr>::value,
2420 void
2421>::type
2422indirect_array<_Tp>::operator>>=(const _Expr& __v) const
2423{
2424 size_t __n = __1d_.size();
2425 for (size_t __i = 0; __i < __n; ++__i)
2426 __vp_[__1d_[__i]] >>= __v[__i];
2427}
2428
2429template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002430inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002431const indirect_array<_Tp>&
2432indirect_array<_Tp>::operator=(const indirect_array& __ia) const
2433{
2434 typedef const size_t* _Ip;
2435 const value_type* __s = __ia.__vp_;
2436 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_;
2437 __i != __e; ++__i, ++__j)
2438 __vp_[*__i] = __s[*__j];
2439 return *this;
2440}
2441
2442template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002443inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002444void
2445indirect_array<_Tp>::operator=(const value_type& __x) const
2446{
2447 typedef const size_t* _Ip;
2448 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
2449 __vp_[*__i] = __x;
2450}
2451
2452template <class _ValExpr>
2453class __indirect_expr
2454{
2455 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2456public:
2457 typedef typename _RmExpr::value_type value_type;
2458 typedef value_type result_type;
2459
2460private:
2461 _ValExpr __expr_;
2462 valarray<size_t> __1d_;
2463
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002464 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002465 __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e)
2466 : __expr_(__e),
2467 __1d_(__ia)
2468 {}
2469
Howard Hinnant73d21a42010-09-04 23:28:19 +00002470#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002471
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002472 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002473 __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
2474 : __expr_(__e),
2475 __1d_(move(__ia))
2476 {}
2477
Howard Hinnant73d21a42010-09-04 23:28:19 +00002478#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002479
2480public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002482 result_type operator[](size_t __i) const
2483 {return __expr_[__1d_[__i]];}
2484
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002485 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002486 size_t size() const {return __1d_.size();}
2487
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002488 template <class> friend class _LIBCPP_VISIBLE valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002489};
2490
2491template<class _ValExpr>
2492class __val_expr
2493{
2494 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2495
2496 _ValExpr __expr_;
2497public:
2498 typedef typename _RmExpr::value_type value_type;
2499 typedef typename _RmExpr::result_type result_type;
2500
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002501 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002502 explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
2503
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002504 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002505 result_type operator[](size_t __i) const
2506 {return __expr_[__i];}
2507
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002509 __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
2510 {return __val_expr<__slice_expr<_ValExpr> >(__expr_, __s);}
2511
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002513 __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const
2514 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __gs.__1d_);}
2515
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002516 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002517 __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
2518 {return __val_expr<__mask_expr<_ValExpr> >(__expr_, __vb);}
2519
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002521 __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
2522 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __vs);}
2523
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002524 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002525 __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
2526 operator+() const
2527 {
2528 typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
2529 return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
2530 }
2531
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002532 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002533 __val_expr<_UnaryOp<negate<value_type>, _ValExpr> >
2534 operator-() const
2535 {
2536 typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
2537 return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
2538 }
2539
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002540 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002541 __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> >
2542 operator~() const
2543 {
2544 typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
2545 return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
2546 }
2547
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002548 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002549 __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> >
2550 operator!() const
2551 {
2552 typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
2553 return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
2554 }
2555
2556 operator valarray<result_type>() const;
2557
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002558 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002559 size_t size() const {return __expr_.size();}
2560
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002562 result_type sum() const
2563 {
2564 size_t __n = __expr_.size();
2565 result_type __r = __n ? __expr_[0] : result_type();
2566 for (size_t __i = 1; __i < __n; ++__i)
2567 __r += __expr_[__i];
2568 return __r;
2569 }
2570
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002572 result_type min() const
2573 {
2574 size_t __n = size();
2575 result_type __r = __n ? (*this)[0] : result_type();
2576 for (size_t __i = 1; __i < __n; ++__i)
2577 {
2578 result_type __x = __expr_[__i];
2579 if (__x < __r)
2580 __r = __x;
2581 }
2582 return __r;
2583 }
2584
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002585 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002586 result_type max() const
2587 {
2588 size_t __n = size();
2589 result_type __r = __n ? (*this)[0] : result_type();
2590 for (size_t __i = 1; __i < __n; ++__i)
2591 {
2592 result_type __x = __expr_[__i];
2593 if (__r < __x)
2594 __r = __x;
2595 }
2596 return __r;
2597 }
2598
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002600 __val_expr<__shift_expr<_ValExpr> > shift (int __i) const
2601 {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));}
2602
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002604 __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const
2605 {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));}
2606
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002608 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> >
2609 apply(value_type __f(value_type)) const
2610 {
2611 typedef __apply_expr<value_type, value_type(*)(value_type)> _Op;
2612 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2613 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2614 }
2615
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002617 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> >
2618 apply(value_type __f(const value_type&)) const
2619 {
2620 typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op;
2621 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2622 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2623 }
2624};
2625
2626template<class _ValExpr>
2627__val_expr<_ValExpr>::operator valarray<result_type>() const
2628{
2629 valarray<result_type> __r;
2630 size_t __n = __expr_.size();
2631 if (__n)
2632 {
2633 __r.__begin_ =
2634 __r.__end_ =
2635 static_cast<result_type*>(::operator new(__n * sizeof(result_type)));
2636 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
2637 ::new (__r.__end_) result_type(__expr_[__i]);
2638 }
2639 return __r;
2640}
2641
2642// valarray
2643
2644template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002645inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002646valarray<_Tp>::valarray(size_t __n)
2647 : __begin_(0),
2648 __end_(0)
2649{
2650 resize(__n);
2651}
2652
2653template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002654inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002655valarray<_Tp>::valarray(const value_type& __x, size_t __n)
2656 : __begin_(0),
2657 __end_(0)
2658{
2659 resize(__n, __x);
2660}
2661
2662template <class _Tp>
2663valarray<_Tp>::valarray(const value_type* __p, size_t __n)
2664 : __begin_(0),
2665 __end_(0)
2666{
2667 if (__n)
2668 {
2669 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2670#ifndef _LIBCPP_NO_EXCEPTIONS
2671 try
2672 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002673#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002674 for (; __n; ++__end_, ++__p, --__n)
2675 ::new (__end_) value_type(*__p);
2676#ifndef _LIBCPP_NO_EXCEPTIONS
2677 }
2678 catch (...)
2679 {
2680 resize(0);
2681 throw;
2682 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002683#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002684 }
2685}
2686
2687template <class _Tp>
2688valarray<_Tp>::valarray(const valarray& __v)
2689 : __begin_(0),
2690 __end_(0)
2691{
2692 if (__v.size())
2693 {
2694 __begin_ = __end_ = static_cast<value_type*>(::operator new(__v.size() * sizeof(value_type)));
2695#ifndef _LIBCPP_NO_EXCEPTIONS
2696 try
2697 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002698#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002699 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
2700 ::new (__end_) value_type(*__p);
2701#ifndef _LIBCPP_NO_EXCEPTIONS
2702 }
2703 catch (...)
2704 {
2705 resize(0);
2706 throw;
2707 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002708#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002709 }
2710}
2711
Howard Hinnant73d21a42010-09-04 23:28:19 +00002712#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002713
2714template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002715inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd143082012-07-21 00:51:28 +00002716valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002717 : __begin_(__v.__begin_),
2718 __end_(__v.__end_)
2719{
2720 __v.__begin_ = __v.__end_ = nullptr;
2721}
2722
Howard Hinnante3e32912011-08-12 21:56:02 +00002723#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2724
2725#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2726
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002727template <class _Tp>
2728valarray<_Tp>::valarray(initializer_list<value_type> __il)
2729 : __begin_(0),
2730 __end_(0)
2731{
2732 size_t __n = __il.size();
2733 if (__n)
2734 {
2735 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2736#ifndef _LIBCPP_NO_EXCEPTIONS
2737 try
2738 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002739#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002740 for (const value_type* __p = __il.begin(); __n; ++__end_, ++__p, --__n)
2741 ::new (__end_) value_type(*__p);
2742#ifndef _LIBCPP_NO_EXCEPTIONS
2743 }
2744 catch (...)
2745 {
2746 resize(0);
2747 throw;
2748 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002749#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002750 }
2751}
2752
Howard Hinnante3e32912011-08-12 21:56:02 +00002753#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002754
2755template <class _Tp>
2756valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
2757 : __begin_(0),
2758 __end_(0)
2759{
2760 size_t __n = __sa.__size_;
2761 if (__n)
2762 {
2763 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2764#ifndef _LIBCPP_NO_EXCEPTIONS
2765 try
2766 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002767#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002768 for (const value_type* __p = __sa.__vp_; __n; ++__end_, __p += __sa.__stride_, --__n)
2769 ::new (__end_) value_type(*__p);
2770#ifndef _LIBCPP_NO_EXCEPTIONS
2771 }
2772 catch (...)
2773 {
2774 resize(0);
2775 throw;
2776 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002777#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002778 }
2779}
2780
2781template <class _Tp>
2782valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
2783 : __begin_(0),
2784 __end_(0)
2785{
2786 size_t __n = __ga.__1d_.size();
2787 if (__n)
2788 {
2789 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2790#ifndef _LIBCPP_NO_EXCEPTIONS
2791 try
2792 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002793#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002794 typedef const size_t* _Ip;
2795 const value_type* __s = __ga.__vp_;
2796 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2797 __i != __e; ++__i, ++__end_)
2798 ::new (__end_) value_type(__s[*__i]);
2799#ifndef _LIBCPP_NO_EXCEPTIONS
2800 }
2801 catch (...)
2802 {
2803 resize(0);
2804 throw;
2805 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002806#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002807 }
2808}
2809
2810template <class _Tp>
2811valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
2812 : __begin_(0),
2813 __end_(0)
2814{
2815 size_t __n = __ma.__1d_.size();
2816 if (__n)
2817 {
2818 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2819#ifndef _LIBCPP_NO_EXCEPTIONS
2820 try
2821 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002822#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002823 typedef const size_t* _Ip;
2824 const value_type* __s = __ma.__vp_;
2825 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2826 __i != __e; ++__i, ++__end_)
2827 ::new (__end_) value_type(__s[*__i]);
2828#ifndef _LIBCPP_NO_EXCEPTIONS
2829 }
2830 catch (...)
2831 {
2832 resize(0);
2833 throw;
2834 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002835#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002836 }
2837}
2838
2839template <class _Tp>
2840valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
2841 : __begin_(0),
2842 __end_(0)
2843{
2844 size_t __n = __ia.__1d_.size();
2845 if (__n)
2846 {
2847 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2848#ifndef _LIBCPP_NO_EXCEPTIONS
2849 try
2850 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002851#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002852 typedef const size_t* _Ip;
2853 const value_type* __s = __ia.__vp_;
2854 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2855 __i != __e; ++__i, ++__end_)
2856 ::new (__end_) value_type(__s[*__i]);
2857#ifndef _LIBCPP_NO_EXCEPTIONS
2858 }
2859 catch (...)
2860 {
2861 resize(0);
2862 throw;
2863 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002864#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002865 }
2866}
2867
2868template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002869inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002870valarray<_Tp>::~valarray()
2871{
2872 resize(0);
2873}
2874
2875template <class _Tp>
2876valarray<_Tp>&
2877valarray<_Tp>::operator=(const valarray& __v)
2878{
2879 if (this != &__v)
2880 {
2881 if (size() != __v.size())
2882 resize(__v.size());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002883 _VSTD::copy(__v.__begin_, __v.__end_, __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002884 }
2885 return *this;
2886}
2887
Howard Hinnant73d21a42010-09-04 23:28:19 +00002888#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002889
2890template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002891inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002892valarray<_Tp>&
Howard Hinnantbd143082012-07-21 00:51:28 +00002893valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002894{
2895 resize(0);
2896 __begin_ = __v.__begin_;
2897 __end_ = __v.__end_;
2898 __v.__begin_ = nullptr;
2899 __v.__end_ = nullptr;
2900 return *this;
2901}
2902
Howard Hinnante3e32912011-08-12 21:56:02 +00002903#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2904
2905#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2906
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002907template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002908inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002909valarray<_Tp>&
2910valarray<_Tp>::operator=(initializer_list<value_type> __il)
2911{
2912 if (size() != __il.size())
2913 resize(__il.size());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002914 _VSTD::copy(__il.begin(), __il.end(), __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002915 return *this;
2916}
2917
Howard Hinnante3e32912011-08-12 21:56:02 +00002918#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002919
2920template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002921inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002922valarray<_Tp>&
2923valarray<_Tp>::operator=(const value_type& __x)
2924{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002925 _VSTD::fill(__begin_, __end_, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002926 return *this;
2927}
2928
2929template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002930inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002931valarray<_Tp>&
2932valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
2933{
2934 value_type* __t = __begin_;
2935 const value_type* __s = __sa.__vp_;
2936 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
2937 *__t = *__s;
2938 return *this;
2939}
2940
2941template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002942inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002943valarray<_Tp>&
2944valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
2945{
2946 typedef const size_t* _Ip;
2947 value_type* __t = __begin_;
2948 const value_type* __s = __ga.__vp_;
2949 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2950 __i != __e; ++__i, ++__t)
2951 *__t = __s[*__i];
2952 return *this;
2953}
2954
2955template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002956inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002957valarray<_Tp>&
2958valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
2959{
2960 typedef const size_t* _Ip;
2961 value_type* __t = __begin_;
2962 const value_type* __s = __ma.__vp_;
2963 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2964 __i != __e; ++__i, ++__t)
2965 *__t = __s[*__i];
2966 return *this;
2967}
2968
2969template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002970inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002971valarray<_Tp>&
2972valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
2973{
2974 typedef const size_t* _Ip;
2975 value_type* __t = __begin_;
2976 const value_type* __s = __ia.__vp_;
2977 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2978 __i != __e; ++__i, ++__t)
2979 *__t = __s[*__i];
2980 return *this;
2981}
2982
2983template <class _Tp>
Howard Hinnantdb866632011-07-27 23:19:59 +00002984template <class _ValExpr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002985inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantdb866632011-07-27 23:19:59 +00002986valarray<_Tp>&
2987valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
2988{
2989 size_t __n = __v.size();
2990 if (size() != __n)
2991 resize(__n);
2992 value_type* __t = __begin_;
2993 for (size_t __i = 0; __i != __n; ++__t, ++__i)
2994 *__t = result_type(__v[__i]);
2995 return *this;
2996}
2997
2998template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002999inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003000__val_expr<__slice_expr<const valarray<_Tp>&> >
3001valarray<_Tp>::operator[](slice __s) const
3002{
3003 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
3004}
3005
3006template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003007inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003008slice_array<_Tp>
3009valarray<_Tp>::operator[](slice __s)
3010{
3011 return slice_array<value_type>(__s, *this);
3012}
3013
3014template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003015inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003016__val_expr<__indirect_expr<const valarray<_Tp>&> >
3017valarray<_Tp>::operator[](const gslice& __gs) const
3018{
3019 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
3020}
3021
3022template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003023inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003024gslice_array<_Tp>
3025valarray<_Tp>::operator[](const gslice& __gs)
3026{
3027 return gslice_array<value_type>(__gs, *this);
3028}
3029
Howard Hinnant73d21a42010-09-04 23:28:19 +00003030#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003031
3032template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003033inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003034__val_expr<__indirect_expr<const valarray<_Tp>&> >
3035valarray<_Tp>::operator[](gslice&& __gs) const
3036{
3037 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
3038}
3039
3040template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003041inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003042gslice_array<_Tp>
3043valarray<_Tp>::operator[](gslice&& __gs)
3044{
3045 return gslice_array<value_type>(move(__gs), *this);
3046}
3047
Howard Hinnant73d21a42010-09-04 23:28:19 +00003048#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003049
3050template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003051inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003052__val_expr<__mask_expr<const valarray<_Tp>&> >
3053valarray<_Tp>::operator[](const valarray<bool>& __vb) const
3054{
3055 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
3056}
3057
3058template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003059inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003060mask_array<_Tp>
3061valarray<_Tp>::operator[](const valarray<bool>& __vb)
3062{
3063 return mask_array<value_type>(__vb, *this);
3064}
3065
Howard Hinnant73d21a42010-09-04 23:28:19 +00003066#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003067
3068template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003069inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003070__val_expr<__mask_expr<const valarray<_Tp>&> >
3071valarray<_Tp>::operator[](valarray<bool>&& __vb) const
3072{
3073 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
3074}
3075
3076template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003077inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003078mask_array<_Tp>
3079valarray<_Tp>::operator[](valarray<bool>&& __vb)
3080{
3081 return mask_array<value_type>(move(__vb), *this);
3082}
3083
Howard Hinnant73d21a42010-09-04 23:28:19 +00003084#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003085
3086template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003087inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003088__val_expr<__indirect_expr<const valarray<_Tp>&> >
3089valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
3090{
3091 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
3092}
3093
3094template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003095inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003096indirect_array<_Tp>
3097valarray<_Tp>::operator[](const valarray<size_t>& __vs)
3098{
3099 return indirect_array<value_type>(__vs, *this);
3100}
3101
Howard Hinnant73d21a42010-09-04 23:28:19 +00003102#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003103
3104template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003105inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003106__val_expr<__indirect_expr<const valarray<_Tp>&> >
3107valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
3108{
3109 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
3110}
3111
3112template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003113inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003114indirect_array<_Tp>
3115valarray<_Tp>::operator[](valarray<size_t>&& __vs)
3116{
3117 return indirect_array<value_type>(move(__vs), *this);
3118}
3119
Howard Hinnant73d21a42010-09-04 23:28:19 +00003120#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003121
3122template <class _Tp>
3123valarray<_Tp>
3124valarray<_Tp>::operator+() const
3125{
3126 valarray<value_type> __r;
3127 size_t __n = size();
3128 if (__n)
3129 {
3130 __r.__begin_ =
3131 __r.__end_ =
3132 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3133 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3134 ::new (__r.__end_) value_type(+*__p);
3135 }
3136 return __r;
3137}
3138
3139template <class _Tp>
3140valarray<_Tp>
3141valarray<_Tp>::operator-() const
3142{
3143 valarray<value_type> __r;
3144 size_t __n = size();
3145 if (__n)
3146 {
3147 __r.__begin_ =
3148 __r.__end_ =
3149 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3150 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3151 ::new (__r.__end_) value_type(-*__p);
3152 }
3153 return __r;
3154}
3155
3156template <class _Tp>
3157valarray<_Tp>
3158valarray<_Tp>::operator~() const
3159{
3160 valarray<value_type> __r;
3161 size_t __n = size();
3162 if (__n)
3163 {
3164 __r.__begin_ =
3165 __r.__end_ =
3166 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3167 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3168 ::new (__r.__end_) value_type(~*__p);
3169 }
3170 return __r;
3171}
3172
3173template <class _Tp>
3174valarray<bool>
3175valarray<_Tp>::operator!() const
3176{
3177 valarray<bool> __r;
3178 size_t __n = size();
3179 if (__n)
3180 {
3181 __r.__begin_ =
3182 __r.__end_ =
3183 static_cast<bool*>(::operator new(__n * sizeof(bool)));
3184 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3185 ::new (__r.__end_) bool(!*__p);
3186 }
3187 return __r;
3188}
3189
3190template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003191inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003192valarray<_Tp>&
3193valarray<_Tp>::operator*=(const value_type& __x)
3194{
3195 for (value_type* __p = __begin_; __p != __end_; ++__p)
3196 *__p *= __x;
3197 return *this;
3198}
3199
3200template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003201inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003202valarray<_Tp>&
3203valarray<_Tp>::operator/=(const value_type& __x)
3204{
3205 for (value_type* __p = __begin_; __p != __end_; ++__p)
3206 *__p /= __x;
3207 return *this;
3208}
3209
3210template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003211inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003212valarray<_Tp>&
3213valarray<_Tp>::operator%=(const value_type& __x)
3214{
3215 for (value_type* __p = __begin_; __p != __end_; ++__p)
3216 *__p %= __x;
3217 return *this;
3218}
3219
3220template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003221inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003222valarray<_Tp>&
3223valarray<_Tp>::operator+=(const value_type& __x)
3224{
3225 for (value_type* __p = __begin_; __p != __end_; ++__p)
3226 *__p += __x;
3227 return *this;
3228}
3229
3230template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003231inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003232valarray<_Tp>&
3233valarray<_Tp>::operator-=(const value_type& __x)
3234{
3235 for (value_type* __p = __begin_; __p != __end_; ++__p)
3236 *__p -= __x;
3237 return *this;
3238}
3239
3240template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003241inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003242valarray<_Tp>&
3243valarray<_Tp>::operator^=(const value_type& __x)
3244{
3245 for (value_type* __p = __begin_; __p != __end_; ++__p)
3246 *__p ^= __x;
3247 return *this;
3248}
3249
3250template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003251inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003252valarray<_Tp>&
3253valarray<_Tp>::operator&=(const value_type& __x)
3254{
3255 for (value_type* __p = __begin_; __p != __end_; ++__p)
3256 *__p &= __x;
3257 return *this;
3258}
3259
3260template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003261inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003262valarray<_Tp>&
3263valarray<_Tp>::operator|=(const value_type& __x)
3264{
3265 for (value_type* __p = __begin_; __p != __end_; ++__p)
3266 *__p |= __x;
3267 return *this;
3268}
3269
3270template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003271inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003272valarray<_Tp>&
3273valarray<_Tp>::operator<<=(const value_type& __x)
3274{
3275 for (value_type* __p = __begin_; __p != __end_; ++__p)
3276 *__p <<= __x;
3277 return *this;
3278}
3279
3280template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003281inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003282valarray<_Tp>&
3283valarray<_Tp>::operator>>=(const value_type& __x)
3284{
3285 for (value_type* __p = __begin_; __p != __end_; ++__p)
3286 *__p >>= __x;
3287 return *this;
3288}
3289
3290template <class _Tp>
3291template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003292inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003293typename enable_if
3294<
3295 __is_val_expr<_Expr>::value,
3296 valarray<_Tp>&
3297>::type
3298valarray<_Tp>::operator*=(const _Expr& __v)
3299{
3300 size_t __i = 0;
3301 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3302 *__t *= __v[__i];
3303 return *this;
3304}
3305
3306template <class _Tp>
3307template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003308inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003309typename enable_if
3310<
3311 __is_val_expr<_Expr>::value,
3312 valarray<_Tp>&
3313>::type
3314valarray<_Tp>::operator/=(const _Expr& __v)
3315{
3316 size_t __i = 0;
3317 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3318 *__t /= __v[__i];
3319 return *this;
3320}
3321
3322template <class _Tp>
3323template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003324inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003325typename enable_if
3326<
3327 __is_val_expr<_Expr>::value,
3328 valarray<_Tp>&
3329>::type
3330valarray<_Tp>::operator%=(const _Expr& __v)
3331{
3332 size_t __i = 0;
3333 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3334 *__t %= __v[__i];
3335 return *this;
3336}
3337
3338template <class _Tp>
3339template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003340inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003341typename enable_if
3342<
3343 __is_val_expr<_Expr>::value,
3344 valarray<_Tp>&
3345>::type
3346valarray<_Tp>::operator+=(const _Expr& __v)
3347{
3348 size_t __i = 0;
3349 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3350 *__t += __v[__i];
3351 return *this;
3352}
3353
3354template <class _Tp>
3355template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003356inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003357typename enable_if
3358<
3359 __is_val_expr<_Expr>::value,
3360 valarray<_Tp>&
3361>::type
3362valarray<_Tp>::operator-=(const _Expr& __v)
3363{
3364 size_t __i = 0;
3365 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3366 *__t -= __v[__i];
3367 return *this;
3368}
3369
3370template <class _Tp>
3371template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003372inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003373typename enable_if
3374<
3375 __is_val_expr<_Expr>::value,
3376 valarray<_Tp>&
3377>::type
3378valarray<_Tp>::operator^=(const _Expr& __v)
3379{
3380 size_t __i = 0;
3381 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3382 *__t ^= __v[__i];
3383 return *this;
3384}
3385
3386template <class _Tp>
3387template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003388inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003389typename enable_if
3390<
3391 __is_val_expr<_Expr>::value,
3392 valarray<_Tp>&
3393>::type
3394valarray<_Tp>::operator|=(const _Expr& __v)
3395{
3396 size_t __i = 0;
3397 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3398 *__t |= __v[__i];
3399 return *this;
3400}
3401
3402template <class _Tp>
3403template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003404inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003405typename enable_if
3406<
3407 __is_val_expr<_Expr>::value,
3408 valarray<_Tp>&
3409>::type
3410valarray<_Tp>::operator&=(const _Expr& __v)
3411{
3412 size_t __i = 0;
3413 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3414 *__t &= __v[__i];
3415 return *this;
3416}
3417
3418template <class _Tp>
3419template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003420inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003421typename enable_if
3422<
3423 __is_val_expr<_Expr>::value,
3424 valarray<_Tp>&
3425>::type
3426valarray<_Tp>::operator<<=(const _Expr& __v)
3427{
3428 size_t __i = 0;
3429 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3430 *__t <<= __v[__i];
3431 return *this;
3432}
3433
3434template <class _Tp>
3435template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003436inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003437typename enable_if
3438<
3439 __is_val_expr<_Expr>::value,
3440 valarray<_Tp>&
3441>::type
3442valarray<_Tp>::operator>>=(const _Expr& __v)
3443{
3444 size_t __i = 0;
3445 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3446 *__t >>= __v[__i];
3447 return *this;
3448}
3449
3450template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003451inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003452void
Howard Hinnantbd143082012-07-21 00:51:28 +00003453valarray<_Tp>::swap(valarray& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003454{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003455 _VSTD::swap(__begin_, __v.__begin_);
3456 _VSTD::swap(__end_, __v.__end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003457}
3458
3459template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003460inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003461_Tp
3462valarray<_Tp>::sum() const
3463{
3464 if (__begin_ == __end_)
3465 return value_type();
3466 const value_type* __p = __begin_;
3467 _Tp __r = *__p;
3468 for (++__p; __p != __end_; ++__p)
3469 __r += *__p;
3470 return __r;
3471}
3472
3473template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003474inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003475_Tp
3476valarray<_Tp>::min() const
3477{
3478 if (__begin_ == __end_)
3479 return value_type();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003480 return *_VSTD::min_element(__begin_, __end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003481}
3482
3483template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003484inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003485_Tp
3486valarray<_Tp>::max() const
3487{
3488 if (__begin_ == __end_)
3489 return value_type();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003490 return *_VSTD::max_element(__begin_, __end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003491}
3492
3493template <class _Tp>
3494valarray<_Tp>
3495valarray<_Tp>::shift(int __i) const
3496{
3497 valarray<value_type> __r;
3498 size_t __n = size();
3499 if (__n)
3500 {
3501 __r.__begin_ =
3502 __r.__end_ =
3503 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3504 const value_type* __sb;
3505 value_type* __tb;
3506 value_type* __te;
3507 if (__i >= 0)
3508 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003509 __i = _VSTD::min(__i, static_cast<int>(__n));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003510 __sb = __begin_ + __i;
3511 __tb = __r.__begin_;
3512 __te = __r.__begin_ + (__n - __i);
3513 }
3514 else
3515 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003516 __i = _VSTD::min(-__i, static_cast<int>(__n));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003517 __sb = __begin_;
3518 __tb = __r.__begin_ + __i;
3519 __te = __r.__begin_ + __n;
3520 }
3521 for (; __r.__end_ != __tb; ++__r.__end_)
3522 ::new (__r.__end_) value_type();
3523 for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
3524 ::new (__r.__end_) value_type(*__sb);
3525 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
3526 ::new (__r.__end_) value_type();
3527 }
3528 return __r;
3529}
3530
3531template <class _Tp>
3532valarray<_Tp>
3533valarray<_Tp>::cshift(int __i) const
3534{
3535 valarray<value_type> __r;
3536 size_t __n = size();
3537 if (__n)
3538 {
3539 __r.__begin_ =
3540 __r.__end_ =
3541 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3542 __i %= static_cast<int>(__n);
3543 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
3544 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
3545 ::new (__r.__end_) value_type(*__s);
3546 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
3547 ::new (__r.__end_) value_type(*__s);
3548 }
3549 return __r;
3550}
3551
3552template <class _Tp>
3553valarray<_Tp>
3554valarray<_Tp>::apply(value_type __f(value_type)) const
3555{
3556 valarray<value_type> __r;
3557 size_t __n = size();
3558 if (__n)
3559 {
3560 __r.__begin_ =
3561 __r.__end_ =
3562 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3563 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3564 ::new (__r.__end_) value_type(__f(*__p));
3565 }
3566 return __r;
3567}
3568
3569template <class _Tp>
3570valarray<_Tp>
3571valarray<_Tp>::apply(value_type __f(const value_type&)) const
3572{
3573 valarray<value_type> __r;
3574 size_t __n = size();
3575 if (__n)
3576 {
3577 __r.__begin_ =
3578 __r.__end_ =
3579 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3580 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3581 ::new (__r.__end_) value_type(__f(*__p));
3582 }
3583 return __r;
3584}
3585
3586template <class _Tp>
3587void
3588valarray<_Tp>::resize(size_t __n, value_type __x)
3589{
3590 if (__begin_ != nullptr)
3591 {
3592 while (__end_ != __begin_)
3593 (--__end_)->~value_type();
3594 ::operator delete(__begin_);
3595 __begin_ = __end_ = nullptr;
3596 }
3597 if (__n)
3598 {
3599 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3600#ifndef _LIBCPP_NO_EXCEPTIONS
3601 try
3602 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003603#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003604 for (; __n; --__n, ++__end_)
3605 ::new (__end_) value_type(__x);
3606#ifndef _LIBCPP_NO_EXCEPTIONS
3607 }
3608 catch (...)
3609 {
3610 resize(0);
3611 throw;
3612 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003613#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003614 }
3615}
3616
3617template<class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003618inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003619void
Howard Hinnantbd143082012-07-21 00:51:28 +00003620swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003621{
3622 __x.swap(__y);
3623}
3624
3625template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003626inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003627typename enable_if
3628<
3629 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3630 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
3631>::type
3632operator*(const _Expr1& __x, const _Expr2& __y)
3633{
3634 typedef typename _Expr1::value_type value_type;
3635 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
3636 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
3637}
3638
3639template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003640inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003641typename enable_if
3642<
3643 __is_val_expr<_Expr>::value,
3644 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3645 _Expr, __scalar_expr<typename _Expr::value_type> > >
3646>::type
3647operator*(const _Expr& __x, const typename _Expr::value_type& __y)
3648{
3649 typedef typename _Expr::value_type value_type;
3650 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3651 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3652 __x, __scalar_expr<value_type>(__y, __x.size())));
3653}
3654
3655template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003656inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003657typename enable_if
3658<
3659 __is_val_expr<_Expr>::value,
3660 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3661 __scalar_expr<typename _Expr::value_type>, _Expr> >
3662>::type
3663operator*(const typename _Expr::value_type& __x, const _Expr& __y)
3664{
3665 typedef typename _Expr::value_type value_type;
3666 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3667 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3668 __scalar_expr<value_type>(__x, __y.size()), __y));
3669}
3670
3671template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003672inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003673typename enable_if
3674<
3675 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3676 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
3677>::type
3678operator/(const _Expr1& __x, const _Expr2& __y)
3679{
3680 typedef typename _Expr1::value_type value_type;
3681 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
3682 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
3683}
3684
3685template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003686inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003687typename enable_if
3688<
3689 __is_val_expr<_Expr>::value,
3690 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3691 _Expr, __scalar_expr<typename _Expr::value_type> > >
3692>::type
3693operator/(const _Expr& __x, const typename _Expr::value_type& __y)
3694{
3695 typedef typename _Expr::value_type value_type;
3696 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3697 return __val_expr<_Op>(_Op(divides<value_type>(),
3698 __x, __scalar_expr<value_type>(__y, __x.size())));
3699}
3700
3701template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003702inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003703typename enable_if
3704<
3705 __is_val_expr<_Expr>::value,
3706 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3707 __scalar_expr<typename _Expr::value_type>, _Expr> >
3708>::type
3709operator/(const typename _Expr::value_type& __x, const _Expr& __y)
3710{
3711 typedef typename _Expr::value_type value_type;
3712 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3713 return __val_expr<_Op>(_Op(divides<value_type>(),
3714 __scalar_expr<value_type>(__x, __y.size()), __y));
3715}
3716
3717template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003718inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003719typename enable_if
3720<
3721 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3722 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3723>::type
3724operator%(const _Expr1& __x, const _Expr2& __y)
3725{
3726 typedef typename _Expr1::value_type value_type;
3727 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
3728 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
3729}
3730
3731template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003732inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003733typename enable_if
3734<
3735 __is_val_expr<_Expr>::value,
3736 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3737 _Expr, __scalar_expr<typename _Expr::value_type> > >
3738>::type
3739operator%(const _Expr& __x, const typename _Expr::value_type& __y)
3740{
3741 typedef typename _Expr::value_type value_type;
3742 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3743 return __val_expr<_Op>(_Op(modulus<value_type>(),
3744 __x, __scalar_expr<value_type>(__y, __x.size())));
3745}
3746
3747template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003748inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003749typename enable_if
3750<
3751 __is_val_expr<_Expr>::value,
3752 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3753 __scalar_expr<typename _Expr::value_type>, _Expr> >
3754>::type
3755operator%(const typename _Expr::value_type& __x, const _Expr& __y)
3756{
3757 typedef typename _Expr::value_type value_type;
3758 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3759 return __val_expr<_Op>(_Op(modulus<value_type>(),
3760 __scalar_expr<value_type>(__x, __y.size()), __y));
3761}
3762
3763template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003764inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003765typename enable_if
3766<
3767 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3768 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3769>::type
3770operator+(const _Expr1& __x, const _Expr2& __y)
3771{
3772 typedef typename _Expr1::value_type value_type;
3773 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
3774 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
3775}
3776
3777template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003778inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003779typename enable_if
3780<
3781 __is_val_expr<_Expr>::value,
3782 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3783 _Expr, __scalar_expr<typename _Expr::value_type> > >
3784>::type
3785operator+(const _Expr& __x, const typename _Expr::value_type& __y)
3786{
3787 typedef typename _Expr::value_type value_type;
3788 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3789 return __val_expr<_Op>(_Op(plus<value_type>(),
3790 __x, __scalar_expr<value_type>(__y, __x.size())));
3791}
3792
3793template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003794inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003795typename enable_if
3796<
3797 __is_val_expr<_Expr>::value,
3798 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3799 __scalar_expr<typename _Expr::value_type>, _Expr> >
3800>::type
3801operator+(const typename _Expr::value_type& __x, const _Expr& __y)
3802{
3803 typedef typename _Expr::value_type value_type;
3804 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3805 return __val_expr<_Op>(_Op(plus<value_type>(),
3806 __scalar_expr<value_type>(__x, __y.size()), __y));
3807}
3808
3809template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003810inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003811typename enable_if
3812<
3813 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3814 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3815>::type
3816operator-(const _Expr1& __x, const _Expr2& __y)
3817{
3818 typedef typename _Expr1::value_type value_type;
3819 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
3820 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
3821}
3822
3823template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003824inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003825typename enable_if
3826<
3827 __is_val_expr<_Expr>::value,
3828 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3829 _Expr, __scalar_expr<typename _Expr::value_type> > >
3830>::type
3831operator-(const _Expr& __x, const typename _Expr::value_type& __y)
3832{
3833 typedef typename _Expr::value_type value_type;
3834 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3835 return __val_expr<_Op>(_Op(minus<value_type>(),
3836 __x, __scalar_expr<value_type>(__y, __x.size())));
3837}
3838
3839template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003840inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003841typename enable_if
3842<
3843 __is_val_expr<_Expr>::value,
3844 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3845 __scalar_expr<typename _Expr::value_type>, _Expr> >
3846>::type
3847operator-(const typename _Expr::value_type& __x, const _Expr& __y)
3848{
3849 typedef typename _Expr::value_type value_type;
3850 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3851 return __val_expr<_Op>(_Op(minus<value_type>(),
3852 __scalar_expr<value_type>(__x, __y.size()), __y));
3853}
3854
3855template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003856inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003857typename enable_if
3858<
3859 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3860 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
3861>::type
3862operator^(const _Expr1& __x, const _Expr2& __y)
3863{
3864 typedef typename _Expr1::value_type value_type;
3865 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
3866 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
3867}
3868
3869template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003870inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003871typename enable_if
3872<
3873 __is_val_expr<_Expr>::value,
3874 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
3875 _Expr, __scalar_expr<typename _Expr::value_type> > >
3876>::type
3877operator^(const _Expr& __x, const typename _Expr::value_type& __y)
3878{
3879 typedef typename _Expr::value_type value_type;
3880 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3881 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
3882 __x, __scalar_expr<value_type>(__y, __x.size())));
3883}
3884
3885template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003886inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003887typename enable_if
3888<
3889 __is_val_expr<_Expr>::value,
3890 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
3891 __scalar_expr<typename _Expr::value_type>, _Expr> >
3892>::type
3893operator^(const typename _Expr::value_type& __x, const _Expr& __y)
3894{
3895 typedef typename _Expr::value_type value_type;
3896 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3897 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
3898 __scalar_expr<value_type>(__x, __y.size()), __y));
3899}
3900
3901template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003902inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003903typename enable_if
3904<
3905 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3906 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
3907>::type
3908operator&(const _Expr1& __x, const _Expr2& __y)
3909{
3910 typedef typename _Expr1::value_type value_type;
3911 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
3912 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
3913}
3914
3915template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003916inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003917typename enable_if
3918<
3919 __is_val_expr<_Expr>::value,
3920 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
3921 _Expr, __scalar_expr<typename _Expr::value_type> > >
3922>::type
3923operator&(const _Expr& __x, const typename _Expr::value_type& __y)
3924{
3925 typedef typename _Expr::value_type value_type;
3926 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3927 return __val_expr<_Op>(_Op(bit_and<value_type>(),
3928 __x, __scalar_expr<value_type>(__y, __x.size())));
3929}
3930
3931template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003932inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003933typename enable_if
3934<
3935 __is_val_expr<_Expr>::value,
3936 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
3937 __scalar_expr<typename _Expr::value_type>, _Expr> >
3938>::type
3939operator&(const typename _Expr::value_type& __x, const _Expr& __y)
3940{
3941 typedef typename _Expr::value_type value_type;
3942 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3943 return __val_expr<_Op>(_Op(bit_and<value_type>(),
3944 __scalar_expr<value_type>(__x, __y.size()), __y));
3945}
3946
3947template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003948inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003949typename enable_if
3950<
3951 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3952 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
3953>::type
3954operator|(const _Expr1& __x, const _Expr2& __y)
3955{
3956 typedef typename _Expr1::value_type value_type;
3957 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
3958 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
3959}
3960
3961template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003962inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003963typename enable_if
3964<
3965 __is_val_expr<_Expr>::value,
3966 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
3967 _Expr, __scalar_expr<typename _Expr::value_type> > >
3968>::type
3969operator|(const _Expr& __x, const typename _Expr::value_type& __y)
3970{
3971 typedef typename _Expr::value_type value_type;
3972 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3973 return __val_expr<_Op>(_Op(bit_or<value_type>(),
3974 __x, __scalar_expr<value_type>(__y, __x.size())));
3975}
3976
3977template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003978inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003979typename enable_if
3980<
3981 __is_val_expr<_Expr>::value,
3982 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
3983 __scalar_expr<typename _Expr::value_type>, _Expr> >
3984>::type
3985operator|(const typename _Expr::value_type& __x, const _Expr& __y)
3986{
3987 typedef typename _Expr::value_type value_type;
3988 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3989 return __val_expr<_Op>(_Op(bit_or<value_type>(),
3990 __scalar_expr<value_type>(__x, __y.size()), __y));
3991}
3992
3993template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003994inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003995typename enable_if
3996<
3997 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3998 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
3999>::type
4000operator<<(const _Expr1& __x, const _Expr2& __y)
4001{
4002 typedef typename _Expr1::value_type value_type;
4003 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
4004 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
4005}
4006
4007template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004008inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004009typename enable_if
4010<
4011 __is_val_expr<_Expr>::value,
4012 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4013 _Expr, __scalar_expr<typename _Expr::value_type> > >
4014>::type
4015operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
4016{
4017 typedef typename _Expr::value_type value_type;
4018 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4019 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4020 __x, __scalar_expr<value_type>(__y, __x.size())));
4021}
4022
4023template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004024inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004025typename enable_if
4026<
4027 __is_val_expr<_Expr>::value,
4028 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4029 __scalar_expr<typename _Expr::value_type>, _Expr> >
4030>::type
4031operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
4032{
4033 typedef typename _Expr::value_type value_type;
4034 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4035 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4036 __scalar_expr<value_type>(__x, __y.size()), __y));
4037}
4038
4039template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004040inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004041typename enable_if
4042<
4043 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4044 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
4045>::type
4046operator>>(const _Expr1& __x, const _Expr2& __y)
4047{
4048 typedef typename _Expr1::value_type value_type;
4049 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
4050 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
4051}
4052
4053template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004054inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004055typename enable_if
4056<
4057 __is_val_expr<_Expr>::value,
4058 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4059 _Expr, __scalar_expr<typename _Expr::value_type> > >
4060>::type
4061operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
4062{
4063 typedef typename _Expr::value_type value_type;
4064 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4065 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4066 __x, __scalar_expr<value_type>(__y, __x.size())));
4067}
4068
4069template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004070inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004071typename enable_if
4072<
4073 __is_val_expr<_Expr>::value,
4074 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4075 __scalar_expr<typename _Expr::value_type>, _Expr> >
4076>::type
4077operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
4078{
4079 typedef typename _Expr::value_type value_type;
4080 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4081 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4082 __scalar_expr<value_type>(__x, __y.size()), __y));
4083}
4084
4085template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004086inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004087typename enable_if
4088<
4089 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4090 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4091>::type
4092operator&&(const _Expr1& __x, const _Expr2& __y)
4093{
4094 typedef typename _Expr1::value_type value_type;
4095 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
4096 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
4097}
4098
4099template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004100inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004101typename enable_if
4102<
4103 __is_val_expr<_Expr>::value,
4104 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4105 _Expr, __scalar_expr<typename _Expr::value_type> > >
4106>::type
4107operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
4108{
4109 typedef typename _Expr::value_type value_type;
4110 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4111 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4112 __x, __scalar_expr<value_type>(__y, __x.size())));
4113}
4114
4115template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004116inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004117typename enable_if
4118<
4119 __is_val_expr<_Expr>::value,
4120 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4121 __scalar_expr<typename _Expr::value_type>, _Expr> >
4122>::type
4123operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
4124{
4125 typedef typename _Expr::value_type value_type;
4126 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4127 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4128 __scalar_expr<value_type>(__x, __y.size()), __y));
4129}
4130
4131template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004132inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004133typename enable_if
4134<
4135 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4136 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4137>::type
4138operator||(const _Expr1& __x, const _Expr2& __y)
4139{
4140 typedef typename _Expr1::value_type value_type;
4141 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
4142 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
4143}
4144
4145template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004146inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004147typename enable_if
4148<
4149 __is_val_expr<_Expr>::value,
4150 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4151 _Expr, __scalar_expr<typename _Expr::value_type> > >
4152>::type
4153operator||(const _Expr& __x, const typename _Expr::value_type& __y)
4154{
4155 typedef typename _Expr::value_type value_type;
4156 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4157 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4158 __x, __scalar_expr<value_type>(__y, __x.size())));
4159}
4160
4161template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004162inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004163typename enable_if
4164<
4165 __is_val_expr<_Expr>::value,
4166 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4167 __scalar_expr<typename _Expr::value_type>, _Expr> >
4168>::type
4169operator||(const typename _Expr::value_type& __x, const _Expr& __y)
4170{
4171 typedef typename _Expr::value_type value_type;
4172 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4173 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4174 __scalar_expr<value_type>(__x, __y.size()), __y));
4175}
4176
4177template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004178inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004179typename enable_if
4180<
4181 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4182 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4183>::type
4184operator==(const _Expr1& __x, const _Expr2& __y)
4185{
4186 typedef typename _Expr1::value_type value_type;
4187 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
4188 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
4189}
4190
4191template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004192inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004193typename enable_if
4194<
4195 __is_val_expr<_Expr>::value,
4196 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4197 _Expr, __scalar_expr<typename _Expr::value_type> > >
4198>::type
4199operator==(const _Expr& __x, const typename _Expr::value_type& __y)
4200{
4201 typedef typename _Expr::value_type value_type;
4202 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4203 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4204 __x, __scalar_expr<value_type>(__y, __x.size())));
4205}
4206
4207template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004208inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004209typename enable_if
4210<
4211 __is_val_expr<_Expr>::value,
4212 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4213 __scalar_expr<typename _Expr::value_type>, _Expr> >
4214>::type
4215operator==(const typename _Expr::value_type& __x, const _Expr& __y)
4216{
4217 typedef typename _Expr::value_type value_type;
4218 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4219 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4220 __scalar_expr<value_type>(__x, __y.size()), __y));
4221}
4222
4223template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004224inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004225typename enable_if
4226<
4227 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4228 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4229>::type
4230operator!=(const _Expr1& __x, const _Expr2& __y)
4231{
4232 typedef typename _Expr1::value_type value_type;
4233 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
4234 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
4235}
4236
4237template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004238inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004239typename enable_if
4240<
4241 __is_val_expr<_Expr>::value,
4242 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4243 _Expr, __scalar_expr<typename _Expr::value_type> > >
4244>::type
4245operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
4246{
4247 typedef typename _Expr::value_type value_type;
4248 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4249 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4250 __x, __scalar_expr<value_type>(__y, __x.size())));
4251}
4252
4253template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004254inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004255typename enable_if
4256<
4257 __is_val_expr<_Expr>::value,
4258 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4259 __scalar_expr<typename _Expr::value_type>, _Expr> >
4260>::type
4261operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
4262{
4263 typedef typename _Expr::value_type value_type;
4264 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4265 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4266 __scalar_expr<value_type>(__x, __y.size()), __y));
4267}
4268
4269template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004270inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004271typename enable_if
4272<
4273 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4274 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
4275>::type
4276operator<(const _Expr1& __x, const _Expr2& __y)
4277{
4278 typedef typename _Expr1::value_type value_type;
4279 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
4280 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
4281}
4282
4283template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004284inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004285typename enable_if
4286<
4287 __is_val_expr<_Expr>::value,
4288 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4289 _Expr, __scalar_expr<typename _Expr::value_type> > >
4290>::type
4291operator<(const _Expr& __x, const typename _Expr::value_type& __y)
4292{
4293 typedef typename _Expr::value_type value_type;
4294 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4295 return __val_expr<_Op>(_Op(less<value_type>(),
4296 __x, __scalar_expr<value_type>(__y, __x.size())));
4297}
4298
4299template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004300inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004301typename enable_if
4302<
4303 __is_val_expr<_Expr>::value,
4304 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4305 __scalar_expr<typename _Expr::value_type>, _Expr> >
4306>::type
4307operator<(const typename _Expr::value_type& __x, const _Expr& __y)
4308{
4309 typedef typename _Expr::value_type value_type;
4310 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4311 return __val_expr<_Op>(_Op(less<value_type>(),
4312 __scalar_expr<value_type>(__x, __y.size()), __y));
4313}
4314
4315template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004316inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004317typename enable_if
4318<
4319 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4320 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
4321>::type
4322operator>(const _Expr1& __x, const _Expr2& __y)
4323{
4324 typedef typename _Expr1::value_type value_type;
4325 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
4326 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
4327}
4328
4329template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004330inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004331typename enable_if
4332<
4333 __is_val_expr<_Expr>::value,
4334 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4335 _Expr, __scalar_expr<typename _Expr::value_type> > >
4336>::type
4337operator>(const _Expr& __x, const typename _Expr::value_type& __y)
4338{
4339 typedef typename _Expr::value_type value_type;
4340 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4341 return __val_expr<_Op>(_Op(greater<value_type>(),
4342 __x, __scalar_expr<value_type>(__y, __x.size())));
4343}
4344
4345template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004346inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004347typename enable_if
4348<
4349 __is_val_expr<_Expr>::value,
4350 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4351 __scalar_expr<typename _Expr::value_type>, _Expr> >
4352>::type
4353operator>(const typename _Expr::value_type& __x, const _Expr& __y)
4354{
4355 typedef typename _Expr::value_type value_type;
4356 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4357 return __val_expr<_Op>(_Op(greater<value_type>(),
4358 __scalar_expr<value_type>(__x, __y.size()), __y));
4359}
4360
4361template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004362inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004363typename enable_if
4364<
4365 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4366 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4367>::type
4368operator<=(const _Expr1& __x, const _Expr2& __y)
4369{
4370 typedef typename _Expr1::value_type value_type;
4371 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
4372 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
4373}
4374
4375template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004376inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004377typename enable_if
4378<
4379 __is_val_expr<_Expr>::value,
4380 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4381 _Expr, __scalar_expr<typename _Expr::value_type> > >
4382>::type
4383operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
4384{
4385 typedef typename _Expr::value_type value_type;
4386 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4387 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4388 __x, __scalar_expr<value_type>(__y, __x.size())));
4389}
4390
4391template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004392inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004393typename enable_if
4394<
4395 __is_val_expr<_Expr>::value,
4396 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4397 __scalar_expr<typename _Expr::value_type>, _Expr> >
4398>::type
4399operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
4400{
4401 typedef typename _Expr::value_type value_type;
4402 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4403 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4404 __scalar_expr<value_type>(__x, __y.size()), __y));
4405}
4406
4407template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004408inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004409typename enable_if
4410<
4411 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4412 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4413>::type
4414operator>=(const _Expr1& __x, const _Expr2& __y)
4415{
4416 typedef typename _Expr1::value_type value_type;
4417 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
4418 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
4419}
4420
4421template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004422inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004423typename enable_if
4424<
4425 __is_val_expr<_Expr>::value,
4426 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4427 _Expr, __scalar_expr<typename _Expr::value_type> > >
4428>::type
4429operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
4430{
4431 typedef typename _Expr::value_type value_type;
4432 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4433 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4434 __x, __scalar_expr<value_type>(__y, __x.size())));
4435}
4436
4437template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004438inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004439typename enable_if
4440<
4441 __is_val_expr<_Expr>::value,
4442 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4443 __scalar_expr<typename _Expr::value_type>, _Expr> >
4444>::type
4445operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
4446{
4447 typedef typename _Expr::value_type value_type;
4448 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4449 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4450 __scalar_expr<value_type>(__x, __y.size()), __y));
4451}
4452
4453template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004454inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004455typename enable_if
4456<
4457 __is_val_expr<_Expr>::value,
4458 __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
4459>::type
4460abs(const _Expr& __x)
4461{
4462 typedef typename _Expr::value_type value_type;
4463 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
4464 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
4465}
4466
4467template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004468inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004469typename enable_if
4470<
4471 __is_val_expr<_Expr>::value,
4472 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
4473>::type
4474acos(const _Expr& __x)
4475{
4476 typedef typename _Expr::value_type value_type;
4477 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
4478 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
4479}
4480
4481template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004482inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004483typename enable_if
4484<
4485 __is_val_expr<_Expr>::value,
4486 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
4487>::type
4488asin(const _Expr& __x)
4489{
4490 typedef typename _Expr::value_type value_type;
4491 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
4492 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
4493}
4494
4495template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004496inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004497typename enable_if
4498<
4499 __is_val_expr<_Expr>::value,
4500 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
4501>::type
4502atan(const _Expr& __x)
4503{
4504 typedef typename _Expr::value_type value_type;
4505 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
4506 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
4507}
4508
4509template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004510inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004511typename enable_if
4512<
4513 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4514 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4515>::type
4516atan2(const _Expr1& __x, const _Expr2& __y)
4517{
4518 typedef typename _Expr1::value_type value_type;
4519 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
4520 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
4521}
4522
4523template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004524inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004525typename enable_if
4526<
4527 __is_val_expr<_Expr>::value,
4528 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4529 _Expr, __scalar_expr<typename _Expr::value_type> > >
4530>::type
4531atan2(const _Expr& __x, const typename _Expr::value_type& __y)
4532{
4533 typedef typename _Expr::value_type value_type;
4534 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4535 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4536 __x, __scalar_expr<value_type>(__y, __x.size())));
4537}
4538
4539template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004540inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004541typename enable_if
4542<
4543 __is_val_expr<_Expr>::value,
4544 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4545 __scalar_expr<typename _Expr::value_type>, _Expr> >
4546>::type
4547atan2(const typename _Expr::value_type& __x, const _Expr& __y)
4548{
4549 typedef typename _Expr::value_type value_type;
4550 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4551 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4552 __scalar_expr<value_type>(__x, __y.size()), __y));
4553}
4554
4555template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004556inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004557typename enable_if
4558<
4559 __is_val_expr<_Expr>::value,
4560 __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
4561>::type
4562cos(const _Expr& __x)
4563{
4564 typedef typename _Expr::value_type value_type;
4565 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
4566 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
4567}
4568
4569template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004570inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004571typename enable_if
4572<
4573 __is_val_expr<_Expr>::value,
4574 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
4575>::type
4576cosh(const _Expr& __x)
4577{
4578 typedef typename _Expr::value_type value_type;
4579 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
4580 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
4581}
4582
4583template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004584inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004585typename enable_if
4586<
4587 __is_val_expr<_Expr>::value,
4588 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
4589>::type
4590exp(const _Expr& __x)
4591{
4592 typedef typename _Expr::value_type value_type;
4593 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
4594 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
4595}
4596
4597template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004598inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004599typename enable_if
4600<
4601 __is_val_expr<_Expr>::value,
4602 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
4603>::type
4604log(const _Expr& __x)
4605{
4606 typedef typename _Expr::value_type value_type;
4607 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
4608 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
4609}
4610
4611template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004612inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004613typename enable_if
4614<
4615 __is_val_expr<_Expr>::value,
4616 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
4617>::type
4618log10(const _Expr& __x)
4619{
4620 typedef typename _Expr::value_type value_type;
4621 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
4622 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
4623}
4624
4625template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004626inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004627typename enable_if
4628<
4629 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4630 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4631>::type
4632pow(const _Expr1& __x, const _Expr2& __y)
4633{
4634 typedef typename _Expr1::value_type value_type;
4635 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
4636 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
4637}
4638
4639template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004640inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004641typename enable_if
4642<
4643 __is_val_expr<_Expr>::value,
4644 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4645 _Expr, __scalar_expr<typename _Expr::value_type> > >
4646>::type
4647pow(const _Expr& __x, const typename _Expr::value_type& __y)
4648{
4649 typedef typename _Expr::value_type value_type;
4650 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4651 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4652 __x, __scalar_expr<value_type>(__y, __x.size())));
4653}
4654
4655template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004656inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004657typename enable_if
4658<
4659 __is_val_expr<_Expr>::value,
4660 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4661 __scalar_expr<typename _Expr::value_type>, _Expr> >
4662>::type
4663pow(const typename _Expr::value_type& __x, const _Expr& __y)
4664{
4665 typedef typename _Expr::value_type value_type;
4666 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4667 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4668 __scalar_expr<value_type>(__x, __y.size()), __y));
4669}
4670
4671template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004672inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004673typename enable_if
4674<
4675 __is_val_expr<_Expr>::value,
4676 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
4677>::type
4678sin(const _Expr& __x)
4679{
4680 typedef typename _Expr::value_type value_type;
4681 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
4682 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
4683}
4684
4685template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004686inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004687typename enable_if
4688<
4689 __is_val_expr<_Expr>::value,
4690 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
4691>::type
4692sinh(const _Expr& __x)
4693{
4694 typedef typename _Expr::value_type value_type;
4695 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
4696 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
4697}
4698
4699template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004700inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004701typename enable_if
4702<
4703 __is_val_expr<_Expr>::value,
4704 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
4705>::type
4706sqrt(const _Expr& __x)
4707{
4708 typedef typename _Expr::value_type value_type;
4709 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
4710 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
4711}
4712
4713template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004714inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004715typename enable_if
4716<
4717 __is_val_expr<_Expr>::value,
4718 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
4719>::type
4720tan(const _Expr& __x)
4721{
4722 typedef typename _Expr::value_type value_type;
4723 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
4724 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
4725}
4726
4727template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004728inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004729typename enable_if
4730<
4731 __is_val_expr<_Expr>::value,
4732 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
4733>::type
4734tanh(const _Expr& __x)
4735{
4736 typedef typename _Expr::value_type value_type;
4737 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
4738 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
4739}
4740
4741template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004742inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004743_Tp*
4744begin(valarray<_Tp>& __v)
4745{
4746 return __v.__begin_;
4747}
4748
4749template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004750inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004751const _Tp*
4752begin(const valarray<_Tp>& __v)
4753{
4754 return __v.__begin_;
4755}
4756
4757template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004758inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004759_Tp*
4760end(valarray<_Tp>& __v)
4761{
4762 return __v.__end_;
4763}
4764
4765template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004766inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004767const _Tp*
4768end(const valarray<_Tp>& __v)
4769{
4770 return __v.__end_;
4771}
4772
Howard Hinnantff926772012-11-06 21:08:48 +00004773_LIBCPP_EXTERN_TEMPLATE(valarray<size_t>::valarray(size_t))
4774_LIBCPP_EXTERN_TEMPLATE(valarray<size_t>::~valarray())
4775_LIBCPP_EXTERN_TEMPLATE(void valarray<size_t>::resize(size_t, size_t))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004776
4777_LIBCPP_END_NAMESPACE_STD
4778
4779#endif // _LIBCPP_VALARRAY