blob: 2b942046db9dfa14db10ac4bde0884a77839853c [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>
Richard Smith73c1fce2014-06-04 19:54:15 +0000348#include <new>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000349
Howard Hinnant66c6f972011-11-29 16:45:27 +0000350#include <__undef_min_max>
351
Howard Hinnant08e17472011-10-17 20:05:10 +0000352#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000353#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000354#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000355
356_LIBCPP_BEGIN_NAMESPACE_STD
357
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000358template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000359
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000360class _LIBCPP_TYPE_VIS_ONLY slice
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361{
362 size_t __start_;
363 size_t __size_;
364 size_t __stride_;
365public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000366 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000367 slice()
368 : __start_(0),
369 __size_(0),
370 __stride_(0)
371 {}
372
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000373 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374 slice(size_t __start, size_t __size, size_t __stride)
375 : __start_(__start),
376 __size_(__size),
377 __stride_(__stride)
378 {}
379
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000380 _LIBCPP_INLINE_VISIBILITY size_t start() const {return __start_;}
381 _LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;}
382 _LIBCPP_INLINE_VISIBILITY size_t stride() const {return __stride_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000383};
384
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000385template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY slice_array;
Howard Hinnant83eade62013-03-06 23:30:19 +0000386class _LIBCPP_TYPE_VIS gslice;
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000387template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY gslice_array;
388template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY mask_array;
389template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY indirect_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000390
391template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000392_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000393_Tp*
394begin(valarray<_Tp>& __v);
395
396template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000397_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000398const _Tp*
399begin(const valarray<_Tp>& __v);
400
401template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000402_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000403_Tp*
404end(valarray<_Tp>& __v);
405
406template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000407_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000408const _Tp*
409end(const valarray<_Tp>& __v);
410
411template <class _Op, class _A0>
412struct _UnaryOp
413{
414 typedef typename _Op::result_type result_type;
415 typedef typename _A0::value_type value_type;
416
417 _Op __op_;
418 _A0 __a0_;
419
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000421 _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {}
422
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000423 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000424 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
425
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000427 size_t size() const {return __a0_.size();}
428};
429
430template <class _Op, class _A0, class _A1>
431struct _BinaryOp
432{
433 typedef typename _Op::result_type result_type;
434 typedef typename _A0::value_type value_type;
435
436 _Op __op_;
437 _A0 __a0_;
438 _A1 __a1_;
439
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000440 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000441 _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1)
442 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
443
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000444 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000445 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
446
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000447 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000448 size_t size() const {return __a0_.size();}
449};
450
451template <class _Tp>
452class __scalar_expr
453{
454public:
455 typedef _Tp value_type;
456 typedef const _Tp& result_type;
457private:
458 const value_type& __t_;
459 size_t __s_;
460public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000461 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462 explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {}
463
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000464 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000465 result_type operator[](size_t) const {return __t_;}
466
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000468 size_t size() const {return __s_;}
469};
470
471template <class _Tp>
472struct __unary_plus : unary_function<_Tp, _Tp>
473{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000475 _Tp operator()(const _Tp& __x) const
476 {return +__x;}
477};
478
479template <class _Tp>
480struct __bit_not : unary_function<_Tp, _Tp>
481{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000483 _Tp operator()(const _Tp& __x) const
484 {return ~__x;}
485};
486
487template <class _Tp>
488struct __bit_shift_left : binary_function<_Tp, _Tp, _Tp>
489{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000491 _Tp operator()(const _Tp& __x, const _Tp& __y) const
492 {return __x << __y;}
493};
494
495template <class _Tp>
496struct __bit_shift_right : binary_function<_Tp, _Tp, _Tp>
497{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000499 _Tp operator()(const _Tp& __x, const _Tp& __y) const
500 {return __x >> __y;}
501};
502
Howard Hinnant99968442011-11-29 18:15:50 +0000503template <class _Tp, class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504struct __apply_expr : unary_function<_Tp, _Tp>
505{
506private:
Howard Hinnant99968442011-11-29 18:15:50 +0000507 _Fp __f_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000508public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000509 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +0000510 explicit __apply_expr(_Fp __f) : __f_(__f) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000511
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000513 _Tp operator()(const _Tp& __x) const
514 {return __f_(__x);}
515};
516
517template <class _Tp>
518struct __abs_expr : unary_function<_Tp, _Tp>
519{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521 _Tp operator()(const _Tp& __x) const
522 {return abs(__x);}
523};
524
525template <class _Tp>
526struct __acos_expr : unary_function<_Tp, _Tp>
527{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529 _Tp operator()(const _Tp& __x) const
530 {return acos(__x);}
531};
532
533template <class _Tp>
534struct __asin_expr : unary_function<_Tp, _Tp>
535{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000537 _Tp operator()(const _Tp& __x) const
538 {return asin(__x);}
539};
540
541template <class _Tp>
542struct __atan_expr : unary_function<_Tp, _Tp>
543{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000544 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000545 _Tp operator()(const _Tp& __x) const
546 {return atan(__x);}
547};
548
549template <class _Tp>
550struct __atan2_expr : binary_function<_Tp, _Tp, _Tp>
551{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000553 _Tp operator()(const _Tp& __x, const _Tp& __y) const
554 {return atan2(__x, __y);}
555};
556
557template <class _Tp>
558struct __cos_expr : unary_function<_Tp, _Tp>
559{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000561 _Tp operator()(const _Tp& __x) const
562 {return cos(__x);}
563};
564
565template <class _Tp>
566struct __cosh_expr : unary_function<_Tp, _Tp>
567{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000569 _Tp operator()(const _Tp& __x) const
570 {return cosh(__x);}
571};
572
573template <class _Tp>
574struct __exp_expr : unary_function<_Tp, _Tp>
575{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000576 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000577 _Tp operator()(const _Tp& __x) const
578 {return exp(__x);}
579};
580
581template <class _Tp>
582struct __log_expr : unary_function<_Tp, _Tp>
583{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000584 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000585 _Tp operator()(const _Tp& __x) const
586 {return log(__x);}
587};
588
589template <class _Tp>
590struct __log10_expr : unary_function<_Tp, _Tp>
591{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000593 _Tp operator()(const _Tp& __x) const
594 {return log10(__x);}
595};
596
597template <class _Tp>
598struct __pow_expr : binary_function<_Tp, _Tp, _Tp>
599{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000601 _Tp operator()(const _Tp& __x, const _Tp& __y) const
602 {return pow(__x, __y);}
603};
604
605template <class _Tp>
606struct __sin_expr : unary_function<_Tp, _Tp>
607{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000608 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000609 _Tp operator()(const _Tp& __x) const
610 {return sin(__x);}
611};
612
613template <class _Tp>
614struct __sinh_expr : unary_function<_Tp, _Tp>
615{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000617 _Tp operator()(const _Tp& __x) const
618 {return sinh(__x);}
619};
620
621template <class _Tp>
622struct __sqrt_expr : unary_function<_Tp, _Tp>
623{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000625 _Tp operator()(const _Tp& __x) const
626 {return sqrt(__x);}
627};
628
629template <class _Tp>
630struct __tan_expr : unary_function<_Tp, _Tp>
631{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000632 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000633 _Tp operator()(const _Tp& __x) const
634 {return tan(__x);}
635};
636
637template <class _Tp>
638struct __tanh_expr : unary_function<_Tp, _Tp>
639{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000640 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000641 _Tp operator()(const _Tp& __x) const
642 {return tanh(__x);}
643};
644
645template <class _ValExpr>
646class __slice_expr
647{
648 typedef typename remove_reference<_ValExpr>::type _RmExpr;
649public:
650 typedef typename _RmExpr::value_type value_type;
651 typedef value_type result_type;
652
653private:
654 _ValExpr __expr_;
655 size_t __start_;
656 size_t __size_;
657 size_t __stride_;
658
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000659 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000660 __slice_expr(const slice& __sl, const _RmExpr& __e)
661 : __expr_(__e),
662 __start_(__sl.start()),
663 __size_(__sl.size()),
664 __stride_(__sl.stride())
665 {}
666public:
667
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000669 result_type operator[](size_t __i) const
670 {return __expr_[__start_ + __i * __stride_];}
671
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000672 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000673 size_t size() const {return __size_;}
674
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000675 template <class> friend class _LIBCPP_TYPE_VIS_ONLY valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676};
677
678template <class _ValExpr>
679class __mask_expr;
680
681template <class _ValExpr>
682class __indirect_expr;
683
684template <class _ValExpr>
685class __shift_expr
686{
687 typedef typename remove_reference<_ValExpr>::type _RmExpr;
688public:
689 typedef typename _RmExpr::value_type value_type;
690 typedef value_type result_type;
691
692private:
693 _ValExpr __expr_;
694 size_t __size_;
695 ptrdiff_t __ul_;
696 ptrdiff_t __sn_;
697 ptrdiff_t __n_;
Howard Hinnant99968442011-11-29 18:15:50 +0000698 static const ptrdiff_t _Np = static_cast<ptrdiff_t>(
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000699 sizeof(ptrdiff_t) * __CHAR_BIT__ - 1);
700
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000702 __shift_expr(int __n, const _RmExpr& __e)
703 : __expr_(__e),
704 __size_(__e.size()),
705 __n_(__n)
706 {
Howard Hinnant99968442011-11-29 18:15:50 +0000707 ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _Np);
708 __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _Np);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000709 __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n);
710 }
711public:
712
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000713 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714 result_type operator[](size_t __j) const
715 {
Howard Hinnantec3773c2011-12-01 20:21:04 +0000716 ptrdiff_t __i = static_cast<ptrdiff_t>(__j);
Howard Hinnant99968442011-11-29 18:15:50 +0000717 ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000718 return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
719 }
720
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000722 size_t size() const {return __size_;}
723
724 template <class> friend class __val_expr;
725};
726
727template <class _ValExpr>
728class __cshift_expr
729{
730 typedef typename remove_reference<_ValExpr>::type _RmExpr;
731public:
732 typedef typename _RmExpr::value_type value_type;
733 typedef value_type result_type;
734
735private:
736 _ValExpr __expr_;
737 size_t __size_;
738 size_t __m_;
739 size_t __o1_;
740 size_t __o2_;
741
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000743 __cshift_expr(int __n, const _RmExpr& __e)
744 : __expr_(__e),
745 __size_(__e.size())
746 {
747 __n %= static_cast<int>(__size_);
748 if (__n >= 0)
749 {
750 __m_ = __size_ - __n;
751 __o1_ = __n;
752 __o2_ = __n - __size_;
753 }
754 else
755 {
756 __m_ = -__n;
757 __o1_ = __n + __size_;
758 __o2_ = __n;
759 }
760 }
761public:
762
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000763 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000764 result_type operator[](size_t __i) const
765 {
766 if (__i < __m_)
767 return __expr_[__i + __o1_];
768 return __expr_[__i + __o2_];
769 }
770
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000771 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000772 size_t size() const {return __size_;}
773
774 template <class> friend class __val_expr;
775};
776
777template<class _ValExpr>
778class __val_expr;
779
780template<class _ValExpr>
781struct __is_val_expr : false_type {};
782
783template<class _ValExpr>
784struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
785
786template<class _Tp>
787struct __is_val_expr<valarray<_Tp> > : true_type {};
788
789template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000790class _LIBCPP_TYPE_VIS_ONLY valarray
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000791{
792public:
793 typedef _Tp value_type;
794 typedef _Tp result_type;
795
796private:
797 value_type* __begin_;
798 value_type* __end_;
799
800public:
801 // construct/destroy:
Douglas Gregor0855dde2012-05-19 07:14:17 +0000802 _LIBCPP_INLINE_VISIBILITY
803 valarray() : __begin_(0), __end_(0) {}
804 explicit valarray(size_t __n);
805 valarray(const value_type& __x, size_t __n);
806 valarray(const value_type* __p, size_t __n);
807 valarray(const valarray& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000808#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbd143082012-07-21 00:51:28 +0000809 valarray(valarray&& __v) _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000810#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000811#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Douglas Gregor0855dde2012-05-19 07:14:17 +0000812 valarray(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +0000813#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Douglas Gregor0855dde2012-05-19 07:14:17 +0000814 valarray(const slice_array<value_type>& __sa);
815 valarray(const gslice_array<value_type>& __ga);
816 valarray(const mask_array<value_type>& __ma);
817 valarray(const indirect_array<value_type>& __ia);
818 ~valarray();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000819
820 // assignment:
Douglas Gregor0855dde2012-05-19 07:14:17 +0000821 valarray& operator=(const valarray& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000822#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbd143082012-07-21 00:51:28 +0000823 valarray& operator=(valarray&& __v) _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000824#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000825#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Douglas Gregor0855dde2012-05-19 07:14:17 +0000826 valarray& operator=(initializer_list<value_type>);
Howard Hinnante3e32912011-08-12 21:56:02 +0000827#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Douglas Gregor0855dde2012-05-19 07:14:17 +0000828 valarray& operator=(const value_type& __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000829 valarray& operator=(const slice_array<value_type>& __sa);
830 valarray& operator=(const gslice_array<value_type>& __ga);
831 valarray& operator=(const mask_array<value_type>& __ma);
832 valarray& operator=(const indirect_array<value_type>& __ia);
Howard Hinnantdb866632011-07-27 23:19:59 +0000833 template <class _ValExpr>
834 valarray& operator=(const __val_expr<_ValExpr>& __v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000835
836 // element access:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000837 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000838 const value_type& operator[](size_t __i) const {return __begin_[__i];}
839
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000841 value_type& operator[](size_t __i) {return __begin_[__i];}
842
843 // subset operations:
844 __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const;
845 slice_array<value_type> operator[](slice __s);
846 __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
847 gslice_array<value_type> operator[](const gslice& __gs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000848#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000849 __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
850 gslice_array<value_type> operator[](gslice&& __gs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000851#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000852 __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const;
853 mask_array<value_type> operator[](const valarray<bool>& __vb);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000854#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000855 __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const;
856 mask_array<value_type> operator[](valarray<bool>&& __vb);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000857#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000858 __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
859 indirect_array<value_type> operator[](const valarray<size_t>& __vs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000860#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000861 __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
862 indirect_array<value_type> operator[](valarray<size_t>&& __vs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000863#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000864
865 // unary operators:
Douglas Gregor0855dde2012-05-19 07:14:17 +0000866 valarray operator+() const;
867 valarray operator-() const;
868 valarray operator~() const;
869 valarray<bool> operator!() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000870
871 // computed assignment:
872 valarray& operator*= (const value_type& __x);
873 valarray& operator/= (const value_type& __x);
874 valarray& operator%= (const value_type& __x);
875 valarray& operator+= (const value_type& __x);
876 valarray& operator-= (const value_type& __x);
877 valarray& operator^= (const value_type& __x);
878 valarray& operator&= (const value_type& __x);
879 valarray& operator|= (const value_type& __x);
880 valarray& operator<<=(const value_type& __x);
881 valarray& operator>>=(const value_type& __x);
882
883 template <class _Expr>
884 typename enable_if
885 <
886 __is_val_expr<_Expr>::value,
887 valarray&
888 >::type
889 operator*= (const _Expr& __v);
890
891 template <class _Expr>
892 typename enable_if
893 <
894 __is_val_expr<_Expr>::value,
895 valarray&
896 >::type
897 operator/= (const _Expr& __v);
898
899 template <class _Expr>
900 typename enable_if
901 <
902 __is_val_expr<_Expr>::value,
903 valarray&
904 >::type
905 operator%= (const _Expr& __v);
906
907 template <class _Expr>
908 typename enable_if
909 <
910 __is_val_expr<_Expr>::value,
911 valarray&
912 >::type
913 operator+= (const _Expr& __v);
914
915 template <class _Expr>
916 typename enable_if
917 <
918 __is_val_expr<_Expr>::value,
919 valarray&
920 >::type
921 operator-= (const _Expr& __v);
922
923 template <class _Expr>
924 typename enable_if
925 <
926 __is_val_expr<_Expr>::value,
927 valarray&
928 >::type
929 operator^= (const _Expr& __v);
930
931 template <class _Expr>
932 typename enable_if
933 <
934 __is_val_expr<_Expr>::value,
935 valarray&
936 >::type
937 operator|= (const _Expr& __v);
938
939 template <class _Expr>
940 typename enable_if
941 <
942 __is_val_expr<_Expr>::value,
943 valarray&
944 >::type
945 operator&= (const _Expr& __v);
946
947 template <class _Expr>
948 typename enable_if
949 <
950 __is_val_expr<_Expr>::value,
951 valarray&
952 >::type
953 operator<<= (const _Expr& __v);
954
955 template <class _Expr>
956 typename enable_if
957 <
958 __is_val_expr<_Expr>::value,
959 valarray&
960 >::type
961 operator>>= (const _Expr& __v);
962
963 // member functions:
Howard Hinnantbd143082012-07-21 00:51:28 +0000964 void swap(valarray& __v) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000965
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000966 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +0000967 size_t size() const {return static_cast<size_t>(__end_ - __begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000968
Douglas Gregor0855dde2012-05-19 07:14:17 +0000969 value_type sum() const;
970 value_type min() const;
971 value_type max() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000972
Douglas Gregor0855dde2012-05-19 07:14:17 +0000973 valarray shift (int __i) const;
974 valarray cshift(int __i) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000975 valarray apply(value_type __f(value_type)) const;
976 valarray apply(value_type __f(const value_type&)) const;
977 void resize(size_t __n, value_type __x = value_type());
978
979private:
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000980 template <class> friend class _LIBCPP_TYPE_VIS_ONLY valarray;
981 template <class> friend class _LIBCPP_TYPE_VIS_ONLY slice_array;
982 template <class> friend class _LIBCPP_TYPE_VIS_ONLY gslice_array;
983 template <class> friend class _LIBCPP_TYPE_VIS_ONLY mask_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000984 template <class> friend class __mask_expr;
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000985 template <class> friend class _LIBCPP_TYPE_VIS_ONLY indirect_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000986 template <class> friend class __indirect_expr;
987 template <class> friend class __val_expr;
988
989 template <class _Up>
990 friend
991 _Up*
992 begin(valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +0000993
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000994 template <class _Up>
995 friend
996 const _Up*
997 begin(const valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +0000998
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000999 template <class _Up>
1000 friend
1001 _Up*
1002 end(valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +00001003
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001004 template <class _Up>
1005 friend
1006 const _Up*
1007 end(const valarray<_Up>& __v);
1008};
1009
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001010_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::valarray(size_t))
1011_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::~valarray())
1012_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void valarray<size_t>::resize(size_t, size_t))
1013
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001014template <class _Op, class _Tp>
1015struct _UnaryOp<_Op, valarray<_Tp> >
1016{
1017 typedef typename _Op::result_type result_type;
1018 typedef _Tp value_type;
1019
1020 _Op __op_;
1021 const valarray<_Tp>& __a0_;
1022
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001023 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001024 _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
1025
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001026 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001027 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
1028
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001029 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001030 size_t size() const {return __a0_.size();}
1031};
1032
1033template <class _Op, class _Tp, class _A1>
1034struct _BinaryOp<_Op, valarray<_Tp>, _A1>
1035{
1036 typedef typename _Op::result_type result_type;
1037 typedef _Tp value_type;
1038
1039 _Op __op_;
1040 const valarray<_Tp>& __a0_;
1041 _A1 __a1_;
1042
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001043 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001044 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
1045 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1046
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001047 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001048 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1049
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001051 size_t size() const {return __a0_.size();}
1052};
1053
1054template <class _Op, class _A0, class _Tp>
1055struct _BinaryOp<_Op, _A0, valarray<_Tp> >
1056{
1057 typedef typename _Op::result_type result_type;
1058 typedef _Tp value_type;
1059
1060 _Op __op_;
1061 _A0 __a0_;
1062 const valarray<_Tp>& __a1_;
1063
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001064 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001065 _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
1066 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1067
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001068 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001069 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1070
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001071 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072 size_t size() const {return __a0_.size();}
1073};
1074
1075template <class _Op, class _Tp>
1076struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> >
1077{
1078 typedef typename _Op::result_type result_type;
1079 typedef _Tp value_type;
1080
1081 _Op __op_;
1082 const valarray<_Tp>& __a0_;
1083 const valarray<_Tp>& __a1_;
1084
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001085 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001086 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
1087 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1088
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001089 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001090 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1091
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001092 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001093 size_t size() const {return __a0_.size();}
1094};
1095
1096// slice_array
1097
1098template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001099class _LIBCPP_TYPE_VIS_ONLY slice_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001100{
1101public:
1102 typedef _Tp value_type;
1103
1104private:
1105 value_type* __vp_;
1106 size_t __size_;
1107 size_t __stride_;
1108
1109public:
1110 template <class _Expr>
1111 typename enable_if
1112 <
1113 __is_val_expr<_Expr>::value,
1114 void
1115 >::type
1116 operator=(const _Expr& __v) const;
1117
1118 template <class _Expr>
1119 typename enable_if
1120 <
1121 __is_val_expr<_Expr>::value,
1122 void
1123 >::type
1124 operator*=(const _Expr& __v) const;
1125
1126 template <class _Expr>
1127 typename enable_if
1128 <
1129 __is_val_expr<_Expr>::value,
1130 void
1131 >::type
1132 operator/=(const _Expr& __v) const;
1133
1134 template <class _Expr>
1135 typename enable_if
1136 <
1137 __is_val_expr<_Expr>::value,
1138 void
1139 >::type
1140 operator%=(const _Expr& __v) const;
1141
1142 template <class _Expr>
1143 typename enable_if
1144 <
1145 __is_val_expr<_Expr>::value,
1146 void
1147 >::type
1148 operator+=(const _Expr& __v) const;
1149
1150 template <class _Expr>
1151 typename enable_if
1152 <
1153 __is_val_expr<_Expr>::value,
1154 void
1155 >::type
1156 operator-=(const _Expr& __v) const;
1157
1158 template <class _Expr>
1159 typename enable_if
1160 <
1161 __is_val_expr<_Expr>::value,
1162 void
1163 >::type
1164 operator^=(const _Expr& __v) const;
1165
1166 template <class _Expr>
1167 typename enable_if
1168 <
1169 __is_val_expr<_Expr>::value,
1170 void
1171 >::type
1172 operator&=(const _Expr& __v) const;
1173
1174 template <class _Expr>
1175 typename enable_if
1176 <
1177 __is_val_expr<_Expr>::value,
1178 void
1179 >::type
1180 operator|=(const _Expr& __v) const;
1181
1182 template <class _Expr>
1183 typename enable_if
1184 <
1185 __is_val_expr<_Expr>::value,
1186 void
1187 >::type
1188 operator<<=(const _Expr& __v) const;
1189
1190 template <class _Expr>
1191 typename enable_if
1192 <
1193 __is_val_expr<_Expr>::value,
1194 void
1195 >::type
1196 operator>>=(const _Expr& __v) const;
1197
1198 const slice_array& operator=(const slice_array& __sa) const;
1199
1200 void operator=(const value_type& __x) const;
1201
1202private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001203 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001204 slice_array(const slice& __sl, const valarray<value_type>& __v)
1205 : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())),
1206 __size_(__sl.size()),
1207 __stride_(__sl.stride())
1208 {}
1209
1210 template <class> friend class valarray;
1211 template <class> friend class sliceExpr;
1212};
1213
1214template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001215inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001216const slice_array<_Tp>&
1217slice_array<_Tp>::operator=(const slice_array& __sa) const
1218{
1219 value_type* __t = __vp_;
1220 const value_type* __s = __sa.__vp_;
1221 for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
1222 *__t = *__s;
Eric Fiselierf4124612014-08-12 00:06:58 +00001223 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001224}
1225
1226template <class _Tp>
1227template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001228inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001229typename enable_if
1230<
1231 __is_val_expr<_Expr>::value,
1232 void
1233>::type
1234slice_array<_Tp>::operator=(const _Expr& __v) const
1235{
1236 value_type* __t = __vp_;
1237 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1238 *__t = __v[__i];
1239}
1240
1241template <class _Tp>
1242template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001243inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001244typename enable_if
1245<
1246 __is_val_expr<_Expr>::value,
1247 void
1248>::type
1249slice_array<_Tp>::operator*=(const _Expr& __v) const
1250{
1251 value_type* __t = __vp_;
1252 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1253 *__t *= __v[__i];
1254}
1255
1256template <class _Tp>
1257template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001258inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001259typename enable_if
1260<
1261 __is_val_expr<_Expr>::value,
1262 void
1263>::type
1264slice_array<_Tp>::operator/=(const _Expr& __v) const
1265{
1266 value_type* __t = __vp_;
1267 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1268 *__t /= __v[__i];
1269}
1270
1271template <class _Tp>
1272template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001273inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001274typename enable_if
1275<
1276 __is_val_expr<_Expr>::value,
1277 void
1278>::type
1279slice_array<_Tp>::operator%=(const _Expr& __v) const
1280{
1281 value_type* __t = __vp_;
1282 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1283 *__t %= __v[__i];
1284}
1285
1286template <class _Tp>
1287template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001288inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001289typename enable_if
1290<
1291 __is_val_expr<_Expr>::value,
1292 void
1293>::type
1294slice_array<_Tp>::operator+=(const _Expr& __v) const
1295{
1296 value_type* __t = __vp_;
1297 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1298 *__t += __v[__i];
1299}
1300
1301template <class _Tp>
1302template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001303inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001304typename enable_if
1305<
1306 __is_val_expr<_Expr>::value,
1307 void
1308>::type
1309slice_array<_Tp>::operator-=(const _Expr& __v) const
1310{
1311 value_type* __t = __vp_;
1312 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1313 *__t -= __v[__i];
1314}
1315
1316template <class _Tp>
1317template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001318inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001319typename enable_if
1320<
1321 __is_val_expr<_Expr>::value,
1322 void
1323>::type
1324slice_array<_Tp>::operator^=(const _Expr& __v) const
1325{
1326 value_type* __t = __vp_;
1327 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1328 *__t ^= __v[__i];
1329}
1330
1331template <class _Tp>
1332template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001333inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001334typename enable_if
1335<
1336 __is_val_expr<_Expr>::value,
1337 void
1338>::type
1339slice_array<_Tp>::operator&=(const _Expr& __v) const
1340{
1341 value_type* __t = __vp_;
1342 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1343 *__t &= __v[__i];
1344}
1345
1346template <class _Tp>
1347template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001348inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001349typename enable_if
1350<
1351 __is_val_expr<_Expr>::value,
1352 void
1353>::type
1354slice_array<_Tp>::operator|=(const _Expr& __v) const
1355{
1356 value_type* __t = __vp_;
1357 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1358 *__t |= __v[__i];
1359}
1360
1361template <class _Tp>
1362template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001363inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001364typename enable_if
1365<
1366 __is_val_expr<_Expr>::value,
1367 void
1368>::type
1369slice_array<_Tp>::operator<<=(const _Expr& __v) const
1370{
1371 value_type* __t = __vp_;
1372 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1373 *__t <<= __v[__i];
1374}
1375
1376template <class _Tp>
1377template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001378inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001379typename enable_if
1380<
1381 __is_val_expr<_Expr>::value,
1382 void
1383>::type
1384slice_array<_Tp>::operator>>=(const _Expr& __v) const
1385{
1386 value_type* __t = __vp_;
1387 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1388 *__t >>= __v[__i];
1389}
1390
1391template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001392inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001393void
1394slice_array<_Tp>::operator=(const value_type& __x) const
1395{
1396 value_type* __t = __vp_;
1397 for (size_t __n = __size_; __n; --__n, __t += __stride_)
1398 *__t = __x;
1399}
1400
1401// gslice
1402
Howard Hinnant83eade62013-03-06 23:30:19 +00001403class _LIBCPP_TYPE_VIS gslice
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001404{
1405 valarray<size_t> __size_;
1406 valarray<size_t> __stride_;
1407 valarray<size_t> __1d_;
Howard Hinnant324bb032010-08-22 00:02:43 +00001408
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001409public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001410 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001411 gslice() {}
Douglas Gregor0855dde2012-05-19 07:14:17 +00001412
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001413 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001414 gslice(size_t __start, const valarray<size_t>& __size,
1415 const valarray<size_t>& __stride)
1416 : __size_(__size),
1417 __stride_(__stride)
1418 {__init(__start);}
1419
Howard Hinnant73d21a42010-09-04 23:28:19 +00001420#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001421
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001423 gslice(size_t __start, const valarray<size_t>& __size,
1424 valarray<size_t>&& __stride)
1425 : __size_(__size),
1426 __stride_(move(__stride))
1427 {__init(__start);}
1428
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001429 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001430 gslice(size_t __start, valarray<size_t>&& __size,
1431 const valarray<size_t>& __stride)
1432 : __size_(move(__size)),
1433 __stride_(__stride)
1434 {__init(__start);}
1435
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001436 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001437 gslice(size_t __start, valarray<size_t>&& __size,
1438 valarray<size_t>&& __stride)
1439 : __size_(move(__size)),
1440 __stride_(move(__stride))
1441 {__init(__start);}
1442
Howard Hinnant73d21a42010-09-04 23:28:19 +00001443#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001444
1445// gslice(const gslice&) = default;
1446// gslice(gslice&&) = default;
1447// gslice& operator=(const gslice&) = default;
1448// gslice& operator=(gslice&&) = default;
1449
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001451 size_t start() const {return __1d_.size() ? __1d_[0] : 0;}
1452
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001453 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001454 valarray<size_t> size() const {return __size_;}
1455
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001456 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001457 valarray<size_t> stride() const {return __stride_;}
1458
1459private:
1460 void __init(size_t __start);
1461
1462 template <class> friend class gslice_array;
1463 template <class> friend class valarray;
1464 template <class> friend class __val_expr;
1465};
1466
1467// gslice_array
1468
1469template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001470class _LIBCPP_TYPE_VIS_ONLY gslice_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001471{
1472public:
1473 typedef _Tp value_type;
1474
1475private:
1476 value_type* __vp_;
1477 valarray<size_t> __1d_;
1478
1479public:
1480 template <class _Expr>
1481 typename enable_if
1482 <
1483 __is_val_expr<_Expr>::value,
1484 void
1485 >::type
1486 operator=(const _Expr& __v) const;
1487
1488 template <class _Expr>
1489 typename enable_if
1490 <
1491 __is_val_expr<_Expr>::value,
1492 void
1493 >::type
1494 operator*=(const _Expr& __v) const;
1495
1496 template <class _Expr>
1497 typename enable_if
1498 <
1499 __is_val_expr<_Expr>::value,
1500 void
1501 >::type
1502 operator/=(const _Expr& __v) const;
1503
1504 template <class _Expr>
1505 typename enable_if
1506 <
1507 __is_val_expr<_Expr>::value,
1508 void
1509 >::type
1510 operator%=(const _Expr& __v) const;
1511
1512 template <class _Expr>
1513 typename enable_if
1514 <
1515 __is_val_expr<_Expr>::value,
1516 void
1517 >::type
1518 operator+=(const _Expr& __v) const;
1519
1520 template <class _Expr>
1521 typename enable_if
1522 <
1523 __is_val_expr<_Expr>::value,
1524 void
1525 >::type
1526 operator-=(const _Expr& __v) const;
1527
1528 template <class _Expr>
1529 typename enable_if
1530 <
1531 __is_val_expr<_Expr>::value,
1532 void
1533 >::type
1534 operator^=(const _Expr& __v) const;
1535
1536 template <class _Expr>
1537 typename enable_if
1538 <
1539 __is_val_expr<_Expr>::value,
1540 void
1541 >::type
1542 operator&=(const _Expr& __v) const;
1543
1544 template <class _Expr>
1545 typename enable_if
1546 <
1547 __is_val_expr<_Expr>::value,
1548 void
1549 >::type
1550 operator|=(const _Expr& __v) const;
1551
1552 template <class _Expr>
1553 typename enable_if
1554 <
1555 __is_val_expr<_Expr>::value,
1556 void
1557 >::type
1558 operator<<=(const _Expr& __v) const;
1559
1560 template <class _Expr>
1561 typename enable_if
1562 <
1563 __is_val_expr<_Expr>::value,
1564 void
1565 >::type
1566 operator>>=(const _Expr& __v) const;
1567
1568 const gslice_array& operator=(const gslice_array& __ga) const;
1569
1570 void operator=(const value_type& __x) const;
1571
1572// gslice_array(const gslice_array&) = default;
1573// gslice_array(gslice_array&&) = default;
1574// gslice_array& operator=(const gslice_array&) = default;
1575// gslice_array& operator=(gslice_array&&) = default;
1576
1577private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001579 gslice_array(const gslice& __gs, const valarray<value_type>& __v)
1580 : __vp_(const_cast<value_type*>(__v.__begin_)),
1581 __1d_(__gs.__1d_)
1582 {}
1583
Howard Hinnant73d21a42010-09-04 23:28:19 +00001584#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001585
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001587 gslice_array(gslice&& __gs, const valarray<value_type>& __v)
1588 : __vp_(const_cast<value_type*>(__v.__begin_)),
1589 __1d_(move(__gs.__1d_))
1590 {}
1591
Howard Hinnant73d21a42010-09-04 23:28:19 +00001592#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001593
1594 template <class> friend class valarray;
1595};
1596
1597template <class _Tp>
1598template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001599inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001600typename enable_if
1601<
1602 __is_val_expr<_Expr>::value,
1603 void
1604>::type
1605gslice_array<_Tp>::operator=(const _Expr& __v) const
1606{
1607 typedef const size_t* _Ip;
1608 size_t __j = 0;
1609 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1610 __vp_[*__i] = __v[__j];
1611}
1612
1613template <class _Tp>
1614template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001615inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001616typename enable_if
1617<
1618 __is_val_expr<_Expr>::value,
1619 void
1620>::type
1621gslice_array<_Tp>::operator*=(const _Expr& __v) const
1622{
1623 typedef const size_t* _Ip;
1624 size_t __j = 0;
1625 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1626 __vp_[*__i] *= __v[__j];
1627}
1628
1629template <class _Tp>
1630template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001631inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001632typename enable_if
1633<
1634 __is_val_expr<_Expr>::value,
1635 void
1636>::type
1637gslice_array<_Tp>::operator/=(const _Expr& __v) const
1638{
1639 typedef const size_t* _Ip;
1640 size_t __j = 0;
1641 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1642 __vp_[*__i] /= __v[__j];
1643}
1644
1645template <class _Tp>
1646template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001647inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001648typename enable_if
1649<
1650 __is_val_expr<_Expr>::value,
1651 void
1652>::type
1653gslice_array<_Tp>::operator%=(const _Expr& __v) const
1654{
1655 typedef const size_t* _Ip;
1656 size_t __j = 0;
1657 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1658 __vp_[*__i] %= __v[__j];
1659}
1660
1661template <class _Tp>
1662template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001663inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001664typename enable_if
1665<
1666 __is_val_expr<_Expr>::value,
1667 void
1668>::type
1669gslice_array<_Tp>::operator+=(const _Expr& __v) const
1670{
1671 typedef const size_t* _Ip;
1672 size_t __j = 0;
1673 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1674 __vp_[*__i] += __v[__j];
1675}
1676
1677template <class _Tp>
1678template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001679inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001680typename enable_if
1681<
1682 __is_val_expr<_Expr>::value,
1683 void
1684>::type
1685gslice_array<_Tp>::operator-=(const _Expr& __v) const
1686{
1687 typedef const size_t* _Ip;
1688 size_t __j = 0;
1689 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1690 __vp_[*__i] -= __v[__j];
1691}
1692
1693template <class _Tp>
1694template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001695inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001696typename enable_if
1697<
1698 __is_val_expr<_Expr>::value,
1699 void
1700>::type
1701gslice_array<_Tp>::operator^=(const _Expr& __v) const
1702{
1703 typedef const size_t* _Ip;
1704 size_t __j = 0;
1705 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1706 __vp_[*__i] ^= __v[__j];
1707}
1708
1709template <class _Tp>
1710template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001711inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001712typename enable_if
1713<
1714 __is_val_expr<_Expr>::value,
1715 void
1716>::type
1717gslice_array<_Tp>::operator&=(const _Expr& __v) const
1718{
1719 typedef const size_t* _Ip;
1720 size_t __j = 0;
1721 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1722 __vp_[*__i] &= __v[__j];
1723}
1724
1725template <class _Tp>
1726template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001727inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001728typename enable_if
1729<
1730 __is_val_expr<_Expr>::value,
1731 void
1732>::type
1733gslice_array<_Tp>::operator|=(const _Expr& __v) const
1734{
1735 typedef const size_t* _Ip;
1736 size_t __j = 0;
1737 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1738 __vp_[*__i] |= __v[__j];
1739}
1740
1741template <class _Tp>
1742template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001743inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001744typename enable_if
1745<
1746 __is_val_expr<_Expr>::value,
1747 void
1748>::type
1749gslice_array<_Tp>::operator<<=(const _Expr& __v) const
1750{
1751 typedef const size_t* _Ip;
1752 size_t __j = 0;
1753 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1754 __vp_[*__i] <<= __v[__j];
1755}
1756
1757template <class _Tp>
1758template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001759inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001760typename enable_if
1761<
1762 __is_val_expr<_Expr>::value,
1763 void
1764>::type
1765gslice_array<_Tp>::operator>>=(const _Expr& __v) const
1766{
1767 typedef const size_t* _Ip;
1768 size_t __j = 0;
1769 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1770 __vp_[*__i] >>= __v[__j];
1771}
1772
1773template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001774inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001775const gslice_array<_Tp>&
1776gslice_array<_Tp>::operator=(const gslice_array& __ga) const
1777{
1778 typedef const size_t* _Ip;
1779 const value_type* __s = __ga.__vp_;
1780 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_;
1781 __i != __e; ++__i, ++__j)
1782 __vp_[*__i] = __s[*__j];
1783 return *this;
1784}
1785
1786template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001787inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001788void
1789gslice_array<_Tp>::operator=(const value_type& __x) const
1790{
1791 typedef const size_t* _Ip;
1792 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1793 __vp_[*__i] = __x;
1794}
1795
1796// mask_array
1797
1798template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001799class _LIBCPP_TYPE_VIS_ONLY mask_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001800{
1801public:
1802 typedef _Tp value_type;
1803
1804private:
1805 value_type* __vp_;
1806 valarray<size_t> __1d_;
1807
1808public:
1809 template <class _Expr>
1810 typename enable_if
1811 <
1812 __is_val_expr<_Expr>::value,
1813 void
1814 >::type
1815 operator=(const _Expr& __v) const;
1816
1817 template <class _Expr>
1818 typename enable_if
1819 <
1820 __is_val_expr<_Expr>::value,
1821 void
1822 >::type
1823 operator*=(const _Expr& __v) const;
1824
1825 template <class _Expr>
1826 typename enable_if
1827 <
1828 __is_val_expr<_Expr>::value,
1829 void
1830 >::type
1831 operator/=(const _Expr& __v) const;
1832
1833 template <class _Expr>
1834 typename enable_if
1835 <
1836 __is_val_expr<_Expr>::value,
1837 void
1838 >::type
1839 operator%=(const _Expr& __v) const;
1840
1841 template <class _Expr>
1842 typename enable_if
1843 <
1844 __is_val_expr<_Expr>::value,
1845 void
1846 >::type
1847 operator+=(const _Expr& __v) const;
1848
1849 template <class _Expr>
1850 typename enable_if
1851 <
1852 __is_val_expr<_Expr>::value,
1853 void
1854 >::type
1855 operator-=(const _Expr& __v) const;
1856
1857 template <class _Expr>
1858 typename enable_if
1859 <
1860 __is_val_expr<_Expr>::value,
1861 void
1862 >::type
1863 operator^=(const _Expr& __v) const;
1864
1865 template <class _Expr>
1866 typename enable_if
1867 <
1868 __is_val_expr<_Expr>::value,
1869 void
1870 >::type
1871 operator&=(const _Expr& __v) const;
1872
1873 template <class _Expr>
1874 typename enable_if
1875 <
1876 __is_val_expr<_Expr>::value,
1877 void
1878 >::type
1879 operator|=(const _Expr& __v) const;
1880
1881 template <class _Expr>
1882 typename enable_if
1883 <
1884 __is_val_expr<_Expr>::value,
1885 void
1886 >::type
1887 operator<<=(const _Expr& __v) const;
1888
1889 template <class _Expr>
1890 typename enable_if
1891 <
1892 __is_val_expr<_Expr>::value,
1893 void
1894 >::type
1895 operator>>=(const _Expr& __v) const;
1896
1897 const mask_array& operator=(const mask_array& __ma) const;
1898
1899 void operator=(const value_type& __x) const;
1900
1901// mask_array(const mask_array&) = default;
1902// mask_array(mask_array&&) = default;
1903// mask_array& operator=(const mask_array&) = default;
1904// mask_array& operator=(mask_array&&) = default;
1905
1906private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001908 mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
1909 : __vp_(const_cast<value_type*>(__v.__begin_)),
Howard Hinnantec3773c2011-12-01 20:21:04 +00001910 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001911 {
1912 size_t __j = 0;
1913 for (size_t __i = 0; __i < __vb.size(); ++__i)
1914 if (__vb[__i])
1915 __1d_[__j++] = __i;
1916 }
1917
1918 template <class> friend class valarray;
1919};
1920
1921template <class _Tp>
1922template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001923inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001924typename enable_if
1925<
1926 __is_val_expr<_Expr>::value,
1927 void
1928>::type
1929mask_array<_Tp>::operator=(const _Expr& __v) const
1930{
1931 size_t __n = __1d_.size();
1932 for (size_t __i = 0; __i < __n; ++__i)
1933 __vp_[__1d_[__i]] = __v[__i];
1934}
1935
1936template <class _Tp>
1937template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001938inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001939typename enable_if
1940<
1941 __is_val_expr<_Expr>::value,
1942 void
1943>::type
1944mask_array<_Tp>::operator*=(const _Expr& __v) const
1945{
1946 size_t __n = __1d_.size();
1947 for (size_t __i = 0; __i < __n; ++__i)
1948 __vp_[__1d_[__i]] *= __v[__i];
1949}
1950
1951template <class _Tp>
1952template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001953inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001954typename enable_if
1955<
1956 __is_val_expr<_Expr>::value,
1957 void
1958>::type
1959mask_array<_Tp>::operator/=(const _Expr& __v) const
1960{
1961 size_t __n = __1d_.size();
1962 for (size_t __i = 0; __i < __n; ++__i)
1963 __vp_[__1d_[__i]] /= __v[__i];
1964}
1965
1966template <class _Tp>
1967template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001968inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001969typename enable_if
1970<
1971 __is_val_expr<_Expr>::value,
1972 void
1973>::type
1974mask_array<_Tp>::operator%=(const _Expr& __v) const
1975{
1976 size_t __n = __1d_.size();
1977 for (size_t __i = 0; __i < __n; ++__i)
1978 __vp_[__1d_[__i]] %= __v[__i];
1979}
1980
1981template <class _Tp>
1982template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001983inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001984typename enable_if
1985<
1986 __is_val_expr<_Expr>::value,
1987 void
1988>::type
1989mask_array<_Tp>::operator+=(const _Expr& __v) const
1990{
1991 size_t __n = __1d_.size();
1992 for (size_t __i = 0; __i < __n; ++__i)
1993 __vp_[__1d_[__i]] += __v[__i];
1994}
1995
1996template <class _Tp>
1997template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001998inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001999typename enable_if
2000<
2001 __is_val_expr<_Expr>::value,
2002 void
2003>::type
2004mask_array<_Tp>::operator-=(const _Expr& __v) const
2005{
2006 size_t __n = __1d_.size();
2007 for (size_t __i = 0; __i < __n; ++__i)
2008 __vp_[__1d_[__i]] -= __v[__i];
2009}
2010
2011template <class _Tp>
2012template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002013inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002014typename enable_if
2015<
2016 __is_val_expr<_Expr>::value,
2017 void
2018>::type
2019mask_array<_Tp>::operator^=(const _Expr& __v) const
2020{
2021 size_t __n = __1d_.size();
2022 for (size_t __i = 0; __i < __n; ++__i)
2023 __vp_[__1d_[__i]] ^= __v[__i];
2024}
2025
2026template <class _Tp>
2027template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002028inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002029typename enable_if
2030<
2031 __is_val_expr<_Expr>::value,
2032 void
2033>::type
2034mask_array<_Tp>::operator&=(const _Expr& __v) const
2035{
2036 size_t __n = __1d_.size();
2037 for (size_t __i = 0; __i < __n; ++__i)
2038 __vp_[__1d_[__i]] &= __v[__i];
2039}
2040
2041template <class _Tp>
2042template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002043inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002044typename enable_if
2045<
2046 __is_val_expr<_Expr>::value,
2047 void
2048>::type
2049mask_array<_Tp>::operator|=(const _Expr& __v) const
2050{
2051 size_t __n = __1d_.size();
2052 for (size_t __i = 0; __i < __n; ++__i)
2053 __vp_[__1d_[__i]] |= __v[__i];
2054}
2055
2056template <class _Tp>
2057template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002058inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002059typename enable_if
2060<
2061 __is_val_expr<_Expr>::value,
2062 void
2063>::type
2064mask_array<_Tp>::operator<<=(const _Expr& __v) const
2065{
2066 size_t __n = __1d_.size();
2067 for (size_t __i = 0; __i < __n; ++__i)
2068 __vp_[__1d_[__i]] <<= __v[__i];
2069}
2070
2071template <class _Tp>
2072template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002073inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002074typename enable_if
2075<
2076 __is_val_expr<_Expr>::value,
2077 void
2078>::type
2079mask_array<_Tp>::operator>>=(const _Expr& __v) const
2080{
2081 size_t __n = __1d_.size();
2082 for (size_t __i = 0; __i < __n; ++__i)
2083 __vp_[__1d_[__i]] >>= __v[__i];
2084}
2085
2086template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002087inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002088const mask_array<_Tp>&
2089mask_array<_Tp>::operator=(const mask_array& __ma) const
2090{
2091 size_t __n = __1d_.size();
2092 for (size_t __i = 0; __i < __n; ++__i)
2093 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
Eric Fiselierf4124612014-08-12 00:06:58 +00002094 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002095}
2096
2097template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002098inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002099void
2100mask_array<_Tp>::operator=(const value_type& __x) const
2101{
2102 size_t __n = __1d_.size();
2103 for (size_t __i = 0; __i < __n; ++__i)
2104 __vp_[__1d_[__i]] = __x;
2105}
2106
2107template <class _ValExpr>
2108class __mask_expr
2109{
2110 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2111public:
2112 typedef typename _RmExpr::value_type value_type;
2113 typedef value_type result_type;
2114
2115private:
2116 _ValExpr __expr_;
2117 valarray<size_t> __1d_;
2118
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002119 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002120 __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
2121 : __expr_(__e),
Howard Hinnantec3773c2011-12-01 20:21:04 +00002122 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002123 {
2124 size_t __j = 0;
2125 for (size_t __i = 0; __i < __vb.size(); ++__i)
2126 if (__vb[__i])
2127 __1d_[__j++] = __i;
2128 }
2129
2130public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002131 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002132 result_type operator[](size_t __i) const
2133 {return __expr_[__1d_[__i]];}
2134
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002136 size_t size() const {return __1d_.size();}
2137
2138 template <class> friend class valarray;
2139};
2140
2141// indirect_array
2142
2143template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002144class _LIBCPP_TYPE_VIS_ONLY indirect_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002145{
2146public:
2147 typedef _Tp value_type;
2148
2149private:
2150 value_type* __vp_;
2151 valarray<size_t> __1d_;
2152
2153public:
2154 template <class _Expr>
2155 typename enable_if
2156 <
2157 __is_val_expr<_Expr>::value,
2158 void
2159 >::type
2160 operator=(const _Expr& __v) const;
2161
2162 template <class _Expr>
2163 typename enable_if
2164 <
2165 __is_val_expr<_Expr>::value,
2166 void
2167 >::type
2168 operator*=(const _Expr& __v) const;
2169
2170 template <class _Expr>
2171 typename enable_if
2172 <
2173 __is_val_expr<_Expr>::value,
2174 void
2175 >::type
2176 operator/=(const _Expr& __v) const;
2177
2178 template <class _Expr>
2179 typename enable_if
2180 <
2181 __is_val_expr<_Expr>::value,
2182 void
2183 >::type
2184 operator%=(const _Expr& __v) const;
2185
2186 template <class _Expr>
2187 typename enable_if
2188 <
2189 __is_val_expr<_Expr>::value,
2190 void
2191 >::type
2192 operator+=(const _Expr& __v) const;
2193
2194 template <class _Expr>
2195 typename enable_if
2196 <
2197 __is_val_expr<_Expr>::value,
2198 void
2199 >::type
2200 operator-=(const _Expr& __v) const;
2201
2202 template <class _Expr>
2203 typename enable_if
2204 <
2205 __is_val_expr<_Expr>::value,
2206 void
2207 >::type
2208 operator^=(const _Expr& __v) const;
2209
2210 template <class _Expr>
2211 typename enable_if
2212 <
2213 __is_val_expr<_Expr>::value,
2214 void
2215 >::type
2216 operator&=(const _Expr& __v) const;
2217
2218 template <class _Expr>
2219 typename enable_if
2220 <
2221 __is_val_expr<_Expr>::value,
2222 void
2223 >::type
2224 operator|=(const _Expr& __v) const;
2225
2226 template <class _Expr>
2227 typename enable_if
2228 <
2229 __is_val_expr<_Expr>::value,
2230 void
2231 >::type
2232 operator<<=(const _Expr& __v) const;
2233
2234 template <class _Expr>
2235 typename enable_if
2236 <
2237 __is_val_expr<_Expr>::value,
2238 void
2239 >::type
2240 operator>>=(const _Expr& __v) const;
2241
2242 const indirect_array& operator=(const indirect_array& __ia) const;
2243
2244 void operator=(const value_type& __x) const;
2245
2246// indirect_array(const indirect_array&) = default;
2247// indirect_array(indirect_array&&) = default;
2248// indirect_array& operator=(const indirect_array&) = default;
2249// indirect_array& operator=(indirect_array&&) = default;
2250
2251private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002252 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002253 indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
2254 : __vp_(const_cast<value_type*>(__v.__begin_)),
2255 __1d_(__ia)
2256 {}
2257
Howard Hinnant73d21a42010-09-04 23:28:19 +00002258#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002259
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002260 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002261 indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
2262 : __vp_(const_cast<value_type*>(__v.__begin_)),
2263 __1d_(move(__ia))
2264 {}
2265
Howard Hinnant73d21a42010-09-04 23:28:19 +00002266#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002267
2268 template <class> friend class valarray;
2269};
2270
2271template <class _Tp>
2272template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002273inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002274typename enable_if
2275<
2276 __is_val_expr<_Expr>::value,
2277 void
2278>::type
2279indirect_array<_Tp>::operator=(const _Expr& __v) const
2280{
2281 size_t __n = __1d_.size();
2282 for (size_t __i = 0; __i < __n; ++__i)
2283 __vp_[__1d_[__i]] = __v[__i];
2284}
2285
2286template <class _Tp>
2287template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002288inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002289typename enable_if
2290<
2291 __is_val_expr<_Expr>::value,
2292 void
2293>::type
2294indirect_array<_Tp>::operator*=(const _Expr& __v) const
2295{
2296 size_t __n = __1d_.size();
2297 for (size_t __i = 0; __i < __n; ++__i)
2298 __vp_[__1d_[__i]] *= __v[__i];
2299}
2300
2301template <class _Tp>
2302template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002303inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002304typename enable_if
2305<
2306 __is_val_expr<_Expr>::value,
2307 void
2308>::type
2309indirect_array<_Tp>::operator/=(const _Expr& __v) const
2310{
2311 size_t __n = __1d_.size();
2312 for (size_t __i = 0; __i < __n; ++__i)
2313 __vp_[__1d_[__i]] /= __v[__i];
2314}
2315
2316template <class _Tp>
2317template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002318inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002319typename enable_if
2320<
2321 __is_val_expr<_Expr>::value,
2322 void
2323>::type
2324indirect_array<_Tp>::operator%=(const _Expr& __v) const
2325{
2326 size_t __n = __1d_.size();
2327 for (size_t __i = 0; __i < __n; ++__i)
2328 __vp_[__1d_[__i]] %= __v[__i];
2329}
2330
2331template <class _Tp>
2332template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002333inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002334typename enable_if
2335<
2336 __is_val_expr<_Expr>::value,
2337 void
2338>::type
2339indirect_array<_Tp>::operator+=(const _Expr& __v) const
2340{
2341 size_t __n = __1d_.size();
2342 for (size_t __i = 0; __i < __n; ++__i)
2343 __vp_[__1d_[__i]] += __v[__i];
2344}
2345
2346template <class _Tp>
2347template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002348inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002349typename enable_if
2350<
2351 __is_val_expr<_Expr>::value,
2352 void
2353>::type
2354indirect_array<_Tp>::operator-=(const _Expr& __v) const
2355{
2356 size_t __n = __1d_.size();
2357 for (size_t __i = 0; __i < __n; ++__i)
2358 __vp_[__1d_[__i]] -= __v[__i];
2359}
2360
2361template <class _Tp>
2362template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002363inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002364typename enable_if
2365<
2366 __is_val_expr<_Expr>::value,
2367 void
2368>::type
2369indirect_array<_Tp>::operator^=(const _Expr& __v) const
2370{
2371 size_t __n = __1d_.size();
2372 for (size_t __i = 0; __i < __n; ++__i)
2373 __vp_[__1d_[__i]] ^= __v[__i];
2374}
2375
2376template <class _Tp>
2377template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002378inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002379typename enable_if
2380<
2381 __is_val_expr<_Expr>::value,
2382 void
2383>::type
2384indirect_array<_Tp>::operator&=(const _Expr& __v) const
2385{
2386 size_t __n = __1d_.size();
2387 for (size_t __i = 0; __i < __n; ++__i)
2388 __vp_[__1d_[__i]] &= __v[__i];
2389}
2390
2391template <class _Tp>
2392template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002393inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002394typename enable_if
2395<
2396 __is_val_expr<_Expr>::value,
2397 void
2398>::type
2399indirect_array<_Tp>::operator|=(const _Expr& __v) const
2400{
2401 size_t __n = __1d_.size();
2402 for (size_t __i = 0; __i < __n; ++__i)
2403 __vp_[__1d_[__i]] |= __v[__i];
2404}
2405
2406template <class _Tp>
2407template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002408inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002409typename enable_if
2410<
2411 __is_val_expr<_Expr>::value,
2412 void
2413>::type
2414indirect_array<_Tp>::operator<<=(const _Expr& __v) const
2415{
2416 size_t __n = __1d_.size();
2417 for (size_t __i = 0; __i < __n; ++__i)
2418 __vp_[__1d_[__i]] <<= __v[__i];
2419}
2420
2421template <class _Tp>
2422template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002423inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002424typename enable_if
2425<
2426 __is_val_expr<_Expr>::value,
2427 void
2428>::type
2429indirect_array<_Tp>::operator>>=(const _Expr& __v) const
2430{
2431 size_t __n = __1d_.size();
2432 for (size_t __i = 0; __i < __n; ++__i)
2433 __vp_[__1d_[__i]] >>= __v[__i];
2434}
2435
2436template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002437inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002438const indirect_array<_Tp>&
2439indirect_array<_Tp>::operator=(const indirect_array& __ia) const
2440{
2441 typedef const size_t* _Ip;
2442 const value_type* __s = __ia.__vp_;
2443 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_;
2444 __i != __e; ++__i, ++__j)
2445 __vp_[*__i] = __s[*__j];
2446 return *this;
2447}
2448
2449template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002450inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002451void
2452indirect_array<_Tp>::operator=(const value_type& __x) const
2453{
2454 typedef const size_t* _Ip;
2455 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
2456 __vp_[*__i] = __x;
2457}
2458
2459template <class _ValExpr>
2460class __indirect_expr
2461{
2462 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2463public:
2464 typedef typename _RmExpr::value_type value_type;
2465 typedef value_type result_type;
2466
2467private:
2468 _ValExpr __expr_;
2469 valarray<size_t> __1d_;
2470
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002471 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002472 __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e)
2473 : __expr_(__e),
2474 __1d_(__ia)
2475 {}
2476
Howard Hinnant73d21a42010-09-04 23:28:19 +00002477#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002478
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002480 __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
2481 : __expr_(__e),
2482 __1d_(move(__ia))
2483 {}
2484
Howard Hinnant73d21a42010-09-04 23:28:19 +00002485#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002486
2487public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002489 result_type operator[](size_t __i) const
2490 {return __expr_[__1d_[__i]];}
2491
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002493 size_t size() const {return __1d_.size();}
2494
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002495 template <class> friend class _LIBCPP_TYPE_VIS_ONLY valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002496};
2497
2498template<class _ValExpr>
2499class __val_expr
2500{
2501 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2502
2503 _ValExpr __expr_;
2504public:
2505 typedef typename _RmExpr::value_type value_type;
2506 typedef typename _RmExpr::result_type result_type;
2507
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002509 explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
2510
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002512 result_type operator[](size_t __i) const
2513 {return __expr_[__i];}
2514
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002516 __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
2517 {return __val_expr<__slice_expr<_ValExpr> >(__expr_, __s);}
2518
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002520 __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const
2521 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __gs.__1d_);}
2522
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002523 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002524 __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
2525 {return __val_expr<__mask_expr<_ValExpr> >(__expr_, __vb);}
2526
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002528 __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
2529 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __vs);}
2530
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002532 __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
2533 operator+() const
2534 {
2535 typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
2536 return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
2537 }
2538
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002539 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002540 __val_expr<_UnaryOp<negate<value_type>, _ValExpr> >
2541 operator-() const
2542 {
2543 typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
2544 return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
2545 }
2546
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002548 __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> >
2549 operator~() const
2550 {
2551 typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
2552 return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
2553 }
2554
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002555 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002556 __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> >
2557 operator!() const
2558 {
2559 typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
2560 return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
2561 }
2562
2563 operator valarray<result_type>() const;
2564
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002565 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002566 size_t size() const {return __expr_.size();}
2567
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002569 result_type sum() const
2570 {
2571 size_t __n = __expr_.size();
2572 result_type __r = __n ? __expr_[0] : result_type();
2573 for (size_t __i = 1; __i < __n; ++__i)
2574 __r += __expr_[__i];
2575 return __r;
2576 }
2577
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002579 result_type min() const
2580 {
2581 size_t __n = size();
2582 result_type __r = __n ? (*this)[0] : result_type();
2583 for (size_t __i = 1; __i < __n; ++__i)
2584 {
2585 result_type __x = __expr_[__i];
2586 if (__x < __r)
2587 __r = __x;
2588 }
2589 return __r;
2590 }
2591
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002593 result_type max() const
2594 {
2595 size_t __n = size();
2596 result_type __r = __n ? (*this)[0] : result_type();
2597 for (size_t __i = 1; __i < __n; ++__i)
2598 {
2599 result_type __x = __expr_[__i];
2600 if (__r < __x)
2601 __r = __x;
2602 }
2603 return __r;
2604 }
2605
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002606 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002607 __val_expr<__shift_expr<_ValExpr> > shift (int __i) const
2608 {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));}
2609
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002611 __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const
2612 {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));}
2613
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002614 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002615 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> >
2616 apply(value_type __f(value_type)) const
2617 {
2618 typedef __apply_expr<value_type, value_type(*)(value_type)> _Op;
2619 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2620 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2621 }
2622
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002624 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> >
2625 apply(value_type __f(const value_type&)) const
2626 {
2627 typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op;
2628 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2629 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2630 }
2631};
2632
2633template<class _ValExpr>
Howard Hinnantd8851432013-09-13 23:27:42 +00002634__val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002635{
2636 valarray<result_type> __r;
2637 size_t __n = __expr_.size();
2638 if (__n)
2639 {
2640 __r.__begin_ =
2641 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00002642 static_cast<result_type*>(_VSTD::__allocate(__n * sizeof(result_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002643 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
2644 ::new (__r.__end_) result_type(__expr_[__i]);
2645 }
2646 return __r;
2647}
2648
2649// valarray
2650
2651template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002652inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002653valarray<_Tp>::valarray(size_t __n)
2654 : __begin_(0),
2655 __end_(0)
2656{
2657 resize(__n);
2658}
2659
2660template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002661inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002662valarray<_Tp>::valarray(const value_type& __x, size_t __n)
2663 : __begin_(0),
2664 __end_(0)
2665{
2666 resize(__n, __x);
2667}
2668
2669template <class _Tp>
2670valarray<_Tp>::valarray(const value_type* __p, size_t __n)
2671 : __begin_(0),
2672 __end_(0)
2673{
2674 if (__n)
2675 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002676 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002677#ifndef _LIBCPP_NO_EXCEPTIONS
2678 try
2679 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002680#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002681 for (; __n; ++__end_, ++__p, --__n)
2682 ::new (__end_) value_type(*__p);
2683#ifndef _LIBCPP_NO_EXCEPTIONS
2684 }
2685 catch (...)
2686 {
2687 resize(0);
2688 throw;
2689 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002690#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002691 }
2692}
2693
2694template <class _Tp>
2695valarray<_Tp>::valarray(const valarray& __v)
2696 : __begin_(0),
2697 __end_(0)
2698{
2699 if (__v.size())
2700 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002701 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__v.size() * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002702#ifndef _LIBCPP_NO_EXCEPTIONS
2703 try
2704 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002705#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002706 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
2707 ::new (__end_) value_type(*__p);
2708#ifndef _LIBCPP_NO_EXCEPTIONS
2709 }
2710 catch (...)
2711 {
2712 resize(0);
2713 throw;
2714 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002715#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002716 }
2717}
2718
Howard Hinnant73d21a42010-09-04 23:28:19 +00002719#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002720
2721template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002722inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd143082012-07-21 00:51:28 +00002723valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002724 : __begin_(__v.__begin_),
2725 __end_(__v.__end_)
2726{
2727 __v.__begin_ = __v.__end_ = nullptr;
2728}
2729
Howard Hinnante3e32912011-08-12 21:56:02 +00002730#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2731
2732#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2733
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002734template <class _Tp>
2735valarray<_Tp>::valarray(initializer_list<value_type> __il)
2736 : __begin_(0),
2737 __end_(0)
2738{
2739 size_t __n = __il.size();
2740 if (__n)
2741 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002742 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002743#ifndef _LIBCPP_NO_EXCEPTIONS
2744 try
2745 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002746#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002747 for (const value_type* __p = __il.begin(); __n; ++__end_, ++__p, --__n)
2748 ::new (__end_) value_type(*__p);
2749#ifndef _LIBCPP_NO_EXCEPTIONS
2750 }
2751 catch (...)
2752 {
2753 resize(0);
2754 throw;
2755 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002756#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002757 }
2758}
2759
Howard Hinnante3e32912011-08-12 21:56:02 +00002760#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002761
2762template <class _Tp>
2763valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
2764 : __begin_(0),
2765 __end_(0)
2766{
2767 size_t __n = __sa.__size_;
2768 if (__n)
2769 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002770 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002771#ifndef _LIBCPP_NO_EXCEPTIONS
2772 try
2773 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002774#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002775 for (const value_type* __p = __sa.__vp_; __n; ++__end_, __p += __sa.__stride_, --__n)
2776 ::new (__end_) value_type(*__p);
2777#ifndef _LIBCPP_NO_EXCEPTIONS
2778 }
2779 catch (...)
2780 {
2781 resize(0);
2782 throw;
2783 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002784#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002785 }
2786}
2787
2788template <class _Tp>
2789valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
2790 : __begin_(0),
2791 __end_(0)
2792{
2793 size_t __n = __ga.__1d_.size();
2794 if (__n)
2795 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002796 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002797#ifndef _LIBCPP_NO_EXCEPTIONS
2798 try
2799 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002800#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002801 typedef const size_t* _Ip;
2802 const value_type* __s = __ga.__vp_;
2803 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2804 __i != __e; ++__i, ++__end_)
2805 ::new (__end_) value_type(__s[*__i]);
2806#ifndef _LIBCPP_NO_EXCEPTIONS
2807 }
2808 catch (...)
2809 {
2810 resize(0);
2811 throw;
2812 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002813#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002814 }
2815}
2816
2817template <class _Tp>
2818valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
2819 : __begin_(0),
2820 __end_(0)
2821{
2822 size_t __n = __ma.__1d_.size();
2823 if (__n)
2824 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002825 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002826#ifndef _LIBCPP_NO_EXCEPTIONS
2827 try
2828 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002829#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002830 typedef const size_t* _Ip;
2831 const value_type* __s = __ma.__vp_;
2832 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2833 __i != __e; ++__i, ++__end_)
2834 ::new (__end_) value_type(__s[*__i]);
2835#ifndef _LIBCPP_NO_EXCEPTIONS
2836 }
2837 catch (...)
2838 {
2839 resize(0);
2840 throw;
2841 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002842#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002843 }
2844}
2845
2846template <class _Tp>
2847valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
2848 : __begin_(0),
2849 __end_(0)
2850{
2851 size_t __n = __ia.__1d_.size();
2852 if (__n)
2853 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002854 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002855#ifndef _LIBCPP_NO_EXCEPTIONS
2856 try
2857 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002858#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002859 typedef const size_t* _Ip;
2860 const value_type* __s = __ia.__vp_;
2861 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2862 __i != __e; ++__i, ++__end_)
2863 ::new (__end_) value_type(__s[*__i]);
2864#ifndef _LIBCPP_NO_EXCEPTIONS
2865 }
2866 catch (...)
2867 {
2868 resize(0);
2869 throw;
2870 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002871#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002872 }
2873}
2874
2875template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002876inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002877valarray<_Tp>::~valarray()
2878{
2879 resize(0);
2880}
2881
2882template <class _Tp>
2883valarray<_Tp>&
2884valarray<_Tp>::operator=(const valarray& __v)
2885{
2886 if (this != &__v)
2887 {
2888 if (size() != __v.size())
2889 resize(__v.size());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002890 _VSTD::copy(__v.__begin_, __v.__end_, __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002891 }
2892 return *this;
2893}
2894
Howard Hinnant73d21a42010-09-04 23:28:19 +00002895#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002896
2897template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002898inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002899valarray<_Tp>&
Howard Hinnantbd143082012-07-21 00:51:28 +00002900valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002901{
2902 resize(0);
2903 __begin_ = __v.__begin_;
2904 __end_ = __v.__end_;
2905 __v.__begin_ = nullptr;
2906 __v.__end_ = nullptr;
2907 return *this;
2908}
2909
Howard Hinnante3e32912011-08-12 21:56:02 +00002910#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2911
2912#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2913
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002914template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002915inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002916valarray<_Tp>&
2917valarray<_Tp>::operator=(initializer_list<value_type> __il)
2918{
2919 if (size() != __il.size())
2920 resize(__il.size());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002921 _VSTD::copy(__il.begin(), __il.end(), __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002922 return *this;
2923}
2924
Howard Hinnante3e32912011-08-12 21:56:02 +00002925#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002926
2927template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002928inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002929valarray<_Tp>&
2930valarray<_Tp>::operator=(const value_type& __x)
2931{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002932 _VSTD::fill(__begin_, __end_, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002933 return *this;
2934}
2935
2936template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002937inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002938valarray<_Tp>&
2939valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
2940{
2941 value_type* __t = __begin_;
2942 const value_type* __s = __sa.__vp_;
2943 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
2944 *__t = *__s;
2945 return *this;
2946}
2947
2948template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002949inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002950valarray<_Tp>&
2951valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
2952{
2953 typedef const size_t* _Ip;
2954 value_type* __t = __begin_;
2955 const value_type* __s = __ga.__vp_;
2956 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2957 __i != __e; ++__i, ++__t)
2958 *__t = __s[*__i];
2959 return *this;
2960}
2961
2962template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002963inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002964valarray<_Tp>&
2965valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
2966{
2967 typedef const size_t* _Ip;
2968 value_type* __t = __begin_;
2969 const value_type* __s = __ma.__vp_;
2970 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2971 __i != __e; ++__i, ++__t)
2972 *__t = __s[*__i];
2973 return *this;
2974}
2975
2976template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002977inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002978valarray<_Tp>&
2979valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
2980{
2981 typedef const size_t* _Ip;
2982 value_type* __t = __begin_;
2983 const value_type* __s = __ia.__vp_;
2984 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2985 __i != __e; ++__i, ++__t)
2986 *__t = __s[*__i];
2987 return *this;
2988}
2989
2990template <class _Tp>
Howard Hinnantdb866632011-07-27 23:19:59 +00002991template <class _ValExpr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002992inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantdb866632011-07-27 23:19:59 +00002993valarray<_Tp>&
2994valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
2995{
2996 size_t __n = __v.size();
2997 if (size() != __n)
2998 resize(__n);
2999 value_type* __t = __begin_;
3000 for (size_t __i = 0; __i != __n; ++__t, ++__i)
3001 *__t = result_type(__v[__i]);
3002 return *this;
3003}
3004
3005template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003006inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003007__val_expr<__slice_expr<const valarray<_Tp>&> >
3008valarray<_Tp>::operator[](slice __s) const
3009{
3010 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
3011}
3012
3013template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003014inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003015slice_array<_Tp>
3016valarray<_Tp>::operator[](slice __s)
3017{
3018 return slice_array<value_type>(__s, *this);
3019}
3020
3021template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003022inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003023__val_expr<__indirect_expr<const valarray<_Tp>&> >
3024valarray<_Tp>::operator[](const gslice& __gs) const
3025{
3026 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
3027}
3028
3029template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003030inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003031gslice_array<_Tp>
3032valarray<_Tp>::operator[](const gslice& __gs)
3033{
3034 return gslice_array<value_type>(__gs, *this);
3035}
3036
Howard Hinnant73d21a42010-09-04 23:28:19 +00003037#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003038
3039template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003040inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003041__val_expr<__indirect_expr<const valarray<_Tp>&> >
3042valarray<_Tp>::operator[](gslice&& __gs) const
3043{
3044 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
3045}
3046
3047template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003048inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003049gslice_array<_Tp>
3050valarray<_Tp>::operator[](gslice&& __gs)
3051{
3052 return gslice_array<value_type>(move(__gs), *this);
3053}
3054
Howard Hinnant73d21a42010-09-04 23:28:19 +00003055#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003056
3057template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003058inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003059__val_expr<__mask_expr<const valarray<_Tp>&> >
3060valarray<_Tp>::operator[](const valarray<bool>& __vb) const
3061{
3062 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
3063}
3064
3065template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003066inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003067mask_array<_Tp>
3068valarray<_Tp>::operator[](const valarray<bool>& __vb)
3069{
3070 return mask_array<value_type>(__vb, *this);
3071}
3072
Howard Hinnant73d21a42010-09-04 23:28:19 +00003073#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003074
3075template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003076inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003077__val_expr<__mask_expr<const valarray<_Tp>&> >
3078valarray<_Tp>::operator[](valarray<bool>&& __vb) const
3079{
3080 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
3081}
3082
3083template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003084inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003085mask_array<_Tp>
3086valarray<_Tp>::operator[](valarray<bool>&& __vb)
3087{
3088 return mask_array<value_type>(move(__vb), *this);
3089}
3090
Howard Hinnant73d21a42010-09-04 23:28:19 +00003091#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003092
3093template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003094inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003095__val_expr<__indirect_expr<const valarray<_Tp>&> >
3096valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
3097{
3098 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
3099}
3100
3101template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003102inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003103indirect_array<_Tp>
3104valarray<_Tp>::operator[](const valarray<size_t>& __vs)
3105{
3106 return indirect_array<value_type>(__vs, *this);
3107}
3108
Howard Hinnant73d21a42010-09-04 23:28:19 +00003109#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003110
3111template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003112inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003113__val_expr<__indirect_expr<const valarray<_Tp>&> >
3114valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
3115{
3116 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
3117}
3118
3119template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003120inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003121indirect_array<_Tp>
3122valarray<_Tp>::operator[](valarray<size_t>&& __vs)
3123{
3124 return indirect_array<value_type>(move(__vs), *this);
3125}
3126
Howard Hinnant73d21a42010-09-04 23:28:19 +00003127#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003128
3129template <class _Tp>
3130valarray<_Tp>
3131valarray<_Tp>::operator+() const
3132{
3133 valarray<value_type> __r;
3134 size_t __n = size();
3135 if (__n)
3136 {
3137 __r.__begin_ =
3138 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003139 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003140 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3141 ::new (__r.__end_) value_type(+*__p);
3142 }
3143 return __r;
3144}
3145
3146template <class _Tp>
3147valarray<_Tp>
3148valarray<_Tp>::operator-() const
3149{
3150 valarray<value_type> __r;
3151 size_t __n = size();
3152 if (__n)
3153 {
3154 __r.__begin_ =
3155 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003156 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003157 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3158 ::new (__r.__end_) value_type(-*__p);
3159 }
3160 return __r;
3161}
3162
3163template <class _Tp>
3164valarray<_Tp>
3165valarray<_Tp>::operator~() const
3166{
3167 valarray<value_type> __r;
3168 size_t __n = size();
3169 if (__n)
3170 {
3171 __r.__begin_ =
3172 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003173 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003174 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3175 ::new (__r.__end_) value_type(~*__p);
3176 }
3177 return __r;
3178}
3179
3180template <class _Tp>
3181valarray<bool>
3182valarray<_Tp>::operator!() const
3183{
3184 valarray<bool> __r;
3185 size_t __n = size();
3186 if (__n)
3187 {
3188 __r.__begin_ =
3189 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003190 static_cast<bool*>(_VSTD::__allocate(__n * sizeof(bool)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003191 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3192 ::new (__r.__end_) bool(!*__p);
3193 }
3194 return __r;
3195}
3196
3197template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003198inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003199valarray<_Tp>&
3200valarray<_Tp>::operator*=(const value_type& __x)
3201{
3202 for (value_type* __p = __begin_; __p != __end_; ++__p)
3203 *__p *= __x;
3204 return *this;
3205}
3206
3207template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003208inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003209valarray<_Tp>&
3210valarray<_Tp>::operator/=(const value_type& __x)
3211{
3212 for (value_type* __p = __begin_; __p != __end_; ++__p)
3213 *__p /= __x;
3214 return *this;
3215}
3216
3217template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003218inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003219valarray<_Tp>&
3220valarray<_Tp>::operator%=(const value_type& __x)
3221{
3222 for (value_type* __p = __begin_; __p != __end_; ++__p)
3223 *__p %= __x;
3224 return *this;
3225}
3226
3227template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003228inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003229valarray<_Tp>&
3230valarray<_Tp>::operator+=(const value_type& __x)
3231{
3232 for (value_type* __p = __begin_; __p != __end_; ++__p)
3233 *__p += __x;
3234 return *this;
3235}
3236
3237template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003238inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003239valarray<_Tp>&
3240valarray<_Tp>::operator-=(const value_type& __x)
3241{
3242 for (value_type* __p = __begin_; __p != __end_; ++__p)
3243 *__p -= __x;
3244 return *this;
3245}
3246
3247template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003248inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003249valarray<_Tp>&
3250valarray<_Tp>::operator^=(const value_type& __x)
3251{
3252 for (value_type* __p = __begin_; __p != __end_; ++__p)
3253 *__p ^= __x;
3254 return *this;
3255}
3256
3257template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003258inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003259valarray<_Tp>&
3260valarray<_Tp>::operator&=(const value_type& __x)
3261{
3262 for (value_type* __p = __begin_; __p != __end_; ++__p)
3263 *__p &= __x;
3264 return *this;
3265}
3266
3267template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003268inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003269valarray<_Tp>&
3270valarray<_Tp>::operator|=(const value_type& __x)
3271{
3272 for (value_type* __p = __begin_; __p != __end_; ++__p)
3273 *__p |= __x;
3274 return *this;
3275}
3276
3277template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003278inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003279valarray<_Tp>&
3280valarray<_Tp>::operator<<=(const value_type& __x)
3281{
3282 for (value_type* __p = __begin_; __p != __end_; ++__p)
3283 *__p <<= __x;
3284 return *this;
3285}
3286
3287template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003288inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003289valarray<_Tp>&
3290valarray<_Tp>::operator>>=(const value_type& __x)
3291{
3292 for (value_type* __p = __begin_; __p != __end_; ++__p)
3293 *__p >>= __x;
3294 return *this;
3295}
3296
3297template <class _Tp>
3298template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003299inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003300typename enable_if
3301<
3302 __is_val_expr<_Expr>::value,
3303 valarray<_Tp>&
3304>::type
3305valarray<_Tp>::operator*=(const _Expr& __v)
3306{
3307 size_t __i = 0;
3308 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3309 *__t *= __v[__i];
3310 return *this;
3311}
3312
3313template <class _Tp>
3314template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003315inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003316typename enable_if
3317<
3318 __is_val_expr<_Expr>::value,
3319 valarray<_Tp>&
3320>::type
3321valarray<_Tp>::operator/=(const _Expr& __v)
3322{
3323 size_t __i = 0;
3324 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3325 *__t /= __v[__i];
3326 return *this;
3327}
3328
3329template <class _Tp>
3330template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003331inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003332typename enable_if
3333<
3334 __is_val_expr<_Expr>::value,
3335 valarray<_Tp>&
3336>::type
3337valarray<_Tp>::operator%=(const _Expr& __v)
3338{
3339 size_t __i = 0;
3340 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3341 *__t %= __v[__i];
3342 return *this;
3343}
3344
3345template <class _Tp>
3346template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003347inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003348typename enable_if
3349<
3350 __is_val_expr<_Expr>::value,
3351 valarray<_Tp>&
3352>::type
3353valarray<_Tp>::operator+=(const _Expr& __v)
3354{
3355 size_t __i = 0;
3356 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3357 *__t += __v[__i];
3358 return *this;
3359}
3360
3361template <class _Tp>
3362template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003363inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003364typename enable_if
3365<
3366 __is_val_expr<_Expr>::value,
3367 valarray<_Tp>&
3368>::type
3369valarray<_Tp>::operator-=(const _Expr& __v)
3370{
3371 size_t __i = 0;
3372 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3373 *__t -= __v[__i];
3374 return *this;
3375}
3376
3377template <class _Tp>
3378template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003379inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003380typename enable_if
3381<
3382 __is_val_expr<_Expr>::value,
3383 valarray<_Tp>&
3384>::type
3385valarray<_Tp>::operator^=(const _Expr& __v)
3386{
3387 size_t __i = 0;
3388 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3389 *__t ^= __v[__i];
3390 return *this;
3391}
3392
3393template <class _Tp>
3394template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003395inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003396typename enable_if
3397<
3398 __is_val_expr<_Expr>::value,
3399 valarray<_Tp>&
3400>::type
3401valarray<_Tp>::operator|=(const _Expr& __v)
3402{
3403 size_t __i = 0;
3404 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3405 *__t |= __v[__i];
3406 return *this;
3407}
3408
3409template <class _Tp>
3410template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003411inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003412typename enable_if
3413<
3414 __is_val_expr<_Expr>::value,
3415 valarray<_Tp>&
3416>::type
3417valarray<_Tp>::operator&=(const _Expr& __v)
3418{
3419 size_t __i = 0;
3420 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3421 *__t &= __v[__i];
3422 return *this;
3423}
3424
3425template <class _Tp>
3426template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003427inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003428typename enable_if
3429<
3430 __is_val_expr<_Expr>::value,
3431 valarray<_Tp>&
3432>::type
3433valarray<_Tp>::operator<<=(const _Expr& __v)
3434{
3435 size_t __i = 0;
3436 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3437 *__t <<= __v[__i];
3438 return *this;
3439}
3440
3441template <class _Tp>
3442template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003443inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003444typename enable_if
3445<
3446 __is_val_expr<_Expr>::value,
3447 valarray<_Tp>&
3448>::type
3449valarray<_Tp>::operator>>=(const _Expr& __v)
3450{
3451 size_t __i = 0;
3452 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3453 *__t >>= __v[__i];
3454 return *this;
3455}
3456
3457template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003458inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003459void
Howard Hinnantbd143082012-07-21 00:51:28 +00003460valarray<_Tp>::swap(valarray& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003461{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003462 _VSTD::swap(__begin_, __v.__begin_);
3463 _VSTD::swap(__end_, __v.__end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003464}
3465
3466template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003467inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003468_Tp
3469valarray<_Tp>::sum() const
3470{
3471 if (__begin_ == __end_)
3472 return value_type();
3473 const value_type* __p = __begin_;
3474 _Tp __r = *__p;
3475 for (++__p; __p != __end_; ++__p)
3476 __r += *__p;
3477 return __r;
3478}
3479
3480template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003481inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003482_Tp
3483valarray<_Tp>::min() const
3484{
3485 if (__begin_ == __end_)
3486 return value_type();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003487 return *_VSTD::min_element(__begin_, __end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003488}
3489
3490template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003491inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003492_Tp
3493valarray<_Tp>::max() const
3494{
3495 if (__begin_ == __end_)
3496 return value_type();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003497 return *_VSTD::max_element(__begin_, __end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003498}
3499
3500template <class _Tp>
3501valarray<_Tp>
3502valarray<_Tp>::shift(int __i) const
3503{
3504 valarray<value_type> __r;
3505 size_t __n = size();
3506 if (__n)
3507 {
3508 __r.__begin_ =
3509 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003510 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003511 const value_type* __sb;
3512 value_type* __tb;
3513 value_type* __te;
3514 if (__i >= 0)
3515 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003516 __i = _VSTD::min(__i, static_cast<int>(__n));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003517 __sb = __begin_ + __i;
3518 __tb = __r.__begin_;
3519 __te = __r.__begin_ + (__n - __i);
3520 }
3521 else
3522 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003523 __i = _VSTD::min(-__i, static_cast<int>(__n));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003524 __sb = __begin_;
3525 __tb = __r.__begin_ + __i;
3526 __te = __r.__begin_ + __n;
3527 }
3528 for (; __r.__end_ != __tb; ++__r.__end_)
3529 ::new (__r.__end_) value_type();
3530 for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
3531 ::new (__r.__end_) value_type(*__sb);
3532 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
3533 ::new (__r.__end_) value_type();
3534 }
3535 return __r;
3536}
3537
3538template <class _Tp>
3539valarray<_Tp>
3540valarray<_Tp>::cshift(int __i) const
3541{
3542 valarray<value_type> __r;
3543 size_t __n = size();
3544 if (__n)
3545 {
3546 __r.__begin_ =
3547 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003548 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003549 __i %= static_cast<int>(__n);
3550 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
3551 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
3552 ::new (__r.__end_) value_type(*__s);
3553 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
3554 ::new (__r.__end_) value_type(*__s);
3555 }
3556 return __r;
3557}
3558
3559template <class _Tp>
3560valarray<_Tp>
3561valarray<_Tp>::apply(value_type __f(value_type)) const
3562{
3563 valarray<value_type> __r;
3564 size_t __n = size();
3565 if (__n)
3566 {
3567 __r.__begin_ =
3568 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003569 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003570 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3571 ::new (__r.__end_) value_type(__f(*__p));
3572 }
3573 return __r;
3574}
3575
3576template <class _Tp>
3577valarray<_Tp>
3578valarray<_Tp>::apply(value_type __f(const value_type&)) const
3579{
3580 valarray<value_type> __r;
3581 size_t __n = size();
3582 if (__n)
3583 {
3584 __r.__begin_ =
3585 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003586 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003587 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3588 ::new (__r.__end_) value_type(__f(*__p));
3589 }
3590 return __r;
3591}
3592
3593template <class _Tp>
3594void
3595valarray<_Tp>::resize(size_t __n, value_type __x)
3596{
3597 if (__begin_ != nullptr)
3598 {
3599 while (__end_ != __begin_)
3600 (--__end_)->~value_type();
Richard Smith73c1fce2014-06-04 19:54:15 +00003601 _VSTD::__deallocate(__begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003602 __begin_ = __end_ = nullptr;
3603 }
3604 if (__n)
3605 {
Richard Smith73c1fce2014-06-04 19:54:15 +00003606 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003607#ifndef _LIBCPP_NO_EXCEPTIONS
3608 try
3609 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003610#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003611 for (; __n; --__n, ++__end_)
3612 ::new (__end_) value_type(__x);
3613#ifndef _LIBCPP_NO_EXCEPTIONS
3614 }
3615 catch (...)
3616 {
3617 resize(0);
3618 throw;
3619 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003620#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003621 }
3622}
3623
3624template<class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003625inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003626void
Howard Hinnantbd143082012-07-21 00:51:28 +00003627swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003628{
3629 __x.swap(__y);
3630}
3631
3632template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003633inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003634typename enable_if
3635<
3636 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3637 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
3638>::type
3639operator*(const _Expr1& __x, const _Expr2& __y)
3640{
3641 typedef typename _Expr1::value_type value_type;
3642 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
3643 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
3644}
3645
3646template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003647inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003648typename enable_if
3649<
3650 __is_val_expr<_Expr>::value,
3651 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3652 _Expr, __scalar_expr<typename _Expr::value_type> > >
3653>::type
3654operator*(const _Expr& __x, const typename _Expr::value_type& __y)
3655{
3656 typedef typename _Expr::value_type value_type;
3657 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3658 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3659 __x, __scalar_expr<value_type>(__y, __x.size())));
3660}
3661
3662template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003663inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003664typename enable_if
3665<
3666 __is_val_expr<_Expr>::value,
3667 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3668 __scalar_expr<typename _Expr::value_type>, _Expr> >
3669>::type
3670operator*(const typename _Expr::value_type& __x, const _Expr& __y)
3671{
3672 typedef typename _Expr::value_type value_type;
3673 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3674 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3675 __scalar_expr<value_type>(__x, __y.size()), __y));
3676}
3677
3678template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003679inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003680typename enable_if
3681<
3682 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3683 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
3684>::type
3685operator/(const _Expr1& __x, const _Expr2& __y)
3686{
3687 typedef typename _Expr1::value_type value_type;
3688 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
3689 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
3690}
3691
3692template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003693inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003694typename enable_if
3695<
3696 __is_val_expr<_Expr>::value,
3697 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3698 _Expr, __scalar_expr<typename _Expr::value_type> > >
3699>::type
3700operator/(const _Expr& __x, const typename _Expr::value_type& __y)
3701{
3702 typedef typename _Expr::value_type value_type;
3703 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3704 return __val_expr<_Op>(_Op(divides<value_type>(),
3705 __x, __scalar_expr<value_type>(__y, __x.size())));
3706}
3707
3708template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003709inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003710typename enable_if
3711<
3712 __is_val_expr<_Expr>::value,
3713 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3714 __scalar_expr<typename _Expr::value_type>, _Expr> >
3715>::type
3716operator/(const typename _Expr::value_type& __x, const _Expr& __y)
3717{
3718 typedef typename _Expr::value_type value_type;
3719 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3720 return __val_expr<_Op>(_Op(divides<value_type>(),
3721 __scalar_expr<value_type>(__x, __y.size()), __y));
3722}
3723
3724template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003725inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003726typename enable_if
3727<
3728 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3729 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3730>::type
3731operator%(const _Expr1& __x, const _Expr2& __y)
3732{
3733 typedef typename _Expr1::value_type value_type;
3734 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
3735 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
3736}
3737
3738template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003739inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003740typename enable_if
3741<
3742 __is_val_expr<_Expr>::value,
3743 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3744 _Expr, __scalar_expr<typename _Expr::value_type> > >
3745>::type
3746operator%(const _Expr& __x, const typename _Expr::value_type& __y)
3747{
3748 typedef typename _Expr::value_type value_type;
3749 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3750 return __val_expr<_Op>(_Op(modulus<value_type>(),
3751 __x, __scalar_expr<value_type>(__y, __x.size())));
3752}
3753
3754template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003755inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003756typename enable_if
3757<
3758 __is_val_expr<_Expr>::value,
3759 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3760 __scalar_expr<typename _Expr::value_type>, _Expr> >
3761>::type
3762operator%(const typename _Expr::value_type& __x, const _Expr& __y)
3763{
3764 typedef typename _Expr::value_type value_type;
3765 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3766 return __val_expr<_Op>(_Op(modulus<value_type>(),
3767 __scalar_expr<value_type>(__x, __y.size()), __y));
3768}
3769
3770template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003771inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003772typename enable_if
3773<
3774 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3775 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3776>::type
3777operator+(const _Expr1& __x, const _Expr2& __y)
3778{
3779 typedef typename _Expr1::value_type value_type;
3780 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
3781 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
3782}
3783
3784template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003785inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003786typename enable_if
3787<
3788 __is_val_expr<_Expr>::value,
3789 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3790 _Expr, __scalar_expr<typename _Expr::value_type> > >
3791>::type
3792operator+(const _Expr& __x, const typename _Expr::value_type& __y)
3793{
3794 typedef typename _Expr::value_type value_type;
3795 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3796 return __val_expr<_Op>(_Op(plus<value_type>(),
3797 __x, __scalar_expr<value_type>(__y, __x.size())));
3798}
3799
3800template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003801inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003802typename enable_if
3803<
3804 __is_val_expr<_Expr>::value,
3805 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3806 __scalar_expr<typename _Expr::value_type>, _Expr> >
3807>::type
3808operator+(const typename _Expr::value_type& __x, const _Expr& __y)
3809{
3810 typedef typename _Expr::value_type value_type;
3811 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3812 return __val_expr<_Op>(_Op(plus<value_type>(),
3813 __scalar_expr<value_type>(__x, __y.size()), __y));
3814}
3815
3816template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003817inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003818typename enable_if
3819<
3820 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3821 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3822>::type
3823operator-(const _Expr1& __x, const _Expr2& __y)
3824{
3825 typedef typename _Expr1::value_type value_type;
3826 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
3827 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
3828}
3829
3830template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003831inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003832typename enable_if
3833<
3834 __is_val_expr<_Expr>::value,
3835 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3836 _Expr, __scalar_expr<typename _Expr::value_type> > >
3837>::type
3838operator-(const _Expr& __x, const typename _Expr::value_type& __y)
3839{
3840 typedef typename _Expr::value_type value_type;
3841 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3842 return __val_expr<_Op>(_Op(minus<value_type>(),
3843 __x, __scalar_expr<value_type>(__y, __x.size())));
3844}
3845
3846template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003847inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003848typename enable_if
3849<
3850 __is_val_expr<_Expr>::value,
3851 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3852 __scalar_expr<typename _Expr::value_type>, _Expr> >
3853>::type
3854operator-(const typename _Expr::value_type& __x, const _Expr& __y)
3855{
3856 typedef typename _Expr::value_type value_type;
3857 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3858 return __val_expr<_Op>(_Op(minus<value_type>(),
3859 __scalar_expr<value_type>(__x, __y.size()), __y));
3860}
3861
3862template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003863inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003864typename enable_if
3865<
3866 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3867 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
3868>::type
3869operator^(const _Expr1& __x, const _Expr2& __y)
3870{
3871 typedef typename _Expr1::value_type value_type;
3872 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
3873 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
3874}
3875
3876template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003877inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003878typename enable_if
3879<
3880 __is_val_expr<_Expr>::value,
3881 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
3882 _Expr, __scalar_expr<typename _Expr::value_type> > >
3883>::type
3884operator^(const _Expr& __x, const typename _Expr::value_type& __y)
3885{
3886 typedef typename _Expr::value_type value_type;
3887 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3888 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
3889 __x, __scalar_expr<value_type>(__y, __x.size())));
3890}
3891
3892template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003893inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003894typename enable_if
3895<
3896 __is_val_expr<_Expr>::value,
3897 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
3898 __scalar_expr<typename _Expr::value_type>, _Expr> >
3899>::type
3900operator^(const typename _Expr::value_type& __x, const _Expr& __y)
3901{
3902 typedef typename _Expr::value_type value_type;
3903 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3904 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
3905 __scalar_expr<value_type>(__x, __y.size()), __y));
3906}
3907
3908template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003909inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003910typename enable_if
3911<
3912 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3913 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
3914>::type
3915operator&(const _Expr1& __x, const _Expr2& __y)
3916{
3917 typedef typename _Expr1::value_type value_type;
3918 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
3919 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
3920}
3921
3922template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003923inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003924typename enable_if
3925<
3926 __is_val_expr<_Expr>::value,
3927 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
3928 _Expr, __scalar_expr<typename _Expr::value_type> > >
3929>::type
3930operator&(const _Expr& __x, const typename _Expr::value_type& __y)
3931{
3932 typedef typename _Expr::value_type value_type;
3933 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3934 return __val_expr<_Op>(_Op(bit_and<value_type>(),
3935 __x, __scalar_expr<value_type>(__y, __x.size())));
3936}
3937
3938template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003939inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003940typename enable_if
3941<
3942 __is_val_expr<_Expr>::value,
3943 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
3944 __scalar_expr<typename _Expr::value_type>, _Expr> >
3945>::type
3946operator&(const typename _Expr::value_type& __x, const _Expr& __y)
3947{
3948 typedef typename _Expr::value_type value_type;
3949 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3950 return __val_expr<_Op>(_Op(bit_and<value_type>(),
3951 __scalar_expr<value_type>(__x, __y.size()), __y));
3952}
3953
3954template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003955inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003956typename enable_if
3957<
3958 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3959 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
3960>::type
3961operator|(const _Expr1& __x, const _Expr2& __y)
3962{
3963 typedef typename _Expr1::value_type value_type;
3964 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
3965 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
3966}
3967
3968template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003969inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003970typename enable_if
3971<
3972 __is_val_expr<_Expr>::value,
3973 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
3974 _Expr, __scalar_expr<typename _Expr::value_type> > >
3975>::type
3976operator|(const _Expr& __x, const typename _Expr::value_type& __y)
3977{
3978 typedef typename _Expr::value_type value_type;
3979 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3980 return __val_expr<_Op>(_Op(bit_or<value_type>(),
3981 __x, __scalar_expr<value_type>(__y, __x.size())));
3982}
3983
3984template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003985inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003986typename enable_if
3987<
3988 __is_val_expr<_Expr>::value,
3989 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
3990 __scalar_expr<typename _Expr::value_type>, _Expr> >
3991>::type
3992operator|(const typename _Expr::value_type& __x, const _Expr& __y)
3993{
3994 typedef typename _Expr::value_type value_type;
3995 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3996 return __val_expr<_Op>(_Op(bit_or<value_type>(),
3997 __scalar_expr<value_type>(__x, __y.size()), __y));
3998}
3999
4000template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004001inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004002typename enable_if
4003<
4004 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4005 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
4006>::type
4007operator<<(const _Expr1& __x, const _Expr2& __y)
4008{
4009 typedef typename _Expr1::value_type value_type;
4010 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
4011 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
4012}
4013
4014template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004015inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004016typename enable_if
4017<
4018 __is_val_expr<_Expr>::value,
4019 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4020 _Expr, __scalar_expr<typename _Expr::value_type> > >
4021>::type
4022operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
4023{
4024 typedef typename _Expr::value_type value_type;
4025 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4026 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4027 __x, __scalar_expr<value_type>(__y, __x.size())));
4028}
4029
4030template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004031inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004032typename enable_if
4033<
4034 __is_val_expr<_Expr>::value,
4035 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4036 __scalar_expr<typename _Expr::value_type>, _Expr> >
4037>::type
4038operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
4039{
4040 typedef typename _Expr::value_type value_type;
4041 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4042 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4043 __scalar_expr<value_type>(__x, __y.size()), __y));
4044}
4045
4046template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004047inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004048typename enable_if
4049<
4050 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4051 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
4052>::type
4053operator>>(const _Expr1& __x, const _Expr2& __y)
4054{
4055 typedef typename _Expr1::value_type value_type;
4056 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
4057 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
4058}
4059
4060template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004061inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004062typename enable_if
4063<
4064 __is_val_expr<_Expr>::value,
4065 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4066 _Expr, __scalar_expr<typename _Expr::value_type> > >
4067>::type
4068operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
4069{
4070 typedef typename _Expr::value_type value_type;
4071 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4072 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4073 __x, __scalar_expr<value_type>(__y, __x.size())));
4074}
4075
4076template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004077inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004078typename enable_if
4079<
4080 __is_val_expr<_Expr>::value,
4081 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4082 __scalar_expr<typename _Expr::value_type>, _Expr> >
4083>::type
4084operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
4085{
4086 typedef typename _Expr::value_type value_type;
4087 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4088 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4089 __scalar_expr<value_type>(__x, __y.size()), __y));
4090}
4091
4092template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004093inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004094typename enable_if
4095<
4096 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4097 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4098>::type
4099operator&&(const _Expr1& __x, const _Expr2& __y)
4100{
4101 typedef typename _Expr1::value_type value_type;
4102 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
4103 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
4104}
4105
4106template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004107inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004108typename enable_if
4109<
4110 __is_val_expr<_Expr>::value,
4111 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4112 _Expr, __scalar_expr<typename _Expr::value_type> > >
4113>::type
4114operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
4115{
4116 typedef typename _Expr::value_type value_type;
4117 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4118 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4119 __x, __scalar_expr<value_type>(__y, __x.size())));
4120}
4121
4122template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004123inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004124typename enable_if
4125<
4126 __is_val_expr<_Expr>::value,
4127 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4128 __scalar_expr<typename _Expr::value_type>, _Expr> >
4129>::type
4130operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
4131{
4132 typedef typename _Expr::value_type value_type;
4133 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4134 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4135 __scalar_expr<value_type>(__x, __y.size()), __y));
4136}
4137
4138template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004139inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004140typename enable_if
4141<
4142 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4143 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4144>::type
4145operator||(const _Expr1& __x, const _Expr2& __y)
4146{
4147 typedef typename _Expr1::value_type value_type;
4148 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
4149 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
4150}
4151
4152template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004153inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004154typename enable_if
4155<
4156 __is_val_expr<_Expr>::value,
4157 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4158 _Expr, __scalar_expr<typename _Expr::value_type> > >
4159>::type
4160operator||(const _Expr& __x, const typename _Expr::value_type& __y)
4161{
4162 typedef typename _Expr::value_type value_type;
4163 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4164 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4165 __x, __scalar_expr<value_type>(__y, __x.size())));
4166}
4167
4168template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004169inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004170typename enable_if
4171<
4172 __is_val_expr<_Expr>::value,
4173 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4174 __scalar_expr<typename _Expr::value_type>, _Expr> >
4175>::type
4176operator||(const typename _Expr::value_type& __x, const _Expr& __y)
4177{
4178 typedef typename _Expr::value_type value_type;
4179 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4180 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4181 __scalar_expr<value_type>(__x, __y.size()), __y));
4182}
4183
4184template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004185inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004186typename enable_if
4187<
4188 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4189 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4190>::type
4191operator==(const _Expr1& __x, const _Expr2& __y)
4192{
4193 typedef typename _Expr1::value_type value_type;
4194 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
4195 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
4196}
4197
4198template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004199inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004200typename enable_if
4201<
4202 __is_val_expr<_Expr>::value,
4203 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4204 _Expr, __scalar_expr<typename _Expr::value_type> > >
4205>::type
4206operator==(const _Expr& __x, const typename _Expr::value_type& __y)
4207{
4208 typedef typename _Expr::value_type value_type;
4209 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4210 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4211 __x, __scalar_expr<value_type>(__y, __x.size())));
4212}
4213
4214template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004215inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004216typename enable_if
4217<
4218 __is_val_expr<_Expr>::value,
4219 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4220 __scalar_expr<typename _Expr::value_type>, _Expr> >
4221>::type
4222operator==(const typename _Expr::value_type& __x, const _Expr& __y)
4223{
4224 typedef typename _Expr::value_type value_type;
4225 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4226 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4227 __scalar_expr<value_type>(__x, __y.size()), __y));
4228}
4229
4230template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004231inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004232typename enable_if
4233<
4234 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4235 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4236>::type
4237operator!=(const _Expr1& __x, const _Expr2& __y)
4238{
4239 typedef typename _Expr1::value_type value_type;
4240 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
4241 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
4242}
4243
4244template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004245inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004246typename enable_if
4247<
4248 __is_val_expr<_Expr>::value,
4249 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4250 _Expr, __scalar_expr<typename _Expr::value_type> > >
4251>::type
4252operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
4253{
4254 typedef typename _Expr::value_type value_type;
4255 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4256 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4257 __x, __scalar_expr<value_type>(__y, __x.size())));
4258}
4259
4260template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004261inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004262typename enable_if
4263<
4264 __is_val_expr<_Expr>::value,
4265 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4266 __scalar_expr<typename _Expr::value_type>, _Expr> >
4267>::type
4268operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
4269{
4270 typedef typename _Expr::value_type value_type;
4271 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4272 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4273 __scalar_expr<value_type>(__x, __y.size()), __y));
4274}
4275
4276template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004277inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004278typename enable_if
4279<
4280 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4281 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
4282>::type
4283operator<(const _Expr1& __x, const _Expr2& __y)
4284{
4285 typedef typename _Expr1::value_type value_type;
4286 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
4287 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
4288}
4289
4290template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004291inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004292typename enable_if
4293<
4294 __is_val_expr<_Expr>::value,
4295 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4296 _Expr, __scalar_expr<typename _Expr::value_type> > >
4297>::type
4298operator<(const _Expr& __x, const typename _Expr::value_type& __y)
4299{
4300 typedef typename _Expr::value_type value_type;
4301 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4302 return __val_expr<_Op>(_Op(less<value_type>(),
4303 __x, __scalar_expr<value_type>(__y, __x.size())));
4304}
4305
4306template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004307inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004308typename enable_if
4309<
4310 __is_val_expr<_Expr>::value,
4311 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4312 __scalar_expr<typename _Expr::value_type>, _Expr> >
4313>::type
4314operator<(const typename _Expr::value_type& __x, const _Expr& __y)
4315{
4316 typedef typename _Expr::value_type value_type;
4317 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4318 return __val_expr<_Op>(_Op(less<value_type>(),
4319 __scalar_expr<value_type>(__x, __y.size()), __y));
4320}
4321
4322template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004323inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004324typename enable_if
4325<
4326 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4327 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
4328>::type
4329operator>(const _Expr1& __x, const _Expr2& __y)
4330{
4331 typedef typename _Expr1::value_type value_type;
4332 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
4333 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
4334}
4335
4336template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004337inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004338typename enable_if
4339<
4340 __is_val_expr<_Expr>::value,
4341 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4342 _Expr, __scalar_expr<typename _Expr::value_type> > >
4343>::type
4344operator>(const _Expr& __x, const typename _Expr::value_type& __y)
4345{
4346 typedef typename _Expr::value_type value_type;
4347 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4348 return __val_expr<_Op>(_Op(greater<value_type>(),
4349 __x, __scalar_expr<value_type>(__y, __x.size())));
4350}
4351
4352template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004353inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004354typename enable_if
4355<
4356 __is_val_expr<_Expr>::value,
4357 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4358 __scalar_expr<typename _Expr::value_type>, _Expr> >
4359>::type
4360operator>(const typename _Expr::value_type& __x, const _Expr& __y)
4361{
4362 typedef typename _Expr::value_type value_type;
4363 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4364 return __val_expr<_Op>(_Op(greater<value_type>(),
4365 __scalar_expr<value_type>(__x, __y.size()), __y));
4366}
4367
4368template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004369inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004370typename enable_if
4371<
4372 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4373 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4374>::type
4375operator<=(const _Expr1& __x, const _Expr2& __y)
4376{
4377 typedef typename _Expr1::value_type value_type;
4378 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
4379 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
4380}
4381
4382template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004383inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004384typename enable_if
4385<
4386 __is_val_expr<_Expr>::value,
4387 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4388 _Expr, __scalar_expr<typename _Expr::value_type> > >
4389>::type
4390operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
4391{
4392 typedef typename _Expr::value_type value_type;
4393 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4394 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4395 __x, __scalar_expr<value_type>(__y, __x.size())));
4396}
4397
4398template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004399inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004400typename enable_if
4401<
4402 __is_val_expr<_Expr>::value,
4403 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4404 __scalar_expr<typename _Expr::value_type>, _Expr> >
4405>::type
4406operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
4407{
4408 typedef typename _Expr::value_type value_type;
4409 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4410 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4411 __scalar_expr<value_type>(__x, __y.size()), __y));
4412}
4413
4414template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004415inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004416typename enable_if
4417<
4418 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4419 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4420>::type
4421operator>=(const _Expr1& __x, const _Expr2& __y)
4422{
4423 typedef typename _Expr1::value_type value_type;
4424 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
4425 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
4426}
4427
4428template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004429inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004430typename enable_if
4431<
4432 __is_val_expr<_Expr>::value,
4433 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4434 _Expr, __scalar_expr<typename _Expr::value_type> > >
4435>::type
4436operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
4437{
4438 typedef typename _Expr::value_type value_type;
4439 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4440 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4441 __x, __scalar_expr<value_type>(__y, __x.size())));
4442}
4443
4444template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004445inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004446typename enable_if
4447<
4448 __is_val_expr<_Expr>::value,
4449 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4450 __scalar_expr<typename _Expr::value_type>, _Expr> >
4451>::type
4452operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
4453{
4454 typedef typename _Expr::value_type value_type;
4455 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4456 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4457 __scalar_expr<value_type>(__x, __y.size()), __y));
4458}
4459
4460template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004461inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004462typename enable_if
4463<
4464 __is_val_expr<_Expr>::value,
4465 __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
4466>::type
4467abs(const _Expr& __x)
4468{
4469 typedef typename _Expr::value_type value_type;
4470 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
4471 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
4472}
4473
4474template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004475inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004476typename enable_if
4477<
4478 __is_val_expr<_Expr>::value,
4479 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
4480>::type
4481acos(const _Expr& __x)
4482{
4483 typedef typename _Expr::value_type value_type;
4484 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
4485 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
4486}
4487
4488template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004489inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004490typename enable_if
4491<
4492 __is_val_expr<_Expr>::value,
4493 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
4494>::type
4495asin(const _Expr& __x)
4496{
4497 typedef typename _Expr::value_type value_type;
4498 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
4499 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
4500}
4501
4502template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004503inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004504typename enable_if
4505<
4506 __is_val_expr<_Expr>::value,
4507 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
4508>::type
4509atan(const _Expr& __x)
4510{
4511 typedef typename _Expr::value_type value_type;
4512 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
4513 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
4514}
4515
4516template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004517inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004518typename enable_if
4519<
4520 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4521 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4522>::type
4523atan2(const _Expr1& __x, const _Expr2& __y)
4524{
4525 typedef typename _Expr1::value_type value_type;
4526 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
4527 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
4528}
4529
4530template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004531inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004532typename enable_if
4533<
4534 __is_val_expr<_Expr>::value,
4535 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4536 _Expr, __scalar_expr<typename _Expr::value_type> > >
4537>::type
4538atan2(const _Expr& __x, const typename _Expr::value_type& __y)
4539{
4540 typedef typename _Expr::value_type value_type;
4541 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4542 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4543 __x, __scalar_expr<value_type>(__y, __x.size())));
4544}
4545
4546template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004547inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004548typename enable_if
4549<
4550 __is_val_expr<_Expr>::value,
4551 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4552 __scalar_expr<typename _Expr::value_type>, _Expr> >
4553>::type
4554atan2(const typename _Expr::value_type& __x, const _Expr& __y)
4555{
4556 typedef typename _Expr::value_type value_type;
4557 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4558 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4559 __scalar_expr<value_type>(__x, __y.size()), __y));
4560}
4561
4562template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004563inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004564typename enable_if
4565<
4566 __is_val_expr<_Expr>::value,
4567 __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
4568>::type
4569cos(const _Expr& __x)
4570{
4571 typedef typename _Expr::value_type value_type;
4572 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
4573 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
4574}
4575
4576template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004577inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004578typename enable_if
4579<
4580 __is_val_expr<_Expr>::value,
4581 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
4582>::type
4583cosh(const _Expr& __x)
4584{
4585 typedef typename _Expr::value_type value_type;
4586 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
4587 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
4588}
4589
4590template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004591inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004592typename enable_if
4593<
4594 __is_val_expr<_Expr>::value,
4595 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
4596>::type
4597exp(const _Expr& __x)
4598{
4599 typedef typename _Expr::value_type value_type;
4600 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
4601 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
4602}
4603
4604template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004605inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004606typename enable_if
4607<
4608 __is_val_expr<_Expr>::value,
4609 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
4610>::type
4611log(const _Expr& __x)
4612{
4613 typedef typename _Expr::value_type value_type;
4614 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
4615 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
4616}
4617
4618template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004619inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004620typename enable_if
4621<
4622 __is_val_expr<_Expr>::value,
4623 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
4624>::type
4625log10(const _Expr& __x)
4626{
4627 typedef typename _Expr::value_type value_type;
4628 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
4629 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
4630}
4631
4632template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004633inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004634typename enable_if
4635<
4636 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4637 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4638>::type
4639pow(const _Expr1& __x, const _Expr2& __y)
4640{
4641 typedef typename _Expr1::value_type value_type;
4642 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
4643 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
4644}
4645
4646template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004647inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004648typename enable_if
4649<
4650 __is_val_expr<_Expr>::value,
4651 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4652 _Expr, __scalar_expr<typename _Expr::value_type> > >
4653>::type
4654pow(const _Expr& __x, const typename _Expr::value_type& __y)
4655{
4656 typedef typename _Expr::value_type value_type;
4657 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4658 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4659 __x, __scalar_expr<value_type>(__y, __x.size())));
4660}
4661
4662template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004663inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004664typename enable_if
4665<
4666 __is_val_expr<_Expr>::value,
4667 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4668 __scalar_expr<typename _Expr::value_type>, _Expr> >
4669>::type
4670pow(const typename _Expr::value_type& __x, const _Expr& __y)
4671{
4672 typedef typename _Expr::value_type value_type;
4673 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4674 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4675 __scalar_expr<value_type>(__x, __y.size()), __y));
4676}
4677
4678template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004679inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004680typename enable_if
4681<
4682 __is_val_expr<_Expr>::value,
4683 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
4684>::type
4685sin(const _Expr& __x)
4686{
4687 typedef typename _Expr::value_type value_type;
4688 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
4689 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
4690}
4691
4692template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004693inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004694typename enable_if
4695<
4696 __is_val_expr<_Expr>::value,
4697 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
4698>::type
4699sinh(const _Expr& __x)
4700{
4701 typedef typename _Expr::value_type value_type;
4702 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
4703 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
4704}
4705
4706template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004707inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004708typename enable_if
4709<
4710 __is_val_expr<_Expr>::value,
4711 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
4712>::type
4713sqrt(const _Expr& __x)
4714{
4715 typedef typename _Expr::value_type value_type;
4716 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
4717 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
4718}
4719
4720template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004721inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004722typename enable_if
4723<
4724 __is_val_expr<_Expr>::value,
4725 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
4726>::type
4727tan(const _Expr& __x)
4728{
4729 typedef typename _Expr::value_type value_type;
4730 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
4731 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
4732}
4733
4734template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004735inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004736typename enable_if
4737<
4738 __is_val_expr<_Expr>::value,
4739 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
4740>::type
4741tanh(const _Expr& __x)
4742{
4743 typedef typename _Expr::value_type value_type;
4744 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
4745 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
4746}
4747
4748template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004749inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004750_Tp*
4751begin(valarray<_Tp>& __v)
4752{
4753 return __v.__begin_;
4754}
4755
4756template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004757inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004758const _Tp*
4759begin(const valarray<_Tp>& __v)
4760{
4761 return __v.__begin_;
4762}
4763
4764template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004765inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004766_Tp*
4767end(valarray<_Tp>& __v)
4768{
4769 return __v.__end_;
4770}
4771
4772template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004773inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004774const _Tp*
4775end(const valarray<_Tp>& __v)
4776{
4777 return __v.__end_;
4778}
4779
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004780_LIBCPP_END_NAMESPACE_STD
4781
4782#endif // _LIBCPP_VALARRAY