blob: 3714350edfffc60ef7d17d5b67401d2e94b6a5f2 [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;
1223}
1224
1225template <class _Tp>
1226template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001227inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001228typename enable_if
1229<
1230 __is_val_expr<_Expr>::value,
1231 void
1232>::type
1233slice_array<_Tp>::operator=(const _Expr& __v) const
1234{
1235 value_type* __t = __vp_;
1236 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1237 *__t = __v[__i];
1238}
1239
1240template <class _Tp>
1241template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001242inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001243typename enable_if
1244<
1245 __is_val_expr<_Expr>::value,
1246 void
1247>::type
1248slice_array<_Tp>::operator*=(const _Expr& __v) const
1249{
1250 value_type* __t = __vp_;
1251 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1252 *__t *= __v[__i];
1253}
1254
1255template <class _Tp>
1256template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001257inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001258typename enable_if
1259<
1260 __is_val_expr<_Expr>::value,
1261 void
1262>::type
1263slice_array<_Tp>::operator/=(const _Expr& __v) const
1264{
1265 value_type* __t = __vp_;
1266 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1267 *__t /= __v[__i];
1268}
1269
1270template <class _Tp>
1271template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001272inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001273typename enable_if
1274<
1275 __is_val_expr<_Expr>::value,
1276 void
1277>::type
1278slice_array<_Tp>::operator%=(const _Expr& __v) const
1279{
1280 value_type* __t = __vp_;
1281 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1282 *__t %= __v[__i];
1283}
1284
1285template <class _Tp>
1286template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001287inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001288typename enable_if
1289<
1290 __is_val_expr<_Expr>::value,
1291 void
1292>::type
1293slice_array<_Tp>::operator+=(const _Expr& __v) const
1294{
1295 value_type* __t = __vp_;
1296 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1297 *__t += __v[__i];
1298}
1299
1300template <class _Tp>
1301template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001302inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001303typename enable_if
1304<
1305 __is_val_expr<_Expr>::value,
1306 void
1307>::type
1308slice_array<_Tp>::operator-=(const _Expr& __v) const
1309{
1310 value_type* __t = __vp_;
1311 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1312 *__t -= __v[__i];
1313}
1314
1315template <class _Tp>
1316template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001317inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001318typename enable_if
1319<
1320 __is_val_expr<_Expr>::value,
1321 void
1322>::type
1323slice_array<_Tp>::operator^=(const _Expr& __v) const
1324{
1325 value_type* __t = __vp_;
1326 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1327 *__t ^= __v[__i];
1328}
1329
1330template <class _Tp>
1331template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001332inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001333typename enable_if
1334<
1335 __is_val_expr<_Expr>::value,
1336 void
1337>::type
1338slice_array<_Tp>::operator&=(const _Expr& __v) const
1339{
1340 value_type* __t = __vp_;
1341 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1342 *__t &= __v[__i];
1343}
1344
1345template <class _Tp>
1346template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001347inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001348typename enable_if
1349<
1350 __is_val_expr<_Expr>::value,
1351 void
1352>::type
1353slice_array<_Tp>::operator|=(const _Expr& __v) const
1354{
1355 value_type* __t = __vp_;
1356 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1357 *__t |= __v[__i];
1358}
1359
1360template <class _Tp>
1361template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001362inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001363typename enable_if
1364<
1365 __is_val_expr<_Expr>::value,
1366 void
1367>::type
1368slice_array<_Tp>::operator<<=(const _Expr& __v) const
1369{
1370 value_type* __t = __vp_;
1371 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1372 *__t <<= __v[__i];
1373}
1374
1375template <class _Tp>
1376template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001377inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001378typename enable_if
1379<
1380 __is_val_expr<_Expr>::value,
1381 void
1382>::type
1383slice_array<_Tp>::operator>>=(const _Expr& __v) const
1384{
1385 value_type* __t = __vp_;
1386 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1387 *__t >>= __v[__i];
1388}
1389
1390template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001391inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001392void
1393slice_array<_Tp>::operator=(const value_type& __x) const
1394{
1395 value_type* __t = __vp_;
1396 for (size_t __n = __size_; __n; --__n, __t += __stride_)
1397 *__t = __x;
1398}
1399
1400// gslice
1401
Howard Hinnant83eade62013-03-06 23:30:19 +00001402class _LIBCPP_TYPE_VIS gslice
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001403{
1404 valarray<size_t> __size_;
1405 valarray<size_t> __stride_;
1406 valarray<size_t> __1d_;
Howard Hinnant324bb032010-08-22 00:02:43 +00001407
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001408public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001409 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001410 gslice() {}
Douglas Gregor0855dde2012-05-19 07:14:17 +00001411
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001412 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001413 gslice(size_t __start, const valarray<size_t>& __size,
1414 const valarray<size_t>& __stride)
1415 : __size_(__size),
1416 __stride_(__stride)
1417 {__init(__start);}
1418
Howard Hinnant73d21a42010-09-04 23:28:19 +00001419#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001420
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001422 gslice(size_t __start, const valarray<size_t>& __size,
1423 valarray<size_t>&& __stride)
1424 : __size_(__size),
1425 __stride_(move(__stride))
1426 {__init(__start);}
1427
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001429 gslice(size_t __start, valarray<size_t>&& __size,
1430 const valarray<size_t>& __stride)
1431 : __size_(move(__size)),
1432 __stride_(__stride)
1433 {__init(__start);}
1434
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001435 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001436 gslice(size_t __start, valarray<size_t>&& __size,
1437 valarray<size_t>&& __stride)
1438 : __size_(move(__size)),
1439 __stride_(move(__stride))
1440 {__init(__start);}
1441
Howard Hinnant73d21a42010-09-04 23:28:19 +00001442#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001443
1444// gslice(const gslice&) = default;
1445// gslice(gslice&&) = default;
1446// gslice& operator=(const gslice&) = default;
1447// gslice& operator=(gslice&&) = default;
1448
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001450 size_t start() const {return __1d_.size() ? __1d_[0] : 0;}
1451
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001452 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001453 valarray<size_t> size() const {return __size_;}
1454
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001456 valarray<size_t> stride() const {return __stride_;}
1457
1458private:
1459 void __init(size_t __start);
1460
1461 template <class> friend class gslice_array;
1462 template <class> friend class valarray;
1463 template <class> friend class __val_expr;
1464};
1465
1466// gslice_array
1467
1468template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001469class _LIBCPP_TYPE_VIS_ONLY gslice_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001470{
1471public:
1472 typedef _Tp value_type;
1473
1474private:
1475 value_type* __vp_;
1476 valarray<size_t> __1d_;
1477
1478public:
1479 template <class _Expr>
1480 typename enable_if
1481 <
1482 __is_val_expr<_Expr>::value,
1483 void
1484 >::type
1485 operator=(const _Expr& __v) const;
1486
1487 template <class _Expr>
1488 typename enable_if
1489 <
1490 __is_val_expr<_Expr>::value,
1491 void
1492 >::type
1493 operator*=(const _Expr& __v) const;
1494
1495 template <class _Expr>
1496 typename enable_if
1497 <
1498 __is_val_expr<_Expr>::value,
1499 void
1500 >::type
1501 operator/=(const _Expr& __v) const;
1502
1503 template <class _Expr>
1504 typename enable_if
1505 <
1506 __is_val_expr<_Expr>::value,
1507 void
1508 >::type
1509 operator%=(const _Expr& __v) const;
1510
1511 template <class _Expr>
1512 typename enable_if
1513 <
1514 __is_val_expr<_Expr>::value,
1515 void
1516 >::type
1517 operator+=(const _Expr& __v) const;
1518
1519 template <class _Expr>
1520 typename enable_if
1521 <
1522 __is_val_expr<_Expr>::value,
1523 void
1524 >::type
1525 operator-=(const _Expr& __v) const;
1526
1527 template <class _Expr>
1528 typename enable_if
1529 <
1530 __is_val_expr<_Expr>::value,
1531 void
1532 >::type
1533 operator^=(const _Expr& __v) const;
1534
1535 template <class _Expr>
1536 typename enable_if
1537 <
1538 __is_val_expr<_Expr>::value,
1539 void
1540 >::type
1541 operator&=(const _Expr& __v) const;
1542
1543 template <class _Expr>
1544 typename enable_if
1545 <
1546 __is_val_expr<_Expr>::value,
1547 void
1548 >::type
1549 operator|=(const _Expr& __v) const;
1550
1551 template <class _Expr>
1552 typename enable_if
1553 <
1554 __is_val_expr<_Expr>::value,
1555 void
1556 >::type
1557 operator<<=(const _Expr& __v) const;
1558
1559 template <class _Expr>
1560 typename enable_if
1561 <
1562 __is_val_expr<_Expr>::value,
1563 void
1564 >::type
1565 operator>>=(const _Expr& __v) const;
1566
1567 const gslice_array& operator=(const gslice_array& __ga) const;
1568
1569 void operator=(const value_type& __x) const;
1570
1571// gslice_array(const gslice_array&) = default;
1572// gslice_array(gslice_array&&) = default;
1573// gslice_array& operator=(const gslice_array&) = default;
1574// gslice_array& operator=(gslice_array&&) = default;
1575
1576private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001578 gslice_array(const gslice& __gs, const valarray<value_type>& __v)
1579 : __vp_(const_cast<value_type*>(__v.__begin_)),
1580 __1d_(__gs.__1d_)
1581 {}
1582
Howard Hinnant73d21a42010-09-04 23:28:19 +00001583#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001584
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001585 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001586 gslice_array(gslice&& __gs, const valarray<value_type>& __v)
1587 : __vp_(const_cast<value_type*>(__v.__begin_)),
1588 __1d_(move(__gs.__1d_))
1589 {}
1590
Howard Hinnant73d21a42010-09-04 23:28:19 +00001591#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001592
1593 template <class> friend class valarray;
1594};
1595
1596template <class _Tp>
1597template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001598inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001599typename enable_if
1600<
1601 __is_val_expr<_Expr>::value,
1602 void
1603>::type
1604gslice_array<_Tp>::operator=(const _Expr& __v) const
1605{
1606 typedef const size_t* _Ip;
1607 size_t __j = 0;
1608 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1609 __vp_[*__i] = __v[__j];
1610}
1611
1612template <class _Tp>
1613template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001614inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001615typename enable_if
1616<
1617 __is_val_expr<_Expr>::value,
1618 void
1619>::type
1620gslice_array<_Tp>::operator*=(const _Expr& __v) const
1621{
1622 typedef const size_t* _Ip;
1623 size_t __j = 0;
1624 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1625 __vp_[*__i] *= __v[__j];
1626}
1627
1628template <class _Tp>
1629template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001630inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001631typename enable_if
1632<
1633 __is_val_expr<_Expr>::value,
1634 void
1635>::type
1636gslice_array<_Tp>::operator/=(const _Expr& __v) const
1637{
1638 typedef const size_t* _Ip;
1639 size_t __j = 0;
1640 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1641 __vp_[*__i] /= __v[__j];
1642}
1643
1644template <class _Tp>
1645template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001646inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001647typename enable_if
1648<
1649 __is_val_expr<_Expr>::value,
1650 void
1651>::type
1652gslice_array<_Tp>::operator%=(const _Expr& __v) const
1653{
1654 typedef const size_t* _Ip;
1655 size_t __j = 0;
1656 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1657 __vp_[*__i] %= __v[__j];
1658}
1659
1660template <class _Tp>
1661template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001662inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001663typename enable_if
1664<
1665 __is_val_expr<_Expr>::value,
1666 void
1667>::type
1668gslice_array<_Tp>::operator+=(const _Expr& __v) const
1669{
1670 typedef const size_t* _Ip;
1671 size_t __j = 0;
1672 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1673 __vp_[*__i] += __v[__j];
1674}
1675
1676template <class _Tp>
1677template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001678inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001679typename enable_if
1680<
1681 __is_val_expr<_Expr>::value,
1682 void
1683>::type
1684gslice_array<_Tp>::operator-=(const _Expr& __v) const
1685{
1686 typedef const size_t* _Ip;
1687 size_t __j = 0;
1688 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1689 __vp_[*__i] -= __v[__j];
1690}
1691
1692template <class _Tp>
1693template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001694inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001695typename enable_if
1696<
1697 __is_val_expr<_Expr>::value,
1698 void
1699>::type
1700gslice_array<_Tp>::operator^=(const _Expr& __v) const
1701{
1702 typedef const size_t* _Ip;
1703 size_t __j = 0;
1704 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1705 __vp_[*__i] ^= __v[__j];
1706}
1707
1708template <class _Tp>
1709template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001710inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001711typename enable_if
1712<
1713 __is_val_expr<_Expr>::value,
1714 void
1715>::type
1716gslice_array<_Tp>::operator&=(const _Expr& __v) const
1717{
1718 typedef const size_t* _Ip;
1719 size_t __j = 0;
1720 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1721 __vp_[*__i] &= __v[__j];
1722}
1723
1724template <class _Tp>
1725template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001726inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001727typename enable_if
1728<
1729 __is_val_expr<_Expr>::value,
1730 void
1731>::type
1732gslice_array<_Tp>::operator|=(const _Expr& __v) const
1733{
1734 typedef const size_t* _Ip;
1735 size_t __j = 0;
1736 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1737 __vp_[*__i] |= __v[__j];
1738}
1739
1740template <class _Tp>
1741template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001742inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001743typename enable_if
1744<
1745 __is_val_expr<_Expr>::value,
1746 void
1747>::type
1748gslice_array<_Tp>::operator<<=(const _Expr& __v) const
1749{
1750 typedef const size_t* _Ip;
1751 size_t __j = 0;
1752 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1753 __vp_[*__i] <<= __v[__j];
1754}
1755
1756template <class _Tp>
1757template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001758inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001759typename enable_if
1760<
1761 __is_val_expr<_Expr>::value,
1762 void
1763>::type
1764gslice_array<_Tp>::operator>>=(const _Expr& __v) const
1765{
1766 typedef const size_t* _Ip;
1767 size_t __j = 0;
1768 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1769 __vp_[*__i] >>= __v[__j];
1770}
1771
1772template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001773inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001774const gslice_array<_Tp>&
1775gslice_array<_Tp>::operator=(const gslice_array& __ga) const
1776{
1777 typedef const size_t* _Ip;
1778 const value_type* __s = __ga.__vp_;
1779 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_;
1780 __i != __e; ++__i, ++__j)
1781 __vp_[*__i] = __s[*__j];
1782 return *this;
1783}
1784
1785template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001786inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001787void
1788gslice_array<_Tp>::operator=(const value_type& __x) const
1789{
1790 typedef const size_t* _Ip;
1791 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1792 __vp_[*__i] = __x;
1793}
1794
1795// mask_array
1796
1797template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001798class _LIBCPP_TYPE_VIS_ONLY mask_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001799{
1800public:
1801 typedef _Tp value_type;
1802
1803private:
1804 value_type* __vp_;
1805 valarray<size_t> __1d_;
1806
1807public:
1808 template <class _Expr>
1809 typename enable_if
1810 <
1811 __is_val_expr<_Expr>::value,
1812 void
1813 >::type
1814 operator=(const _Expr& __v) const;
1815
1816 template <class _Expr>
1817 typename enable_if
1818 <
1819 __is_val_expr<_Expr>::value,
1820 void
1821 >::type
1822 operator*=(const _Expr& __v) const;
1823
1824 template <class _Expr>
1825 typename enable_if
1826 <
1827 __is_val_expr<_Expr>::value,
1828 void
1829 >::type
1830 operator/=(const _Expr& __v) const;
1831
1832 template <class _Expr>
1833 typename enable_if
1834 <
1835 __is_val_expr<_Expr>::value,
1836 void
1837 >::type
1838 operator%=(const _Expr& __v) const;
1839
1840 template <class _Expr>
1841 typename enable_if
1842 <
1843 __is_val_expr<_Expr>::value,
1844 void
1845 >::type
1846 operator+=(const _Expr& __v) const;
1847
1848 template <class _Expr>
1849 typename enable_if
1850 <
1851 __is_val_expr<_Expr>::value,
1852 void
1853 >::type
1854 operator-=(const _Expr& __v) const;
1855
1856 template <class _Expr>
1857 typename enable_if
1858 <
1859 __is_val_expr<_Expr>::value,
1860 void
1861 >::type
1862 operator^=(const _Expr& __v) const;
1863
1864 template <class _Expr>
1865 typename enable_if
1866 <
1867 __is_val_expr<_Expr>::value,
1868 void
1869 >::type
1870 operator&=(const _Expr& __v) const;
1871
1872 template <class _Expr>
1873 typename enable_if
1874 <
1875 __is_val_expr<_Expr>::value,
1876 void
1877 >::type
1878 operator|=(const _Expr& __v) const;
1879
1880 template <class _Expr>
1881 typename enable_if
1882 <
1883 __is_val_expr<_Expr>::value,
1884 void
1885 >::type
1886 operator<<=(const _Expr& __v) const;
1887
1888 template <class _Expr>
1889 typename enable_if
1890 <
1891 __is_val_expr<_Expr>::value,
1892 void
1893 >::type
1894 operator>>=(const _Expr& __v) const;
1895
1896 const mask_array& operator=(const mask_array& __ma) const;
1897
1898 void operator=(const value_type& __x) const;
1899
1900// mask_array(const mask_array&) = default;
1901// mask_array(mask_array&&) = default;
1902// mask_array& operator=(const mask_array&) = default;
1903// mask_array& operator=(mask_array&&) = default;
1904
1905private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001907 mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
1908 : __vp_(const_cast<value_type*>(__v.__begin_)),
Howard Hinnantec3773c2011-12-01 20:21:04 +00001909 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001910 {
1911 size_t __j = 0;
1912 for (size_t __i = 0; __i < __vb.size(); ++__i)
1913 if (__vb[__i])
1914 __1d_[__j++] = __i;
1915 }
1916
1917 template <class> friend class valarray;
1918};
1919
1920template <class _Tp>
1921template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001922inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001923typename enable_if
1924<
1925 __is_val_expr<_Expr>::value,
1926 void
1927>::type
1928mask_array<_Tp>::operator=(const _Expr& __v) const
1929{
1930 size_t __n = __1d_.size();
1931 for (size_t __i = 0; __i < __n; ++__i)
1932 __vp_[__1d_[__i]] = __v[__i];
1933}
1934
1935template <class _Tp>
1936template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001937inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001938typename enable_if
1939<
1940 __is_val_expr<_Expr>::value,
1941 void
1942>::type
1943mask_array<_Tp>::operator*=(const _Expr& __v) const
1944{
1945 size_t __n = __1d_.size();
1946 for (size_t __i = 0; __i < __n; ++__i)
1947 __vp_[__1d_[__i]] *= __v[__i];
1948}
1949
1950template <class _Tp>
1951template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001952inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001953typename enable_if
1954<
1955 __is_val_expr<_Expr>::value,
1956 void
1957>::type
1958mask_array<_Tp>::operator/=(const _Expr& __v) const
1959{
1960 size_t __n = __1d_.size();
1961 for (size_t __i = 0; __i < __n; ++__i)
1962 __vp_[__1d_[__i]] /= __v[__i];
1963}
1964
1965template <class _Tp>
1966template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001967inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001968typename enable_if
1969<
1970 __is_val_expr<_Expr>::value,
1971 void
1972>::type
1973mask_array<_Tp>::operator%=(const _Expr& __v) const
1974{
1975 size_t __n = __1d_.size();
1976 for (size_t __i = 0; __i < __n; ++__i)
1977 __vp_[__1d_[__i]] %= __v[__i];
1978}
1979
1980template <class _Tp>
1981template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001982inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001983typename enable_if
1984<
1985 __is_val_expr<_Expr>::value,
1986 void
1987>::type
1988mask_array<_Tp>::operator+=(const _Expr& __v) const
1989{
1990 size_t __n = __1d_.size();
1991 for (size_t __i = 0; __i < __n; ++__i)
1992 __vp_[__1d_[__i]] += __v[__i];
1993}
1994
1995template <class _Tp>
1996template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00001997inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001998typename enable_if
1999<
2000 __is_val_expr<_Expr>::value,
2001 void
2002>::type
2003mask_array<_Tp>::operator-=(const _Expr& __v) const
2004{
2005 size_t __n = __1d_.size();
2006 for (size_t __i = 0; __i < __n; ++__i)
2007 __vp_[__1d_[__i]] -= __v[__i];
2008}
2009
2010template <class _Tp>
2011template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002012inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002013typename enable_if
2014<
2015 __is_val_expr<_Expr>::value,
2016 void
2017>::type
2018mask_array<_Tp>::operator^=(const _Expr& __v) const
2019{
2020 size_t __n = __1d_.size();
2021 for (size_t __i = 0; __i < __n; ++__i)
2022 __vp_[__1d_[__i]] ^= __v[__i];
2023}
2024
2025template <class _Tp>
2026template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002027inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002028typename enable_if
2029<
2030 __is_val_expr<_Expr>::value,
2031 void
2032>::type
2033mask_array<_Tp>::operator&=(const _Expr& __v) const
2034{
2035 size_t __n = __1d_.size();
2036 for (size_t __i = 0; __i < __n; ++__i)
2037 __vp_[__1d_[__i]] &= __v[__i];
2038}
2039
2040template <class _Tp>
2041template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002042inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002043typename enable_if
2044<
2045 __is_val_expr<_Expr>::value,
2046 void
2047>::type
2048mask_array<_Tp>::operator|=(const _Expr& __v) const
2049{
2050 size_t __n = __1d_.size();
2051 for (size_t __i = 0; __i < __n; ++__i)
2052 __vp_[__1d_[__i]] |= __v[__i];
2053}
2054
2055template <class _Tp>
2056template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002057inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002058typename enable_if
2059<
2060 __is_val_expr<_Expr>::value,
2061 void
2062>::type
2063mask_array<_Tp>::operator<<=(const _Expr& __v) const
2064{
2065 size_t __n = __1d_.size();
2066 for (size_t __i = 0; __i < __n; ++__i)
2067 __vp_[__1d_[__i]] <<= __v[__i];
2068}
2069
2070template <class _Tp>
2071template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002072inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002073typename enable_if
2074<
2075 __is_val_expr<_Expr>::value,
2076 void
2077>::type
2078mask_array<_Tp>::operator>>=(const _Expr& __v) const
2079{
2080 size_t __n = __1d_.size();
2081 for (size_t __i = 0; __i < __n; ++__i)
2082 __vp_[__1d_[__i]] >>= __v[__i];
2083}
2084
2085template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002086inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002087const mask_array<_Tp>&
2088mask_array<_Tp>::operator=(const mask_array& __ma) const
2089{
2090 size_t __n = __1d_.size();
2091 for (size_t __i = 0; __i < __n; ++__i)
2092 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
2093}
2094
2095template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002096inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002097void
2098mask_array<_Tp>::operator=(const value_type& __x) const
2099{
2100 size_t __n = __1d_.size();
2101 for (size_t __i = 0; __i < __n; ++__i)
2102 __vp_[__1d_[__i]] = __x;
2103}
2104
2105template <class _ValExpr>
2106class __mask_expr
2107{
2108 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2109public:
2110 typedef typename _RmExpr::value_type value_type;
2111 typedef value_type result_type;
2112
2113private:
2114 _ValExpr __expr_;
2115 valarray<size_t> __1d_;
2116
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002117 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002118 __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
2119 : __expr_(__e),
Howard Hinnantec3773c2011-12-01 20:21:04 +00002120 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002121 {
2122 size_t __j = 0;
2123 for (size_t __i = 0; __i < __vb.size(); ++__i)
2124 if (__vb[__i])
2125 __1d_[__j++] = __i;
2126 }
2127
2128public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002129 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002130 result_type operator[](size_t __i) const
2131 {return __expr_[__1d_[__i]];}
2132
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002133 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002134 size_t size() const {return __1d_.size();}
2135
2136 template <class> friend class valarray;
2137};
2138
2139// indirect_array
2140
2141template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002142class _LIBCPP_TYPE_VIS_ONLY indirect_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002143{
2144public:
2145 typedef _Tp value_type;
2146
2147private:
2148 value_type* __vp_;
2149 valarray<size_t> __1d_;
2150
2151public:
2152 template <class _Expr>
2153 typename enable_if
2154 <
2155 __is_val_expr<_Expr>::value,
2156 void
2157 >::type
2158 operator=(const _Expr& __v) const;
2159
2160 template <class _Expr>
2161 typename enable_if
2162 <
2163 __is_val_expr<_Expr>::value,
2164 void
2165 >::type
2166 operator*=(const _Expr& __v) const;
2167
2168 template <class _Expr>
2169 typename enable_if
2170 <
2171 __is_val_expr<_Expr>::value,
2172 void
2173 >::type
2174 operator/=(const _Expr& __v) const;
2175
2176 template <class _Expr>
2177 typename enable_if
2178 <
2179 __is_val_expr<_Expr>::value,
2180 void
2181 >::type
2182 operator%=(const _Expr& __v) const;
2183
2184 template <class _Expr>
2185 typename enable_if
2186 <
2187 __is_val_expr<_Expr>::value,
2188 void
2189 >::type
2190 operator+=(const _Expr& __v) const;
2191
2192 template <class _Expr>
2193 typename enable_if
2194 <
2195 __is_val_expr<_Expr>::value,
2196 void
2197 >::type
2198 operator-=(const _Expr& __v) const;
2199
2200 template <class _Expr>
2201 typename enable_if
2202 <
2203 __is_val_expr<_Expr>::value,
2204 void
2205 >::type
2206 operator^=(const _Expr& __v) const;
2207
2208 template <class _Expr>
2209 typename enable_if
2210 <
2211 __is_val_expr<_Expr>::value,
2212 void
2213 >::type
2214 operator&=(const _Expr& __v) const;
2215
2216 template <class _Expr>
2217 typename enable_if
2218 <
2219 __is_val_expr<_Expr>::value,
2220 void
2221 >::type
2222 operator|=(const _Expr& __v) const;
2223
2224 template <class _Expr>
2225 typename enable_if
2226 <
2227 __is_val_expr<_Expr>::value,
2228 void
2229 >::type
2230 operator<<=(const _Expr& __v) const;
2231
2232 template <class _Expr>
2233 typename enable_if
2234 <
2235 __is_val_expr<_Expr>::value,
2236 void
2237 >::type
2238 operator>>=(const _Expr& __v) const;
2239
2240 const indirect_array& operator=(const indirect_array& __ia) const;
2241
2242 void operator=(const value_type& __x) const;
2243
2244// indirect_array(const indirect_array&) = default;
2245// indirect_array(indirect_array&&) = default;
2246// indirect_array& operator=(const indirect_array&) = default;
2247// indirect_array& operator=(indirect_array&&) = default;
2248
2249private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002251 indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
2252 : __vp_(const_cast<value_type*>(__v.__begin_)),
2253 __1d_(__ia)
2254 {}
2255
Howard Hinnant73d21a42010-09-04 23:28:19 +00002256#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002257
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002259 indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
2260 : __vp_(const_cast<value_type*>(__v.__begin_)),
2261 __1d_(move(__ia))
2262 {}
2263
Howard Hinnant73d21a42010-09-04 23:28:19 +00002264#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002265
2266 template <class> friend class valarray;
2267};
2268
2269template <class _Tp>
2270template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002271inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002272typename enable_if
2273<
2274 __is_val_expr<_Expr>::value,
2275 void
2276>::type
2277indirect_array<_Tp>::operator=(const _Expr& __v) const
2278{
2279 size_t __n = __1d_.size();
2280 for (size_t __i = 0; __i < __n; ++__i)
2281 __vp_[__1d_[__i]] = __v[__i];
2282}
2283
2284template <class _Tp>
2285template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002286inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002287typename enable_if
2288<
2289 __is_val_expr<_Expr>::value,
2290 void
2291>::type
2292indirect_array<_Tp>::operator*=(const _Expr& __v) const
2293{
2294 size_t __n = __1d_.size();
2295 for (size_t __i = 0; __i < __n; ++__i)
2296 __vp_[__1d_[__i]] *= __v[__i];
2297}
2298
2299template <class _Tp>
2300template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002301inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002302typename enable_if
2303<
2304 __is_val_expr<_Expr>::value,
2305 void
2306>::type
2307indirect_array<_Tp>::operator/=(const _Expr& __v) const
2308{
2309 size_t __n = __1d_.size();
2310 for (size_t __i = 0; __i < __n; ++__i)
2311 __vp_[__1d_[__i]] /= __v[__i];
2312}
2313
2314template <class _Tp>
2315template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002316inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002317typename enable_if
2318<
2319 __is_val_expr<_Expr>::value,
2320 void
2321>::type
2322indirect_array<_Tp>::operator%=(const _Expr& __v) const
2323{
2324 size_t __n = __1d_.size();
2325 for (size_t __i = 0; __i < __n; ++__i)
2326 __vp_[__1d_[__i]] %= __v[__i];
2327}
2328
2329template <class _Tp>
2330template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002331inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002332typename enable_if
2333<
2334 __is_val_expr<_Expr>::value,
2335 void
2336>::type
2337indirect_array<_Tp>::operator+=(const _Expr& __v) const
2338{
2339 size_t __n = __1d_.size();
2340 for (size_t __i = 0; __i < __n; ++__i)
2341 __vp_[__1d_[__i]] += __v[__i];
2342}
2343
2344template <class _Tp>
2345template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002346inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002347typename enable_if
2348<
2349 __is_val_expr<_Expr>::value,
2350 void
2351>::type
2352indirect_array<_Tp>::operator-=(const _Expr& __v) const
2353{
2354 size_t __n = __1d_.size();
2355 for (size_t __i = 0; __i < __n; ++__i)
2356 __vp_[__1d_[__i]] -= __v[__i];
2357}
2358
2359template <class _Tp>
2360template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002361inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002362typename enable_if
2363<
2364 __is_val_expr<_Expr>::value,
2365 void
2366>::type
2367indirect_array<_Tp>::operator^=(const _Expr& __v) const
2368{
2369 size_t __n = __1d_.size();
2370 for (size_t __i = 0; __i < __n; ++__i)
2371 __vp_[__1d_[__i]] ^= __v[__i];
2372}
2373
2374template <class _Tp>
2375template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002376inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002377typename enable_if
2378<
2379 __is_val_expr<_Expr>::value,
2380 void
2381>::type
2382indirect_array<_Tp>::operator&=(const _Expr& __v) const
2383{
2384 size_t __n = __1d_.size();
2385 for (size_t __i = 0; __i < __n; ++__i)
2386 __vp_[__1d_[__i]] &= __v[__i];
2387}
2388
2389template <class _Tp>
2390template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002391inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002392typename enable_if
2393<
2394 __is_val_expr<_Expr>::value,
2395 void
2396>::type
2397indirect_array<_Tp>::operator|=(const _Expr& __v) const
2398{
2399 size_t __n = __1d_.size();
2400 for (size_t __i = 0; __i < __n; ++__i)
2401 __vp_[__1d_[__i]] |= __v[__i];
2402}
2403
2404template <class _Tp>
2405template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002406inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002407typename enable_if
2408<
2409 __is_val_expr<_Expr>::value,
2410 void
2411>::type
2412indirect_array<_Tp>::operator<<=(const _Expr& __v) const
2413{
2414 size_t __n = __1d_.size();
2415 for (size_t __i = 0; __i < __n; ++__i)
2416 __vp_[__1d_[__i]] <<= __v[__i];
2417}
2418
2419template <class _Tp>
2420template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002421inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002422typename enable_if
2423<
2424 __is_val_expr<_Expr>::value,
2425 void
2426>::type
2427indirect_array<_Tp>::operator>>=(const _Expr& __v) const
2428{
2429 size_t __n = __1d_.size();
2430 for (size_t __i = 0; __i < __n; ++__i)
2431 __vp_[__1d_[__i]] >>= __v[__i];
2432}
2433
2434template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002435inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002436const indirect_array<_Tp>&
2437indirect_array<_Tp>::operator=(const indirect_array& __ia) const
2438{
2439 typedef const size_t* _Ip;
2440 const value_type* __s = __ia.__vp_;
2441 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_;
2442 __i != __e; ++__i, ++__j)
2443 __vp_[*__i] = __s[*__j];
2444 return *this;
2445}
2446
2447template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002448inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002449void
2450indirect_array<_Tp>::operator=(const value_type& __x) const
2451{
2452 typedef const size_t* _Ip;
2453 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
2454 __vp_[*__i] = __x;
2455}
2456
2457template <class _ValExpr>
2458class __indirect_expr
2459{
2460 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2461public:
2462 typedef typename _RmExpr::value_type value_type;
2463 typedef value_type result_type;
2464
2465private:
2466 _ValExpr __expr_;
2467 valarray<size_t> __1d_;
2468
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002470 __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e)
2471 : __expr_(__e),
2472 __1d_(__ia)
2473 {}
2474
Howard Hinnant73d21a42010-09-04 23:28:19 +00002475#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002476
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002478 __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
2479 : __expr_(__e),
2480 __1d_(move(__ia))
2481 {}
2482
Howard Hinnant73d21a42010-09-04 23:28:19 +00002483#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002484
2485public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002486 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002487 result_type operator[](size_t __i) const
2488 {return __expr_[__1d_[__i]];}
2489
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002491 size_t size() const {return __1d_.size();}
2492
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002493 template <class> friend class _LIBCPP_TYPE_VIS_ONLY valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002494};
2495
2496template<class _ValExpr>
2497class __val_expr
2498{
2499 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2500
2501 _ValExpr __expr_;
2502public:
2503 typedef typename _RmExpr::value_type value_type;
2504 typedef typename _RmExpr::result_type result_type;
2505
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002506 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002507 explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
2508
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002509 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002510 result_type operator[](size_t __i) const
2511 {return __expr_[__i];}
2512
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002514 __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
2515 {return __val_expr<__slice_expr<_ValExpr> >(__expr_, __s);}
2516
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002518 __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const
2519 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __gs.__1d_);}
2520
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002521 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002522 __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
2523 {return __val_expr<__mask_expr<_ValExpr> >(__expr_, __vb);}
2524
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002526 __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
2527 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __vs);}
2528
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002529 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002530 __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
2531 operator+() const
2532 {
2533 typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
2534 return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
2535 }
2536
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002538 __val_expr<_UnaryOp<negate<value_type>, _ValExpr> >
2539 operator-() const
2540 {
2541 typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
2542 return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
2543 }
2544
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002545 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002546 __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> >
2547 operator~() const
2548 {
2549 typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
2550 return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
2551 }
2552
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002554 __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> >
2555 operator!() const
2556 {
2557 typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
2558 return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
2559 }
2560
2561 operator valarray<result_type>() const;
2562
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002563 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002564 size_t size() const {return __expr_.size();}
2565
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002567 result_type sum() const
2568 {
2569 size_t __n = __expr_.size();
2570 result_type __r = __n ? __expr_[0] : result_type();
2571 for (size_t __i = 1; __i < __n; ++__i)
2572 __r += __expr_[__i];
2573 return __r;
2574 }
2575
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002576 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002577 result_type min() const
2578 {
2579 size_t __n = size();
2580 result_type __r = __n ? (*this)[0] : result_type();
2581 for (size_t __i = 1; __i < __n; ++__i)
2582 {
2583 result_type __x = __expr_[__i];
2584 if (__x < __r)
2585 __r = __x;
2586 }
2587 return __r;
2588 }
2589
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002590 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002591 result_type max() const
2592 {
2593 size_t __n = size();
2594 result_type __r = __n ? (*this)[0] : result_type();
2595 for (size_t __i = 1; __i < __n; ++__i)
2596 {
2597 result_type __x = __expr_[__i];
2598 if (__r < __x)
2599 __r = __x;
2600 }
2601 return __r;
2602 }
2603
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002605 __val_expr<__shift_expr<_ValExpr> > shift (int __i) const
2606 {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));}
2607
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002608 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002609 __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const
2610 {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));}
2611
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002613 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> >
2614 apply(value_type __f(value_type)) const
2615 {
2616 typedef __apply_expr<value_type, value_type(*)(value_type)> _Op;
2617 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2618 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2619 }
2620
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002622 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> >
2623 apply(value_type __f(const value_type&)) const
2624 {
2625 typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op;
2626 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2627 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2628 }
2629};
2630
2631template<class _ValExpr>
Howard Hinnantd8851432013-09-13 23:27:42 +00002632__val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002633{
2634 valarray<result_type> __r;
2635 size_t __n = __expr_.size();
2636 if (__n)
2637 {
2638 __r.__begin_ =
2639 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00002640 static_cast<result_type*>(_VSTD::__allocate(__n * sizeof(result_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002641 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
2642 ::new (__r.__end_) result_type(__expr_[__i]);
2643 }
2644 return __r;
2645}
2646
2647// valarray
2648
2649template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002650inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002651valarray<_Tp>::valarray(size_t __n)
2652 : __begin_(0),
2653 __end_(0)
2654{
2655 resize(__n);
2656}
2657
2658template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002659inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002660valarray<_Tp>::valarray(const value_type& __x, size_t __n)
2661 : __begin_(0),
2662 __end_(0)
2663{
2664 resize(__n, __x);
2665}
2666
2667template <class _Tp>
2668valarray<_Tp>::valarray(const value_type* __p, size_t __n)
2669 : __begin_(0),
2670 __end_(0)
2671{
2672 if (__n)
2673 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002674 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002675#ifndef _LIBCPP_NO_EXCEPTIONS
2676 try
2677 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002678#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002679 for (; __n; ++__end_, ++__p, --__n)
2680 ::new (__end_) value_type(*__p);
2681#ifndef _LIBCPP_NO_EXCEPTIONS
2682 }
2683 catch (...)
2684 {
2685 resize(0);
2686 throw;
2687 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002688#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002689 }
2690}
2691
2692template <class _Tp>
2693valarray<_Tp>::valarray(const valarray& __v)
2694 : __begin_(0),
2695 __end_(0)
2696{
2697 if (__v.size())
2698 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002699 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__v.size() * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002700#ifndef _LIBCPP_NO_EXCEPTIONS
2701 try
2702 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002703#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002704 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
2705 ::new (__end_) value_type(*__p);
2706#ifndef _LIBCPP_NO_EXCEPTIONS
2707 }
2708 catch (...)
2709 {
2710 resize(0);
2711 throw;
2712 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002713#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002714 }
2715}
2716
Howard Hinnant73d21a42010-09-04 23:28:19 +00002717#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002718
2719template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002720inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd143082012-07-21 00:51:28 +00002721valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002722 : __begin_(__v.__begin_),
2723 __end_(__v.__end_)
2724{
2725 __v.__begin_ = __v.__end_ = nullptr;
2726}
2727
Howard Hinnante3e32912011-08-12 21:56:02 +00002728#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2729
2730#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2731
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002732template <class _Tp>
2733valarray<_Tp>::valarray(initializer_list<value_type> __il)
2734 : __begin_(0),
2735 __end_(0)
2736{
2737 size_t __n = __il.size();
2738 if (__n)
2739 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002740 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002741#ifndef _LIBCPP_NO_EXCEPTIONS
2742 try
2743 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002744#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002745 for (const value_type* __p = __il.begin(); __n; ++__end_, ++__p, --__n)
2746 ::new (__end_) value_type(*__p);
2747#ifndef _LIBCPP_NO_EXCEPTIONS
2748 }
2749 catch (...)
2750 {
2751 resize(0);
2752 throw;
2753 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002754#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002755 }
2756}
2757
Howard Hinnante3e32912011-08-12 21:56:02 +00002758#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002759
2760template <class _Tp>
2761valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
2762 : __begin_(0),
2763 __end_(0)
2764{
2765 size_t __n = __sa.__size_;
2766 if (__n)
2767 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002768 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002769#ifndef _LIBCPP_NO_EXCEPTIONS
2770 try
2771 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002772#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002773 for (const value_type* __p = __sa.__vp_; __n; ++__end_, __p += __sa.__stride_, --__n)
2774 ::new (__end_) value_type(*__p);
2775#ifndef _LIBCPP_NO_EXCEPTIONS
2776 }
2777 catch (...)
2778 {
2779 resize(0);
2780 throw;
2781 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002782#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002783 }
2784}
2785
2786template <class _Tp>
2787valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
2788 : __begin_(0),
2789 __end_(0)
2790{
2791 size_t __n = __ga.__1d_.size();
2792 if (__n)
2793 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002794 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002795#ifndef _LIBCPP_NO_EXCEPTIONS
2796 try
2797 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002798#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002799 typedef const size_t* _Ip;
2800 const value_type* __s = __ga.__vp_;
2801 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2802 __i != __e; ++__i, ++__end_)
2803 ::new (__end_) value_type(__s[*__i]);
2804#ifndef _LIBCPP_NO_EXCEPTIONS
2805 }
2806 catch (...)
2807 {
2808 resize(0);
2809 throw;
2810 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002811#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002812 }
2813}
2814
2815template <class _Tp>
2816valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
2817 : __begin_(0),
2818 __end_(0)
2819{
2820 size_t __n = __ma.__1d_.size();
2821 if (__n)
2822 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002823 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002824#ifndef _LIBCPP_NO_EXCEPTIONS
2825 try
2826 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002827#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002828 typedef const size_t* _Ip;
2829 const value_type* __s = __ma.__vp_;
2830 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2831 __i != __e; ++__i, ++__end_)
2832 ::new (__end_) value_type(__s[*__i]);
2833#ifndef _LIBCPP_NO_EXCEPTIONS
2834 }
2835 catch (...)
2836 {
2837 resize(0);
2838 throw;
2839 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002840#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002841 }
2842}
2843
2844template <class _Tp>
2845valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
2846 : __begin_(0),
2847 __end_(0)
2848{
2849 size_t __n = __ia.__1d_.size();
2850 if (__n)
2851 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002852 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002853#ifndef _LIBCPP_NO_EXCEPTIONS
2854 try
2855 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002856#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002857 typedef const size_t* _Ip;
2858 const value_type* __s = __ia.__vp_;
2859 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2860 __i != __e; ++__i, ++__end_)
2861 ::new (__end_) value_type(__s[*__i]);
2862#ifndef _LIBCPP_NO_EXCEPTIONS
2863 }
2864 catch (...)
2865 {
2866 resize(0);
2867 throw;
2868 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002869#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002870 }
2871}
2872
2873template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002874inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002875valarray<_Tp>::~valarray()
2876{
2877 resize(0);
2878}
2879
2880template <class _Tp>
2881valarray<_Tp>&
2882valarray<_Tp>::operator=(const valarray& __v)
2883{
2884 if (this != &__v)
2885 {
2886 if (size() != __v.size())
2887 resize(__v.size());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002888 _VSTD::copy(__v.__begin_, __v.__end_, __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002889 }
2890 return *this;
2891}
2892
Howard Hinnant73d21a42010-09-04 23:28:19 +00002893#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002894
2895template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002896inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002897valarray<_Tp>&
Howard Hinnantbd143082012-07-21 00:51:28 +00002898valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002899{
2900 resize(0);
2901 __begin_ = __v.__begin_;
2902 __end_ = __v.__end_;
2903 __v.__begin_ = nullptr;
2904 __v.__end_ = nullptr;
2905 return *this;
2906}
2907
Howard Hinnante3e32912011-08-12 21:56:02 +00002908#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2909
2910#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2911
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002912template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002913inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002914valarray<_Tp>&
2915valarray<_Tp>::operator=(initializer_list<value_type> __il)
2916{
2917 if (size() != __il.size())
2918 resize(__il.size());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002919 _VSTD::copy(__il.begin(), __il.end(), __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002920 return *this;
2921}
2922
Howard Hinnante3e32912011-08-12 21:56:02 +00002923#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002924
2925template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002926inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002927valarray<_Tp>&
2928valarray<_Tp>::operator=(const value_type& __x)
2929{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002930 _VSTD::fill(__begin_, __end_, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002931 return *this;
2932}
2933
2934template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002935inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002936valarray<_Tp>&
2937valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
2938{
2939 value_type* __t = __begin_;
2940 const value_type* __s = __sa.__vp_;
2941 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
2942 *__t = *__s;
2943 return *this;
2944}
2945
2946template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002947inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002948valarray<_Tp>&
2949valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
2950{
2951 typedef const size_t* _Ip;
2952 value_type* __t = __begin_;
2953 const value_type* __s = __ga.__vp_;
2954 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2955 __i != __e; ++__i, ++__t)
2956 *__t = __s[*__i];
2957 return *this;
2958}
2959
2960template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002961inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002962valarray<_Tp>&
2963valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
2964{
2965 typedef const size_t* _Ip;
2966 value_type* __t = __begin_;
2967 const value_type* __s = __ma.__vp_;
2968 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2969 __i != __e; ++__i, ++__t)
2970 *__t = __s[*__i];
2971 return *this;
2972}
2973
2974template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002975inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002976valarray<_Tp>&
2977valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
2978{
2979 typedef const size_t* _Ip;
2980 value_type* __t = __begin_;
2981 const value_type* __s = __ia.__vp_;
2982 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2983 __i != __e; ++__i, ++__t)
2984 *__t = __s[*__i];
2985 return *this;
2986}
2987
2988template <class _Tp>
Howard Hinnantdb866632011-07-27 23:19:59 +00002989template <class _ValExpr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00002990inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantdb866632011-07-27 23:19:59 +00002991valarray<_Tp>&
2992valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
2993{
2994 size_t __n = __v.size();
2995 if (size() != __n)
2996 resize(__n);
2997 value_type* __t = __begin_;
2998 for (size_t __i = 0; __i != __n; ++__t, ++__i)
2999 *__t = result_type(__v[__i]);
3000 return *this;
3001}
3002
3003template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003004inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003005__val_expr<__slice_expr<const valarray<_Tp>&> >
3006valarray<_Tp>::operator[](slice __s) const
3007{
3008 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
3009}
3010
3011template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003012inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003013slice_array<_Tp>
3014valarray<_Tp>::operator[](slice __s)
3015{
3016 return slice_array<value_type>(__s, *this);
3017}
3018
3019template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003020inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003021__val_expr<__indirect_expr<const valarray<_Tp>&> >
3022valarray<_Tp>::operator[](const gslice& __gs) const
3023{
3024 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
3025}
3026
3027template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003028inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003029gslice_array<_Tp>
3030valarray<_Tp>::operator[](const gslice& __gs)
3031{
3032 return gslice_array<value_type>(__gs, *this);
3033}
3034
Howard Hinnant73d21a42010-09-04 23:28:19 +00003035#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003036
3037template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003038inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003039__val_expr<__indirect_expr<const valarray<_Tp>&> >
3040valarray<_Tp>::operator[](gslice&& __gs) const
3041{
3042 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
3043}
3044
3045template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003046inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003047gslice_array<_Tp>
3048valarray<_Tp>::operator[](gslice&& __gs)
3049{
3050 return gslice_array<value_type>(move(__gs), *this);
3051}
3052
Howard Hinnant73d21a42010-09-04 23:28:19 +00003053#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003054
3055template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003056inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003057__val_expr<__mask_expr<const valarray<_Tp>&> >
3058valarray<_Tp>::operator[](const valarray<bool>& __vb) const
3059{
3060 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
3061}
3062
3063template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003064inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003065mask_array<_Tp>
3066valarray<_Tp>::operator[](const valarray<bool>& __vb)
3067{
3068 return mask_array<value_type>(__vb, *this);
3069}
3070
Howard Hinnant73d21a42010-09-04 23:28:19 +00003071#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003072
3073template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003074inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003075__val_expr<__mask_expr<const valarray<_Tp>&> >
3076valarray<_Tp>::operator[](valarray<bool>&& __vb) const
3077{
3078 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
3079}
3080
3081template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003082inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003083mask_array<_Tp>
3084valarray<_Tp>::operator[](valarray<bool>&& __vb)
3085{
3086 return mask_array<value_type>(move(__vb), *this);
3087}
3088
Howard Hinnant73d21a42010-09-04 23:28:19 +00003089#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003090
3091template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003092inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003093__val_expr<__indirect_expr<const valarray<_Tp>&> >
3094valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
3095{
3096 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
3097}
3098
3099template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003100inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003101indirect_array<_Tp>
3102valarray<_Tp>::operator[](const valarray<size_t>& __vs)
3103{
3104 return indirect_array<value_type>(__vs, *this);
3105}
3106
Howard Hinnant73d21a42010-09-04 23:28:19 +00003107#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003108
3109template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003110inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003111__val_expr<__indirect_expr<const valarray<_Tp>&> >
3112valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
3113{
3114 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
3115}
3116
3117template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003118inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003119indirect_array<_Tp>
3120valarray<_Tp>::operator[](valarray<size_t>&& __vs)
3121{
3122 return indirect_array<value_type>(move(__vs), *this);
3123}
3124
Howard Hinnant73d21a42010-09-04 23:28:19 +00003125#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003126
3127template <class _Tp>
3128valarray<_Tp>
3129valarray<_Tp>::operator+() const
3130{
3131 valarray<value_type> __r;
3132 size_t __n = size();
3133 if (__n)
3134 {
3135 __r.__begin_ =
3136 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003137 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003138 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3139 ::new (__r.__end_) value_type(+*__p);
3140 }
3141 return __r;
3142}
3143
3144template <class _Tp>
3145valarray<_Tp>
3146valarray<_Tp>::operator-() const
3147{
3148 valarray<value_type> __r;
3149 size_t __n = size();
3150 if (__n)
3151 {
3152 __r.__begin_ =
3153 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003154 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003155 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3156 ::new (__r.__end_) value_type(-*__p);
3157 }
3158 return __r;
3159}
3160
3161template <class _Tp>
3162valarray<_Tp>
3163valarray<_Tp>::operator~() const
3164{
3165 valarray<value_type> __r;
3166 size_t __n = size();
3167 if (__n)
3168 {
3169 __r.__begin_ =
3170 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003171 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003172 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3173 ::new (__r.__end_) value_type(~*__p);
3174 }
3175 return __r;
3176}
3177
3178template <class _Tp>
3179valarray<bool>
3180valarray<_Tp>::operator!() const
3181{
3182 valarray<bool> __r;
3183 size_t __n = size();
3184 if (__n)
3185 {
3186 __r.__begin_ =
3187 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003188 static_cast<bool*>(_VSTD::__allocate(__n * sizeof(bool)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003189 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3190 ::new (__r.__end_) bool(!*__p);
3191 }
3192 return __r;
3193}
3194
3195template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003196inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003197valarray<_Tp>&
3198valarray<_Tp>::operator*=(const value_type& __x)
3199{
3200 for (value_type* __p = __begin_; __p != __end_; ++__p)
3201 *__p *= __x;
3202 return *this;
3203}
3204
3205template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003206inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003207valarray<_Tp>&
3208valarray<_Tp>::operator/=(const value_type& __x)
3209{
3210 for (value_type* __p = __begin_; __p != __end_; ++__p)
3211 *__p /= __x;
3212 return *this;
3213}
3214
3215template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003216inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003217valarray<_Tp>&
3218valarray<_Tp>::operator%=(const value_type& __x)
3219{
3220 for (value_type* __p = __begin_; __p != __end_; ++__p)
3221 *__p %= __x;
3222 return *this;
3223}
3224
3225template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003226inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003227valarray<_Tp>&
3228valarray<_Tp>::operator+=(const value_type& __x)
3229{
3230 for (value_type* __p = __begin_; __p != __end_; ++__p)
3231 *__p += __x;
3232 return *this;
3233}
3234
3235template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003236inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003237valarray<_Tp>&
3238valarray<_Tp>::operator-=(const value_type& __x)
3239{
3240 for (value_type* __p = __begin_; __p != __end_; ++__p)
3241 *__p -= __x;
3242 return *this;
3243}
3244
3245template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003246inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003247valarray<_Tp>&
3248valarray<_Tp>::operator^=(const value_type& __x)
3249{
3250 for (value_type* __p = __begin_; __p != __end_; ++__p)
3251 *__p ^= __x;
3252 return *this;
3253}
3254
3255template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003256inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003257valarray<_Tp>&
3258valarray<_Tp>::operator&=(const value_type& __x)
3259{
3260 for (value_type* __p = __begin_; __p != __end_; ++__p)
3261 *__p &= __x;
3262 return *this;
3263}
3264
3265template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003266inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003267valarray<_Tp>&
3268valarray<_Tp>::operator|=(const value_type& __x)
3269{
3270 for (value_type* __p = __begin_; __p != __end_; ++__p)
3271 *__p |= __x;
3272 return *this;
3273}
3274
3275template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003276inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003277valarray<_Tp>&
3278valarray<_Tp>::operator<<=(const value_type& __x)
3279{
3280 for (value_type* __p = __begin_; __p != __end_; ++__p)
3281 *__p <<= __x;
3282 return *this;
3283}
3284
3285template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003286inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003287valarray<_Tp>&
3288valarray<_Tp>::operator>>=(const value_type& __x)
3289{
3290 for (value_type* __p = __begin_; __p != __end_; ++__p)
3291 *__p >>= __x;
3292 return *this;
3293}
3294
3295template <class _Tp>
3296template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003297inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003298typename enable_if
3299<
3300 __is_val_expr<_Expr>::value,
3301 valarray<_Tp>&
3302>::type
3303valarray<_Tp>::operator*=(const _Expr& __v)
3304{
3305 size_t __i = 0;
3306 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3307 *__t *= __v[__i];
3308 return *this;
3309}
3310
3311template <class _Tp>
3312template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003313inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003314typename enable_if
3315<
3316 __is_val_expr<_Expr>::value,
3317 valarray<_Tp>&
3318>::type
3319valarray<_Tp>::operator/=(const _Expr& __v)
3320{
3321 size_t __i = 0;
3322 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3323 *__t /= __v[__i];
3324 return *this;
3325}
3326
3327template <class _Tp>
3328template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003329inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003330typename enable_if
3331<
3332 __is_val_expr<_Expr>::value,
3333 valarray<_Tp>&
3334>::type
3335valarray<_Tp>::operator%=(const _Expr& __v)
3336{
3337 size_t __i = 0;
3338 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3339 *__t %= __v[__i];
3340 return *this;
3341}
3342
3343template <class _Tp>
3344template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003345inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003346typename enable_if
3347<
3348 __is_val_expr<_Expr>::value,
3349 valarray<_Tp>&
3350>::type
3351valarray<_Tp>::operator+=(const _Expr& __v)
3352{
3353 size_t __i = 0;
3354 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3355 *__t += __v[__i];
3356 return *this;
3357}
3358
3359template <class _Tp>
3360template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003361inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003362typename enable_if
3363<
3364 __is_val_expr<_Expr>::value,
3365 valarray<_Tp>&
3366>::type
3367valarray<_Tp>::operator-=(const _Expr& __v)
3368{
3369 size_t __i = 0;
3370 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3371 *__t -= __v[__i];
3372 return *this;
3373}
3374
3375template <class _Tp>
3376template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003377inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003378typename enable_if
3379<
3380 __is_val_expr<_Expr>::value,
3381 valarray<_Tp>&
3382>::type
3383valarray<_Tp>::operator^=(const _Expr& __v)
3384{
3385 size_t __i = 0;
3386 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3387 *__t ^= __v[__i];
3388 return *this;
3389}
3390
3391template <class _Tp>
3392template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003393inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003394typename enable_if
3395<
3396 __is_val_expr<_Expr>::value,
3397 valarray<_Tp>&
3398>::type
3399valarray<_Tp>::operator|=(const _Expr& __v)
3400{
3401 size_t __i = 0;
3402 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3403 *__t |= __v[__i];
3404 return *this;
3405}
3406
3407template <class _Tp>
3408template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003409inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003410typename enable_if
3411<
3412 __is_val_expr<_Expr>::value,
3413 valarray<_Tp>&
3414>::type
3415valarray<_Tp>::operator&=(const _Expr& __v)
3416{
3417 size_t __i = 0;
3418 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3419 *__t &= __v[__i];
3420 return *this;
3421}
3422
3423template <class _Tp>
3424template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003425inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003426typename enable_if
3427<
3428 __is_val_expr<_Expr>::value,
3429 valarray<_Tp>&
3430>::type
3431valarray<_Tp>::operator<<=(const _Expr& __v)
3432{
3433 size_t __i = 0;
3434 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3435 *__t <<= __v[__i];
3436 return *this;
3437}
3438
3439template <class _Tp>
3440template <class _Expr>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003441inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003442typename enable_if
3443<
3444 __is_val_expr<_Expr>::value,
3445 valarray<_Tp>&
3446>::type
3447valarray<_Tp>::operator>>=(const _Expr& __v)
3448{
3449 size_t __i = 0;
3450 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3451 *__t >>= __v[__i];
3452 return *this;
3453}
3454
3455template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003456inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003457void
Howard Hinnantbd143082012-07-21 00:51:28 +00003458valarray<_Tp>::swap(valarray& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003459{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003460 _VSTD::swap(__begin_, __v.__begin_);
3461 _VSTD::swap(__end_, __v.__end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003462}
3463
3464template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003465inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003466_Tp
3467valarray<_Tp>::sum() const
3468{
3469 if (__begin_ == __end_)
3470 return value_type();
3471 const value_type* __p = __begin_;
3472 _Tp __r = *__p;
3473 for (++__p; __p != __end_; ++__p)
3474 __r += *__p;
3475 return __r;
3476}
3477
3478template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003479inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003480_Tp
3481valarray<_Tp>::min() const
3482{
3483 if (__begin_ == __end_)
3484 return value_type();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003485 return *_VSTD::min_element(__begin_, __end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003486}
3487
3488template <class _Tp>
Douglas Gregor0855dde2012-05-19 07:14:17 +00003489inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003490_Tp
3491valarray<_Tp>::max() const
3492{
3493 if (__begin_ == __end_)
3494 return value_type();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003495 return *_VSTD::max_element(__begin_, __end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003496}
3497
3498template <class _Tp>
3499valarray<_Tp>
3500valarray<_Tp>::shift(int __i) const
3501{
3502 valarray<value_type> __r;
3503 size_t __n = size();
3504 if (__n)
3505 {
3506 __r.__begin_ =
3507 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003508 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003509 const value_type* __sb;
3510 value_type* __tb;
3511 value_type* __te;
3512 if (__i >= 0)
3513 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003514 __i = _VSTD::min(__i, static_cast<int>(__n));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003515 __sb = __begin_ + __i;
3516 __tb = __r.__begin_;
3517 __te = __r.__begin_ + (__n - __i);
3518 }
3519 else
3520 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003521 __i = _VSTD::min(-__i, static_cast<int>(__n));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003522 __sb = __begin_;
3523 __tb = __r.__begin_ + __i;
3524 __te = __r.__begin_ + __n;
3525 }
3526 for (; __r.__end_ != __tb; ++__r.__end_)
3527 ::new (__r.__end_) value_type();
3528 for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
3529 ::new (__r.__end_) value_type(*__sb);
3530 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
3531 ::new (__r.__end_) value_type();
3532 }
3533 return __r;
3534}
3535
3536template <class _Tp>
3537valarray<_Tp>
3538valarray<_Tp>::cshift(int __i) const
3539{
3540 valarray<value_type> __r;
3541 size_t __n = size();
3542 if (__n)
3543 {
3544 __r.__begin_ =
3545 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003546 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003547 __i %= static_cast<int>(__n);
3548 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
3549 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
3550 ::new (__r.__end_) value_type(*__s);
3551 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
3552 ::new (__r.__end_) value_type(*__s);
3553 }
3554 return __r;
3555}
3556
3557template <class _Tp>
3558valarray<_Tp>
3559valarray<_Tp>::apply(value_type __f(value_type)) const
3560{
3561 valarray<value_type> __r;
3562 size_t __n = size();
3563 if (__n)
3564 {
3565 __r.__begin_ =
3566 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003567 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003568 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3569 ::new (__r.__end_) value_type(__f(*__p));
3570 }
3571 return __r;
3572}
3573
3574template <class _Tp>
3575valarray<_Tp>
3576valarray<_Tp>::apply(value_type __f(const value_type&)) const
3577{
3578 valarray<value_type> __r;
3579 size_t __n = size();
3580 if (__n)
3581 {
3582 __r.__begin_ =
3583 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003584 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003585 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3586 ::new (__r.__end_) value_type(__f(*__p));
3587 }
3588 return __r;
3589}
3590
3591template <class _Tp>
3592void
3593valarray<_Tp>::resize(size_t __n, value_type __x)
3594{
3595 if (__begin_ != nullptr)
3596 {
3597 while (__end_ != __begin_)
3598 (--__end_)->~value_type();
Richard Smith73c1fce2014-06-04 19:54:15 +00003599 _VSTD::__deallocate(__begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003600 __begin_ = __end_ = nullptr;
3601 }
3602 if (__n)
3603 {
Richard Smith73c1fce2014-06-04 19:54:15 +00003604 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003605#ifndef _LIBCPP_NO_EXCEPTIONS
3606 try
3607 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003608#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003609 for (; __n; --__n, ++__end_)
3610 ::new (__end_) value_type(__x);
3611#ifndef _LIBCPP_NO_EXCEPTIONS
3612 }
3613 catch (...)
3614 {
3615 resize(0);
3616 throw;
3617 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003618#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003619 }
3620}
3621
3622template<class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003623inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003624void
Howard Hinnantbd143082012-07-21 00:51:28 +00003625swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003626{
3627 __x.swap(__y);
3628}
3629
3630template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003631inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003632typename enable_if
3633<
3634 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3635 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
3636>::type
3637operator*(const _Expr1& __x, const _Expr2& __y)
3638{
3639 typedef typename _Expr1::value_type value_type;
3640 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
3641 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
3642}
3643
3644template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003645inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003646typename enable_if
3647<
3648 __is_val_expr<_Expr>::value,
3649 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3650 _Expr, __scalar_expr<typename _Expr::value_type> > >
3651>::type
3652operator*(const _Expr& __x, const typename _Expr::value_type& __y)
3653{
3654 typedef typename _Expr::value_type value_type;
3655 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3656 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3657 __x, __scalar_expr<value_type>(__y, __x.size())));
3658}
3659
3660template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003661inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003662typename enable_if
3663<
3664 __is_val_expr<_Expr>::value,
3665 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3666 __scalar_expr<typename _Expr::value_type>, _Expr> >
3667>::type
3668operator*(const typename _Expr::value_type& __x, const _Expr& __y)
3669{
3670 typedef typename _Expr::value_type value_type;
3671 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3672 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3673 __scalar_expr<value_type>(__x, __y.size()), __y));
3674}
3675
3676template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003677inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003678typename enable_if
3679<
3680 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3681 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
3682>::type
3683operator/(const _Expr1& __x, const _Expr2& __y)
3684{
3685 typedef typename _Expr1::value_type value_type;
3686 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
3687 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
3688}
3689
3690template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003691inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003692typename enable_if
3693<
3694 __is_val_expr<_Expr>::value,
3695 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3696 _Expr, __scalar_expr<typename _Expr::value_type> > >
3697>::type
3698operator/(const _Expr& __x, const typename _Expr::value_type& __y)
3699{
3700 typedef typename _Expr::value_type value_type;
3701 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3702 return __val_expr<_Op>(_Op(divides<value_type>(),
3703 __x, __scalar_expr<value_type>(__y, __x.size())));
3704}
3705
3706template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003707inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003708typename enable_if
3709<
3710 __is_val_expr<_Expr>::value,
3711 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3712 __scalar_expr<typename _Expr::value_type>, _Expr> >
3713>::type
3714operator/(const typename _Expr::value_type& __x, const _Expr& __y)
3715{
3716 typedef typename _Expr::value_type value_type;
3717 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3718 return __val_expr<_Op>(_Op(divides<value_type>(),
3719 __scalar_expr<value_type>(__x, __y.size()), __y));
3720}
3721
3722template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003723inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003724typename enable_if
3725<
3726 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3727 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3728>::type
3729operator%(const _Expr1& __x, const _Expr2& __y)
3730{
3731 typedef typename _Expr1::value_type value_type;
3732 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
3733 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
3734}
3735
3736template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003737inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003738typename enable_if
3739<
3740 __is_val_expr<_Expr>::value,
3741 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3742 _Expr, __scalar_expr<typename _Expr::value_type> > >
3743>::type
3744operator%(const _Expr& __x, const typename _Expr::value_type& __y)
3745{
3746 typedef typename _Expr::value_type value_type;
3747 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3748 return __val_expr<_Op>(_Op(modulus<value_type>(),
3749 __x, __scalar_expr<value_type>(__y, __x.size())));
3750}
3751
3752template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003753inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003754typename enable_if
3755<
3756 __is_val_expr<_Expr>::value,
3757 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3758 __scalar_expr<typename _Expr::value_type>, _Expr> >
3759>::type
3760operator%(const typename _Expr::value_type& __x, const _Expr& __y)
3761{
3762 typedef typename _Expr::value_type value_type;
3763 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3764 return __val_expr<_Op>(_Op(modulus<value_type>(),
3765 __scalar_expr<value_type>(__x, __y.size()), __y));
3766}
3767
3768template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003769inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003770typename enable_if
3771<
3772 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3773 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3774>::type
3775operator+(const _Expr1& __x, const _Expr2& __y)
3776{
3777 typedef typename _Expr1::value_type value_type;
3778 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
3779 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
3780}
3781
3782template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003783inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003784typename enable_if
3785<
3786 __is_val_expr<_Expr>::value,
3787 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3788 _Expr, __scalar_expr<typename _Expr::value_type> > >
3789>::type
3790operator+(const _Expr& __x, const typename _Expr::value_type& __y)
3791{
3792 typedef typename _Expr::value_type value_type;
3793 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3794 return __val_expr<_Op>(_Op(plus<value_type>(),
3795 __x, __scalar_expr<value_type>(__y, __x.size())));
3796}
3797
3798template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003799inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003800typename enable_if
3801<
3802 __is_val_expr<_Expr>::value,
3803 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3804 __scalar_expr<typename _Expr::value_type>, _Expr> >
3805>::type
3806operator+(const typename _Expr::value_type& __x, const _Expr& __y)
3807{
3808 typedef typename _Expr::value_type value_type;
3809 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3810 return __val_expr<_Op>(_Op(plus<value_type>(),
3811 __scalar_expr<value_type>(__x, __y.size()), __y));
3812}
3813
3814template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003815inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003816typename enable_if
3817<
3818 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3819 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3820>::type
3821operator-(const _Expr1& __x, const _Expr2& __y)
3822{
3823 typedef typename _Expr1::value_type value_type;
3824 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
3825 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
3826}
3827
3828template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003829inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003830typename enable_if
3831<
3832 __is_val_expr<_Expr>::value,
3833 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3834 _Expr, __scalar_expr<typename _Expr::value_type> > >
3835>::type
3836operator-(const _Expr& __x, const typename _Expr::value_type& __y)
3837{
3838 typedef typename _Expr::value_type value_type;
3839 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3840 return __val_expr<_Op>(_Op(minus<value_type>(),
3841 __x, __scalar_expr<value_type>(__y, __x.size())));
3842}
3843
3844template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003845inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003846typename enable_if
3847<
3848 __is_val_expr<_Expr>::value,
3849 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3850 __scalar_expr<typename _Expr::value_type>, _Expr> >
3851>::type
3852operator-(const typename _Expr::value_type& __x, const _Expr& __y)
3853{
3854 typedef typename _Expr::value_type value_type;
3855 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3856 return __val_expr<_Op>(_Op(minus<value_type>(),
3857 __scalar_expr<value_type>(__x, __y.size()), __y));
3858}
3859
3860template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003861inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003862typename enable_if
3863<
3864 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3865 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
3866>::type
3867operator^(const _Expr1& __x, const _Expr2& __y)
3868{
3869 typedef typename _Expr1::value_type value_type;
3870 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
3871 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
3872}
3873
3874template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003875inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003876typename enable_if
3877<
3878 __is_val_expr<_Expr>::value,
3879 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
3880 _Expr, __scalar_expr<typename _Expr::value_type> > >
3881>::type
3882operator^(const _Expr& __x, const typename _Expr::value_type& __y)
3883{
3884 typedef typename _Expr::value_type value_type;
3885 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3886 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
3887 __x, __scalar_expr<value_type>(__y, __x.size())));
3888}
3889
3890template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003891inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003892typename enable_if
3893<
3894 __is_val_expr<_Expr>::value,
3895 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
3896 __scalar_expr<typename _Expr::value_type>, _Expr> >
3897>::type
3898operator^(const typename _Expr::value_type& __x, const _Expr& __y)
3899{
3900 typedef typename _Expr::value_type value_type;
3901 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3902 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
3903 __scalar_expr<value_type>(__x, __y.size()), __y));
3904}
3905
3906template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003907inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003908typename enable_if
3909<
3910 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3911 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
3912>::type
3913operator&(const _Expr1& __x, const _Expr2& __y)
3914{
3915 typedef typename _Expr1::value_type value_type;
3916 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
3917 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
3918}
3919
3920template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003921inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003922typename enable_if
3923<
3924 __is_val_expr<_Expr>::value,
3925 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
3926 _Expr, __scalar_expr<typename _Expr::value_type> > >
3927>::type
3928operator&(const _Expr& __x, const typename _Expr::value_type& __y)
3929{
3930 typedef typename _Expr::value_type value_type;
3931 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3932 return __val_expr<_Op>(_Op(bit_and<value_type>(),
3933 __x, __scalar_expr<value_type>(__y, __x.size())));
3934}
3935
3936template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003937inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003938typename enable_if
3939<
3940 __is_val_expr<_Expr>::value,
3941 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
3942 __scalar_expr<typename _Expr::value_type>, _Expr> >
3943>::type
3944operator&(const typename _Expr::value_type& __x, const _Expr& __y)
3945{
3946 typedef typename _Expr::value_type value_type;
3947 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3948 return __val_expr<_Op>(_Op(bit_and<value_type>(),
3949 __scalar_expr<value_type>(__x, __y.size()), __y));
3950}
3951
3952template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003953inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003954typename enable_if
3955<
3956 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3957 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
3958>::type
3959operator|(const _Expr1& __x, const _Expr2& __y)
3960{
3961 typedef typename _Expr1::value_type value_type;
3962 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
3963 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
3964}
3965
3966template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003967inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003968typename enable_if
3969<
3970 __is_val_expr<_Expr>::value,
3971 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
3972 _Expr, __scalar_expr<typename _Expr::value_type> > >
3973>::type
3974operator|(const _Expr& __x, const typename _Expr::value_type& __y)
3975{
3976 typedef typename _Expr::value_type value_type;
3977 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3978 return __val_expr<_Op>(_Op(bit_or<value_type>(),
3979 __x, __scalar_expr<value_type>(__y, __x.size())));
3980}
3981
3982template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003983inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003984typename enable_if
3985<
3986 __is_val_expr<_Expr>::value,
3987 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
3988 __scalar_expr<typename _Expr::value_type>, _Expr> >
3989>::type
3990operator|(const typename _Expr::value_type& __x, const _Expr& __y)
3991{
3992 typedef typename _Expr::value_type value_type;
3993 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3994 return __val_expr<_Op>(_Op(bit_or<value_type>(),
3995 __scalar_expr<value_type>(__x, __y.size()), __y));
3996}
3997
3998template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003999inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004000typename enable_if
4001<
4002 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4003 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
4004>::type
4005operator<<(const _Expr1& __x, const _Expr2& __y)
4006{
4007 typedef typename _Expr1::value_type value_type;
4008 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
4009 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
4010}
4011
4012template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004013inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004014typename enable_if
4015<
4016 __is_val_expr<_Expr>::value,
4017 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4018 _Expr, __scalar_expr<typename _Expr::value_type> > >
4019>::type
4020operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
4021{
4022 typedef typename _Expr::value_type value_type;
4023 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4024 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4025 __x, __scalar_expr<value_type>(__y, __x.size())));
4026}
4027
4028template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004029inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004030typename enable_if
4031<
4032 __is_val_expr<_Expr>::value,
4033 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4034 __scalar_expr<typename _Expr::value_type>, _Expr> >
4035>::type
4036operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
4037{
4038 typedef typename _Expr::value_type value_type;
4039 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4040 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4041 __scalar_expr<value_type>(__x, __y.size()), __y));
4042}
4043
4044template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004045inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004046typename enable_if
4047<
4048 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4049 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
4050>::type
4051operator>>(const _Expr1& __x, const _Expr2& __y)
4052{
4053 typedef typename _Expr1::value_type value_type;
4054 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
4055 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
4056}
4057
4058template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004059inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004060typename enable_if
4061<
4062 __is_val_expr<_Expr>::value,
4063 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4064 _Expr, __scalar_expr<typename _Expr::value_type> > >
4065>::type
4066operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
4067{
4068 typedef typename _Expr::value_type value_type;
4069 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4070 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4071 __x, __scalar_expr<value_type>(__y, __x.size())));
4072}
4073
4074template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004075inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004076typename enable_if
4077<
4078 __is_val_expr<_Expr>::value,
4079 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4080 __scalar_expr<typename _Expr::value_type>, _Expr> >
4081>::type
4082operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
4083{
4084 typedef typename _Expr::value_type value_type;
4085 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4086 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4087 __scalar_expr<value_type>(__x, __y.size()), __y));
4088}
4089
4090template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004091inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004092typename enable_if
4093<
4094 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4095 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4096>::type
4097operator&&(const _Expr1& __x, const _Expr2& __y)
4098{
4099 typedef typename _Expr1::value_type value_type;
4100 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
4101 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
4102}
4103
4104template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004105inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004106typename enable_if
4107<
4108 __is_val_expr<_Expr>::value,
4109 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4110 _Expr, __scalar_expr<typename _Expr::value_type> > >
4111>::type
4112operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
4113{
4114 typedef typename _Expr::value_type value_type;
4115 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4116 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4117 __x, __scalar_expr<value_type>(__y, __x.size())));
4118}
4119
4120template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004121inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004122typename enable_if
4123<
4124 __is_val_expr<_Expr>::value,
4125 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4126 __scalar_expr<typename _Expr::value_type>, _Expr> >
4127>::type
4128operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
4129{
4130 typedef typename _Expr::value_type value_type;
4131 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4132 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4133 __scalar_expr<value_type>(__x, __y.size()), __y));
4134}
4135
4136template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004137inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004138typename enable_if
4139<
4140 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4141 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4142>::type
4143operator||(const _Expr1& __x, const _Expr2& __y)
4144{
4145 typedef typename _Expr1::value_type value_type;
4146 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
4147 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
4148}
4149
4150template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004151inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004152typename enable_if
4153<
4154 __is_val_expr<_Expr>::value,
4155 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4156 _Expr, __scalar_expr<typename _Expr::value_type> > >
4157>::type
4158operator||(const _Expr& __x, const typename _Expr::value_type& __y)
4159{
4160 typedef typename _Expr::value_type value_type;
4161 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4162 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4163 __x, __scalar_expr<value_type>(__y, __x.size())));
4164}
4165
4166template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004167inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004168typename enable_if
4169<
4170 __is_val_expr<_Expr>::value,
4171 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4172 __scalar_expr<typename _Expr::value_type>, _Expr> >
4173>::type
4174operator||(const typename _Expr::value_type& __x, const _Expr& __y)
4175{
4176 typedef typename _Expr::value_type value_type;
4177 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4178 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4179 __scalar_expr<value_type>(__x, __y.size()), __y));
4180}
4181
4182template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004183inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004184typename enable_if
4185<
4186 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4187 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4188>::type
4189operator==(const _Expr1& __x, const _Expr2& __y)
4190{
4191 typedef typename _Expr1::value_type value_type;
4192 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
4193 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
4194}
4195
4196template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004197inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004198typename enable_if
4199<
4200 __is_val_expr<_Expr>::value,
4201 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4202 _Expr, __scalar_expr<typename _Expr::value_type> > >
4203>::type
4204operator==(const _Expr& __x, const typename _Expr::value_type& __y)
4205{
4206 typedef typename _Expr::value_type value_type;
4207 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4208 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4209 __x, __scalar_expr<value_type>(__y, __x.size())));
4210}
4211
4212template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004213inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004214typename enable_if
4215<
4216 __is_val_expr<_Expr>::value,
4217 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4218 __scalar_expr<typename _Expr::value_type>, _Expr> >
4219>::type
4220operator==(const typename _Expr::value_type& __x, const _Expr& __y)
4221{
4222 typedef typename _Expr::value_type value_type;
4223 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4224 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4225 __scalar_expr<value_type>(__x, __y.size()), __y));
4226}
4227
4228template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004229inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004230typename enable_if
4231<
4232 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4233 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4234>::type
4235operator!=(const _Expr1& __x, const _Expr2& __y)
4236{
4237 typedef typename _Expr1::value_type value_type;
4238 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
4239 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
4240}
4241
4242template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004243inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004244typename enable_if
4245<
4246 __is_val_expr<_Expr>::value,
4247 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4248 _Expr, __scalar_expr<typename _Expr::value_type> > >
4249>::type
4250operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
4251{
4252 typedef typename _Expr::value_type value_type;
4253 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4254 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4255 __x, __scalar_expr<value_type>(__y, __x.size())));
4256}
4257
4258template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004259inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004260typename enable_if
4261<
4262 __is_val_expr<_Expr>::value,
4263 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4264 __scalar_expr<typename _Expr::value_type>, _Expr> >
4265>::type
4266operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
4267{
4268 typedef typename _Expr::value_type value_type;
4269 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4270 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4271 __scalar_expr<value_type>(__x, __y.size()), __y));
4272}
4273
4274template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004275inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004276typename enable_if
4277<
4278 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4279 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
4280>::type
4281operator<(const _Expr1& __x, const _Expr2& __y)
4282{
4283 typedef typename _Expr1::value_type value_type;
4284 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
4285 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
4286}
4287
4288template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004289inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004290typename enable_if
4291<
4292 __is_val_expr<_Expr>::value,
4293 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4294 _Expr, __scalar_expr<typename _Expr::value_type> > >
4295>::type
4296operator<(const _Expr& __x, const typename _Expr::value_type& __y)
4297{
4298 typedef typename _Expr::value_type value_type;
4299 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4300 return __val_expr<_Op>(_Op(less<value_type>(),
4301 __x, __scalar_expr<value_type>(__y, __x.size())));
4302}
4303
4304template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004305inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004306typename enable_if
4307<
4308 __is_val_expr<_Expr>::value,
4309 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4310 __scalar_expr<typename _Expr::value_type>, _Expr> >
4311>::type
4312operator<(const typename _Expr::value_type& __x, const _Expr& __y)
4313{
4314 typedef typename _Expr::value_type value_type;
4315 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4316 return __val_expr<_Op>(_Op(less<value_type>(),
4317 __scalar_expr<value_type>(__x, __y.size()), __y));
4318}
4319
4320template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004321inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004322typename enable_if
4323<
4324 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4325 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
4326>::type
4327operator>(const _Expr1& __x, const _Expr2& __y)
4328{
4329 typedef typename _Expr1::value_type value_type;
4330 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
4331 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
4332}
4333
4334template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004335inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004336typename enable_if
4337<
4338 __is_val_expr<_Expr>::value,
4339 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4340 _Expr, __scalar_expr<typename _Expr::value_type> > >
4341>::type
4342operator>(const _Expr& __x, const typename _Expr::value_type& __y)
4343{
4344 typedef typename _Expr::value_type value_type;
4345 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4346 return __val_expr<_Op>(_Op(greater<value_type>(),
4347 __x, __scalar_expr<value_type>(__y, __x.size())));
4348}
4349
4350template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004351inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004352typename enable_if
4353<
4354 __is_val_expr<_Expr>::value,
4355 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4356 __scalar_expr<typename _Expr::value_type>, _Expr> >
4357>::type
4358operator>(const typename _Expr::value_type& __x, const _Expr& __y)
4359{
4360 typedef typename _Expr::value_type value_type;
4361 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4362 return __val_expr<_Op>(_Op(greater<value_type>(),
4363 __scalar_expr<value_type>(__x, __y.size()), __y));
4364}
4365
4366template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004367inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004368typename enable_if
4369<
4370 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4371 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4372>::type
4373operator<=(const _Expr1& __x, const _Expr2& __y)
4374{
4375 typedef typename _Expr1::value_type value_type;
4376 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
4377 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
4378}
4379
4380template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004381inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004382typename enable_if
4383<
4384 __is_val_expr<_Expr>::value,
4385 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4386 _Expr, __scalar_expr<typename _Expr::value_type> > >
4387>::type
4388operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
4389{
4390 typedef typename _Expr::value_type value_type;
4391 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4392 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4393 __x, __scalar_expr<value_type>(__y, __x.size())));
4394}
4395
4396template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004397inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004398typename enable_if
4399<
4400 __is_val_expr<_Expr>::value,
4401 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4402 __scalar_expr<typename _Expr::value_type>, _Expr> >
4403>::type
4404operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
4405{
4406 typedef typename _Expr::value_type value_type;
4407 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4408 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4409 __scalar_expr<value_type>(__x, __y.size()), __y));
4410}
4411
4412template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004413inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004414typename enable_if
4415<
4416 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4417 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4418>::type
4419operator>=(const _Expr1& __x, const _Expr2& __y)
4420{
4421 typedef typename _Expr1::value_type value_type;
4422 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
4423 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
4424}
4425
4426template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004427inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004428typename enable_if
4429<
4430 __is_val_expr<_Expr>::value,
4431 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4432 _Expr, __scalar_expr<typename _Expr::value_type> > >
4433>::type
4434operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
4435{
4436 typedef typename _Expr::value_type value_type;
4437 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4438 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4439 __x, __scalar_expr<value_type>(__y, __x.size())));
4440}
4441
4442template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004443inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004444typename enable_if
4445<
4446 __is_val_expr<_Expr>::value,
4447 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4448 __scalar_expr<typename _Expr::value_type>, _Expr> >
4449>::type
4450operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
4451{
4452 typedef typename _Expr::value_type value_type;
4453 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4454 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4455 __scalar_expr<value_type>(__x, __y.size()), __y));
4456}
4457
4458template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004459inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004460typename enable_if
4461<
4462 __is_val_expr<_Expr>::value,
4463 __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
4464>::type
4465abs(const _Expr& __x)
4466{
4467 typedef typename _Expr::value_type value_type;
4468 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
4469 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
4470}
4471
4472template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004473inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004474typename enable_if
4475<
4476 __is_val_expr<_Expr>::value,
4477 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
4478>::type
4479acos(const _Expr& __x)
4480{
4481 typedef typename _Expr::value_type value_type;
4482 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
4483 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
4484}
4485
4486template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004487inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004488typename enable_if
4489<
4490 __is_val_expr<_Expr>::value,
4491 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
4492>::type
4493asin(const _Expr& __x)
4494{
4495 typedef typename _Expr::value_type value_type;
4496 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
4497 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
4498}
4499
4500template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004501inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004502typename enable_if
4503<
4504 __is_val_expr<_Expr>::value,
4505 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
4506>::type
4507atan(const _Expr& __x)
4508{
4509 typedef typename _Expr::value_type value_type;
4510 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
4511 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
4512}
4513
4514template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004515inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004516typename enable_if
4517<
4518 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4519 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4520>::type
4521atan2(const _Expr1& __x, const _Expr2& __y)
4522{
4523 typedef typename _Expr1::value_type value_type;
4524 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
4525 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
4526}
4527
4528template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004529inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004530typename enable_if
4531<
4532 __is_val_expr<_Expr>::value,
4533 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4534 _Expr, __scalar_expr<typename _Expr::value_type> > >
4535>::type
4536atan2(const _Expr& __x, const typename _Expr::value_type& __y)
4537{
4538 typedef typename _Expr::value_type value_type;
4539 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4540 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4541 __x, __scalar_expr<value_type>(__y, __x.size())));
4542}
4543
4544template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004545inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004546typename enable_if
4547<
4548 __is_val_expr<_Expr>::value,
4549 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4550 __scalar_expr<typename _Expr::value_type>, _Expr> >
4551>::type
4552atan2(const typename _Expr::value_type& __x, const _Expr& __y)
4553{
4554 typedef typename _Expr::value_type value_type;
4555 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4556 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4557 __scalar_expr<value_type>(__x, __y.size()), __y));
4558}
4559
4560template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004561inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004562typename enable_if
4563<
4564 __is_val_expr<_Expr>::value,
4565 __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
4566>::type
4567cos(const _Expr& __x)
4568{
4569 typedef typename _Expr::value_type value_type;
4570 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
4571 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
4572}
4573
4574template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004575inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004576typename enable_if
4577<
4578 __is_val_expr<_Expr>::value,
4579 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
4580>::type
4581cosh(const _Expr& __x)
4582{
4583 typedef typename _Expr::value_type value_type;
4584 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
4585 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
4586}
4587
4588template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004589inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004590typename enable_if
4591<
4592 __is_val_expr<_Expr>::value,
4593 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
4594>::type
4595exp(const _Expr& __x)
4596{
4597 typedef typename _Expr::value_type value_type;
4598 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
4599 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
4600}
4601
4602template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004603inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004604typename enable_if
4605<
4606 __is_val_expr<_Expr>::value,
4607 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
4608>::type
4609log(const _Expr& __x)
4610{
4611 typedef typename _Expr::value_type value_type;
4612 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
4613 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
4614}
4615
4616template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004617inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004618typename enable_if
4619<
4620 __is_val_expr<_Expr>::value,
4621 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
4622>::type
4623log10(const _Expr& __x)
4624{
4625 typedef typename _Expr::value_type value_type;
4626 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
4627 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
4628}
4629
4630template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004631inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004632typename enable_if
4633<
4634 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4635 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4636>::type
4637pow(const _Expr1& __x, const _Expr2& __y)
4638{
4639 typedef typename _Expr1::value_type value_type;
4640 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
4641 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
4642}
4643
4644template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004645inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004646typename enable_if
4647<
4648 __is_val_expr<_Expr>::value,
4649 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4650 _Expr, __scalar_expr<typename _Expr::value_type> > >
4651>::type
4652pow(const _Expr& __x, const typename _Expr::value_type& __y)
4653{
4654 typedef typename _Expr::value_type value_type;
4655 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4656 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4657 __x, __scalar_expr<value_type>(__y, __x.size())));
4658}
4659
4660template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004661inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004662typename enable_if
4663<
4664 __is_val_expr<_Expr>::value,
4665 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4666 __scalar_expr<typename _Expr::value_type>, _Expr> >
4667>::type
4668pow(const typename _Expr::value_type& __x, const _Expr& __y)
4669{
4670 typedef typename _Expr::value_type value_type;
4671 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4672 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4673 __scalar_expr<value_type>(__x, __y.size()), __y));
4674}
4675
4676template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004677inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004678typename enable_if
4679<
4680 __is_val_expr<_Expr>::value,
4681 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
4682>::type
4683sin(const _Expr& __x)
4684{
4685 typedef typename _Expr::value_type value_type;
4686 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
4687 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
4688}
4689
4690template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004691inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004692typename enable_if
4693<
4694 __is_val_expr<_Expr>::value,
4695 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
4696>::type
4697sinh(const _Expr& __x)
4698{
4699 typedef typename _Expr::value_type value_type;
4700 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
4701 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
4702}
4703
4704template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004705inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004706typename enable_if
4707<
4708 __is_val_expr<_Expr>::value,
4709 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
4710>::type
4711sqrt(const _Expr& __x)
4712{
4713 typedef typename _Expr::value_type value_type;
4714 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
4715 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
4716}
4717
4718template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004719inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004720typename enable_if
4721<
4722 __is_val_expr<_Expr>::value,
4723 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
4724>::type
4725tan(const _Expr& __x)
4726{
4727 typedef typename _Expr::value_type value_type;
4728 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
4729 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
4730}
4731
4732template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004733inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004734typename enable_if
4735<
4736 __is_val_expr<_Expr>::value,
4737 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
4738>::type
4739tanh(const _Expr& __x)
4740{
4741 typedef typename _Expr::value_type value_type;
4742 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
4743 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
4744}
4745
4746template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004747inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004748_Tp*
4749begin(valarray<_Tp>& __v)
4750{
4751 return __v.__begin_;
4752}
4753
4754template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004755inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004756const _Tp*
4757begin(const valarray<_Tp>& __v)
4758{
4759 return __v.__begin_;
4760}
4761
4762template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004763inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004764_Tp*
4765end(valarray<_Tp>& __v)
4766{
4767 return __v.__end_;
4768}
4769
4770template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004771inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004772const _Tp*
4773end(const valarray<_Tp>& __v)
4774{
4775 return __v.__end_;
4776}
4777
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004778_LIBCPP_END_NAMESPACE_STD
4779
4780#endif // _LIBCPP_VALARRAY