blob: bdaa58836f39e7382a1ae69e0485f3f8255a929f [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>
Dan Albert90dc8dd2014-08-26 11:20:46 -0700348#include <new>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000349
Howard Hinnant66c6f972011-11-29 16:45:27 +0000350#include <__undef_min_max>
Dan Albert5cb52822015-03-04 10:47:52 -0800351#include <__undef___deallocate>
Howard Hinnant66c6f972011-11-29 16:45:27 +0000352
Howard Hinnant08e17472011-10-17 20:05:10 +0000353#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000354#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000355#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000356
357_LIBCPP_BEGIN_NAMESPACE_STD
358
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000359template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000360
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000361class _LIBCPP_TYPE_VIS_ONLY slice
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000362{
363 size_t __start_;
364 size_t __size_;
365 size_t __stride_;
366public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000367 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000368 slice()
369 : __start_(0),
370 __size_(0),
371 __stride_(0)
372 {}
373
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000374 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000375 slice(size_t __start, size_t __size, size_t __stride)
376 : __start_(__start),
377 __size_(__size),
378 __stride_(__stride)
379 {}
380
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000381 _LIBCPP_INLINE_VISIBILITY size_t start() const {return __start_;}
382 _LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;}
383 _LIBCPP_INLINE_VISIBILITY size_t stride() const {return __stride_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384};
385
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000386template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY slice_array;
Howard Hinnant83eade62013-03-06 23:30:19 +0000387class _LIBCPP_TYPE_VIS gslice;
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000388template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY gslice_array;
389template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY mask_array;
390template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY indirect_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000391
392template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000393_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000394_Tp*
395begin(valarray<_Tp>& __v);
396
397template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000398_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000399const _Tp*
400begin(const valarray<_Tp>& __v);
401
402template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000403_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000404_Tp*
405end(valarray<_Tp>& __v);
406
407template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000408_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000409const _Tp*
410end(const valarray<_Tp>& __v);
411
412template <class _Op, class _A0>
413struct _UnaryOp
414{
415 typedef typename _Op::result_type result_type;
416 typedef typename _A0::value_type value_type;
417
418 _Op __op_;
419 _A0 __a0_;
420
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000422 _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {}
423
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000425 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
426
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000427 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000428 size_t size() const {return __a0_.size();}
429};
430
431template <class _Op, class _A0, class _A1>
432struct _BinaryOp
433{
434 typedef typename _Op::result_type result_type;
435 typedef typename _A0::value_type value_type;
436
437 _Op __op_;
438 _A0 __a0_;
439 _A1 __a1_;
440
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000441 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000442 _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1)
443 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
444
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000446 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
447
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000449 size_t size() const {return __a0_.size();}
450};
451
452template <class _Tp>
453class __scalar_expr
454{
455public:
456 typedef _Tp value_type;
457 typedef const _Tp& result_type;
458private:
459 const value_type& __t_;
460 size_t __s_;
461public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000463 explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {}
464
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000466 result_type operator[](size_t) const {return __t_;}
467
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000468 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000469 size_t size() const {return __s_;}
470};
471
472template <class _Tp>
473struct __unary_plus : unary_function<_Tp, _Tp>
474{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000476 _Tp operator()(const _Tp& __x) const
477 {return +__x;}
478};
479
480template <class _Tp>
481struct __bit_not : unary_function<_Tp, _Tp>
482{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000484 _Tp operator()(const _Tp& __x) const
485 {return ~__x;}
486};
487
488template <class _Tp>
489struct __bit_shift_left : binary_function<_Tp, _Tp, _Tp>
490{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000492 _Tp operator()(const _Tp& __x, const _Tp& __y) const
493 {return __x << __y;}
494};
495
496template <class _Tp>
497struct __bit_shift_right : binary_function<_Tp, _Tp, _Tp>
498{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000500 _Tp operator()(const _Tp& __x, const _Tp& __y) const
501 {return __x >> __y;}
502};
503
Howard Hinnant99968442011-11-29 18:15:50 +0000504template <class _Tp, class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000505struct __apply_expr : unary_function<_Tp, _Tp>
506{
507private:
Howard Hinnant99968442011-11-29 18:15:50 +0000508 _Fp __f_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000509public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +0000511 explicit __apply_expr(_Fp __f) : __f_(__f) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000512
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000514 _Tp operator()(const _Tp& __x) const
515 {return __f_(__x);}
516};
517
518template <class _Tp>
519struct __abs_expr : unary_function<_Tp, _Tp>
520{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000521 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000522 _Tp operator()(const _Tp& __x) const
523 {return abs(__x);}
524};
525
526template <class _Tp>
527struct __acos_expr : unary_function<_Tp, _Tp>
528{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000529 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000530 _Tp operator()(const _Tp& __x) const
531 {return acos(__x);}
532};
533
534template <class _Tp>
535struct __asin_expr : unary_function<_Tp, _Tp>
536{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000538 _Tp operator()(const _Tp& __x) const
539 {return asin(__x);}
540};
541
542template <class _Tp>
543struct __atan_expr : unary_function<_Tp, _Tp>
544{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000545 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000546 _Tp operator()(const _Tp& __x) const
547 {return atan(__x);}
548};
549
550template <class _Tp>
551struct __atan2_expr : binary_function<_Tp, _Tp, _Tp>
552{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000554 _Tp operator()(const _Tp& __x, const _Tp& __y) const
555 {return atan2(__x, __y);}
556};
557
558template <class _Tp>
559struct __cos_expr : unary_function<_Tp, _Tp>
560{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000562 _Tp operator()(const _Tp& __x) const
563 {return cos(__x);}
564};
565
566template <class _Tp>
567struct __cosh_expr : unary_function<_Tp, _Tp>
568{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000570 _Tp operator()(const _Tp& __x) const
571 {return cosh(__x);}
572};
573
574template <class _Tp>
575struct __exp_expr : unary_function<_Tp, _Tp>
576{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000578 _Tp operator()(const _Tp& __x) const
579 {return exp(__x);}
580};
581
582template <class _Tp>
583struct __log_expr : unary_function<_Tp, _Tp>
584{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000585 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000586 _Tp operator()(const _Tp& __x) const
587 {return log(__x);}
588};
589
590template <class _Tp>
591struct __log10_expr : unary_function<_Tp, _Tp>
592{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000594 _Tp operator()(const _Tp& __x) const
595 {return log10(__x);}
596};
597
598template <class _Tp>
599struct __pow_expr : binary_function<_Tp, _Tp, _Tp>
600{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000601 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000602 _Tp operator()(const _Tp& __x, const _Tp& __y) const
603 {return pow(__x, __y);}
604};
605
606template <class _Tp>
607struct __sin_expr : unary_function<_Tp, _Tp>
608{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000610 _Tp operator()(const _Tp& __x) const
611 {return sin(__x);}
612};
613
614template <class _Tp>
615struct __sinh_expr : unary_function<_Tp, _Tp>
616{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000618 _Tp operator()(const _Tp& __x) const
619 {return sinh(__x);}
620};
621
622template <class _Tp>
623struct __sqrt_expr : unary_function<_Tp, _Tp>
624{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000626 _Tp operator()(const _Tp& __x) const
627 {return sqrt(__x);}
628};
629
630template <class _Tp>
631struct __tan_expr : unary_function<_Tp, _Tp>
632{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000633 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000634 _Tp operator()(const _Tp& __x) const
635 {return tan(__x);}
636};
637
638template <class _Tp>
639struct __tanh_expr : unary_function<_Tp, _Tp>
640{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000641 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000642 _Tp operator()(const _Tp& __x) const
643 {return tanh(__x);}
644};
645
646template <class _ValExpr>
647class __slice_expr
648{
649 typedef typename remove_reference<_ValExpr>::type _RmExpr;
650public:
651 typedef typename _RmExpr::value_type value_type;
652 typedef value_type result_type;
653
654private:
655 _ValExpr __expr_;
656 size_t __start_;
657 size_t __size_;
658 size_t __stride_;
659
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661 __slice_expr(const slice& __sl, const _RmExpr& __e)
662 : __expr_(__e),
663 __start_(__sl.start()),
664 __size_(__sl.size()),
665 __stride_(__sl.stride())
666 {}
667public:
668
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670 result_type operator[](size_t __i) const
671 {return __expr_[__start_ + __i * __stride_];}
672
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000674 size_t size() const {return __size_;}
675
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000676 template <class> friend class _LIBCPP_TYPE_VIS_ONLY valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000677};
678
679template <class _ValExpr>
680class __mask_expr;
681
682template <class _ValExpr>
683class __indirect_expr;
684
685template <class _ValExpr>
686class __shift_expr
687{
688 typedef typename remove_reference<_ValExpr>::type _RmExpr;
689public:
690 typedef typename _RmExpr::value_type value_type;
691 typedef value_type result_type;
692
693private:
694 _ValExpr __expr_;
695 size_t __size_;
696 ptrdiff_t __ul_;
697 ptrdiff_t __sn_;
698 ptrdiff_t __n_;
Howard Hinnant99968442011-11-29 18:15:50 +0000699 static const ptrdiff_t _Np = static_cast<ptrdiff_t>(
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000700 sizeof(ptrdiff_t) * __CHAR_BIT__ - 1);
701
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000702 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000703 __shift_expr(int __n, const _RmExpr& __e)
704 : __expr_(__e),
705 __size_(__e.size()),
706 __n_(__n)
707 {
Howard Hinnant99968442011-11-29 18:15:50 +0000708 ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _Np);
709 __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _Np);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000710 __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n);
711 }
712public:
713
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000715 result_type operator[](size_t __j) const
716 {
Howard Hinnantec3773c2011-12-01 20:21:04 +0000717 ptrdiff_t __i = static_cast<ptrdiff_t>(__j);
Howard Hinnant99968442011-11-29 18:15:50 +0000718 ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000719 return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
720 }
721
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000723 size_t size() const {return __size_;}
724
725 template <class> friend class __val_expr;
726};
727
728template <class _ValExpr>
729class __cshift_expr
730{
731 typedef typename remove_reference<_ValExpr>::type _RmExpr;
732public:
733 typedef typename _RmExpr::value_type value_type;
734 typedef value_type result_type;
735
736private:
737 _ValExpr __expr_;
738 size_t __size_;
739 size_t __m_;
740 size_t __o1_;
741 size_t __o2_;
742
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000743 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000744 __cshift_expr(int __n, const _RmExpr& __e)
745 : __expr_(__e),
746 __size_(__e.size())
747 {
748 __n %= static_cast<int>(__size_);
749 if (__n >= 0)
750 {
751 __m_ = __size_ - __n;
752 __o1_ = __n;
753 __o2_ = __n - __size_;
754 }
755 else
756 {
757 __m_ = -__n;
758 __o1_ = __n + __size_;
759 __o2_ = __n;
760 }
761 }
762public:
763
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000764 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000765 result_type operator[](size_t __i) const
766 {
767 if (__i < __m_)
768 return __expr_[__i + __o1_];
769 return __expr_[__i + __o2_];
770 }
771
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000772 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000773 size_t size() const {return __size_;}
774
775 template <class> friend class __val_expr;
776};
777
778template<class _ValExpr>
779class __val_expr;
780
781template<class _ValExpr>
782struct __is_val_expr : false_type {};
783
784template<class _ValExpr>
785struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
786
787template<class _Tp>
788struct __is_val_expr<valarray<_Tp> > : true_type {};
789
790template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000791class _LIBCPP_TYPE_VIS_ONLY valarray
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000792{
793public:
794 typedef _Tp value_type;
795 typedef _Tp result_type;
796
797private:
798 value_type* __begin_;
799 value_type* __end_;
800
801public:
802 // construct/destroy:
Douglas Gregor0855dde2012-05-19 07:14:17 +0000803 _LIBCPP_INLINE_VISIBILITY
804 valarray() : __begin_(0), __end_(0) {}
805 explicit valarray(size_t __n);
806 valarray(const value_type& __x, size_t __n);
807 valarray(const value_type* __p, size_t __n);
808 valarray(const valarray& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000809#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbd143082012-07-21 00:51:28 +0000810 valarray(valarray&& __v) _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000811#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000812#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Douglas Gregor0855dde2012-05-19 07:14:17 +0000813 valarray(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +0000814#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Douglas Gregor0855dde2012-05-19 07:14:17 +0000815 valarray(const slice_array<value_type>& __sa);
816 valarray(const gslice_array<value_type>& __ga);
817 valarray(const mask_array<value_type>& __ma);
818 valarray(const indirect_array<value_type>& __ia);
819 ~valarray();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000820
821 // assignment:
Douglas Gregor0855dde2012-05-19 07:14:17 +0000822 valarray& operator=(const valarray& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000823#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbd143082012-07-21 00:51:28 +0000824 valarray& operator=(valarray&& __v) _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000825#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000826#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Douglas Gregor0855dde2012-05-19 07:14:17 +0000827 valarray& operator=(initializer_list<value_type>);
Howard Hinnante3e32912011-08-12 21:56:02 +0000828#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Douglas Gregor0855dde2012-05-19 07:14:17 +0000829 valarray& operator=(const value_type& __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000830 valarray& operator=(const slice_array<value_type>& __sa);
831 valarray& operator=(const gslice_array<value_type>& __ga);
832 valarray& operator=(const mask_array<value_type>& __ma);
833 valarray& operator=(const indirect_array<value_type>& __ia);
Howard Hinnantdb866632011-07-27 23:19:59 +0000834 template <class _ValExpr>
835 valarray& operator=(const __val_expr<_ValExpr>& __v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000836
837 // element access:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000839 const value_type& operator[](size_t __i) const {return __begin_[__i];}
840
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000841 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000842 value_type& operator[](size_t __i) {return __begin_[__i];}
843
844 // subset operations:
845 __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const;
846 slice_array<value_type> operator[](slice __s);
847 __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
848 gslice_array<value_type> operator[](const gslice& __gs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000849#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000850 __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
851 gslice_array<value_type> operator[](gslice&& __gs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000852#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000853 __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const;
854 mask_array<value_type> operator[](const valarray<bool>& __vb);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000855#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000856 __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const;
857 mask_array<value_type> operator[](valarray<bool>&& __vb);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000858#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000859 __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
860 indirect_array<value_type> operator[](const valarray<size_t>& __vs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000861#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862 __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
863 indirect_array<value_type> operator[](valarray<size_t>&& __vs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000864#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000865
866 // unary operators:
Douglas Gregor0855dde2012-05-19 07:14:17 +0000867 valarray operator+() const;
868 valarray operator-() const;
869 valarray operator~() const;
870 valarray<bool> operator!() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000871
872 // computed assignment:
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 valarray& operator<<=(const value_type& __x);
882 valarray& operator>>=(const value_type& __x);
883
884 template <class _Expr>
885 typename enable_if
886 <
887 __is_val_expr<_Expr>::value,
888 valarray&
889 >::type
890 operator*= (const _Expr& __v);
891
892 template <class _Expr>
893 typename enable_if
894 <
895 __is_val_expr<_Expr>::value,
896 valarray&
897 >::type
898 operator/= (const _Expr& __v);
899
900 template <class _Expr>
901 typename enable_if
902 <
903 __is_val_expr<_Expr>::value,
904 valarray&
905 >::type
906 operator%= (const _Expr& __v);
907
908 template <class _Expr>
909 typename enable_if
910 <
911 __is_val_expr<_Expr>::value,
912 valarray&
913 >::type
914 operator+= (const _Expr& __v);
915
916 template <class _Expr>
917 typename enable_if
918 <
919 __is_val_expr<_Expr>::value,
920 valarray&
921 >::type
922 operator-= (const _Expr& __v);
923
924 template <class _Expr>
925 typename enable_if
926 <
927 __is_val_expr<_Expr>::value,
928 valarray&
929 >::type
930 operator^= (const _Expr& __v);
931
932 template <class _Expr>
933 typename enable_if
934 <
935 __is_val_expr<_Expr>::value,
936 valarray&
937 >::type
938 operator|= (const _Expr& __v);
939
940 template <class _Expr>
941 typename enable_if
942 <
943 __is_val_expr<_Expr>::value,
944 valarray&
945 >::type
946 operator&= (const _Expr& __v);
947
948 template <class _Expr>
949 typename enable_if
950 <
951 __is_val_expr<_Expr>::value,
952 valarray&
953 >::type
954 operator<<= (const _Expr& __v);
955
956 template <class _Expr>
957 typename enable_if
958 <
959 __is_val_expr<_Expr>::value,
960 valarray&
961 >::type
962 operator>>= (const _Expr& __v);
963
964 // member functions:
Howard Hinnantbd143082012-07-21 00:51:28 +0000965 void swap(valarray& __v) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000966
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +0000968 size_t size() const {return static_cast<size_t>(__end_ - __begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000969
Douglas Gregor0855dde2012-05-19 07:14:17 +0000970 value_type sum() const;
971 value_type min() const;
972 value_type max() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000973
Douglas Gregor0855dde2012-05-19 07:14:17 +0000974 valarray shift (int __i) const;
975 valarray cshift(int __i) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000976 valarray apply(value_type __f(value_type)) const;
977 valarray apply(value_type __f(const value_type&)) const;
978 void resize(size_t __n, value_type __x = value_type());
979
980private:
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000981 template <class> friend class _LIBCPP_TYPE_VIS_ONLY valarray;
982 template <class> friend class _LIBCPP_TYPE_VIS_ONLY slice_array;
983 template <class> friend class _LIBCPP_TYPE_VIS_ONLY gslice_array;
984 template <class> friend class _LIBCPP_TYPE_VIS_ONLY mask_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000985 template <class> friend class __mask_expr;
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000986 template <class> friend class _LIBCPP_TYPE_VIS_ONLY indirect_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000987 template <class> friend class __indirect_expr;
988 template <class> friend class __val_expr;
989
990 template <class _Up>
991 friend
992 _Up*
993 begin(valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +0000994
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000995 template <class _Up>
996 friend
997 const _Up*
998 begin(const valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +0000999
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001000 template <class _Up>
1001 friend
1002 _Up*
1003 end(valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +00001004
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001005 template <class _Up>
1006 friend
1007 const _Up*
1008 end(const valarray<_Up>& __v);
1009};
1010
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001011_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::valarray(size_t))
1012_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::~valarray())
1013_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void valarray<size_t>::resize(size_t, size_t))
1014
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001015template <class _Op, class _Tp>
1016struct _UnaryOp<_Op, valarray<_Tp> >
1017{
1018 typedef typename _Op::result_type result_type;
1019 typedef _Tp value_type;
1020
1021 _Op __op_;
1022 const valarray<_Tp>& __a0_;
1023
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001024 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001025 _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
1026
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001027 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001028 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
1029
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001030 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001031 size_t size() const {return __a0_.size();}
1032};
1033
1034template <class _Op, class _Tp, class _A1>
1035struct _BinaryOp<_Op, valarray<_Tp>, _A1>
1036{
1037 typedef typename _Op::result_type result_type;
1038 typedef _Tp value_type;
1039
1040 _Op __op_;
1041 const valarray<_Tp>& __a0_;
1042 _A1 __a1_;
1043
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001044 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001045 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
1046 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1047
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001048 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001049 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1050
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001051 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001052 size_t size() const {return __a0_.size();}
1053};
1054
1055template <class _Op, class _A0, class _Tp>
1056struct _BinaryOp<_Op, _A0, valarray<_Tp> >
1057{
1058 typedef typename _Op::result_type result_type;
1059 typedef _Tp value_type;
1060
1061 _Op __op_;
1062 _A0 __a0_;
1063 const valarray<_Tp>& __a1_;
1064
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001065 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001066 _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
1067 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1068
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001069 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1071
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001072 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001073 size_t size() const {return __a0_.size();}
1074};
1075
1076template <class _Op, class _Tp>
1077struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> >
1078{
1079 typedef typename _Op::result_type result_type;
1080 typedef _Tp value_type;
1081
1082 _Op __op_;
1083 const valarray<_Tp>& __a0_;
1084 const valarray<_Tp>& __a1_;
1085
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001086 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001087 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
1088 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1089
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001091 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1092
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001094 size_t size() const {return __a0_.size();}
1095};
1096
1097// slice_array
1098
1099template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001100class _LIBCPP_TYPE_VIS_ONLY slice_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001101{
1102public:
1103 typedef _Tp value_type;
1104
1105private:
1106 value_type* __vp_;
1107 size_t __size_;
1108 size_t __stride_;
1109
1110public:
1111 template <class _Expr>
1112 typename enable_if
1113 <
1114 __is_val_expr<_Expr>::value,
1115 void
1116 >::type
1117 operator=(const _Expr& __v) const;
1118
1119 template <class _Expr>
1120 typename enable_if
1121 <
1122 __is_val_expr<_Expr>::value,
1123 void
1124 >::type
1125 operator*=(const _Expr& __v) const;
1126
1127 template <class _Expr>
1128 typename enable_if
1129 <
1130 __is_val_expr<_Expr>::value,
1131 void
1132 >::type
1133 operator/=(const _Expr& __v) const;
1134
1135 template <class _Expr>
1136 typename enable_if
1137 <
1138 __is_val_expr<_Expr>::value,
1139 void
1140 >::type
1141 operator%=(const _Expr& __v) const;
1142
1143 template <class _Expr>
1144 typename enable_if
1145 <
1146 __is_val_expr<_Expr>::value,
1147 void
1148 >::type
1149 operator+=(const _Expr& __v) const;
1150
1151 template <class _Expr>
1152 typename enable_if
1153 <
1154 __is_val_expr<_Expr>::value,
1155 void
1156 >::type
1157 operator-=(const _Expr& __v) const;
1158
1159 template <class _Expr>
1160 typename enable_if
1161 <
1162 __is_val_expr<_Expr>::value,
1163 void
1164 >::type
1165 operator^=(const _Expr& __v) const;
1166
1167 template <class _Expr>
1168 typename enable_if
1169 <
1170 __is_val_expr<_Expr>::value,
1171 void
1172 >::type
1173 operator&=(const _Expr& __v) const;
1174
1175 template <class _Expr>
1176 typename enable_if
1177 <
1178 __is_val_expr<_Expr>::value,
1179 void
1180 >::type
1181 operator|=(const _Expr& __v) const;
1182
1183 template <class _Expr>
1184 typename enable_if
1185 <
1186 __is_val_expr<_Expr>::value,
1187 void
1188 >::type
1189 operator<<=(const _Expr& __v) const;
1190
1191 template <class _Expr>
1192 typename enable_if
1193 <
1194 __is_val_expr<_Expr>::value,
1195 void
1196 >::type
1197 operator>>=(const _Expr& __v) const;
1198
1199 const slice_array& operator=(const slice_array& __sa) const;
1200
1201 void operator=(const value_type& __x) const;
1202
1203private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001204 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001205 slice_array(const slice& __sl, const valarray<value_type>& __v)
1206 : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())),
1207 __size_(__sl.size()),
1208 __stride_(__sl.stride())
1209 {}
1210
1211 template <class> friend class valarray;
1212 template <class> friend class sliceExpr;
1213};
1214
1215template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001216inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001217const slice_array<_Tp>&
1218slice_array<_Tp>::operator=(const slice_array& __sa) const
1219{
1220 value_type* __t = __vp_;
1221 const value_type* __s = __sa.__vp_;
1222 for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
1223 *__t = *__s;
Dan Albert90dc8dd2014-08-26 11:20:46 -07001224 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001225}
1226
1227template <class _Tp>
1228template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001229inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001230typename enable_if
1231<
1232 __is_val_expr<_Expr>::value,
1233 void
1234>::type
1235slice_array<_Tp>::operator=(const _Expr& __v) const
1236{
1237 value_type* __t = __vp_;
1238 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1239 *__t = __v[__i];
1240}
1241
1242template <class _Tp>
1243template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001244inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001245typename enable_if
1246<
1247 __is_val_expr<_Expr>::value,
1248 void
1249>::type
1250slice_array<_Tp>::operator*=(const _Expr& __v) const
1251{
1252 value_type* __t = __vp_;
1253 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1254 *__t *= __v[__i];
1255}
1256
1257template <class _Tp>
1258template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001259inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001260typename enable_if
1261<
1262 __is_val_expr<_Expr>::value,
1263 void
1264>::type
1265slice_array<_Tp>::operator/=(const _Expr& __v) const
1266{
1267 value_type* __t = __vp_;
1268 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1269 *__t /= __v[__i];
1270}
1271
1272template <class _Tp>
1273template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001274inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001275typename enable_if
1276<
1277 __is_val_expr<_Expr>::value,
1278 void
1279>::type
1280slice_array<_Tp>::operator%=(const _Expr& __v) const
1281{
1282 value_type* __t = __vp_;
1283 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1284 *__t %= __v[__i];
1285}
1286
1287template <class _Tp>
1288template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001289inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001290typename enable_if
1291<
1292 __is_val_expr<_Expr>::value,
1293 void
1294>::type
1295slice_array<_Tp>::operator+=(const _Expr& __v) const
1296{
1297 value_type* __t = __vp_;
1298 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1299 *__t += __v[__i];
1300}
1301
1302template <class _Tp>
1303template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001304inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001305typename enable_if
1306<
1307 __is_val_expr<_Expr>::value,
1308 void
1309>::type
1310slice_array<_Tp>::operator-=(const _Expr& __v) const
1311{
1312 value_type* __t = __vp_;
1313 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1314 *__t -= __v[__i];
1315}
1316
1317template <class _Tp>
1318template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001319inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001320typename enable_if
1321<
1322 __is_val_expr<_Expr>::value,
1323 void
1324>::type
1325slice_array<_Tp>::operator^=(const _Expr& __v) const
1326{
1327 value_type* __t = __vp_;
1328 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1329 *__t ^= __v[__i];
1330}
1331
1332template <class _Tp>
1333template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001334inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001335typename enable_if
1336<
1337 __is_val_expr<_Expr>::value,
1338 void
1339>::type
1340slice_array<_Tp>::operator&=(const _Expr& __v) const
1341{
1342 value_type* __t = __vp_;
1343 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1344 *__t &= __v[__i];
1345}
1346
1347template <class _Tp>
1348template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001349inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001350typename enable_if
1351<
1352 __is_val_expr<_Expr>::value,
1353 void
1354>::type
1355slice_array<_Tp>::operator|=(const _Expr& __v) const
1356{
1357 value_type* __t = __vp_;
1358 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1359 *__t |= __v[__i];
1360}
1361
1362template <class _Tp>
1363template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001364inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001365typename enable_if
1366<
1367 __is_val_expr<_Expr>::value,
1368 void
1369>::type
1370slice_array<_Tp>::operator<<=(const _Expr& __v) const
1371{
1372 value_type* __t = __vp_;
1373 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1374 *__t <<= __v[__i];
1375}
1376
1377template <class _Tp>
1378template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001379inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001380typename enable_if
1381<
1382 __is_val_expr<_Expr>::value,
1383 void
1384>::type
1385slice_array<_Tp>::operator>>=(const _Expr& __v) const
1386{
1387 value_type* __t = __vp_;
1388 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1389 *__t >>= __v[__i];
1390}
1391
1392template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001393inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001394void
1395slice_array<_Tp>::operator=(const value_type& __x) const
1396{
1397 value_type* __t = __vp_;
1398 for (size_t __n = __size_; __n; --__n, __t += __stride_)
1399 *__t = __x;
1400}
1401
1402// gslice
1403
Howard Hinnant83eade62013-03-06 23:30:19 +00001404class _LIBCPP_TYPE_VIS gslice
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001405{
1406 valarray<size_t> __size_;
1407 valarray<size_t> __stride_;
1408 valarray<size_t> __1d_;
Howard Hinnant324bb032010-08-22 00:02:43 +00001409
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001410public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001411 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001412 gslice() {}
Douglas Gregor0855dde2012-05-19 07:14:17 +00001413
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001414 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001415 gslice(size_t __start, const valarray<size_t>& __size,
1416 const valarray<size_t>& __stride)
1417 : __size_(__size),
1418 __stride_(__stride)
1419 {__init(__start);}
1420
Howard Hinnant73d21a42010-09-04 23:28:19 +00001421#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001422
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001423 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001424 gslice(size_t __start, const valarray<size_t>& __size,
1425 valarray<size_t>&& __stride)
1426 : __size_(__size),
1427 __stride_(move(__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 const valarray<size_t>& __stride)
1433 : __size_(move(__size)),
1434 __stride_(__stride)
1435 {__init(__start);}
1436
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001437 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001438 gslice(size_t __start, valarray<size_t>&& __size,
1439 valarray<size_t>&& __stride)
1440 : __size_(move(__size)),
1441 __stride_(move(__stride))
1442 {__init(__start);}
1443
Howard Hinnant73d21a42010-09-04 23:28:19 +00001444#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001445
1446// gslice(const gslice&) = default;
1447// gslice(gslice&&) = default;
1448// gslice& operator=(const gslice&) = default;
1449// gslice& operator=(gslice&&) = default;
1450
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001451 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001452 size_t start() const {return __1d_.size() ? __1d_[0] : 0;}
1453
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001454 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001455 valarray<size_t> size() const {return __size_;}
1456
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001457 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001458 valarray<size_t> stride() const {return __stride_;}
1459
1460private:
1461 void __init(size_t __start);
1462
1463 template <class> friend class gslice_array;
1464 template <class> friend class valarray;
1465 template <class> friend class __val_expr;
1466};
1467
1468// gslice_array
1469
1470template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001471class _LIBCPP_TYPE_VIS_ONLY gslice_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001472{
1473public:
1474 typedef _Tp value_type;
1475
1476private:
1477 value_type* __vp_;
1478 valarray<size_t> __1d_;
1479
1480public:
1481 template <class _Expr>
1482 typename enable_if
1483 <
1484 __is_val_expr<_Expr>::value,
1485 void
1486 >::type
1487 operator=(const _Expr& __v) const;
1488
1489 template <class _Expr>
1490 typename enable_if
1491 <
1492 __is_val_expr<_Expr>::value,
1493 void
1494 >::type
1495 operator*=(const _Expr& __v) const;
1496
1497 template <class _Expr>
1498 typename enable_if
1499 <
1500 __is_val_expr<_Expr>::value,
1501 void
1502 >::type
1503 operator/=(const _Expr& __v) const;
1504
1505 template <class _Expr>
1506 typename enable_if
1507 <
1508 __is_val_expr<_Expr>::value,
1509 void
1510 >::type
1511 operator%=(const _Expr& __v) const;
1512
1513 template <class _Expr>
1514 typename enable_if
1515 <
1516 __is_val_expr<_Expr>::value,
1517 void
1518 >::type
1519 operator+=(const _Expr& __v) const;
1520
1521 template <class _Expr>
1522 typename enable_if
1523 <
1524 __is_val_expr<_Expr>::value,
1525 void
1526 >::type
1527 operator-=(const _Expr& __v) const;
1528
1529 template <class _Expr>
1530 typename enable_if
1531 <
1532 __is_val_expr<_Expr>::value,
1533 void
1534 >::type
1535 operator^=(const _Expr& __v) const;
1536
1537 template <class _Expr>
1538 typename enable_if
1539 <
1540 __is_val_expr<_Expr>::value,
1541 void
1542 >::type
1543 operator&=(const _Expr& __v) const;
1544
1545 template <class _Expr>
1546 typename enable_if
1547 <
1548 __is_val_expr<_Expr>::value,
1549 void
1550 >::type
1551 operator|=(const _Expr& __v) const;
1552
1553 template <class _Expr>
1554 typename enable_if
1555 <
1556 __is_val_expr<_Expr>::value,
1557 void
1558 >::type
1559 operator<<=(const _Expr& __v) const;
1560
1561 template <class _Expr>
1562 typename enable_if
1563 <
1564 __is_val_expr<_Expr>::value,
1565 void
1566 >::type
1567 operator>>=(const _Expr& __v) const;
1568
1569 const gslice_array& operator=(const gslice_array& __ga) const;
1570
1571 void operator=(const value_type& __x) const;
1572
1573// gslice_array(const gslice_array&) = default;
1574// gslice_array(gslice_array&&) = default;
1575// gslice_array& operator=(const gslice_array&) = default;
1576// gslice_array& operator=(gslice_array&&) = default;
1577
1578private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001579 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001580 gslice_array(const gslice& __gs, const valarray<value_type>& __v)
1581 : __vp_(const_cast<value_type*>(__v.__begin_)),
1582 __1d_(__gs.__1d_)
1583 {}
1584
Howard Hinnant73d21a42010-09-04 23:28:19 +00001585#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001586
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001588 gslice_array(gslice&& __gs, const valarray<value_type>& __v)
1589 : __vp_(const_cast<value_type*>(__v.__begin_)),
1590 __1d_(move(__gs.__1d_))
1591 {}
1592
Howard Hinnant73d21a42010-09-04 23:28:19 +00001593#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001594
1595 template <class> friend class valarray;
1596};
1597
1598template <class _Tp>
1599template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001600inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001601typename enable_if
1602<
1603 __is_val_expr<_Expr>::value,
1604 void
1605>::type
1606gslice_array<_Tp>::operator=(const _Expr& __v) const
1607{
1608 typedef const size_t* _Ip;
1609 size_t __j = 0;
1610 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1611 __vp_[*__i] = __v[__j];
1612}
1613
1614template <class _Tp>
1615template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001616inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001617typename enable_if
1618<
1619 __is_val_expr<_Expr>::value,
1620 void
1621>::type
1622gslice_array<_Tp>::operator*=(const _Expr& __v) const
1623{
1624 typedef const size_t* _Ip;
1625 size_t __j = 0;
1626 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1627 __vp_[*__i] *= __v[__j];
1628}
1629
1630template <class _Tp>
1631template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001632inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001633typename enable_if
1634<
1635 __is_val_expr<_Expr>::value,
1636 void
1637>::type
1638gslice_array<_Tp>::operator/=(const _Expr& __v) const
1639{
1640 typedef const size_t* _Ip;
1641 size_t __j = 0;
1642 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1643 __vp_[*__i] /= __v[__j];
1644}
1645
1646template <class _Tp>
1647template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001648inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001649typename enable_if
1650<
1651 __is_val_expr<_Expr>::value,
1652 void
1653>::type
1654gslice_array<_Tp>::operator%=(const _Expr& __v) const
1655{
1656 typedef const size_t* _Ip;
1657 size_t __j = 0;
1658 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1659 __vp_[*__i] %= __v[__j];
1660}
1661
1662template <class _Tp>
1663template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001664inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001665typename enable_if
1666<
1667 __is_val_expr<_Expr>::value,
1668 void
1669>::type
1670gslice_array<_Tp>::operator+=(const _Expr& __v) const
1671{
1672 typedef const size_t* _Ip;
1673 size_t __j = 0;
1674 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1675 __vp_[*__i] += __v[__j];
1676}
1677
1678template <class _Tp>
1679template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001680inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001681typename enable_if
1682<
1683 __is_val_expr<_Expr>::value,
1684 void
1685>::type
1686gslice_array<_Tp>::operator-=(const _Expr& __v) const
1687{
1688 typedef const size_t* _Ip;
1689 size_t __j = 0;
1690 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1691 __vp_[*__i] -= __v[__j];
1692}
1693
1694template <class _Tp>
1695template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001696inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001697typename enable_if
1698<
1699 __is_val_expr<_Expr>::value,
1700 void
1701>::type
1702gslice_array<_Tp>::operator^=(const _Expr& __v) const
1703{
1704 typedef const size_t* _Ip;
1705 size_t __j = 0;
1706 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1707 __vp_[*__i] ^= __v[__j];
1708}
1709
1710template <class _Tp>
1711template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001712inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001713typename enable_if
1714<
1715 __is_val_expr<_Expr>::value,
1716 void
1717>::type
1718gslice_array<_Tp>::operator&=(const _Expr& __v) const
1719{
1720 typedef const size_t* _Ip;
1721 size_t __j = 0;
1722 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1723 __vp_[*__i] &= __v[__j];
1724}
1725
1726template <class _Tp>
1727template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001728inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001729typename enable_if
1730<
1731 __is_val_expr<_Expr>::value,
1732 void
1733>::type
1734gslice_array<_Tp>::operator|=(const _Expr& __v) const
1735{
1736 typedef const size_t* _Ip;
1737 size_t __j = 0;
1738 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1739 __vp_[*__i] |= __v[__j];
1740}
1741
1742template <class _Tp>
1743template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001744inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001745typename enable_if
1746<
1747 __is_val_expr<_Expr>::value,
1748 void
1749>::type
1750gslice_array<_Tp>::operator<<=(const _Expr& __v) const
1751{
1752 typedef const size_t* _Ip;
1753 size_t __j = 0;
1754 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1755 __vp_[*__i] <<= __v[__j];
1756}
1757
1758template <class _Tp>
1759template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001760inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001761typename enable_if
1762<
1763 __is_val_expr<_Expr>::value,
1764 void
1765>::type
1766gslice_array<_Tp>::operator>>=(const _Expr& __v) const
1767{
1768 typedef const size_t* _Ip;
1769 size_t __j = 0;
1770 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1771 __vp_[*__i] >>= __v[__j];
1772}
1773
1774template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001775inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001776const gslice_array<_Tp>&
1777gslice_array<_Tp>::operator=(const gslice_array& __ga) const
1778{
1779 typedef const size_t* _Ip;
1780 const value_type* __s = __ga.__vp_;
1781 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_;
1782 __i != __e; ++__i, ++__j)
1783 __vp_[*__i] = __s[*__j];
1784 return *this;
1785}
1786
1787template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001788inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001789void
1790gslice_array<_Tp>::operator=(const value_type& __x) const
1791{
1792 typedef const size_t* _Ip;
1793 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1794 __vp_[*__i] = __x;
1795}
1796
1797// mask_array
1798
1799template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001800class _LIBCPP_TYPE_VIS_ONLY mask_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001801{
1802public:
1803 typedef _Tp value_type;
1804
1805private:
1806 value_type* __vp_;
1807 valarray<size_t> __1d_;
1808
1809public:
1810 template <class _Expr>
1811 typename enable_if
1812 <
1813 __is_val_expr<_Expr>::value,
1814 void
1815 >::type
1816 operator=(const _Expr& __v) const;
1817
1818 template <class _Expr>
1819 typename enable_if
1820 <
1821 __is_val_expr<_Expr>::value,
1822 void
1823 >::type
1824 operator*=(const _Expr& __v) const;
1825
1826 template <class _Expr>
1827 typename enable_if
1828 <
1829 __is_val_expr<_Expr>::value,
1830 void
1831 >::type
1832 operator/=(const _Expr& __v) const;
1833
1834 template <class _Expr>
1835 typename enable_if
1836 <
1837 __is_val_expr<_Expr>::value,
1838 void
1839 >::type
1840 operator%=(const _Expr& __v) const;
1841
1842 template <class _Expr>
1843 typename enable_if
1844 <
1845 __is_val_expr<_Expr>::value,
1846 void
1847 >::type
1848 operator+=(const _Expr& __v) const;
1849
1850 template <class _Expr>
1851 typename enable_if
1852 <
1853 __is_val_expr<_Expr>::value,
1854 void
1855 >::type
1856 operator-=(const _Expr& __v) const;
1857
1858 template <class _Expr>
1859 typename enable_if
1860 <
1861 __is_val_expr<_Expr>::value,
1862 void
1863 >::type
1864 operator^=(const _Expr& __v) const;
1865
1866 template <class _Expr>
1867 typename enable_if
1868 <
1869 __is_val_expr<_Expr>::value,
1870 void
1871 >::type
1872 operator&=(const _Expr& __v) const;
1873
1874 template <class _Expr>
1875 typename enable_if
1876 <
1877 __is_val_expr<_Expr>::value,
1878 void
1879 >::type
1880 operator|=(const _Expr& __v) const;
1881
1882 template <class _Expr>
1883 typename enable_if
1884 <
1885 __is_val_expr<_Expr>::value,
1886 void
1887 >::type
1888 operator<<=(const _Expr& __v) const;
1889
1890 template <class _Expr>
1891 typename enable_if
1892 <
1893 __is_val_expr<_Expr>::value,
1894 void
1895 >::type
1896 operator>>=(const _Expr& __v) const;
1897
1898 const mask_array& operator=(const mask_array& __ma) const;
1899
1900 void operator=(const value_type& __x) const;
1901
1902// mask_array(const mask_array&) = default;
1903// mask_array(mask_array&&) = default;
1904// mask_array& operator=(const mask_array&) = default;
1905// mask_array& operator=(mask_array&&) = default;
1906
1907private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001909 mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
1910 : __vp_(const_cast<value_type*>(__v.__begin_)),
Howard Hinnantec3773c2011-12-01 20:21:04 +00001911 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001912 {
1913 size_t __j = 0;
1914 for (size_t __i = 0; __i < __vb.size(); ++__i)
1915 if (__vb[__i])
1916 __1d_[__j++] = __i;
1917 }
1918
1919 template <class> friend class valarray;
1920};
1921
1922template <class _Tp>
1923template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001924inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001925typename enable_if
1926<
1927 __is_val_expr<_Expr>::value,
1928 void
1929>::type
1930mask_array<_Tp>::operator=(const _Expr& __v) const
1931{
1932 size_t __n = __1d_.size();
1933 for (size_t __i = 0; __i < __n; ++__i)
1934 __vp_[__1d_[__i]] = __v[__i];
1935}
1936
1937template <class _Tp>
1938template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001939inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001940typename enable_if
1941<
1942 __is_val_expr<_Expr>::value,
1943 void
1944>::type
1945mask_array<_Tp>::operator*=(const _Expr& __v) const
1946{
1947 size_t __n = __1d_.size();
1948 for (size_t __i = 0; __i < __n; ++__i)
1949 __vp_[__1d_[__i]] *= __v[__i];
1950}
1951
1952template <class _Tp>
1953template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001954inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001955typename enable_if
1956<
1957 __is_val_expr<_Expr>::value,
1958 void
1959>::type
1960mask_array<_Tp>::operator/=(const _Expr& __v) const
1961{
1962 size_t __n = __1d_.size();
1963 for (size_t __i = 0; __i < __n; ++__i)
1964 __vp_[__1d_[__i]] /= __v[__i];
1965}
1966
1967template <class _Tp>
1968template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001969inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001970typename enable_if
1971<
1972 __is_val_expr<_Expr>::value,
1973 void
1974>::type
1975mask_array<_Tp>::operator%=(const _Expr& __v) const
1976{
1977 size_t __n = __1d_.size();
1978 for (size_t __i = 0; __i < __n; ++__i)
1979 __vp_[__1d_[__i]] %= __v[__i];
1980}
1981
1982template <class _Tp>
1983template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001984inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001985typename enable_if
1986<
1987 __is_val_expr<_Expr>::value,
1988 void
1989>::type
1990mask_array<_Tp>::operator+=(const _Expr& __v) const
1991{
1992 size_t __n = __1d_.size();
1993 for (size_t __i = 0; __i < __n; ++__i)
1994 __vp_[__1d_[__i]] += __v[__i];
1995}
1996
1997template <class _Tp>
1998template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001999inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002000typename enable_if
2001<
2002 __is_val_expr<_Expr>::value,
2003 void
2004>::type
2005mask_array<_Tp>::operator-=(const _Expr& __v) const
2006{
2007 size_t __n = __1d_.size();
2008 for (size_t __i = 0; __i < __n; ++__i)
2009 __vp_[__1d_[__i]] -= __v[__i];
2010}
2011
2012template <class _Tp>
2013template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002014inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002015typename enable_if
2016<
2017 __is_val_expr<_Expr>::value,
2018 void
2019>::type
2020mask_array<_Tp>::operator^=(const _Expr& __v) const
2021{
2022 size_t __n = __1d_.size();
2023 for (size_t __i = 0; __i < __n; ++__i)
2024 __vp_[__1d_[__i]] ^= __v[__i];
2025}
2026
2027template <class _Tp>
2028template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002029inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002030typename enable_if
2031<
2032 __is_val_expr<_Expr>::value,
2033 void
2034>::type
2035mask_array<_Tp>::operator&=(const _Expr& __v) const
2036{
2037 size_t __n = __1d_.size();
2038 for (size_t __i = 0; __i < __n; ++__i)
2039 __vp_[__1d_[__i]] &= __v[__i];
2040}
2041
2042template <class _Tp>
2043template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002044inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002045typename enable_if
2046<
2047 __is_val_expr<_Expr>::value,
2048 void
2049>::type
2050mask_array<_Tp>::operator|=(const _Expr& __v) const
2051{
2052 size_t __n = __1d_.size();
2053 for (size_t __i = 0; __i < __n; ++__i)
2054 __vp_[__1d_[__i]] |= __v[__i];
2055}
2056
2057template <class _Tp>
2058template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002059inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002060typename enable_if
2061<
2062 __is_val_expr<_Expr>::value,
2063 void
2064>::type
2065mask_array<_Tp>::operator<<=(const _Expr& __v) const
2066{
2067 size_t __n = __1d_.size();
2068 for (size_t __i = 0; __i < __n; ++__i)
2069 __vp_[__1d_[__i]] <<= __v[__i];
2070}
2071
2072template <class _Tp>
2073template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002074inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002075typename enable_if
2076<
2077 __is_val_expr<_Expr>::value,
2078 void
2079>::type
2080mask_array<_Tp>::operator>>=(const _Expr& __v) const
2081{
2082 size_t __n = __1d_.size();
2083 for (size_t __i = 0; __i < __n; ++__i)
2084 __vp_[__1d_[__i]] >>= __v[__i];
2085}
2086
2087template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002088inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002089const mask_array<_Tp>&
2090mask_array<_Tp>::operator=(const mask_array& __ma) const
2091{
2092 size_t __n = __1d_.size();
2093 for (size_t __i = 0; __i < __n; ++__i)
2094 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
Dan Albert90dc8dd2014-08-26 11:20:46 -07002095 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002096}
2097
2098template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002099inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002100void
2101mask_array<_Tp>::operator=(const value_type& __x) const
2102{
2103 size_t __n = __1d_.size();
2104 for (size_t __i = 0; __i < __n; ++__i)
2105 __vp_[__1d_[__i]] = __x;
2106}
2107
2108template <class _ValExpr>
2109class __mask_expr
2110{
2111 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2112public:
2113 typedef typename _RmExpr::value_type value_type;
2114 typedef value_type result_type;
2115
2116private:
2117 _ValExpr __expr_;
2118 valarray<size_t> __1d_;
2119
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002120 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002121 __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
2122 : __expr_(__e),
Howard Hinnantec3773c2011-12-01 20:21:04 +00002123 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002124 {
2125 size_t __j = 0;
2126 for (size_t __i = 0; __i < __vb.size(); ++__i)
2127 if (__vb[__i])
2128 __1d_[__j++] = __i;
2129 }
2130
2131public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002132 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002133 result_type operator[](size_t __i) const
2134 {return __expr_[__1d_[__i]];}
2135
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002136 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002137 size_t size() const {return __1d_.size();}
2138
2139 template <class> friend class valarray;
2140};
2141
2142// indirect_array
2143
2144template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002145class _LIBCPP_TYPE_VIS_ONLY indirect_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002146{
2147public:
2148 typedef _Tp value_type;
2149
2150private:
2151 value_type* __vp_;
2152 valarray<size_t> __1d_;
2153
2154public:
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 template <class _Expr>
2236 typename enable_if
2237 <
2238 __is_val_expr<_Expr>::value,
2239 void
2240 >::type
2241 operator>>=(const _Expr& __v) const;
2242
2243 const indirect_array& operator=(const indirect_array& __ia) const;
2244
2245 void operator=(const value_type& __x) const;
2246
2247// indirect_array(const indirect_array&) = default;
2248// indirect_array(indirect_array&&) = default;
2249// indirect_array& operator=(const indirect_array&) = default;
2250// indirect_array& operator=(indirect_array&&) = default;
2251
2252private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002254 indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
2255 : __vp_(const_cast<value_type*>(__v.__begin_)),
2256 __1d_(__ia)
2257 {}
2258
Howard Hinnant73d21a42010-09-04 23:28:19 +00002259#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002260
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002261 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002262 indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
2263 : __vp_(const_cast<value_type*>(__v.__begin_)),
2264 __1d_(move(__ia))
2265 {}
2266
Howard Hinnant73d21a42010-09-04 23:28:19 +00002267#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002268
2269 template <class> friend class valarray;
2270};
2271
2272template <class _Tp>
2273template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002274inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002275typename enable_if
2276<
2277 __is_val_expr<_Expr>::value,
2278 void
2279>::type
2280indirect_array<_Tp>::operator=(const _Expr& __v) const
2281{
2282 size_t __n = __1d_.size();
2283 for (size_t __i = 0; __i < __n; ++__i)
2284 __vp_[__1d_[__i]] = __v[__i];
2285}
2286
2287template <class _Tp>
2288template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002289inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002290typename enable_if
2291<
2292 __is_val_expr<_Expr>::value,
2293 void
2294>::type
2295indirect_array<_Tp>::operator*=(const _Expr& __v) const
2296{
2297 size_t __n = __1d_.size();
2298 for (size_t __i = 0; __i < __n; ++__i)
2299 __vp_[__1d_[__i]] *= __v[__i];
2300}
2301
2302template <class _Tp>
2303template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002304inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002305typename enable_if
2306<
2307 __is_val_expr<_Expr>::value,
2308 void
2309>::type
2310indirect_array<_Tp>::operator/=(const _Expr& __v) const
2311{
2312 size_t __n = __1d_.size();
2313 for (size_t __i = 0; __i < __n; ++__i)
2314 __vp_[__1d_[__i]] /= __v[__i];
2315}
2316
2317template <class _Tp>
2318template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002319inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002320typename enable_if
2321<
2322 __is_val_expr<_Expr>::value,
2323 void
2324>::type
2325indirect_array<_Tp>::operator%=(const _Expr& __v) const
2326{
2327 size_t __n = __1d_.size();
2328 for (size_t __i = 0; __i < __n; ++__i)
2329 __vp_[__1d_[__i]] %= __v[__i];
2330}
2331
2332template <class _Tp>
2333template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002334inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002335typename enable_if
2336<
2337 __is_val_expr<_Expr>::value,
2338 void
2339>::type
2340indirect_array<_Tp>::operator+=(const _Expr& __v) const
2341{
2342 size_t __n = __1d_.size();
2343 for (size_t __i = 0; __i < __n; ++__i)
2344 __vp_[__1d_[__i]] += __v[__i];
2345}
2346
2347template <class _Tp>
2348template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002349inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002350typename enable_if
2351<
2352 __is_val_expr<_Expr>::value,
2353 void
2354>::type
2355indirect_array<_Tp>::operator-=(const _Expr& __v) const
2356{
2357 size_t __n = __1d_.size();
2358 for (size_t __i = 0; __i < __n; ++__i)
2359 __vp_[__1d_[__i]] -= __v[__i];
2360}
2361
2362template <class _Tp>
2363template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002364inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002365typename enable_if
2366<
2367 __is_val_expr<_Expr>::value,
2368 void
2369>::type
2370indirect_array<_Tp>::operator^=(const _Expr& __v) const
2371{
2372 size_t __n = __1d_.size();
2373 for (size_t __i = 0; __i < __n; ++__i)
2374 __vp_[__1d_[__i]] ^= __v[__i];
2375}
2376
2377template <class _Tp>
2378template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002379inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002380typename enable_if
2381<
2382 __is_val_expr<_Expr>::value,
2383 void
2384>::type
2385indirect_array<_Tp>::operator&=(const _Expr& __v) const
2386{
2387 size_t __n = __1d_.size();
2388 for (size_t __i = 0; __i < __n; ++__i)
2389 __vp_[__1d_[__i]] &= __v[__i];
2390}
2391
2392template <class _Tp>
2393template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002394inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002395typename enable_if
2396<
2397 __is_val_expr<_Expr>::value,
2398 void
2399>::type
2400indirect_array<_Tp>::operator|=(const _Expr& __v) const
2401{
2402 size_t __n = __1d_.size();
2403 for (size_t __i = 0; __i < __n; ++__i)
2404 __vp_[__1d_[__i]] |= __v[__i];
2405}
2406
2407template <class _Tp>
2408template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002409inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002410typename enable_if
2411<
2412 __is_val_expr<_Expr>::value,
2413 void
2414>::type
2415indirect_array<_Tp>::operator<<=(const _Expr& __v) const
2416{
2417 size_t __n = __1d_.size();
2418 for (size_t __i = 0; __i < __n; ++__i)
2419 __vp_[__1d_[__i]] <<= __v[__i];
2420}
2421
2422template <class _Tp>
2423template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002424inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002425typename enable_if
2426<
2427 __is_val_expr<_Expr>::value,
2428 void
2429>::type
2430indirect_array<_Tp>::operator>>=(const _Expr& __v) const
2431{
2432 size_t __n = __1d_.size();
2433 for (size_t __i = 0; __i < __n; ++__i)
2434 __vp_[__1d_[__i]] >>= __v[__i];
2435}
2436
2437template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002438inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002439const indirect_array<_Tp>&
2440indirect_array<_Tp>::operator=(const indirect_array& __ia) const
2441{
2442 typedef const size_t* _Ip;
2443 const value_type* __s = __ia.__vp_;
2444 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_;
2445 __i != __e; ++__i, ++__j)
2446 __vp_[*__i] = __s[*__j];
2447 return *this;
2448}
2449
2450template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002451inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002452void
2453indirect_array<_Tp>::operator=(const value_type& __x) const
2454{
2455 typedef const size_t* _Ip;
2456 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
2457 __vp_[*__i] = __x;
2458}
2459
2460template <class _ValExpr>
2461class __indirect_expr
2462{
2463 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2464public:
2465 typedef typename _RmExpr::value_type value_type;
2466 typedef value_type result_type;
2467
2468private:
2469 _ValExpr __expr_;
2470 valarray<size_t> __1d_;
2471
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002472 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002473 __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e)
2474 : __expr_(__e),
2475 __1d_(__ia)
2476 {}
2477
Howard Hinnant73d21a42010-09-04 23:28:19 +00002478#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002479
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002481 __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
2482 : __expr_(__e),
2483 __1d_(move(__ia))
2484 {}
2485
Howard Hinnant73d21a42010-09-04 23:28:19 +00002486#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002487
2488public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002489 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002490 result_type operator[](size_t __i) const
2491 {return __expr_[__1d_[__i]];}
2492
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002493 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002494 size_t size() const {return __1d_.size();}
2495
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002496 template <class> friend class _LIBCPP_TYPE_VIS_ONLY valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002497};
2498
2499template<class _ValExpr>
2500class __val_expr
2501{
2502 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2503
2504 _ValExpr __expr_;
2505public:
2506 typedef typename _RmExpr::value_type value_type;
2507 typedef typename _RmExpr::result_type result_type;
2508
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002509 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002510 explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
2511
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002513 result_type operator[](size_t __i) const
2514 {return __expr_[__i];}
2515
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002516 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002517 __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
2518 {return __val_expr<__slice_expr<_ValExpr> >(__expr_, __s);}
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 gslice& __gs) const
2522 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __gs.__1d_);}
2523
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002524 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002525 __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
2526 {return __val_expr<__mask_expr<_ValExpr> >(__expr_, __vb);}
2527
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002529 __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
2530 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __vs);}
2531
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002532 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002533 __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
2534 operator+() const
2535 {
2536 typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
2537 return __val_expr<_NewExpr>(_NewExpr(__unary_plus<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<negate<value_type>, _ValExpr> >
2542 operator-() const
2543 {
2544 typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
2545 return __val_expr<_NewExpr>(_NewExpr(negate<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<__bit_not<value_type>, _ValExpr> >
2550 operator~() const
2551 {
2552 typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
2553 return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
2554 }
2555
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002557 __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> >
2558 operator!() const
2559 {
2560 typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
2561 return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
2562 }
2563
2564 operator valarray<result_type>() const;
2565
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002567 size_t size() const {return __expr_.size();}
2568
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002570 result_type sum() const
2571 {
2572 size_t __n = __expr_.size();
2573 result_type __r = __n ? __expr_[0] : result_type();
2574 for (size_t __i = 1; __i < __n; ++__i)
2575 __r += __expr_[__i];
2576 return __r;
2577 }
2578
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002579 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002580 result_type min() const
2581 {
2582 size_t __n = size();
2583 result_type __r = __n ? (*this)[0] : result_type();
2584 for (size_t __i = 1; __i < __n; ++__i)
2585 {
2586 result_type __x = __expr_[__i];
2587 if (__x < __r)
2588 __r = __x;
2589 }
2590 return __r;
2591 }
2592
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002594 result_type max() const
2595 {
2596 size_t __n = size();
2597 result_type __r = __n ? (*this)[0] : result_type();
2598 for (size_t __i = 1; __i < __n; ++__i)
2599 {
2600 result_type __x = __expr_[__i];
2601 if (__r < __x)
2602 __r = __x;
2603 }
2604 return __r;
2605 }
2606
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002608 __val_expr<__shift_expr<_ValExpr> > shift (int __i) const
2609 {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));}
2610
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002612 __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const
2613 {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));}
2614
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002615 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002616 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> >
2617 apply(value_type __f(value_type)) const
2618 {
2619 typedef __apply_expr<value_type, value_type(*)(value_type)> _Op;
2620 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2621 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2622 }
2623
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002625 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> >
2626 apply(value_type __f(const value_type&)) const
2627 {
2628 typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op;
2629 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2630 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2631 }
2632};
2633
2634template<class _ValExpr>
Howard Hinnantd8851432013-09-13 23:27:42 +00002635__val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002636{
2637 valarray<result_type> __r;
2638 size_t __n = __expr_.size();
2639 if (__n)
2640 {
2641 __r.__begin_ =
2642 __r.__end_ =
Dan Albert90dc8dd2014-08-26 11:20:46 -07002643 static_cast<result_type*>(_VSTD::__allocate(__n * sizeof(result_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002644 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
2645 ::new (__r.__end_) result_type(__expr_[__i]);
2646 }
2647 return __r;
2648}
2649
2650// valarray
2651
2652template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002653inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002654valarray<_Tp>::valarray(size_t __n)
2655 : __begin_(0),
2656 __end_(0)
2657{
2658 resize(__n);
2659}
2660
2661template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002662inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002663valarray<_Tp>::valarray(const value_type& __x, size_t __n)
2664 : __begin_(0),
2665 __end_(0)
2666{
2667 resize(__n, __x);
2668}
2669
2670template <class _Tp>
2671valarray<_Tp>::valarray(const value_type* __p, size_t __n)
2672 : __begin_(0),
2673 __end_(0)
2674{
2675 if (__n)
2676 {
Dan Albert90dc8dd2014-08-26 11:20:46 -07002677 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002678#ifndef _LIBCPP_NO_EXCEPTIONS
2679 try
2680 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002681#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002682 for (; __n; ++__end_, ++__p, --__n)
2683 ::new (__end_) value_type(*__p);
2684#ifndef _LIBCPP_NO_EXCEPTIONS
2685 }
2686 catch (...)
2687 {
2688 resize(0);
2689 throw;
2690 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002691#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002692 }
2693}
2694
2695template <class _Tp>
2696valarray<_Tp>::valarray(const valarray& __v)
2697 : __begin_(0),
2698 __end_(0)
2699{
2700 if (__v.size())
2701 {
Dan Albert90dc8dd2014-08-26 11:20:46 -07002702 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__v.size() * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002703#ifndef _LIBCPP_NO_EXCEPTIONS
2704 try
2705 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002706#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002707 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
2708 ::new (__end_) value_type(*__p);
2709#ifndef _LIBCPP_NO_EXCEPTIONS
2710 }
2711 catch (...)
2712 {
2713 resize(0);
2714 throw;
2715 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002716#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002717 }
2718}
2719
Howard Hinnant73d21a42010-09-04 23:28:19 +00002720#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002721
2722template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002723inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd143082012-07-21 00:51:28 +00002724valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002725 : __begin_(__v.__begin_),
2726 __end_(__v.__end_)
2727{
2728 __v.__begin_ = __v.__end_ = nullptr;
2729}
2730
Howard Hinnante3e32912011-08-12 21:56:02 +00002731#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2732
2733#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2734
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002735template <class _Tp>
2736valarray<_Tp>::valarray(initializer_list<value_type> __il)
2737 : __begin_(0),
2738 __end_(0)
2739{
2740 size_t __n = __il.size();
2741 if (__n)
2742 {
Dan Albert90dc8dd2014-08-26 11:20:46 -07002743 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002744#ifndef _LIBCPP_NO_EXCEPTIONS
2745 try
2746 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002747#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002748 for (const value_type* __p = __il.begin(); __n; ++__end_, ++__p, --__n)
2749 ::new (__end_) value_type(*__p);
2750#ifndef _LIBCPP_NO_EXCEPTIONS
2751 }
2752 catch (...)
2753 {
2754 resize(0);
2755 throw;
2756 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002757#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002758 }
2759}
2760
Howard Hinnante3e32912011-08-12 21:56:02 +00002761#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002762
2763template <class _Tp>
2764valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
2765 : __begin_(0),
2766 __end_(0)
2767{
2768 size_t __n = __sa.__size_;
2769 if (__n)
2770 {
Dan Albert90dc8dd2014-08-26 11:20:46 -07002771 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002772#ifndef _LIBCPP_NO_EXCEPTIONS
2773 try
2774 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002775#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002776 for (const value_type* __p = __sa.__vp_; __n; ++__end_, __p += __sa.__stride_, --__n)
2777 ::new (__end_) value_type(*__p);
2778#ifndef _LIBCPP_NO_EXCEPTIONS
2779 }
2780 catch (...)
2781 {
2782 resize(0);
2783 throw;
2784 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002785#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002786 }
2787}
2788
2789template <class _Tp>
2790valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
2791 : __begin_(0),
2792 __end_(0)
2793{
2794 size_t __n = __ga.__1d_.size();
2795 if (__n)
2796 {
Dan Albert90dc8dd2014-08-26 11:20:46 -07002797 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002798#ifndef _LIBCPP_NO_EXCEPTIONS
2799 try
2800 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002801#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002802 typedef const size_t* _Ip;
2803 const value_type* __s = __ga.__vp_;
2804 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2805 __i != __e; ++__i, ++__end_)
2806 ::new (__end_) value_type(__s[*__i]);
2807#ifndef _LIBCPP_NO_EXCEPTIONS
2808 }
2809 catch (...)
2810 {
2811 resize(0);
2812 throw;
2813 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002814#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002815 }
2816}
2817
2818template <class _Tp>
2819valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
2820 : __begin_(0),
2821 __end_(0)
2822{
2823 size_t __n = __ma.__1d_.size();
2824 if (__n)
2825 {
Dan Albert90dc8dd2014-08-26 11:20:46 -07002826 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002827#ifndef _LIBCPP_NO_EXCEPTIONS
2828 try
2829 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002830#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002831 typedef const size_t* _Ip;
2832 const value_type* __s = __ma.__vp_;
2833 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2834 __i != __e; ++__i, ++__end_)
2835 ::new (__end_) value_type(__s[*__i]);
2836#ifndef _LIBCPP_NO_EXCEPTIONS
2837 }
2838 catch (...)
2839 {
2840 resize(0);
2841 throw;
2842 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002843#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002844 }
2845}
2846
2847template <class _Tp>
2848valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
2849 : __begin_(0),
2850 __end_(0)
2851{
2852 size_t __n = __ia.__1d_.size();
2853 if (__n)
2854 {
Dan Albert90dc8dd2014-08-26 11:20:46 -07002855 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002856#ifndef _LIBCPP_NO_EXCEPTIONS
2857 try
2858 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002859#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002860 typedef const size_t* _Ip;
2861 const value_type* __s = __ia.__vp_;
2862 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2863 __i != __e; ++__i, ++__end_)
2864 ::new (__end_) value_type(__s[*__i]);
2865#ifndef _LIBCPP_NO_EXCEPTIONS
2866 }
2867 catch (...)
2868 {
2869 resize(0);
2870 throw;
2871 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002872#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002873 }
2874}
2875
2876template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002877inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002878valarray<_Tp>::~valarray()
2879{
2880 resize(0);
2881}
2882
2883template <class _Tp>
2884valarray<_Tp>&
2885valarray<_Tp>::operator=(const valarray& __v)
2886{
2887 if (this != &__v)
2888 {
2889 if (size() != __v.size())
2890 resize(__v.size());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002891 _VSTD::copy(__v.__begin_, __v.__end_, __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002892 }
2893 return *this;
2894}
2895
Howard Hinnant73d21a42010-09-04 23:28:19 +00002896#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002897
2898template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002899inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002900valarray<_Tp>&
Howard Hinnantbd143082012-07-21 00:51:28 +00002901valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002902{
2903 resize(0);
2904 __begin_ = __v.__begin_;
2905 __end_ = __v.__end_;
2906 __v.__begin_ = nullptr;
2907 __v.__end_ = nullptr;
2908 return *this;
2909}
2910
Howard Hinnante3e32912011-08-12 21:56:02 +00002911#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2912
2913#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2914
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002915template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002916inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002917valarray<_Tp>&
2918valarray<_Tp>::operator=(initializer_list<value_type> __il)
2919{
2920 if (size() != __il.size())
2921 resize(__il.size());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002922 _VSTD::copy(__il.begin(), __il.end(), __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002923 return *this;
2924}
2925
Howard Hinnante3e32912011-08-12 21:56:02 +00002926#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002927
2928template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002929inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002930valarray<_Tp>&
2931valarray<_Tp>::operator=(const value_type& __x)
2932{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002933 _VSTD::fill(__begin_, __end_, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002934 return *this;
2935}
2936
2937template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002938inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002939valarray<_Tp>&
2940valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
2941{
2942 value_type* __t = __begin_;
2943 const value_type* __s = __sa.__vp_;
2944 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
2945 *__t = *__s;
2946 return *this;
2947}
2948
2949template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002950inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002951valarray<_Tp>&
2952valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
2953{
2954 typedef const size_t* _Ip;
2955 value_type* __t = __begin_;
2956 const value_type* __s = __ga.__vp_;
2957 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2958 __i != __e; ++__i, ++__t)
2959 *__t = __s[*__i];
2960 return *this;
2961}
2962
2963template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002964inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002965valarray<_Tp>&
2966valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
2967{
2968 typedef const size_t* _Ip;
2969 value_type* __t = __begin_;
2970 const value_type* __s = __ma.__vp_;
2971 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2972 __i != __e; ++__i, ++__t)
2973 *__t = __s[*__i];
2974 return *this;
2975}
2976
2977template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002978inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002979valarray<_Tp>&
2980valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
2981{
2982 typedef const size_t* _Ip;
2983 value_type* __t = __begin_;
2984 const value_type* __s = __ia.__vp_;
2985 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2986 __i != __e; ++__i, ++__t)
2987 *__t = __s[*__i];
2988 return *this;
2989}
2990
2991template <class _Tp>
Howard Hinnantdb866632011-07-27 23:19:59 +00002992template <class _ValExpr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002993inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantdb866632011-07-27 23:19:59 +00002994valarray<_Tp>&
2995valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
2996{
2997 size_t __n = __v.size();
2998 if (size() != __n)
2999 resize(__n);
3000 value_type* __t = __begin_;
3001 for (size_t __i = 0; __i != __n; ++__t, ++__i)
3002 *__t = result_type(__v[__i]);
3003 return *this;
3004}
3005
3006template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003007inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003008__val_expr<__slice_expr<const valarray<_Tp>&> >
3009valarray<_Tp>::operator[](slice __s) const
3010{
3011 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__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 +00003016slice_array<_Tp>
3017valarray<_Tp>::operator[](slice __s)
3018{
3019 return slice_array<value_type>(__s, *this);
3020}
3021
3022template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003023inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003024__val_expr<__indirect_expr<const valarray<_Tp>&> >
3025valarray<_Tp>::operator[](const gslice& __gs) const
3026{
3027 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
3028}
3029
3030template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003031inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003032gslice_array<_Tp>
3033valarray<_Tp>::operator[](const gslice& __gs)
3034{
3035 return gslice_array<value_type>(__gs, *this);
3036}
3037
Howard Hinnant73d21a42010-09-04 23:28:19 +00003038#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003039
3040template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003041inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003042__val_expr<__indirect_expr<const valarray<_Tp>&> >
3043valarray<_Tp>::operator[](gslice&& __gs) const
3044{
3045 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
3046}
3047
3048template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003049inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003050gslice_array<_Tp>
3051valarray<_Tp>::operator[](gslice&& __gs)
3052{
3053 return gslice_array<value_type>(move(__gs), *this);
3054}
3055
Howard Hinnant73d21a42010-09-04 23:28:19 +00003056#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003057
3058template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003059inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003060__val_expr<__mask_expr<const valarray<_Tp>&> >
3061valarray<_Tp>::operator[](const valarray<bool>& __vb) const
3062{
3063 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
3064}
3065
3066template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003067inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003068mask_array<_Tp>
3069valarray<_Tp>::operator[](const valarray<bool>& __vb)
3070{
3071 return mask_array<value_type>(__vb, *this);
3072}
3073
Howard Hinnant73d21a42010-09-04 23:28:19 +00003074#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003075
3076template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003077inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003078__val_expr<__mask_expr<const valarray<_Tp>&> >
3079valarray<_Tp>::operator[](valarray<bool>&& __vb) const
3080{
3081 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
3082}
3083
3084template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003085inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003086mask_array<_Tp>
3087valarray<_Tp>::operator[](valarray<bool>&& __vb)
3088{
3089 return mask_array<value_type>(move(__vb), *this);
3090}
3091
Howard Hinnant73d21a42010-09-04 23:28:19 +00003092#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003093
3094template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003095inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003096__val_expr<__indirect_expr<const valarray<_Tp>&> >
3097valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
3098{
3099 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
3100}
3101
3102template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003103inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003104indirect_array<_Tp>
3105valarray<_Tp>::operator[](const valarray<size_t>& __vs)
3106{
3107 return indirect_array<value_type>(__vs, *this);
3108}
3109
Howard Hinnant73d21a42010-09-04 23:28:19 +00003110#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003111
3112template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003113inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003114__val_expr<__indirect_expr<const valarray<_Tp>&> >
3115valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
3116{
3117 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
3118}
3119
3120template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003121inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003122indirect_array<_Tp>
3123valarray<_Tp>::operator[](valarray<size_t>&& __vs)
3124{
3125 return indirect_array<value_type>(move(__vs), *this);
3126}
3127
Howard Hinnant73d21a42010-09-04 23:28:19 +00003128#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003129
3130template <class _Tp>
3131valarray<_Tp>
3132valarray<_Tp>::operator+() const
3133{
3134 valarray<value_type> __r;
3135 size_t __n = size();
3136 if (__n)
3137 {
3138 __r.__begin_ =
3139 __r.__end_ =
Dan Albert90dc8dd2014-08-26 11:20:46 -07003140 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003141 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3142 ::new (__r.__end_) value_type(+*__p);
3143 }
3144 return __r;
3145}
3146
3147template <class _Tp>
3148valarray<_Tp>
3149valarray<_Tp>::operator-() const
3150{
3151 valarray<value_type> __r;
3152 size_t __n = size();
3153 if (__n)
3154 {
3155 __r.__begin_ =
3156 __r.__end_ =
Dan Albert90dc8dd2014-08-26 11:20:46 -07003157 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003158 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3159 ::new (__r.__end_) value_type(-*__p);
3160 }
3161 return __r;
3162}
3163
3164template <class _Tp>
3165valarray<_Tp>
3166valarray<_Tp>::operator~() const
3167{
3168 valarray<value_type> __r;
3169 size_t __n = size();
3170 if (__n)
3171 {
3172 __r.__begin_ =
3173 __r.__end_ =
Dan Albert90dc8dd2014-08-26 11:20:46 -07003174 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003175 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3176 ::new (__r.__end_) value_type(~*__p);
3177 }
3178 return __r;
3179}
3180
3181template <class _Tp>
3182valarray<bool>
3183valarray<_Tp>::operator!() const
3184{
3185 valarray<bool> __r;
3186 size_t __n = size();
3187 if (__n)
3188 {
3189 __r.__begin_ =
3190 __r.__end_ =
Dan Albert90dc8dd2014-08-26 11:20:46 -07003191 static_cast<bool*>(_VSTD::__allocate(__n * sizeof(bool)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003192 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3193 ::new (__r.__end_) bool(!*__p);
3194 }
3195 return __r;
3196}
3197
3198template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003199inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003200valarray<_Tp>&
3201valarray<_Tp>::operator*=(const value_type& __x)
3202{
3203 for (value_type* __p = __begin_; __p != __end_; ++__p)
3204 *__p *= __x;
3205 return *this;
3206}
3207
3208template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003209inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003210valarray<_Tp>&
3211valarray<_Tp>::operator/=(const value_type& __x)
3212{
3213 for (value_type* __p = __begin_; __p != __end_; ++__p)
3214 *__p /= __x;
3215 return *this;
3216}
3217
3218template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003219inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003220valarray<_Tp>&
3221valarray<_Tp>::operator%=(const value_type& __x)
3222{
3223 for (value_type* __p = __begin_; __p != __end_; ++__p)
3224 *__p %= __x;
3225 return *this;
3226}
3227
3228template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003229inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003230valarray<_Tp>&
3231valarray<_Tp>::operator+=(const value_type& __x)
3232{
3233 for (value_type* __p = __begin_; __p != __end_; ++__p)
3234 *__p += __x;
3235 return *this;
3236}
3237
3238template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003239inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003240valarray<_Tp>&
3241valarray<_Tp>::operator-=(const value_type& __x)
3242{
3243 for (value_type* __p = __begin_; __p != __end_; ++__p)
3244 *__p -= __x;
3245 return *this;
3246}
3247
3248template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003249inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003250valarray<_Tp>&
3251valarray<_Tp>::operator^=(const value_type& __x)
3252{
3253 for (value_type* __p = __begin_; __p != __end_; ++__p)
3254 *__p ^= __x;
3255 return *this;
3256}
3257
3258template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003259inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003260valarray<_Tp>&
3261valarray<_Tp>::operator&=(const value_type& __x)
3262{
3263 for (value_type* __p = __begin_; __p != __end_; ++__p)
3264 *__p &= __x;
3265 return *this;
3266}
3267
3268template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003269inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003270valarray<_Tp>&
3271valarray<_Tp>::operator|=(const value_type& __x)
3272{
3273 for (value_type* __p = __begin_; __p != __end_; ++__p)
3274 *__p |= __x;
3275 return *this;
3276}
3277
3278template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003279inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003280valarray<_Tp>&
3281valarray<_Tp>::operator<<=(const value_type& __x)
3282{
3283 for (value_type* __p = __begin_; __p != __end_; ++__p)
3284 *__p <<= __x;
3285 return *this;
3286}
3287
3288template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003289inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003290valarray<_Tp>&
3291valarray<_Tp>::operator>>=(const value_type& __x)
3292{
3293 for (value_type* __p = __begin_; __p != __end_; ++__p)
3294 *__p >>= __x;
3295 return *this;
3296}
3297
3298template <class _Tp>
3299template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003300inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003301typename enable_if
3302<
3303 __is_val_expr<_Expr>::value,
3304 valarray<_Tp>&
3305>::type
3306valarray<_Tp>::operator*=(const _Expr& __v)
3307{
3308 size_t __i = 0;
3309 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3310 *__t *= __v[__i];
3311 return *this;
3312}
3313
3314template <class _Tp>
3315template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003316inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003317typename enable_if
3318<
3319 __is_val_expr<_Expr>::value,
3320 valarray<_Tp>&
3321>::type
3322valarray<_Tp>::operator/=(const _Expr& __v)
3323{
3324 size_t __i = 0;
3325 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3326 *__t /= __v[__i];
3327 return *this;
3328}
3329
3330template <class _Tp>
3331template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003332inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003333typename enable_if
3334<
3335 __is_val_expr<_Expr>::value,
3336 valarray<_Tp>&
3337>::type
3338valarray<_Tp>::operator%=(const _Expr& __v)
3339{
3340 size_t __i = 0;
3341 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3342 *__t %= __v[__i];
3343 return *this;
3344}
3345
3346template <class _Tp>
3347template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003348inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003349typename enable_if
3350<
3351 __is_val_expr<_Expr>::value,
3352 valarray<_Tp>&
3353>::type
3354valarray<_Tp>::operator+=(const _Expr& __v)
3355{
3356 size_t __i = 0;
3357 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3358 *__t += __v[__i];
3359 return *this;
3360}
3361
3362template <class _Tp>
3363template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003364inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003365typename enable_if
3366<
3367 __is_val_expr<_Expr>::value,
3368 valarray<_Tp>&
3369>::type
3370valarray<_Tp>::operator-=(const _Expr& __v)
3371{
3372 size_t __i = 0;
3373 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3374 *__t -= __v[__i];
3375 return *this;
3376}
3377
3378template <class _Tp>
3379template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003380inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003381typename enable_if
3382<
3383 __is_val_expr<_Expr>::value,
3384 valarray<_Tp>&
3385>::type
3386valarray<_Tp>::operator^=(const _Expr& __v)
3387{
3388 size_t __i = 0;
3389 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3390 *__t ^= __v[__i];
3391 return *this;
3392}
3393
3394template <class _Tp>
3395template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003396inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003397typename enable_if
3398<
3399 __is_val_expr<_Expr>::value,
3400 valarray<_Tp>&
3401>::type
3402valarray<_Tp>::operator|=(const _Expr& __v)
3403{
3404 size_t __i = 0;
3405 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3406 *__t |= __v[__i];
3407 return *this;
3408}
3409
3410template <class _Tp>
3411template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003412inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003413typename enable_if
3414<
3415 __is_val_expr<_Expr>::value,
3416 valarray<_Tp>&
3417>::type
3418valarray<_Tp>::operator&=(const _Expr& __v)
3419{
3420 size_t __i = 0;
3421 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3422 *__t &= __v[__i];
3423 return *this;
3424}
3425
3426template <class _Tp>
3427template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003428inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003429typename enable_if
3430<
3431 __is_val_expr<_Expr>::value,
3432 valarray<_Tp>&
3433>::type
3434valarray<_Tp>::operator<<=(const _Expr& __v)
3435{
3436 size_t __i = 0;
3437 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3438 *__t <<= __v[__i];
3439 return *this;
3440}
3441
3442template <class _Tp>
3443template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003444inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003445typename enable_if
3446<
3447 __is_val_expr<_Expr>::value,
3448 valarray<_Tp>&
3449>::type
3450valarray<_Tp>::operator>>=(const _Expr& __v)
3451{
3452 size_t __i = 0;
3453 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3454 *__t >>= __v[__i];
3455 return *this;
3456}
3457
3458template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003459inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003460void
Howard Hinnantbd143082012-07-21 00:51:28 +00003461valarray<_Tp>::swap(valarray& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003462{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003463 _VSTD::swap(__begin_, __v.__begin_);
3464 _VSTD::swap(__end_, __v.__end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003465}
3466
3467template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003468inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003469_Tp
3470valarray<_Tp>::sum() const
3471{
3472 if (__begin_ == __end_)
3473 return value_type();
3474 const value_type* __p = __begin_;
3475 _Tp __r = *__p;
3476 for (++__p; __p != __end_; ++__p)
3477 __r += *__p;
3478 return __r;
3479}
3480
3481template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003482inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003483_Tp
3484valarray<_Tp>::min() const
3485{
3486 if (__begin_ == __end_)
3487 return value_type();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003488 return *_VSTD::min_element(__begin_, __end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003489}
3490
3491template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003492inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003493_Tp
3494valarray<_Tp>::max() const
3495{
3496 if (__begin_ == __end_)
3497 return value_type();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003498 return *_VSTD::max_element(__begin_, __end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003499}
3500
3501template <class _Tp>
3502valarray<_Tp>
3503valarray<_Tp>::shift(int __i) const
3504{
3505 valarray<value_type> __r;
3506 size_t __n = size();
3507 if (__n)
3508 {
3509 __r.__begin_ =
3510 __r.__end_ =
Dan Albert90dc8dd2014-08-26 11:20:46 -07003511 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003512 const value_type* __sb;
3513 value_type* __tb;
3514 value_type* __te;
3515 if (__i >= 0)
3516 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003517 __i = _VSTD::min(__i, static_cast<int>(__n));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003518 __sb = __begin_ + __i;
3519 __tb = __r.__begin_;
3520 __te = __r.__begin_ + (__n - __i);
3521 }
3522 else
3523 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003524 __i = _VSTD::min(-__i, static_cast<int>(__n));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003525 __sb = __begin_;
3526 __tb = __r.__begin_ + __i;
3527 __te = __r.__begin_ + __n;
3528 }
3529 for (; __r.__end_ != __tb; ++__r.__end_)
3530 ::new (__r.__end_) value_type();
3531 for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
3532 ::new (__r.__end_) value_type(*__sb);
3533 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
3534 ::new (__r.__end_) value_type();
3535 }
3536 return __r;
3537}
3538
3539template <class _Tp>
3540valarray<_Tp>
3541valarray<_Tp>::cshift(int __i) const
3542{
3543 valarray<value_type> __r;
3544 size_t __n = size();
3545 if (__n)
3546 {
3547 __r.__begin_ =
3548 __r.__end_ =
Dan Albert90dc8dd2014-08-26 11:20:46 -07003549 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003550 __i %= static_cast<int>(__n);
3551 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
3552 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
3553 ::new (__r.__end_) value_type(*__s);
3554 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
3555 ::new (__r.__end_) value_type(*__s);
3556 }
3557 return __r;
3558}
3559
3560template <class _Tp>
3561valarray<_Tp>
3562valarray<_Tp>::apply(value_type __f(value_type)) const
3563{
3564 valarray<value_type> __r;
3565 size_t __n = size();
3566 if (__n)
3567 {
3568 __r.__begin_ =
3569 __r.__end_ =
Dan Albert90dc8dd2014-08-26 11:20:46 -07003570 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003571 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3572 ::new (__r.__end_) value_type(__f(*__p));
3573 }
3574 return __r;
3575}
3576
3577template <class _Tp>
3578valarray<_Tp>
3579valarray<_Tp>::apply(value_type __f(const value_type&)) const
3580{
3581 valarray<value_type> __r;
3582 size_t __n = size();
3583 if (__n)
3584 {
3585 __r.__begin_ =
3586 __r.__end_ =
Dan Albert90dc8dd2014-08-26 11:20:46 -07003587 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003588 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3589 ::new (__r.__end_) value_type(__f(*__p));
3590 }
3591 return __r;
3592}
3593
3594template <class _Tp>
3595void
3596valarray<_Tp>::resize(size_t __n, value_type __x)
3597{
3598 if (__begin_ != nullptr)
3599 {
3600 while (__end_ != __begin_)
3601 (--__end_)->~value_type();
Dan Albert90dc8dd2014-08-26 11:20:46 -07003602 _VSTD::__deallocate(__begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003603 __begin_ = __end_ = nullptr;
3604 }
3605 if (__n)
3606 {
Dan Albert90dc8dd2014-08-26 11:20:46 -07003607 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003608#ifndef _LIBCPP_NO_EXCEPTIONS
3609 try
3610 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003611#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003612 for (; __n; --__n, ++__end_)
3613 ::new (__end_) value_type(__x);
3614#ifndef _LIBCPP_NO_EXCEPTIONS
3615 }
3616 catch (...)
3617 {
3618 resize(0);
3619 throw;
3620 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003621#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003622 }
3623}
3624
3625template<class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003626inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003627void
Howard Hinnantbd143082012-07-21 00:51:28 +00003628swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003629{
3630 __x.swap(__y);
3631}
3632
3633template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003634inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003635typename enable_if
3636<
3637 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3638 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
3639>::type
3640operator*(const _Expr1& __x, const _Expr2& __y)
3641{
3642 typedef typename _Expr1::value_type value_type;
3643 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
3644 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
3645}
3646
3647template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003648inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003649typename enable_if
3650<
3651 __is_val_expr<_Expr>::value,
3652 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3653 _Expr, __scalar_expr<typename _Expr::value_type> > >
3654>::type
3655operator*(const _Expr& __x, const typename _Expr::value_type& __y)
3656{
3657 typedef typename _Expr::value_type value_type;
3658 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3659 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3660 __x, __scalar_expr<value_type>(__y, __x.size())));
3661}
3662
3663template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003664inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003665typename enable_if
3666<
3667 __is_val_expr<_Expr>::value,
3668 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3669 __scalar_expr<typename _Expr::value_type>, _Expr> >
3670>::type
3671operator*(const typename _Expr::value_type& __x, const _Expr& __y)
3672{
3673 typedef typename _Expr::value_type value_type;
3674 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3675 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3676 __scalar_expr<value_type>(__x, __y.size()), __y));
3677}
3678
3679template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003680inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003681typename enable_if
3682<
3683 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3684 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
3685>::type
3686operator/(const _Expr1& __x, const _Expr2& __y)
3687{
3688 typedef typename _Expr1::value_type value_type;
3689 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
3690 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
3691}
3692
3693template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003694inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003695typename enable_if
3696<
3697 __is_val_expr<_Expr>::value,
3698 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3699 _Expr, __scalar_expr<typename _Expr::value_type> > >
3700>::type
3701operator/(const _Expr& __x, const typename _Expr::value_type& __y)
3702{
3703 typedef typename _Expr::value_type value_type;
3704 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3705 return __val_expr<_Op>(_Op(divides<value_type>(),
3706 __x, __scalar_expr<value_type>(__y, __x.size())));
3707}
3708
3709template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003710inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003711typename enable_if
3712<
3713 __is_val_expr<_Expr>::value,
3714 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3715 __scalar_expr<typename _Expr::value_type>, _Expr> >
3716>::type
3717operator/(const typename _Expr::value_type& __x, const _Expr& __y)
3718{
3719 typedef typename _Expr::value_type value_type;
3720 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3721 return __val_expr<_Op>(_Op(divides<value_type>(),
3722 __scalar_expr<value_type>(__x, __y.size()), __y));
3723}
3724
3725template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003726inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003727typename enable_if
3728<
3729 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3730 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3731>::type
3732operator%(const _Expr1& __x, const _Expr2& __y)
3733{
3734 typedef typename _Expr1::value_type value_type;
3735 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
3736 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
3737}
3738
3739template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003740inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003741typename enable_if
3742<
3743 __is_val_expr<_Expr>::value,
3744 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3745 _Expr, __scalar_expr<typename _Expr::value_type> > >
3746>::type
3747operator%(const _Expr& __x, const typename _Expr::value_type& __y)
3748{
3749 typedef typename _Expr::value_type value_type;
3750 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3751 return __val_expr<_Op>(_Op(modulus<value_type>(),
3752 __x, __scalar_expr<value_type>(__y, __x.size())));
3753}
3754
3755template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003756inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003757typename enable_if
3758<
3759 __is_val_expr<_Expr>::value,
3760 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3761 __scalar_expr<typename _Expr::value_type>, _Expr> >
3762>::type
3763operator%(const typename _Expr::value_type& __x, const _Expr& __y)
3764{
3765 typedef typename _Expr::value_type value_type;
3766 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3767 return __val_expr<_Op>(_Op(modulus<value_type>(),
3768 __scalar_expr<value_type>(__x, __y.size()), __y));
3769}
3770
3771template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003772inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003773typename enable_if
3774<
3775 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3776 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3777>::type
3778operator+(const _Expr1& __x, const _Expr2& __y)
3779{
3780 typedef typename _Expr1::value_type value_type;
3781 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
3782 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
3783}
3784
3785template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003786inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003787typename enable_if
3788<
3789 __is_val_expr<_Expr>::value,
3790 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3791 _Expr, __scalar_expr<typename _Expr::value_type> > >
3792>::type
3793operator+(const _Expr& __x, const typename _Expr::value_type& __y)
3794{
3795 typedef typename _Expr::value_type value_type;
3796 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3797 return __val_expr<_Op>(_Op(plus<value_type>(),
3798 __x, __scalar_expr<value_type>(__y, __x.size())));
3799}
3800
3801template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003802inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003803typename enable_if
3804<
3805 __is_val_expr<_Expr>::value,
3806 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3807 __scalar_expr<typename _Expr::value_type>, _Expr> >
3808>::type
3809operator+(const typename _Expr::value_type& __x, const _Expr& __y)
3810{
3811 typedef typename _Expr::value_type value_type;
3812 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3813 return __val_expr<_Op>(_Op(plus<value_type>(),
3814 __scalar_expr<value_type>(__x, __y.size()), __y));
3815}
3816
3817template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003818inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003819typename enable_if
3820<
3821 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3822 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3823>::type
3824operator-(const _Expr1& __x, const _Expr2& __y)
3825{
3826 typedef typename _Expr1::value_type value_type;
3827 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
3828 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
3829}
3830
3831template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003832inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003833typename enable_if
3834<
3835 __is_val_expr<_Expr>::value,
3836 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3837 _Expr, __scalar_expr<typename _Expr::value_type> > >
3838>::type
3839operator-(const _Expr& __x, const typename _Expr::value_type& __y)
3840{
3841 typedef typename _Expr::value_type value_type;
3842 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3843 return __val_expr<_Op>(_Op(minus<value_type>(),
3844 __x, __scalar_expr<value_type>(__y, __x.size())));
3845}
3846
3847template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003848inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003849typename enable_if
3850<
3851 __is_val_expr<_Expr>::value,
3852 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3853 __scalar_expr<typename _Expr::value_type>, _Expr> >
3854>::type
3855operator-(const typename _Expr::value_type& __x, const _Expr& __y)
3856{
3857 typedef typename _Expr::value_type value_type;
3858 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3859 return __val_expr<_Op>(_Op(minus<value_type>(),
3860 __scalar_expr<value_type>(__x, __y.size()), __y));
3861}
3862
3863template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003864inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003865typename enable_if
3866<
3867 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3868 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
3869>::type
3870operator^(const _Expr1& __x, const _Expr2& __y)
3871{
3872 typedef typename _Expr1::value_type value_type;
3873 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
3874 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
3875}
3876
3877template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003878inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003879typename enable_if
3880<
3881 __is_val_expr<_Expr>::value,
3882 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
3883 _Expr, __scalar_expr<typename _Expr::value_type> > >
3884>::type
3885operator^(const _Expr& __x, const typename _Expr::value_type& __y)
3886{
3887 typedef typename _Expr::value_type value_type;
3888 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3889 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
3890 __x, __scalar_expr<value_type>(__y, __x.size())));
3891}
3892
3893template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003894inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003895typename enable_if
3896<
3897 __is_val_expr<_Expr>::value,
3898 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
3899 __scalar_expr<typename _Expr::value_type>, _Expr> >
3900>::type
3901operator^(const typename _Expr::value_type& __x, const _Expr& __y)
3902{
3903 typedef typename _Expr::value_type value_type;
3904 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3905 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
3906 __scalar_expr<value_type>(__x, __y.size()), __y));
3907}
3908
3909template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003910inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003911typename enable_if
3912<
3913 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3914 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
3915>::type
3916operator&(const _Expr1& __x, const _Expr2& __y)
3917{
3918 typedef typename _Expr1::value_type value_type;
3919 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
3920 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
3921}
3922
3923template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003924inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003925typename enable_if
3926<
3927 __is_val_expr<_Expr>::value,
3928 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
3929 _Expr, __scalar_expr<typename _Expr::value_type> > >
3930>::type
3931operator&(const _Expr& __x, const typename _Expr::value_type& __y)
3932{
3933 typedef typename _Expr::value_type value_type;
3934 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3935 return __val_expr<_Op>(_Op(bit_and<value_type>(),
3936 __x, __scalar_expr<value_type>(__y, __x.size())));
3937}
3938
3939template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003940inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003941typename enable_if
3942<
3943 __is_val_expr<_Expr>::value,
3944 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
3945 __scalar_expr<typename _Expr::value_type>, _Expr> >
3946>::type
3947operator&(const typename _Expr::value_type& __x, const _Expr& __y)
3948{
3949 typedef typename _Expr::value_type value_type;
3950 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3951 return __val_expr<_Op>(_Op(bit_and<value_type>(),
3952 __scalar_expr<value_type>(__x, __y.size()), __y));
3953}
3954
3955template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003956inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003957typename enable_if
3958<
3959 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3960 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
3961>::type
3962operator|(const _Expr1& __x, const _Expr2& __y)
3963{
3964 typedef typename _Expr1::value_type value_type;
3965 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
3966 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
3967}
3968
3969template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003970inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003971typename enable_if
3972<
3973 __is_val_expr<_Expr>::value,
3974 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
3975 _Expr, __scalar_expr<typename _Expr::value_type> > >
3976>::type
3977operator|(const _Expr& __x, const typename _Expr::value_type& __y)
3978{
3979 typedef typename _Expr::value_type value_type;
3980 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3981 return __val_expr<_Op>(_Op(bit_or<value_type>(),
3982 __x, __scalar_expr<value_type>(__y, __x.size())));
3983}
3984
3985template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003986inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003987typename enable_if
3988<
3989 __is_val_expr<_Expr>::value,
3990 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
3991 __scalar_expr<typename _Expr::value_type>, _Expr> >
3992>::type
3993operator|(const typename _Expr::value_type& __x, const _Expr& __y)
3994{
3995 typedef typename _Expr::value_type value_type;
3996 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3997 return __val_expr<_Op>(_Op(bit_or<value_type>(),
3998 __scalar_expr<value_type>(__x, __y.size()), __y));
3999}
4000
4001template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004002inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004003typename enable_if
4004<
4005 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4006 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
4007>::type
4008operator<<(const _Expr1& __x, const _Expr2& __y)
4009{
4010 typedef typename _Expr1::value_type value_type;
4011 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
4012 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
4013}
4014
4015template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004016inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004017typename enable_if
4018<
4019 __is_val_expr<_Expr>::value,
4020 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4021 _Expr, __scalar_expr<typename _Expr::value_type> > >
4022>::type
4023operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
4024{
4025 typedef typename _Expr::value_type value_type;
4026 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4027 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4028 __x, __scalar_expr<value_type>(__y, __x.size())));
4029}
4030
4031template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004032inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004033typename enable_if
4034<
4035 __is_val_expr<_Expr>::value,
4036 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4037 __scalar_expr<typename _Expr::value_type>, _Expr> >
4038>::type
4039operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
4040{
4041 typedef typename _Expr::value_type value_type;
4042 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4043 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4044 __scalar_expr<value_type>(__x, __y.size()), __y));
4045}
4046
4047template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004048inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004049typename enable_if
4050<
4051 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4052 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
4053>::type
4054operator>>(const _Expr1& __x, const _Expr2& __y)
4055{
4056 typedef typename _Expr1::value_type value_type;
4057 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
4058 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
4059}
4060
4061template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004062inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004063typename enable_if
4064<
4065 __is_val_expr<_Expr>::value,
4066 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4067 _Expr, __scalar_expr<typename _Expr::value_type> > >
4068>::type
4069operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
4070{
4071 typedef typename _Expr::value_type value_type;
4072 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4073 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4074 __x, __scalar_expr<value_type>(__y, __x.size())));
4075}
4076
4077template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004078inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004079typename enable_if
4080<
4081 __is_val_expr<_Expr>::value,
4082 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4083 __scalar_expr<typename _Expr::value_type>, _Expr> >
4084>::type
4085operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
4086{
4087 typedef typename _Expr::value_type value_type;
4088 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4089 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4090 __scalar_expr<value_type>(__x, __y.size()), __y));
4091}
4092
4093template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004094inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004095typename enable_if
4096<
4097 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4098 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4099>::type
4100operator&&(const _Expr1& __x, const _Expr2& __y)
4101{
4102 typedef typename _Expr1::value_type value_type;
4103 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
4104 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
4105}
4106
4107template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004108inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004109typename enable_if
4110<
4111 __is_val_expr<_Expr>::value,
4112 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4113 _Expr, __scalar_expr<typename _Expr::value_type> > >
4114>::type
4115operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
4116{
4117 typedef typename _Expr::value_type value_type;
4118 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4119 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4120 __x, __scalar_expr<value_type>(__y, __x.size())));
4121}
4122
4123template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004124inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004125typename enable_if
4126<
4127 __is_val_expr<_Expr>::value,
4128 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4129 __scalar_expr<typename _Expr::value_type>, _Expr> >
4130>::type
4131operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
4132{
4133 typedef typename _Expr::value_type value_type;
4134 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4135 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4136 __scalar_expr<value_type>(__x, __y.size()), __y));
4137}
4138
4139template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004140inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004141typename enable_if
4142<
4143 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4144 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4145>::type
4146operator||(const _Expr1& __x, const _Expr2& __y)
4147{
4148 typedef typename _Expr1::value_type value_type;
4149 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
4150 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
4151}
4152
4153template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004154inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004155typename enable_if
4156<
4157 __is_val_expr<_Expr>::value,
4158 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4159 _Expr, __scalar_expr<typename _Expr::value_type> > >
4160>::type
4161operator||(const _Expr& __x, const typename _Expr::value_type& __y)
4162{
4163 typedef typename _Expr::value_type value_type;
4164 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4165 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4166 __x, __scalar_expr<value_type>(__y, __x.size())));
4167}
4168
4169template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004170inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004171typename enable_if
4172<
4173 __is_val_expr<_Expr>::value,
4174 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4175 __scalar_expr<typename _Expr::value_type>, _Expr> >
4176>::type
4177operator||(const typename _Expr::value_type& __x, const _Expr& __y)
4178{
4179 typedef typename _Expr::value_type value_type;
4180 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4181 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4182 __scalar_expr<value_type>(__x, __y.size()), __y));
4183}
4184
4185template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004186inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004187typename enable_if
4188<
4189 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4190 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4191>::type
4192operator==(const _Expr1& __x, const _Expr2& __y)
4193{
4194 typedef typename _Expr1::value_type value_type;
4195 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
4196 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
4197}
4198
4199template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004200inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004201typename enable_if
4202<
4203 __is_val_expr<_Expr>::value,
4204 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4205 _Expr, __scalar_expr<typename _Expr::value_type> > >
4206>::type
4207operator==(const _Expr& __x, const typename _Expr::value_type& __y)
4208{
4209 typedef typename _Expr::value_type value_type;
4210 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4211 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4212 __x, __scalar_expr<value_type>(__y, __x.size())));
4213}
4214
4215template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004216inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004217typename enable_if
4218<
4219 __is_val_expr<_Expr>::value,
4220 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4221 __scalar_expr<typename _Expr::value_type>, _Expr> >
4222>::type
4223operator==(const typename _Expr::value_type& __x, const _Expr& __y)
4224{
4225 typedef typename _Expr::value_type value_type;
4226 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4227 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4228 __scalar_expr<value_type>(__x, __y.size()), __y));
4229}
4230
4231template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004232inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004233typename enable_if
4234<
4235 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4236 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4237>::type
4238operator!=(const _Expr1& __x, const _Expr2& __y)
4239{
4240 typedef typename _Expr1::value_type value_type;
4241 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
4242 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
4243}
4244
4245template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004246inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004247typename enable_if
4248<
4249 __is_val_expr<_Expr>::value,
4250 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4251 _Expr, __scalar_expr<typename _Expr::value_type> > >
4252>::type
4253operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
4254{
4255 typedef typename _Expr::value_type value_type;
4256 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4257 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4258 __x, __scalar_expr<value_type>(__y, __x.size())));
4259}
4260
4261template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004262inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004263typename enable_if
4264<
4265 __is_val_expr<_Expr>::value,
4266 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4267 __scalar_expr<typename _Expr::value_type>, _Expr> >
4268>::type
4269operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
4270{
4271 typedef typename _Expr::value_type value_type;
4272 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4273 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4274 __scalar_expr<value_type>(__x, __y.size()), __y));
4275}
4276
4277template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004278inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004279typename enable_if
4280<
4281 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4282 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
4283>::type
4284operator<(const _Expr1& __x, const _Expr2& __y)
4285{
4286 typedef typename _Expr1::value_type value_type;
4287 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
4288 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
4289}
4290
4291template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004292inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004293typename enable_if
4294<
4295 __is_val_expr<_Expr>::value,
4296 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4297 _Expr, __scalar_expr<typename _Expr::value_type> > >
4298>::type
4299operator<(const _Expr& __x, const typename _Expr::value_type& __y)
4300{
4301 typedef typename _Expr::value_type value_type;
4302 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4303 return __val_expr<_Op>(_Op(less<value_type>(),
4304 __x, __scalar_expr<value_type>(__y, __x.size())));
4305}
4306
4307template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004308inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004309typename enable_if
4310<
4311 __is_val_expr<_Expr>::value,
4312 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4313 __scalar_expr<typename _Expr::value_type>, _Expr> >
4314>::type
4315operator<(const typename _Expr::value_type& __x, const _Expr& __y)
4316{
4317 typedef typename _Expr::value_type value_type;
4318 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4319 return __val_expr<_Op>(_Op(less<value_type>(),
4320 __scalar_expr<value_type>(__x, __y.size()), __y));
4321}
4322
4323template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004324inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004325typename enable_if
4326<
4327 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4328 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
4329>::type
4330operator>(const _Expr1& __x, const _Expr2& __y)
4331{
4332 typedef typename _Expr1::value_type value_type;
4333 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
4334 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
4335}
4336
4337template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004338inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004339typename enable_if
4340<
4341 __is_val_expr<_Expr>::value,
4342 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4343 _Expr, __scalar_expr<typename _Expr::value_type> > >
4344>::type
4345operator>(const _Expr& __x, const typename _Expr::value_type& __y)
4346{
4347 typedef typename _Expr::value_type value_type;
4348 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4349 return __val_expr<_Op>(_Op(greater<value_type>(),
4350 __x, __scalar_expr<value_type>(__y, __x.size())));
4351}
4352
4353template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004354inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004355typename enable_if
4356<
4357 __is_val_expr<_Expr>::value,
4358 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4359 __scalar_expr<typename _Expr::value_type>, _Expr> >
4360>::type
4361operator>(const typename _Expr::value_type& __x, const _Expr& __y)
4362{
4363 typedef typename _Expr::value_type value_type;
4364 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4365 return __val_expr<_Op>(_Op(greater<value_type>(),
4366 __scalar_expr<value_type>(__x, __y.size()), __y));
4367}
4368
4369template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004370inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004371typename enable_if
4372<
4373 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4374 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4375>::type
4376operator<=(const _Expr1& __x, const _Expr2& __y)
4377{
4378 typedef typename _Expr1::value_type value_type;
4379 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
4380 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
4381}
4382
4383template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004384inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004385typename enable_if
4386<
4387 __is_val_expr<_Expr>::value,
4388 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4389 _Expr, __scalar_expr<typename _Expr::value_type> > >
4390>::type
4391operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
4392{
4393 typedef typename _Expr::value_type value_type;
4394 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4395 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4396 __x, __scalar_expr<value_type>(__y, __x.size())));
4397}
4398
4399template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004400inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004401typename enable_if
4402<
4403 __is_val_expr<_Expr>::value,
4404 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4405 __scalar_expr<typename _Expr::value_type>, _Expr> >
4406>::type
4407operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
4408{
4409 typedef typename _Expr::value_type value_type;
4410 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4411 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4412 __scalar_expr<value_type>(__x, __y.size()), __y));
4413}
4414
4415template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004416inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004417typename enable_if
4418<
4419 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4420 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4421>::type
4422operator>=(const _Expr1& __x, const _Expr2& __y)
4423{
4424 typedef typename _Expr1::value_type value_type;
4425 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
4426 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
4427}
4428
4429template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004430inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004431typename enable_if
4432<
4433 __is_val_expr<_Expr>::value,
4434 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4435 _Expr, __scalar_expr<typename _Expr::value_type> > >
4436>::type
4437operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
4438{
4439 typedef typename _Expr::value_type value_type;
4440 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4441 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4442 __x, __scalar_expr<value_type>(__y, __x.size())));
4443}
4444
4445template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004446inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004447typename enable_if
4448<
4449 __is_val_expr<_Expr>::value,
4450 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4451 __scalar_expr<typename _Expr::value_type>, _Expr> >
4452>::type
4453operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
4454{
4455 typedef typename _Expr::value_type value_type;
4456 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4457 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4458 __scalar_expr<value_type>(__x, __y.size()), __y));
4459}
4460
4461template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004462inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004463typename enable_if
4464<
4465 __is_val_expr<_Expr>::value,
4466 __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
4467>::type
4468abs(const _Expr& __x)
4469{
4470 typedef typename _Expr::value_type value_type;
4471 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
4472 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
4473}
4474
4475template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004476inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004477typename enable_if
4478<
4479 __is_val_expr<_Expr>::value,
4480 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
4481>::type
4482acos(const _Expr& __x)
4483{
4484 typedef typename _Expr::value_type value_type;
4485 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
4486 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
4487}
4488
4489template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004490inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004491typename enable_if
4492<
4493 __is_val_expr<_Expr>::value,
4494 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
4495>::type
4496asin(const _Expr& __x)
4497{
4498 typedef typename _Expr::value_type value_type;
4499 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
4500 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
4501}
4502
4503template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004504inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004505typename enable_if
4506<
4507 __is_val_expr<_Expr>::value,
4508 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
4509>::type
4510atan(const _Expr& __x)
4511{
4512 typedef typename _Expr::value_type value_type;
4513 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
4514 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
4515}
4516
4517template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004518inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004519typename enable_if
4520<
4521 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4522 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4523>::type
4524atan2(const _Expr1& __x, const _Expr2& __y)
4525{
4526 typedef typename _Expr1::value_type value_type;
4527 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
4528 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
4529}
4530
4531template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004532inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004533typename enable_if
4534<
4535 __is_val_expr<_Expr>::value,
4536 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4537 _Expr, __scalar_expr<typename _Expr::value_type> > >
4538>::type
4539atan2(const _Expr& __x, const typename _Expr::value_type& __y)
4540{
4541 typedef typename _Expr::value_type value_type;
4542 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4543 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4544 __x, __scalar_expr<value_type>(__y, __x.size())));
4545}
4546
4547template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004548inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004549typename enable_if
4550<
4551 __is_val_expr<_Expr>::value,
4552 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4553 __scalar_expr<typename _Expr::value_type>, _Expr> >
4554>::type
4555atan2(const typename _Expr::value_type& __x, const _Expr& __y)
4556{
4557 typedef typename _Expr::value_type value_type;
4558 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4559 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4560 __scalar_expr<value_type>(__x, __y.size()), __y));
4561}
4562
4563template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004564inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004565typename enable_if
4566<
4567 __is_val_expr<_Expr>::value,
4568 __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
4569>::type
4570cos(const _Expr& __x)
4571{
4572 typedef typename _Expr::value_type value_type;
4573 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
4574 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
4575}
4576
4577template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004578inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004579typename enable_if
4580<
4581 __is_val_expr<_Expr>::value,
4582 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
4583>::type
4584cosh(const _Expr& __x)
4585{
4586 typedef typename _Expr::value_type value_type;
4587 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
4588 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
4589}
4590
4591template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004592inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004593typename enable_if
4594<
4595 __is_val_expr<_Expr>::value,
4596 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
4597>::type
4598exp(const _Expr& __x)
4599{
4600 typedef typename _Expr::value_type value_type;
4601 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
4602 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
4603}
4604
4605template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004606inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004607typename enable_if
4608<
4609 __is_val_expr<_Expr>::value,
4610 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
4611>::type
4612log(const _Expr& __x)
4613{
4614 typedef typename _Expr::value_type value_type;
4615 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
4616 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
4617}
4618
4619template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004620inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004621typename enable_if
4622<
4623 __is_val_expr<_Expr>::value,
4624 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
4625>::type
4626log10(const _Expr& __x)
4627{
4628 typedef typename _Expr::value_type value_type;
4629 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
4630 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
4631}
4632
4633template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004634inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004635typename enable_if
4636<
4637 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4638 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4639>::type
4640pow(const _Expr1& __x, const _Expr2& __y)
4641{
4642 typedef typename _Expr1::value_type value_type;
4643 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
4644 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
4645}
4646
4647template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004648inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004649typename enable_if
4650<
4651 __is_val_expr<_Expr>::value,
4652 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4653 _Expr, __scalar_expr<typename _Expr::value_type> > >
4654>::type
4655pow(const _Expr& __x, const typename _Expr::value_type& __y)
4656{
4657 typedef typename _Expr::value_type value_type;
4658 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4659 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4660 __x, __scalar_expr<value_type>(__y, __x.size())));
4661}
4662
4663template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004664inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004665typename enable_if
4666<
4667 __is_val_expr<_Expr>::value,
4668 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4669 __scalar_expr<typename _Expr::value_type>, _Expr> >
4670>::type
4671pow(const typename _Expr::value_type& __x, const _Expr& __y)
4672{
4673 typedef typename _Expr::value_type value_type;
4674 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4675 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4676 __scalar_expr<value_type>(__x, __y.size()), __y));
4677}
4678
4679template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004680inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004681typename enable_if
4682<
4683 __is_val_expr<_Expr>::value,
4684 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
4685>::type
4686sin(const _Expr& __x)
4687{
4688 typedef typename _Expr::value_type value_type;
4689 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
4690 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
4691}
4692
4693template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004694inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004695typename enable_if
4696<
4697 __is_val_expr<_Expr>::value,
4698 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
4699>::type
4700sinh(const _Expr& __x)
4701{
4702 typedef typename _Expr::value_type value_type;
4703 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
4704 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
4705}
4706
4707template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004708inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004709typename enable_if
4710<
4711 __is_val_expr<_Expr>::value,
4712 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
4713>::type
4714sqrt(const _Expr& __x)
4715{
4716 typedef typename _Expr::value_type value_type;
4717 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
4718 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
4719}
4720
4721template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004722inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004723typename enable_if
4724<
4725 __is_val_expr<_Expr>::value,
4726 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
4727>::type
4728tan(const _Expr& __x)
4729{
4730 typedef typename _Expr::value_type value_type;
4731 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
4732 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
4733}
4734
4735template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004736inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004737typename enable_if
4738<
4739 __is_val_expr<_Expr>::value,
4740 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
4741>::type
4742tanh(const _Expr& __x)
4743{
4744 typedef typename _Expr::value_type value_type;
4745 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
4746 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
4747}
4748
4749template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004750inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004751_Tp*
4752begin(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 +00004759const _Tp*
4760begin(const valarray<_Tp>& __v)
4761{
4762 return __v.__begin_;
4763}
4764
4765template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004766inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004767_Tp*
4768end(valarray<_Tp>& __v)
4769{
4770 return __v.__end_;
4771}
4772
4773template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004774inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004775const _Tp*
4776end(const valarray<_Tp>& __v)
4777{
4778 return __v.__end_;
4779}
4780
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004781_LIBCPP_END_NAMESPACE_STD
4782
4783#endif // _LIBCPP_VALARRAY