blob: f0f1f62a1db844ce9e0ca706513d09f4d024f471 [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
Eric Fiselierc3589a82017-01-04 23:56:00 +0000358template<class _Tp> class _LIBCPP_TEMPLATE_VIS valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000359
Eric Fiselierc3589a82017-01-04 23:56:00 +0000360class _LIBCPP_TEMPLATE_VIS 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
Eric Fiselierc3589a82017-01-04 23:56:00 +0000385template <class _Tp> class _LIBCPP_TEMPLATE_VIS slice_array;
Howard Hinnant83eade62013-03-06 23:30:19 +0000386class _LIBCPP_TYPE_VIS gslice;
Eric Fiselierc3589a82017-01-04 23:56:00 +0000387template <class _Tp> class _LIBCPP_TEMPLATE_VIS gslice_array;
388template <class _Tp> class _LIBCPP_TEMPLATE_VIS mask_array;
389template <class _Tp> class _LIBCPP_TEMPLATE_VIS 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
Eric Fiselierc3589a82017-01-04 23:56:00 +0000675 template <class> friend class _LIBCPP_TEMPLATE_VIS 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>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000790class _LIBCPP_TEMPLATE_VIS 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) {}
Eric Fiselierb6a049f2016-09-16 00:13:55 +0000804 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
805 explicit valarray(size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000806 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor0855dde2012-05-19 07:14:17 +0000807 valarray(const value_type& __x, size_t __n);
808 valarray(const value_type* __p, size_t __n);
809 valarray(const valarray& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000810#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd143082012-07-21 00:51:28 +0000812 valarray(valarray&& __v) _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000813#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000814#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Douglas Gregor0855dde2012-05-19 07:14:17 +0000815 valarray(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +0000816#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Douglas Gregor0855dde2012-05-19 07:14:17 +0000817 valarray(const slice_array<value_type>& __sa);
818 valarray(const gslice_array<value_type>& __ga);
819 valarray(const mask_array<value_type>& __ma);
820 valarray(const indirect_array<value_type>& __ia);
Eric Fiselierb6a049f2016-09-16 00:13:55 +0000821 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Douglas Gregor0855dde2012-05-19 07:14:17 +0000822 ~valarray();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000823
824 // assignment:
Douglas Gregor0855dde2012-05-19 07:14:17 +0000825 valarray& operator=(const valarray& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000826#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd143082012-07-21 00:51:28 +0000828 valarray& operator=(valarray&& __v) _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000829#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000830#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000831 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor0855dde2012-05-19 07:14:17 +0000832 valarray& operator=(initializer_list<value_type>);
Howard Hinnante3e32912011-08-12 21:56:02 +0000833#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000834 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor0855dde2012-05-19 07:14:17 +0000835 valarray& operator=(const value_type& __x);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000837 valarray& operator=(const slice_array<value_type>& __sa);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000839 valarray& operator=(const gslice_array<value_type>& __ga);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000841 valarray& operator=(const mask_array<value_type>& __ma);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000842 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000843 valarray& operator=(const indirect_array<value_type>& __ia);
Howard Hinnantdb866632011-07-27 23:19:59 +0000844 template <class _ValExpr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000845 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantdb866632011-07-27 23:19:59 +0000846 valarray& operator=(const __val_expr<_ValExpr>& __v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000847
848 // element access:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000849 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000850 const value_type& operator[](size_t __i) const {return __begin_[__i];}
851
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000852 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000853 value_type& operator[](size_t __i) {return __begin_[__i];}
854
855 // subset operations:
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000857 __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000859 slice_array<value_type> operator[](slice __s);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000861 __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000862 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000863 gslice_array<value_type> operator[](const gslice& __gs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000864#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000866 __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000868 gslice_array<value_type> operator[](gslice&& __gs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000869#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000871 __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000872 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000873 mask_array<value_type> operator[](const valarray<bool>& __vb);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000874#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000876 __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000877 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000878 mask_array<value_type> operator[](valarray<bool>&& __vb);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000879#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000881 __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000882 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000883 indirect_array<value_type> operator[](const valarray<size_t>& __vs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000884#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000886 __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000888 indirect_array<value_type> operator[](valarray<size_t>&& __vs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000889#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000890
891 // unary operators:
Douglas Gregor0855dde2012-05-19 07:14:17 +0000892 valarray operator+() const;
893 valarray operator-() const;
894 valarray operator~() const;
895 valarray<bool> operator!() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896
897 // computed assignment:
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899 valarray& operator*= (const value_type& __x);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000901 valarray& operator/= (const value_type& __x);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000903 valarray& operator%= (const value_type& __x);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000904 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000905 valarray& operator+= (const value_type& __x);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000907 valarray& operator-= (const value_type& __x);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000909 valarray& operator^= (const value_type& __x);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000911 valarray& operator&= (const value_type& __x);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000912 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000913 valarray& operator|= (const value_type& __x);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000915 valarray& operator<<=(const value_type& __x);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000916 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000917 valarray& operator>>=(const value_type& __x);
918
919 template <class _Expr>
920 typename enable_if
921 <
922 __is_val_expr<_Expr>::value,
923 valarray&
924 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000925 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000926 operator*= (const _Expr& __v);
927
928 template <class _Expr>
929 typename enable_if
930 <
931 __is_val_expr<_Expr>::value,
932 valarray&
933 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000934 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000935 operator/= (const _Expr& __v);
936
937 template <class _Expr>
938 typename enable_if
939 <
940 __is_val_expr<_Expr>::value,
941 valarray&
942 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000943 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000944 operator%= (const _Expr& __v);
945
946 template <class _Expr>
947 typename enable_if
948 <
949 __is_val_expr<_Expr>::value,
950 valarray&
951 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000952 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000953 operator+= (const _Expr& __v);
954
955 template <class _Expr>
956 typename enable_if
957 <
958 __is_val_expr<_Expr>::value,
959 valarray&
960 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000961 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000962 operator-= (const _Expr& __v);
963
964 template <class _Expr>
965 typename enable_if
966 <
967 __is_val_expr<_Expr>::value,
968 valarray&
969 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000970 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000971 operator^= (const _Expr& __v);
972
973 template <class _Expr>
974 typename enable_if
975 <
976 __is_val_expr<_Expr>::value,
977 valarray&
978 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000979 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000980 operator|= (const _Expr& __v);
981
982 template <class _Expr>
983 typename enable_if
984 <
985 __is_val_expr<_Expr>::value,
986 valarray&
987 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000988 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000989 operator&= (const _Expr& __v);
990
991 template <class _Expr>
992 typename enable_if
993 <
994 __is_val_expr<_Expr>::value,
995 valarray&
996 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000997 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000998 operator<<= (const _Expr& __v);
999
1000 template <class _Expr>
1001 typename enable_if
1002 <
1003 __is_val_expr<_Expr>::value,
1004 valarray&
1005 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001007 operator>>= (const _Expr& __v);
1008
1009 // member functions:
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001010 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd143082012-07-21 00:51:28 +00001011 void swap(valarray& __v) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001012
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001013 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001014 size_t size() const {return static_cast<size_t>(__end_ - __begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001015
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001016 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor0855dde2012-05-19 07:14:17 +00001017 value_type sum() const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001018 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor0855dde2012-05-19 07:14:17 +00001019 value_type min() const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001020 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor0855dde2012-05-19 07:14:17 +00001021 value_type max() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001022
Douglas Gregor0855dde2012-05-19 07:14:17 +00001023 valarray shift (int __i) const;
1024 valarray cshift(int __i) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001025 valarray apply(value_type __f(value_type)) const;
1026 valarray apply(value_type __f(const value_type&)) const;
1027 void resize(size_t __n, value_type __x = value_type());
1028
1029private:
Eric Fiselierc3589a82017-01-04 23:56:00 +00001030 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
1031 template <class> friend class _LIBCPP_TEMPLATE_VIS slice_array;
1032 template <class> friend class _LIBCPP_TEMPLATE_VIS gslice_array;
1033 template <class> friend class _LIBCPP_TEMPLATE_VIS mask_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001034 template <class> friend class __mask_expr;
Eric Fiselierc3589a82017-01-04 23:56:00 +00001035 template <class> friend class _LIBCPP_TEMPLATE_VIS indirect_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001036 template <class> friend class __indirect_expr;
1037 template <class> friend class __val_expr;
1038
1039 template <class _Up>
1040 friend
1041 _Up*
1042 begin(valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +00001043
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001044 template <class _Up>
1045 friend
1046 const _Up*
1047 begin(const valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +00001048
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001049 template <class _Up>
1050 friend
1051 _Up*
1052 end(valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +00001053
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001054 template <class _Up>
1055 friend
1056 const _Up*
1057 end(const valarray<_Up>& __v);
1058};
1059
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001060_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::valarray(size_t))
1061_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::~valarray())
1062_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void valarray<size_t>::resize(size_t, size_t))
1063
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001064template <class _Op, class _Tp>
1065struct _UnaryOp<_Op, valarray<_Tp> >
1066{
1067 typedef typename _Op::result_type result_type;
1068 typedef _Tp value_type;
1069
1070 _Op __op_;
1071 const valarray<_Tp>& __a0_;
1072
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001073 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001074 _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
1075
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001076 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001077 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
1078
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001079 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001080 size_t size() const {return __a0_.size();}
1081};
1082
1083template <class _Op, class _Tp, class _A1>
1084struct _BinaryOp<_Op, valarray<_Tp>, _A1>
1085{
1086 typedef typename _Op::result_type result_type;
1087 typedef _Tp value_type;
1088
1089 _Op __op_;
1090 const valarray<_Tp>& __a0_;
1091 _A1 __a1_;
1092
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001094 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
1095 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1096
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001098 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1099
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001101 size_t size() const {return __a0_.size();}
1102};
1103
1104template <class _Op, class _A0, class _Tp>
1105struct _BinaryOp<_Op, _A0, valarray<_Tp> >
1106{
1107 typedef typename _Op::result_type result_type;
1108 typedef _Tp value_type;
1109
1110 _Op __op_;
1111 _A0 __a0_;
1112 const valarray<_Tp>& __a1_;
1113
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001114 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001115 _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
1116 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1117
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001118 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001119 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1120
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001121 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001122 size_t size() const {return __a0_.size();}
1123};
1124
1125template <class _Op, class _Tp>
1126struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> >
1127{
1128 typedef typename _Op::result_type result_type;
1129 typedef _Tp value_type;
1130
1131 _Op __op_;
1132 const valarray<_Tp>& __a0_;
1133 const valarray<_Tp>& __a1_;
1134
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001136 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
1137 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1138
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001139 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001140 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1141
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001142 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001143 size_t size() const {return __a0_.size();}
1144};
1145
1146// slice_array
1147
1148template <class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +00001149class _LIBCPP_TEMPLATE_VIS slice_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001150{
1151public:
1152 typedef _Tp value_type;
1153
1154private:
1155 value_type* __vp_;
1156 size_t __size_;
1157 size_t __stride_;
1158
1159public:
1160 template <class _Expr>
1161 typename enable_if
1162 <
1163 __is_val_expr<_Expr>::value,
1164 void
1165 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001166 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001167 operator=(const _Expr& __v) const;
1168
1169 template <class _Expr>
1170 typename enable_if
1171 <
1172 __is_val_expr<_Expr>::value,
1173 void
1174 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001175 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001176 operator*=(const _Expr& __v) const;
1177
1178 template <class _Expr>
1179 typename enable_if
1180 <
1181 __is_val_expr<_Expr>::value,
1182 void
1183 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001184 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001185 operator/=(const _Expr& __v) const;
1186
1187 template <class _Expr>
1188 typename enable_if
1189 <
1190 __is_val_expr<_Expr>::value,
1191 void
1192 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001193 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001194 operator%=(const _Expr& __v) const;
1195
1196 template <class _Expr>
1197 typename enable_if
1198 <
1199 __is_val_expr<_Expr>::value,
1200 void
1201 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001202 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001203 operator+=(const _Expr& __v) const;
1204
1205 template <class _Expr>
1206 typename enable_if
1207 <
1208 __is_val_expr<_Expr>::value,
1209 void
1210 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001211 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001212 operator-=(const _Expr& __v) const;
1213
1214 template <class _Expr>
1215 typename enable_if
1216 <
1217 __is_val_expr<_Expr>::value,
1218 void
1219 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001220 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001221 operator^=(const _Expr& __v) const;
1222
1223 template <class _Expr>
1224 typename enable_if
1225 <
1226 __is_val_expr<_Expr>::value,
1227 void
1228 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001229 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001230 operator&=(const _Expr& __v) const;
1231
1232 template <class _Expr>
1233 typename enable_if
1234 <
1235 __is_val_expr<_Expr>::value,
1236 void
1237 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001238 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001239 operator|=(const _Expr& __v) const;
1240
1241 template <class _Expr>
1242 typename enable_if
1243 <
1244 __is_val_expr<_Expr>::value,
1245 void
1246 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001247 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001248 operator<<=(const _Expr& __v) const;
1249
1250 template <class _Expr>
1251 typename enable_if
1252 <
1253 __is_val_expr<_Expr>::value,
1254 void
1255 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001256 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001257 operator>>=(const _Expr& __v) const;
1258
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001259 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001260 const slice_array& operator=(const slice_array& __sa) const;
1261
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001262 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001263 void operator=(const value_type& __x) const;
1264
1265private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001266 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001267 slice_array(const slice& __sl, const valarray<value_type>& __v)
1268 : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())),
1269 __size_(__sl.size()),
1270 __stride_(__sl.stride())
1271 {}
1272
1273 template <class> friend class valarray;
1274 template <class> friend class sliceExpr;
1275};
1276
1277template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001278inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001279const slice_array<_Tp>&
1280slice_array<_Tp>::operator=(const slice_array& __sa) const
1281{
1282 value_type* __t = __vp_;
1283 const value_type* __s = __sa.__vp_;
1284 for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
1285 *__t = *__s;
Eric Fiselierf4124612014-08-12 00:06:58 +00001286 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001287}
1288
1289template <class _Tp>
1290template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001291inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001292typename enable_if
1293<
1294 __is_val_expr<_Expr>::value,
1295 void
1296>::type
1297slice_array<_Tp>::operator=(const _Expr& __v) const
1298{
1299 value_type* __t = __vp_;
1300 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1301 *__t = __v[__i];
1302}
1303
1304template <class _Tp>
1305template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001306inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001307typename enable_if
1308<
1309 __is_val_expr<_Expr>::value,
1310 void
1311>::type
1312slice_array<_Tp>::operator*=(const _Expr& __v) const
1313{
1314 value_type* __t = __vp_;
1315 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1316 *__t *= __v[__i];
1317}
1318
1319template <class _Tp>
1320template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001321inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001322typename enable_if
1323<
1324 __is_val_expr<_Expr>::value,
1325 void
1326>::type
1327slice_array<_Tp>::operator/=(const _Expr& __v) const
1328{
1329 value_type* __t = __vp_;
1330 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1331 *__t /= __v[__i];
1332}
1333
1334template <class _Tp>
1335template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001336inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001337typename enable_if
1338<
1339 __is_val_expr<_Expr>::value,
1340 void
1341>::type
1342slice_array<_Tp>::operator%=(const _Expr& __v) const
1343{
1344 value_type* __t = __vp_;
1345 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1346 *__t %= __v[__i];
1347}
1348
1349template <class _Tp>
1350template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001351inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001352typename enable_if
1353<
1354 __is_val_expr<_Expr>::value,
1355 void
1356>::type
1357slice_array<_Tp>::operator+=(const _Expr& __v) const
1358{
1359 value_type* __t = __vp_;
1360 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1361 *__t += __v[__i];
1362}
1363
1364template <class _Tp>
1365template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001366inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001367typename enable_if
1368<
1369 __is_val_expr<_Expr>::value,
1370 void
1371>::type
1372slice_array<_Tp>::operator-=(const _Expr& __v) const
1373{
1374 value_type* __t = __vp_;
1375 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1376 *__t -= __v[__i];
1377}
1378
1379template <class _Tp>
1380template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001381inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001382typename enable_if
1383<
1384 __is_val_expr<_Expr>::value,
1385 void
1386>::type
1387slice_array<_Tp>::operator^=(const _Expr& __v) const
1388{
1389 value_type* __t = __vp_;
1390 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1391 *__t ^= __v[__i];
1392}
1393
1394template <class _Tp>
1395template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001396inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001397typename enable_if
1398<
1399 __is_val_expr<_Expr>::value,
1400 void
1401>::type
1402slice_array<_Tp>::operator&=(const _Expr& __v) const
1403{
1404 value_type* __t = __vp_;
1405 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1406 *__t &= __v[__i];
1407}
1408
1409template <class _Tp>
1410template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001411inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001412typename enable_if
1413<
1414 __is_val_expr<_Expr>::value,
1415 void
1416>::type
1417slice_array<_Tp>::operator|=(const _Expr& __v) const
1418{
1419 value_type* __t = __vp_;
1420 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1421 *__t |= __v[__i];
1422}
1423
1424template <class _Tp>
1425template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001426inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001427typename enable_if
1428<
1429 __is_val_expr<_Expr>::value,
1430 void
1431>::type
1432slice_array<_Tp>::operator<<=(const _Expr& __v) const
1433{
1434 value_type* __t = __vp_;
1435 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1436 *__t <<= __v[__i];
1437}
1438
1439template <class _Tp>
1440template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001441inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001442typename enable_if
1443<
1444 __is_val_expr<_Expr>::value,
1445 void
1446>::type
1447slice_array<_Tp>::operator>>=(const _Expr& __v) const
1448{
1449 value_type* __t = __vp_;
1450 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1451 *__t >>= __v[__i];
1452}
1453
1454template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001455inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001456void
1457slice_array<_Tp>::operator=(const value_type& __x) const
1458{
1459 value_type* __t = __vp_;
1460 for (size_t __n = __size_; __n; --__n, __t += __stride_)
1461 *__t = __x;
1462}
1463
1464// gslice
1465
Howard Hinnant83eade62013-03-06 23:30:19 +00001466class _LIBCPP_TYPE_VIS gslice
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001467{
1468 valarray<size_t> __size_;
1469 valarray<size_t> __stride_;
1470 valarray<size_t> __1d_;
Howard Hinnant324bb032010-08-22 00:02:43 +00001471
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001472public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001474 gslice() {}
Douglas Gregor0855dde2012-05-19 07:14:17 +00001475
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001477 gslice(size_t __start, const valarray<size_t>& __size,
1478 const valarray<size_t>& __stride)
1479 : __size_(__size),
1480 __stride_(__stride)
1481 {__init(__start);}
1482
Howard Hinnant73d21a42010-09-04 23:28:19 +00001483#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001484
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001485 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001486 gslice(size_t __start, const valarray<size_t>& __size,
1487 valarray<size_t>&& __stride)
1488 : __size_(__size),
1489 __stride_(move(__stride))
1490 {__init(__start);}
1491
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001493 gslice(size_t __start, valarray<size_t>&& __size,
1494 const valarray<size_t>& __stride)
1495 : __size_(move(__size)),
1496 __stride_(__stride)
1497 {__init(__start);}
1498
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001500 gslice(size_t __start, valarray<size_t>&& __size,
1501 valarray<size_t>&& __stride)
1502 : __size_(move(__size)),
1503 __stride_(move(__stride))
1504 {__init(__start);}
1505
Howard Hinnant73d21a42010-09-04 23:28:19 +00001506#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001507
1508// gslice(const gslice&) = default;
1509// gslice(gslice&&) = default;
1510// gslice& operator=(const gslice&) = default;
1511// gslice& operator=(gslice&&) = default;
1512
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001514 size_t start() const {return __1d_.size() ? __1d_[0] : 0;}
1515
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001516 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001517 valarray<size_t> size() const {return __size_;}
1518
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001520 valarray<size_t> stride() const {return __stride_;}
1521
1522private:
1523 void __init(size_t __start);
1524
1525 template <class> friend class gslice_array;
1526 template <class> friend class valarray;
1527 template <class> friend class __val_expr;
1528};
1529
1530// gslice_array
1531
1532template <class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +00001533class _LIBCPP_TEMPLATE_VIS gslice_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001534{
1535public:
1536 typedef _Tp value_type;
1537
1538private:
1539 value_type* __vp_;
1540 valarray<size_t> __1d_;
1541
1542public:
1543 template <class _Expr>
1544 typename enable_if
1545 <
1546 __is_val_expr<_Expr>::value,
1547 void
1548 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001550 operator=(const _Expr& __v) const;
1551
1552 template <class _Expr>
1553 typename enable_if
1554 <
1555 __is_val_expr<_Expr>::value,
1556 void
1557 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001558 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001559 operator*=(const _Expr& __v) const;
1560
1561 template <class _Expr>
1562 typename enable_if
1563 <
1564 __is_val_expr<_Expr>::value,
1565 void
1566 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001568 operator/=(const _Expr& __v) const;
1569
1570 template <class _Expr>
1571 typename enable_if
1572 <
1573 __is_val_expr<_Expr>::value,
1574 void
1575 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001576 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001577 operator%=(const _Expr& __v) const;
1578
1579 template <class _Expr>
1580 typename enable_if
1581 <
1582 __is_val_expr<_Expr>::value,
1583 void
1584 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001585 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001586 operator+=(const _Expr& __v) const;
1587
1588 template <class _Expr>
1589 typename enable_if
1590 <
1591 __is_val_expr<_Expr>::value,
1592 void
1593 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001595 operator-=(const _Expr& __v) const;
1596
1597 template <class _Expr>
1598 typename enable_if
1599 <
1600 __is_val_expr<_Expr>::value,
1601 void
1602 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001604 operator^=(const _Expr& __v) const;
1605
1606 template <class _Expr>
1607 typename enable_if
1608 <
1609 __is_val_expr<_Expr>::value,
1610 void
1611 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001613 operator&=(const _Expr& __v) const;
1614
1615 template <class _Expr>
1616 typename enable_if
1617 <
1618 __is_val_expr<_Expr>::value,
1619 void
1620 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001622 operator|=(const _Expr& __v) const;
1623
1624 template <class _Expr>
1625 typename enable_if
1626 <
1627 __is_val_expr<_Expr>::value,
1628 void
1629 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001631 operator<<=(const _Expr& __v) const;
1632
1633 template <class _Expr>
1634 typename enable_if
1635 <
1636 __is_val_expr<_Expr>::value,
1637 void
1638 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001640 operator>>=(const _Expr& __v) const;
1641
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001643 const gslice_array& operator=(const gslice_array& __ga) const;
1644
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001646 void operator=(const value_type& __x) const;
1647
1648// gslice_array(const gslice_array&) = default;
1649// gslice_array(gslice_array&&) = default;
1650// gslice_array& operator=(const gslice_array&) = default;
1651// gslice_array& operator=(gslice_array&&) = default;
1652
1653private:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001654 gslice_array(const gslice& __gs, const valarray<value_type>& __v)
1655 : __vp_(const_cast<value_type*>(__v.__begin_)),
1656 __1d_(__gs.__1d_)
1657 {}
1658
Howard Hinnant73d21a42010-09-04 23:28:19 +00001659#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001660 gslice_array(gslice&& __gs, const valarray<value_type>& __v)
1661 : __vp_(const_cast<value_type*>(__v.__begin_)),
1662 __1d_(move(__gs.__1d_))
1663 {}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001664#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001665
1666 template <class> friend class valarray;
1667};
1668
1669template <class _Tp>
1670template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001671inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001672typename enable_if
1673<
1674 __is_val_expr<_Expr>::value,
1675 void
1676>::type
1677gslice_array<_Tp>::operator=(const _Expr& __v) const
1678{
1679 typedef const size_t* _Ip;
1680 size_t __j = 0;
1681 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1682 __vp_[*__i] = __v[__j];
1683}
1684
1685template <class _Tp>
1686template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001687inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001688typename enable_if
1689<
1690 __is_val_expr<_Expr>::value,
1691 void
1692>::type
1693gslice_array<_Tp>::operator*=(const _Expr& __v) const
1694{
1695 typedef const size_t* _Ip;
1696 size_t __j = 0;
1697 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1698 __vp_[*__i] *= __v[__j];
1699}
1700
1701template <class _Tp>
1702template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001703inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001704typename enable_if
1705<
1706 __is_val_expr<_Expr>::value,
1707 void
1708>::type
1709gslice_array<_Tp>::operator/=(const _Expr& __v) const
1710{
1711 typedef const size_t* _Ip;
1712 size_t __j = 0;
1713 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1714 __vp_[*__i] /= __v[__j];
1715}
1716
1717template <class _Tp>
1718template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001719inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001720typename enable_if
1721<
1722 __is_val_expr<_Expr>::value,
1723 void
1724>::type
1725gslice_array<_Tp>::operator%=(const _Expr& __v) const
1726{
1727 typedef const size_t* _Ip;
1728 size_t __j = 0;
1729 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1730 __vp_[*__i] %= __v[__j];
1731}
1732
1733template <class _Tp>
1734template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001735inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001736typename enable_if
1737<
1738 __is_val_expr<_Expr>::value,
1739 void
1740>::type
1741gslice_array<_Tp>::operator+=(const _Expr& __v) const
1742{
1743 typedef const size_t* _Ip;
1744 size_t __j = 0;
1745 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1746 __vp_[*__i] += __v[__j];
1747}
1748
1749template <class _Tp>
1750template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001751inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001752typename enable_if
1753<
1754 __is_val_expr<_Expr>::value,
1755 void
1756>::type
1757gslice_array<_Tp>::operator-=(const _Expr& __v) const
1758{
1759 typedef const size_t* _Ip;
1760 size_t __j = 0;
1761 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1762 __vp_[*__i] -= __v[__j];
1763}
1764
1765template <class _Tp>
1766template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001767inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001768typename enable_if
1769<
1770 __is_val_expr<_Expr>::value,
1771 void
1772>::type
1773gslice_array<_Tp>::operator^=(const _Expr& __v) const
1774{
1775 typedef const size_t* _Ip;
1776 size_t __j = 0;
1777 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1778 __vp_[*__i] ^= __v[__j];
1779}
1780
1781template <class _Tp>
1782template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001783inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001784typename enable_if
1785<
1786 __is_val_expr<_Expr>::value,
1787 void
1788>::type
1789gslice_array<_Tp>::operator&=(const _Expr& __v) const
1790{
1791 typedef const size_t* _Ip;
1792 size_t __j = 0;
1793 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1794 __vp_[*__i] &= __v[__j];
1795}
1796
1797template <class _Tp>
1798template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001799inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001800typename enable_if
1801<
1802 __is_val_expr<_Expr>::value,
1803 void
1804>::type
1805gslice_array<_Tp>::operator|=(const _Expr& __v) const
1806{
1807 typedef const size_t* _Ip;
1808 size_t __j = 0;
1809 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1810 __vp_[*__i] |= __v[__j];
1811}
1812
1813template <class _Tp>
1814template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001815inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001816typename enable_if
1817<
1818 __is_val_expr<_Expr>::value,
1819 void
1820>::type
1821gslice_array<_Tp>::operator<<=(const _Expr& __v) const
1822{
1823 typedef const size_t* _Ip;
1824 size_t __j = 0;
1825 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1826 __vp_[*__i] <<= __v[__j];
1827}
1828
1829template <class _Tp>
1830template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001831inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001832typename enable_if
1833<
1834 __is_val_expr<_Expr>::value,
1835 void
1836>::type
1837gslice_array<_Tp>::operator>>=(const _Expr& __v) const
1838{
1839 typedef const size_t* _Ip;
1840 size_t __j = 0;
1841 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1842 __vp_[*__i] >>= __v[__j];
1843}
1844
1845template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001846inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001847const gslice_array<_Tp>&
1848gslice_array<_Tp>::operator=(const gslice_array& __ga) const
1849{
1850 typedef const size_t* _Ip;
1851 const value_type* __s = __ga.__vp_;
1852 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_;
1853 __i != __e; ++__i, ++__j)
1854 __vp_[*__i] = __s[*__j];
1855 return *this;
1856}
1857
1858template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001859inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001860void
1861gslice_array<_Tp>::operator=(const value_type& __x) const
1862{
1863 typedef const size_t* _Ip;
1864 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1865 __vp_[*__i] = __x;
1866}
1867
1868// mask_array
1869
1870template <class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +00001871class _LIBCPP_TEMPLATE_VIS mask_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001872{
1873public:
1874 typedef _Tp value_type;
1875
1876private:
1877 value_type* __vp_;
1878 valarray<size_t> __1d_;
1879
1880public:
1881 template <class _Expr>
1882 typename enable_if
1883 <
1884 __is_val_expr<_Expr>::value,
1885 void
1886 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001888 operator=(const _Expr& __v) const;
1889
1890 template <class _Expr>
1891 typename enable_if
1892 <
1893 __is_val_expr<_Expr>::value,
1894 void
1895 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001897 operator*=(const _Expr& __v) const;
1898
1899 template <class _Expr>
1900 typename enable_if
1901 <
1902 __is_val_expr<_Expr>::value,
1903 void
1904 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001906 operator/=(const _Expr& __v) const;
1907
1908 template <class _Expr>
1909 typename enable_if
1910 <
1911 __is_val_expr<_Expr>::value,
1912 void
1913 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001915 operator%=(const _Expr& __v) const;
1916
1917 template <class _Expr>
1918 typename enable_if
1919 <
1920 __is_val_expr<_Expr>::value,
1921 void
1922 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001924 operator+=(const _Expr& __v) const;
1925
1926 template <class _Expr>
1927 typename enable_if
1928 <
1929 __is_val_expr<_Expr>::value,
1930 void
1931 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001932 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001933 operator-=(const _Expr& __v) const;
1934
1935 template <class _Expr>
1936 typename enable_if
1937 <
1938 __is_val_expr<_Expr>::value,
1939 void
1940 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001941 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001942 operator^=(const _Expr& __v) const;
1943
1944 template <class _Expr>
1945 typename enable_if
1946 <
1947 __is_val_expr<_Expr>::value,
1948 void
1949 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001951 operator&=(const _Expr& __v) const;
1952
1953 template <class _Expr>
1954 typename enable_if
1955 <
1956 __is_val_expr<_Expr>::value,
1957 void
1958 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001959 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001960 operator|=(const _Expr& __v) const;
1961
1962 template <class _Expr>
1963 typename enable_if
1964 <
1965 __is_val_expr<_Expr>::value,
1966 void
1967 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001968 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001969 operator<<=(const _Expr& __v) const;
1970
1971 template <class _Expr>
1972 typename enable_if
1973 <
1974 __is_val_expr<_Expr>::value,
1975 void
1976 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001977 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001978 operator>>=(const _Expr& __v) const;
1979
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001981 const mask_array& operator=(const mask_array& __ma) const;
1982
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001983 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001984 void operator=(const value_type& __x) const;
1985
1986// mask_array(const mask_array&) = default;
1987// mask_array(mask_array&&) = default;
1988// mask_array& operator=(const mask_array&) = default;
1989// mask_array& operator=(mask_array&&) = default;
1990
1991private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001992 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001993 mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
1994 : __vp_(const_cast<value_type*>(__v.__begin_)),
Howard Hinnantec3773c2011-12-01 20:21:04 +00001995 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001996 {
1997 size_t __j = 0;
1998 for (size_t __i = 0; __i < __vb.size(); ++__i)
1999 if (__vb[__i])
2000 __1d_[__j++] = __i;
2001 }
2002
2003 template <class> friend class valarray;
2004};
2005
2006template <class _Tp>
2007template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002008inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002009typename enable_if
2010<
2011 __is_val_expr<_Expr>::value,
2012 void
2013>::type
2014mask_array<_Tp>::operator=(const _Expr& __v) const
2015{
2016 size_t __n = __1d_.size();
2017 for (size_t __i = 0; __i < __n; ++__i)
2018 __vp_[__1d_[__i]] = __v[__i];
2019}
2020
2021template <class _Tp>
2022template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002023inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002024typename enable_if
2025<
2026 __is_val_expr<_Expr>::value,
2027 void
2028>::type
2029mask_array<_Tp>::operator*=(const _Expr& __v) const
2030{
2031 size_t __n = __1d_.size();
2032 for (size_t __i = 0; __i < __n; ++__i)
2033 __vp_[__1d_[__i]] *= __v[__i];
2034}
2035
2036template <class _Tp>
2037template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002038inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002039typename enable_if
2040<
2041 __is_val_expr<_Expr>::value,
2042 void
2043>::type
2044mask_array<_Tp>::operator/=(const _Expr& __v) const
2045{
2046 size_t __n = __1d_.size();
2047 for (size_t __i = 0; __i < __n; ++__i)
2048 __vp_[__1d_[__i]] /= __v[__i];
2049}
2050
2051template <class _Tp>
2052template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002053inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002054typename enable_if
2055<
2056 __is_val_expr<_Expr>::value,
2057 void
2058>::type
2059mask_array<_Tp>::operator%=(const _Expr& __v) const
2060{
2061 size_t __n = __1d_.size();
2062 for (size_t __i = 0; __i < __n; ++__i)
2063 __vp_[__1d_[__i]] %= __v[__i];
2064}
2065
2066template <class _Tp>
2067template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002068inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002069typename enable_if
2070<
2071 __is_val_expr<_Expr>::value,
2072 void
2073>::type
2074mask_array<_Tp>::operator+=(const _Expr& __v) const
2075{
2076 size_t __n = __1d_.size();
2077 for (size_t __i = 0; __i < __n; ++__i)
2078 __vp_[__1d_[__i]] += __v[__i];
2079}
2080
2081template <class _Tp>
2082template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002083inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002084typename enable_if
2085<
2086 __is_val_expr<_Expr>::value,
2087 void
2088>::type
2089mask_array<_Tp>::operator-=(const _Expr& __v) const
2090{
2091 size_t __n = __1d_.size();
2092 for (size_t __i = 0; __i < __n; ++__i)
2093 __vp_[__1d_[__i]] -= __v[__i];
2094}
2095
2096template <class _Tp>
2097template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002098inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002099typename enable_if
2100<
2101 __is_val_expr<_Expr>::value,
2102 void
2103>::type
2104mask_array<_Tp>::operator^=(const _Expr& __v) const
2105{
2106 size_t __n = __1d_.size();
2107 for (size_t __i = 0; __i < __n; ++__i)
2108 __vp_[__1d_[__i]] ^= __v[__i];
2109}
2110
2111template <class _Tp>
2112template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002113inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002114typename enable_if
2115<
2116 __is_val_expr<_Expr>::value,
2117 void
2118>::type
2119mask_array<_Tp>::operator&=(const _Expr& __v) const
2120{
2121 size_t __n = __1d_.size();
2122 for (size_t __i = 0; __i < __n; ++__i)
2123 __vp_[__1d_[__i]] &= __v[__i];
2124}
2125
2126template <class _Tp>
2127template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002128inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002129typename enable_if
2130<
2131 __is_val_expr<_Expr>::value,
2132 void
2133>::type
2134mask_array<_Tp>::operator|=(const _Expr& __v) const
2135{
2136 size_t __n = __1d_.size();
2137 for (size_t __i = 0; __i < __n; ++__i)
2138 __vp_[__1d_[__i]] |= __v[__i];
2139}
2140
2141template <class _Tp>
2142template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002143inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002144typename enable_if
2145<
2146 __is_val_expr<_Expr>::value,
2147 void
2148>::type
2149mask_array<_Tp>::operator<<=(const _Expr& __v) const
2150{
2151 size_t __n = __1d_.size();
2152 for (size_t __i = 0; __i < __n; ++__i)
2153 __vp_[__1d_[__i]] <<= __v[__i];
2154}
2155
2156template <class _Tp>
2157template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002158inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002159typename enable_if
2160<
2161 __is_val_expr<_Expr>::value,
2162 void
2163>::type
2164mask_array<_Tp>::operator>>=(const _Expr& __v) const
2165{
2166 size_t __n = __1d_.size();
2167 for (size_t __i = 0; __i < __n; ++__i)
2168 __vp_[__1d_[__i]] >>= __v[__i];
2169}
2170
2171template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002172inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002173const mask_array<_Tp>&
2174mask_array<_Tp>::operator=(const mask_array& __ma) const
2175{
2176 size_t __n = __1d_.size();
2177 for (size_t __i = 0; __i < __n; ++__i)
2178 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
Eric Fiselierf4124612014-08-12 00:06:58 +00002179 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002180}
2181
2182template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002183inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002184void
2185mask_array<_Tp>::operator=(const value_type& __x) const
2186{
2187 size_t __n = __1d_.size();
2188 for (size_t __i = 0; __i < __n; ++__i)
2189 __vp_[__1d_[__i]] = __x;
2190}
2191
2192template <class _ValExpr>
2193class __mask_expr
2194{
2195 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2196public:
2197 typedef typename _RmExpr::value_type value_type;
2198 typedef value_type result_type;
2199
2200private:
2201 _ValExpr __expr_;
2202 valarray<size_t> __1d_;
2203
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002204 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002205 __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
2206 : __expr_(__e),
Howard Hinnantec3773c2011-12-01 20:21:04 +00002207 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002208 {
2209 size_t __j = 0;
2210 for (size_t __i = 0; __i < __vb.size(); ++__i)
2211 if (__vb[__i])
2212 __1d_[__j++] = __i;
2213 }
2214
2215public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002216 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002217 result_type operator[](size_t __i) const
2218 {return __expr_[__1d_[__i]];}
2219
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002220 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002221 size_t size() const {return __1d_.size();}
2222
2223 template <class> friend class valarray;
2224};
2225
2226// indirect_array
2227
2228template <class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +00002229class _LIBCPP_TEMPLATE_VIS indirect_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002230{
2231public:
2232 typedef _Tp value_type;
2233
2234private:
2235 value_type* __vp_;
2236 valarray<size_t> __1d_;
2237
2238public:
2239 template <class _Expr>
2240 typename enable_if
2241 <
2242 __is_val_expr<_Expr>::value,
2243 void
2244 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002245 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002246 operator=(const _Expr& __v) const;
2247
2248 template <class _Expr>
2249 typename enable_if
2250 <
2251 __is_val_expr<_Expr>::value,
2252 void
2253 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002254 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002255 operator*=(const _Expr& __v) const;
2256
2257 template <class _Expr>
2258 typename enable_if
2259 <
2260 __is_val_expr<_Expr>::value,
2261 void
2262 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002263 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002264 operator/=(const _Expr& __v) const;
2265
2266 template <class _Expr>
2267 typename enable_if
2268 <
2269 __is_val_expr<_Expr>::value,
2270 void
2271 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002272 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002273 operator%=(const _Expr& __v) const;
2274
2275 template <class _Expr>
2276 typename enable_if
2277 <
2278 __is_val_expr<_Expr>::value,
2279 void
2280 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002281 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002282 operator+=(const _Expr& __v) const;
2283
2284 template <class _Expr>
2285 typename enable_if
2286 <
2287 __is_val_expr<_Expr>::value,
2288 void
2289 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002290 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002291 operator-=(const _Expr& __v) const;
2292
2293 template <class _Expr>
2294 typename enable_if
2295 <
2296 __is_val_expr<_Expr>::value,
2297 void
2298 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002299 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002300 operator^=(const _Expr& __v) const;
2301
2302 template <class _Expr>
2303 typename enable_if
2304 <
2305 __is_val_expr<_Expr>::value,
2306 void
2307 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002308 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002309 operator&=(const _Expr& __v) const;
2310
2311 template <class _Expr>
2312 typename enable_if
2313 <
2314 __is_val_expr<_Expr>::value,
2315 void
2316 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002317 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002318 operator|=(const _Expr& __v) const;
2319
2320 template <class _Expr>
2321 typename enable_if
2322 <
2323 __is_val_expr<_Expr>::value,
2324 void
2325 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002326 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002327 operator<<=(const _Expr& __v) const;
2328
2329 template <class _Expr>
2330 typename enable_if
2331 <
2332 __is_val_expr<_Expr>::value,
2333 void
2334 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002335 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002336 operator>>=(const _Expr& __v) const;
2337
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002338 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002339 const indirect_array& operator=(const indirect_array& __ia) const;
2340
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002341 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002342 void operator=(const value_type& __x) const;
2343
2344// indirect_array(const indirect_array&) = default;
2345// indirect_array(indirect_array&&) = default;
2346// indirect_array& operator=(const indirect_array&) = default;
2347// indirect_array& operator=(indirect_array&&) = default;
2348
2349private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002350 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002351 indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
2352 : __vp_(const_cast<value_type*>(__v.__begin_)),
2353 __1d_(__ia)
2354 {}
2355
Howard Hinnant73d21a42010-09-04 23:28:19 +00002356#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002357
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002358 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002359 indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
2360 : __vp_(const_cast<value_type*>(__v.__begin_)),
2361 __1d_(move(__ia))
2362 {}
2363
Howard Hinnant73d21a42010-09-04 23:28:19 +00002364#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002365
2366 template <class> friend class valarray;
2367};
2368
2369template <class _Tp>
2370template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002371inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002372typename enable_if
2373<
2374 __is_val_expr<_Expr>::value,
2375 void
2376>::type
2377indirect_array<_Tp>::operator=(const _Expr& __v) const
2378{
2379 size_t __n = __1d_.size();
2380 for (size_t __i = 0; __i < __n; ++__i)
2381 __vp_[__1d_[__i]] = __v[__i];
2382}
2383
2384template <class _Tp>
2385template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002386inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002387typename enable_if
2388<
2389 __is_val_expr<_Expr>::value,
2390 void
2391>::type
2392indirect_array<_Tp>::operator*=(const _Expr& __v) const
2393{
2394 size_t __n = __1d_.size();
2395 for (size_t __i = 0; __i < __n; ++__i)
2396 __vp_[__1d_[__i]] *= __v[__i];
2397}
2398
2399template <class _Tp>
2400template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002401inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002402typename enable_if
2403<
2404 __is_val_expr<_Expr>::value,
2405 void
2406>::type
2407indirect_array<_Tp>::operator/=(const _Expr& __v) const
2408{
2409 size_t __n = __1d_.size();
2410 for (size_t __i = 0; __i < __n; ++__i)
2411 __vp_[__1d_[__i]] /= __v[__i];
2412}
2413
2414template <class _Tp>
2415template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002416inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002417typename enable_if
2418<
2419 __is_val_expr<_Expr>::value,
2420 void
2421>::type
2422indirect_array<_Tp>::operator%=(const _Expr& __v) const
2423{
2424 size_t __n = __1d_.size();
2425 for (size_t __i = 0; __i < __n; ++__i)
2426 __vp_[__1d_[__i]] %= __v[__i];
2427}
2428
2429template <class _Tp>
2430template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002431inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002432typename enable_if
2433<
2434 __is_val_expr<_Expr>::value,
2435 void
2436>::type
2437indirect_array<_Tp>::operator+=(const _Expr& __v) const
2438{
2439 size_t __n = __1d_.size();
2440 for (size_t __i = 0; __i < __n; ++__i)
2441 __vp_[__1d_[__i]] += __v[__i];
2442}
2443
2444template <class _Tp>
2445template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002446inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002447typename enable_if
2448<
2449 __is_val_expr<_Expr>::value,
2450 void
2451>::type
2452indirect_array<_Tp>::operator-=(const _Expr& __v) const
2453{
2454 size_t __n = __1d_.size();
2455 for (size_t __i = 0; __i < __n; ++__i)
2456 __vp_[__1d_[__i]] -= __v[__i];
2457}
2458
2459template <class _Tp>
2460template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002461inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002462typename enable_if
2463<
2464 __is_val_expr<_Expr>::value,
2465 void
2466>::type
2467indirect_array<_Tp>::operator^=(const _Expr& __v) const
2468{
2469 size_t __n = __1d_.size();
2470 for (size_t __i = 0; __i < __n; ++__i)
2471 __vp_[__1d_[__i]] ^= __v[__i];
2472}
2473
2474template <class _Tp>
2475template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002476inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002477typename enable_if
2478<
2479 __is_val_expr<_Expr>::value,
2480 void
2481>::type
2482indirect_array<_Tp>::operator&=(const _Expr& __v) const
2483{
2484 size_t __n = __1d_.size();
2485 for (size_t __i = 0; __i < __n; ++__i)
2486 __vp_[__1d_[__i]] &= __v[__i];
2487}
2488
2489template <class _Tp>
2490template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002491inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002492typename enable_if
2493<
2494 __is_val_expr<_Expr>::value,
2495 void
2496>::type
2497indirect_array<_Tp>::operator|=(const _Expr& __v) const
2498{
2499 size_t __n = __1d_.size();
2500 for (size_t __i = 0; __i < __n; ++__i)
2501 __vp_[__1d_[__i]] |= __v[__i];
2502}
2503
2504template <class _Tp>
2505template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002506inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002507typename enable_if
2508<
2509 __is_val_expr<_Expr>::value,
2510 void
2511>::type
2512indirect_array<_Tp>::operator<<=(const _Expr& __v) const
2513{
2514 size_t __n = __1d_.size();
2515 for (size_t __i = 0; __i < __n; ++__i)
2516 __vp_[__1d_[__i]] <<= __v[__i];
2517}
2518
2519template <class _Tp>
2520template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002521inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002522typename enable_if
2523<
2524 __is_val_expr<_Expr>::value,
2525 void
2526>::type
2527indirect_array<_Tp>::operator>>=(const _Expr& __v) const
2528{
2529 size_t __n = __1d_.size();
2530 for (size_t __i = 0; __i < __n; ++__i)
2531 __vp_[__1d_[__i]] >>= __v[__i];
2532}
2533
2534template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002535inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002536const indirect_array<_Tp>&
2537indirect_array<_Tp>::operator=(const indirect_array& __ia) const
2538{
2539 typedef const size_t* _Ip;
2540 const value_type* __s = __ia.__vp_;
2541 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_;
2542 __i != __e; ++__i, ++__j)
2543 __vp_[*__i] = __s[*__j];
2544 return *this;
2545}
2546
2547template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002548inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002549void
2550indirect_array<_Tp>::operator=(const value_type& __x) const
2551{
2552 typedef const size_t* _Ip;
2553 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
2554 __vp_[*__i] = __x;
2555}
2556
2557template <class _ValExpr>
2558class __indirect_expr
2559{
2560 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2561public:
2562 typedef typename _RmExpr::value_type value_type;
2563 typedef value_type result_type;
2564
2565private:
2566 _ValExpr __expr_;
2567 valarray<size_t> __1d_;
2568
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002570 __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e)
2571 : __expr_(__e),
2572 __1d_(__ia)
2573 {}
2574
Howard Hinnant73d21a42010-09-04 23:28:19 +00002575#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002576
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002578 __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
2579 : __expr_(__e),
2580 __1d_(move(__ia))
2581 {}
2582
Howard Hinnant73d21a42010-09-04 23:28:19 +00002583#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002584
2585public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002587 result_type operator[](size_t __i) const
2588 {return __expr_[__1d_[__i]];}
2589
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002590 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002591 size_t size() const {return __1d_.size();}
2592
Eric Fiselierc3589a82017-01-04 23:56:00 +00002593 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002594};
2595
2596template<class _ValExpr>
2597class __val_expr
2598{
2599 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2600
2601 _ValExpr __expr_;
2602public:
2603 typedef typename _RmExpr::value_type value_type;
2604 typedef typename _RmExpr::result_type result_type;
2605
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002606 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002607 explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
2608
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002610 result_type operator[](size_t __i) const
2611 {return __expr_[__i];}
2612
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002613 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002614 __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
2615 {return __val_expr<__slice_expr<_ValExpr> >(__expr_, __s);}
2616
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002618 __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const
2619 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __gs.__1d_);}
2620
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002622 __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
2623 {return __val_expr<__mask_expr<_ValExpr> >(__expr_, __vb);}
2624
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002626 __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
2627 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __vs);}
2628
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002629 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002630 __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
2631 operator+() const
2632 {
2633 typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
2634 return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
2635 }
2636
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002637 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002638 __val_expr<_UnaryOp<negate<value_type>, _ValExpr> >
2639 operator-() const
2640 {
2641 typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
2642 return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
2643 }
2644
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002646 __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> >
2647 operator~() const
2648 {
2649 typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
2650 return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
2651 }
2652
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002653 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002654 __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> >
2655 operator!() const
2656 {
2657 typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
2658 return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
2659 }
2660
2661 operator valarray<result_type>() const;
2662
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002663 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002664 size_t size() const {return __expr_.size();}
2665
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002666 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002667 result_type sum() const
2668 {
2669 size_t __n = __expr_.size();
2670 result_type __r = __n ? __expr_[0] : result_type();
2671 for (size_t __i = 1; __i < __n; ++__i)
2672 __r += __expr_[__i];
2673 return __r;
2674 }
2675
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002677 result_type min() const
2678 {
2679 size_t __n = size();
2680 result_type __r = __n ? (*this)[0] : result_type();
2681 for (size_t __i = 1; __i < __n; ++__i)
2682 {
2683 result_type __x = __expr_[__i];
2684 if (__x < __r)
2685 __r = __x;
2686 }
2687 return __r;
2688 }
2689
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002691 result_type max() const
2692 {
2693 size_t __n = size();
2694 result_type __r = __n ? (*this)[0] : result_type();
2695 for (size_t __i = 1; __i < __n; ++__i)
2696 {
2697 result_type __x = __expr_[__i];
2698 if (__r < __x)
2699 __r = __x;
2700 }
2701 return __r;
2702 }
2703
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002704 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002705 __val_expr<__shift_expr<_ValExpr> > shift (int __i) const
2706 {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));}
2707
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002709 __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const
2710 {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));}
2711
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002713 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> >
2714 apply(value_type __f(value_type)) const
2715 {
2716 typedef __apply_expr<value_type, value_type(*)(value_type)> _Op;
2717 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2718 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2719 }
2720
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002722 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> >
2723 apply(value_type __f(const value_type&)) const
2724 {
2725 typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op;
2726 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2727 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2728 }
2729};
2730
2731template<class _ValExpr>
Howard Hinnantd8851432013-09-13 23:27:42 +00002732__val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002733{
2734 valarray<result_type> __r;
2735 size_t __n = __expr_.size();
2736 if (__n)
2737 {
2738 __r.__begin_ =
2739 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00002740 static_cast<result_type*>(_VSTD::__allocate(__n * sizeof(result_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002741 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
2742 ::new (__r.__end_) result_type(__expr_[__i]);
2743 }
2744 return __r;
2745}
2746
2747// valarray
2748
2749template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002750inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002751valarray<_Tp>::valarray(size_t __n)
2752 : __begin_(0),
2753 __end_(0)
2754{
2755 resize(__n);
2756}
2757
2758template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002759inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002760valarray<_Tp>::valarray(const value_type& __x, size_t __n)
2761 : __begin_(0),
2762 __end_(0)
2763{
2764 resize(__n, __x);
2765}
2766
2767template <class _Tp>
2768valarray<_Tp>::valarray(const value_type* __p, size_t __n)
2769 : __begin_(0),
2770 __end_(0)
2771{
2772 if (__n)
2773 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002774 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002775#ifndef _LIBCPP_NO_EXCEPTIONS
2776 try
2777 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002778#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002779 for (; __n; ++__end_, ++__p, --__n)
2780 ::new (__end_) value_type(*__p);
2781#ifndef _LIBCPP_NO_EXCEPTIONS
2782 }
2783 catch (...)
2784 {
2785 resize(0);
2786 throw;
2787 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002788#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002789 }
2790}
2791
2792template <class _Tp>
2793valarray<_Tp>::valarray(const valarray& __v)
2794 : __begin_(0),
2795 __end_(0)
2796{
2797 if (__v.size())
2798 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002799 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__v.size() * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002800#ifndef _LIBCPP_NO_EXCEPTIONS
2801 try
2802 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002803#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002804 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
2805 ::new (__end_) value_type(*__p);
2806#ifndef _LIBCPP_NO_EXCEPTIONS
2807 }
2808 catch (...)
2809 {
2810 resize(0);
2811 throw;
2812 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002813#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002814 }
2815}
2816
Howard Hinnant73d21a42010-09-04 23:28:19 +00002817#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002818
2819template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002820inline
Howard Hinnantbd143082012-07-21 00:51:28 +00002821valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002822 : __begin_(__v.__begin_),
2823 __end_(__v.__end_)
2824{
2825 __v.__begin_ = __v.__end_ = nullptr;
2826}
2827
Howard Hinnante3e32912011-08-12 21:56:02 +00002828#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2829
2830#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2831
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002832template <class _Tp>
2833valarray<_Tp>::valarray(initializer_list<value_type> __il)
2834 : __begin_(0),
2835 __end_(0)
2836{
2837 size_t __n = __il.size();
2838 if (__n)
2839 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002840 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002841#ifndef _LIBCPP_NO_EXCEPTIONS
2842 try
2843 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002844#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002845 for (const value_type* __p = __il.begin(); __n; ++__end_, ++__p, --__n)
2846 ::new (__end_) value_type(*__p);
2847#ifndef _LIBCPP_NO_EXCEPTIONS
2848 }
2849 catch (...)
2850 {
2851 resize(0);
2852 throw;
2853 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002854#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002855 }
2856}
2857
Howard Hinnante3e32912011-08-12 21:56:02 +00002858#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002859
2860template <class _Tp>
2861valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
2862 : __begin_(0),
2863 __end_(0)
2864{
2865 size_t __n = __sa.__size_;
2866 if (__n)
2867 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002868 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002869#ifndef _LIBCPP_NO_EXCEPTIONS
2870 try
2871 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002872#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002873 for (const value_type* __p = __sa.__vp_; __n; ++__end_, __p += __sa.__stride_, --__n)
2874 ::new (__end_) value_type(*__p);
2875#ifndef _LIBCPP_NO_EXCEPTIONS
2876 }
2877 catch (...)
2878 {
2879 resize(0);
2880 throw;
2881 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002882#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002883 }
2884}
2885
2886template <class _Tp>
2887valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
2888 : __begin_(0),
2889 __end_(0)
2890{
2891 size_t __n = __ga.__1d_.size();
2892 if (__n)
2893 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002894 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002895#ifndef _LIBCPP_NO_EXCEPTIONS
2896 try
2897 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002898#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002899 typedef const size_t* _Ip;
2900 const value_type* __s = __ga.__vp_;
2901 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2902 __i != __e; ++__i, ++__end_)
2903 ::new (__end_) value_type(__s[*__i]);
2904#ifndef _LIBCPP_NO_EXCEPTIONS
2905 }
2906 catch (...)
2907 {
2908 resize(0);
2909 throw;
2910 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002911#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002912 }
2913}
2914
2915template <class _Tp>
2916valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
2917 : __begin_(0),
2918 __end_(0)
2919{
2920 size_t __n = __ma.__1d_.size();
2921 if (__n)
2922 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002923 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002924#ifndef _LIBCPP_NO_EXCEPTIONS
2925 try
2926 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002927#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002928 typedef const size_t* _Ip;
2929 const value_type* __s = __ma.__vp_;
2930 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2931 __i != __e; ++__i, ++__end_)
2932 ::new (__end_) value_type(__s[*__i]);
2933#ifndef _LIBCPP_NO_EXCEPTIONS
2934 }
2935 catch (...)
2936 {
2937 resize(0);
2938 throw;
2939 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002940#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002941 }
2942}
2943
2944template <class _Tp>
2945valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
2946 : __begin_(0),
2947 __end_(0)
2948{
2949 size_t __n = __ia.__1d_.size();
2950 if (__n)
2951 {
Richard Smith73c1fce2014-06-04 19:54:15 +00002952 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002953#ifndef _LIBCPP_NO_EXCEPTIONS
2954 try
2955 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002956#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002957 typedef const size_t* _Ip;
2958 const value_type* __s = __ia.__vp_;
2959 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2960 __i != __e; ++__i, ++__end_)
2961 ::new (__end_) value_type(__s[*__i]);
2962#ifndef _LIBCPP_NO_EXCEPTIONS
2963 }
2964 catch (...)
2965 {
2966 resize(0);
2967 throw;
2968 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002969#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002970 }
2971}
2972
2973template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002974inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002975valarray<_Tp>::~valarray()
2976{
2977 resize(0);
2978}
2979
2980template <class _Tp>
2981valarray<_Tp>&
2982valarray<_Tp>::operator=(const valarray& __v)
2983{
2984 if (this != &__v)
2985 {
2986 if (size() != __v.size())
2987 resize(__v.size());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002988 _VSTD::copy(__v.__begin_, __v.__end_, __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002989 }
2990 return *this;
2991}
2992
Howard Hinnant73d21a42010-09-04 23:28:19 +00002993#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002994
2995template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002996inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002997valarray<_Tp>&
Howard Hinnantbd143082012-07-21 00:51:28 +00002998valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002999{
3000 resize(0);
3001 __begin_ = __v.__begin_;
3002 __end_ = __v.__end_;
3003 __v.__begin_ = nullptr;
3004 __v.__end_ = nullptr;
3005 return *this;
3006}
3007
Howard Hinnante3e32912011-08-12 21:56:02 +00003008#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3009
3010#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
3011
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003012template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003013inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003014valarray<_Tp>&
3015valarray<_Tp>::operator=(initializer_list<value_type> __il)
3016{
3017 if (size() != __il.size())
3018 resize(__il.size());
Howard Hinnant0949eed2011-06-30 21:18:19 +00003019 _VSTD::copy(__il.begin(), __il.end(), __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003020 return *this;
3021}
3022
Howard Hinnante3e32912011-08-12 21:56:02 +00003023#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003024
3025template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003026inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003027valarray<_Tp>&
3028valarray<_Tp>::operator=(const value_type& __x)
3029{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003030 _VSTD::fill(__begin_, __end_, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003031 return *this;
3032}
3033
3034template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003035inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003036valarray<_Tp>&
3037valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
3038{
3039 value_type* __t = __begin_;
3040 const value_type* __s = __sa.__vp_;
3041 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
3042 *__t = *__s;
3043 return *this;
3044}
3045
3046template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003047inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003048valarray<_Tp>&
3049valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
3050{
3051 typedef const size_t* _Ip;
3052 value_type* __t = __begin_;
3053 const value_type* __s = __ga.__vp_;
3054 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
3055 __i != __e; ++__i, ++__t)
3056 *__t = __s[*__i];
3057 return *this;
3058}
3059
3060template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003061inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003062valarray<_Tp>&
3063valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
3064{
3065 typedef const size_t* _Ip;
3066 value_type* __t = __begin_;
3067 const value_type* __s = __ma.__vp_;
3068 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
3069 __i != __e; ++__i, ++__t)
3070 *__t = __s[*__i];
3071 return *this;
3072}
3073
3074template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003075inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003076valarray<_Tp>&
3077valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
3078{
3079 typedef const size_t* _Ip;
3080 value_type* __t = __begin_;
3081 const value_type* __s = __ia.__vp_;
3082 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
3083 __i != __e; ++__i, ++__t)
3084 *__t = __s[*__i];
3085 return *this;
3086}
3087
3088template <class _Tp>
Howard Hinnantdb866632011-07-27 23:19:59 +00003089template <class _ValExpr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003090inline
Howard Hinnantdb866632011-07-27 23:19:59 +00003091valarray<_Tp>&
3092valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
3093{
3094 size_t __n = __v.size();
3095 if (size() != __n)
3096 resize(__n);
3097 value_type* __t = __begin_;
3098 for (size_t __i = 0; __i != __n; ++__t, ++__i)
3099 *__t = result_type(__v[__i]);
3100 return *this;
3101}
3102
3103template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003104inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003105__val_expr<__slice_expr<const valarray<_Tp>&> >
3106valarray<_Tp>::operator[](slice __s) const
3107{
3108 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
3109}
3110
3111template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003112inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003113slice_array<_Tp>
3114valarray<_Tp>::operator[](slice __s)
3115{
3116 return slice_array<value_type>(__s, *this);
3117}
3118
3119template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003120inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003121__val_expr<__indirect_expr<const valarray<_Tp>&> >
3122valarray<_Tp>::operator[](const gslice& __gs) const
3123{
3124 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
3125}
3126
3127template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003128inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003129gslice_array<_Tp>
3130valarray<_Tp>::operator[](const gslice& __gs)
3131{
3132 return gslice_array<value_type>(__gs, *this);
3133}
3134
Howard Hinnant73d21a42010-09-04 23:28:19 +00003135#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003136
3137template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003138inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003139__val_expr<__indirect_expr<const valarray<_Tp>&> >
3140valarray<_Tp>::operator[](gslice&& __gs) const
3141{
3142 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
3143}
3144
3145template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003146inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003147gslice_array<_Tp>
3148valarray<_Tp>::operator[](gslice&& __gs)
3149{
3150 return gslice_array<value_type>(move(__gs), *this);
3151}
3152
Howard Hinnant73d21a42010-09-04 23:28:19 +00003153#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003154
3155template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003156inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003157__val_expr<__mask_expr<const valarray<_Tp>&> >
3158valarray<_Tp>::operator[](const valarray<bool>& __vb) const
3159{
3160 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
3161}
3162
3163template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003164inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003165mask_array<_Tp>
3166valarray<_Tp>::operator[](const valarray<bool>& __vb)
3167{
3168 return mask_array<value_type>(__vb, *this);
3169}
3170
Howard Hinnant73d21a42010-09-04 23:28:19 +00003171#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003172
3173template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003174inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003175__val_expr<__mask_expr<const valarray<_Tp>&> >
3176valarray<_Tp>::operator[](valarray<bool>&& __vb) const
3177{
3178 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
3179}
3180
3181template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003182inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003183mask_array<_Tp>
3184valarray<_Tp>::operator[](valarray<bool>&& __vb)
3185{
3186 return mask_array<value_type>(move(__vb), *this);
3187}
3188
Howard Hinnant73d21a42010-09-04 23:28:19 +00003189#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003190
3191template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003192inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003193__val_expr<__indirect_expr<const valarray<_Tp>&> >
3194valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
3195{
3196 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
3197}
3198
3199template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003200inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003201indirect_array<_Tp>
3202valarray<_Tp>::operator[](const valarray<size_t>& __vs)
3203{
3204 return indirect_array<value_type>(__vs, *this);
3205}
3206
Howard Hinnant73d21a42010-09-04 23:28:19 +00003207#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003208
3209template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003210inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003211__val_expr<__indirect_expr<const valarray<_Tp>&> >
3212valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
3213{
3214 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
3215}
3216
3217template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003218inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003219indirect_array<_Tp>
3220valarray<_Tp>::operator[](valarray<size_t>&& __vs)
3221{
3222 return indirect_array<value_type>(move(__vs), *this);
3223}
3224
Howard Hinnant73d21a42010-09-04 23:28:19 +00003225#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003226
3227template <class _Tp>
3228valarray<_Tp>
3229valarray<_Tp>::operator+() const
3230{
3231 valarray<value_type> __r;
3232 size_t __n = size();
3233 if (__n)
3234 {
3235 __r.__begin_ =
3236 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003237 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003238 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3239 ::new (__r.__end_) value_type(+*__p);
3240 }
3241 return __r;
3242}
3243
3244template <class _Tp>
3245valarray<_Tp>
3246valarray<_Tp>::operator-() const
3247{
3248 valarray<value_type> __r;
3249 size_t __n = size();
3250 if (__n)
3251 {
3252 __r.__begin_ =
3253 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003254 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003255 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3256 ::new (__r.__end_) value_type(-*__p);
3257 }
3258 return __r;
3259}
3260
3261template <class _Tp>
3262valarray<_Tp>
3263valarray<_Tp>::operator~() const
3264{
3265 valarray<value_type> __r;
3266 size_t __n = size();
3267 if (__n)
3268 {
3269 __r.__begin_ =
3270 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003271 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003272 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3273 ::new (__r.__end_) value_type(~*__p);
3274 }
3275 return __r;
3276}
3277
3278template <class _Tp>
3279valarray<bool>
3280valarray<_Tp>::operator!() const
3281{
3282 valarray<bool> __r;
3283 size_t __n = size();
3284 if (__n)
3285 {
3286 __r.__begin_ =
3287 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003288 static_cast<bool*>(_VSTD::__allocate(__n * sizeof(bool)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003289 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3290 ::new (__r.__end_) bool(!*__p);
3291 }
3292 return __r;
3293}
3294
3295template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003296inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003297valarray<_Tp>&
3298valarray<_Tp>::operator*=(const value_type& __x)
3299{
3300 for (value_type* __p = __begin_; __p != __end_; ++__p)
3301 *__p *= __x;
3302 return *this;
3303}
3304
3305template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003306inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003307valarray<_Tp>&
3308valarray<_Tp>::operator/=(const value_type& __x)
3309{
3310 for (value_type* __p = __begin_; __p != __end_; ++__p)
3311 *__p /= __x;
3312 return *this;
3313}
3314
3315template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003316inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003317valarray<_Tp>&
3318valarray<_Tp>::operator%=(const value_type& __x)
3319{
3320 for (value_type* __p = __begin_; __p != __end_; ++__p)
3321 *__p %= __x;
3322 return *this;
3323}
3324
3325template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003326inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003327valarray<_Tp>&
3328valarray<_Tp>::operator+=(const value_type& __x)
3329{
3330 for (value_type* __p = __begin_; __p != __end_; ++__p)
3331 *__p += __x;
3332 return *this;
3333}
3334
3335template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003336inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003337valarray<_Tp>&
3338valarray<_Tp>::operator-=(const value_type& __x)
3339{
3340 for (value_type* __p = __begin_; __p != __end_; ++__p)
3341 *__p -= __x;
3342 return *this;
3343}
3344
3345template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003346inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003347valarray<_Tp>&
3348valarray<_Tp>::operator^=(const value_type& __x)
3349{
3350 for (value_type* __p = __begin_; __p != __end_; ++__p)
3351 *__p ^= __x;
3352 return *this;
3353}
3354
3355template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003356inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003357valarray<_Tp>&
3358valarray<_Tp>::operator&=(const value_type& __x)
3359{
3360 for (value_type* __p = __begin_; __p != __end_; ++__p)
3361 *__p &= __x;
3362 return *this;
3363}
3364
3365template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003366inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003367valarray<_Tp>&
3368valarray<_Tp>::operator|=(const value_type& __x)
3369{
3370 for (value_type* __p = __begin_; __p != __end_; ++__p)
3371 *__p |= __x;
3372 return *this;
3373}
3374
3375template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003376inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003377valarray<_Tp>&
3378valarray<_Tp>::operator<<=(const value_type& __x)
3379{
3380 for (value_type* __p = __begin_; __p != __end_; ++__p)
3381 *__p <<= __x;
3382 return *this;
3383}
3384
3385template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003386inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003387valarray<_Tp>&
3388valarray<_Tp>::operator>>=(const value_type& __x)
3389{
3390 for (value_type* __p = __begin_; __p != __end_; ++__p)
3391 *__p >>= __x;
3392 return *this;
3393}
3394
3395template <class _Tp>
3396template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003397inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003398typename enable_if
3399<
3400 __is_val_expr<_Expr>::value,
3401 valarray<_Tp>&
3402>::type
3403valarray<_Tp>::operator*=(const _Expr& __v)
3404{
3405 size_t __i = 0;
3406 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3407 *__t *= __v[__i];
3408 return *this;
3409}
3410
3411template <class _Tp>
3412template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003413inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003414typename enable_if
3415<
3416 __is_val_expr<_Expr>::value,
3417 valarray<_Tp>&
3418>::type
3419valarray<_Tp>::operator/=(const _Expr& __v)
3420{
3421 size_t __i = 0;
3422 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3423 *__t /= __v[__i];
3424 return *this;
3425}
3426
3427template <class _Tp>
3428template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003429inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003430typename enable_if
3431<
3432 __is_val_expr<_Expr>::value,
3433 valarray<_Tp>&
3434>::type
3435valarray<_Tp>::operator%=(const _Expr& __v)
3436{
3437 size_t __i = 0;
3438 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3439 *__t %= __v[__i];
3440 return *this;
3441}
3442
3443template <class _Tp>
3444template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003445inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003446typename enable_if
3447<
3448 __is_val_expr<_Expr>::value,
3449 valarray<_Tp>&
3450>::type
3451valarray<_Tp>::operator+=(const _Expr& __v)
3452{
3453 size_t __i = 0;
3454 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3455 *__t += __v[__i];
3456 return *this;
3457}
3458
3459template <class _Tp>
3460template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003461inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003462typename enable_if
3463<
3464 __is_val_expr<_Expr>::value,
3465 valarray<_Tp>&
3466>::type
3467valarray<_Tp>::operator-=(const _Expr& __v)
3468{
3469 size_t __i = 0;
3470 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3471 *__t -= __v[__i];
3472 return *this;
3473}
3474
3475template <class _Tp>
3476template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003477inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003478typename enable_if
3479<
3480 __is_val_expr<_Expr>::value,
3481 valarray<_Tp>&
3482>::type
3483valarray<_Tp>::operator^=(const _Expr& __v)
3484{
3485 size_t __i = 0;
3486 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3487 *__t ^= __v[__i];
3488 return *this;
3489}
3490
3491template <class _Tp>
3492template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003493inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003494typename enable_if
3495<
3496 __is_val_expr<_Expr>::value,
3497 valarray<_Tp>&
3498>::type
3499valarray<_Tp>::operator|=(const _Expr& __v)
3500{
3501 size_t __i = 0;
3502 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3503 *__t |= __v[__i];
3504 return *this;
3505}
3506
3507template <class _Tp>
3508template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003509inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003510typename enable_if
3511<
3512 __is_val_expr<_Expr>::value,
3513 valarray<_Tp>&
3514>::type
3515valarray<_Tp>::operator&=(const _Expr& __v)
3516{
3517 size_t __i = 0;
3518 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3519 *__t &= __v[__i];
3520 return *this;
3521}
3522
3523template <class _Tp>
3524template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003525inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003526typename enable_if
3527<
3528 __is_val_expr<_Expr>::value,
3529 valarray<_Tp>&
3530>::type
3531valarray<_Tp>::operator<<=(const _Expr& __v)
3532{
3533 size_t __i = 0;
3534 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3535 *__t <<= __v[__i];
3536 return *this;
3537}
3538
3539template <class _Tp>
3540template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003541inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003542typename enable_if
3543<
3544 __is_val_expr<_Expr>::value,
3545 valarray<_Tp>&
3546>::type
3547valarray<_Tp>::operator>>=(const _Expr& __v)
3548{
3549 size_t __i = 0;
3550 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3551 *__t >>= __v[__i];
3552 return *this;
3553}
3554
3555template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003556inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003557void
Howard Hinnantbd143082012-07-21 00:51:28 +00003558valarray<_Tp>::swap(valarray& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003559{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003560 _VSTD::swap(__begin_, __v.__begin_);
3561 _VSTD::swap(__end_, __v.__end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003562}
3563
3564template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003565inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003566_Tp
3567valarray<_Tp>::sum() const
3568{
3569 if (__begin_ == __end_)
3570 return value_type();
3571 const value_type* __p = __begin_;
3572 _Tp __r = *__p;
3573 for (++__p; __p != __end_; ++__p)
3574 __r += *__p;
3575 return __r;
3576}
3577
3578template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003579inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003580_Tp
3581valarray<_Tp>::min() const
3582{
3583 if (__begin_ == __end_)
3584 return value_type();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003585 return *_VSTD::min_element(__begin_, __end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003586}
3587
3588template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003589inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003590_Tp
3591valarray<_Tp>::max() const
3592{
3593 if (__begin_ == __end_)
3594 return value_type();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003595 return *_VSTD::max_element(__begin_, __end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003596}
3597
3598template <class _Tp>
3599valarray<_Tp>
3600valarray<_Tp>::shift(int __i) const
3601{
3602 valarray<value_type> __r;
3603 size_t __n = size();
3604 if (__n)
3605 {
3606 __r.__begin_ =
3607 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003608 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003609 const value_type* __sb;
3610 value_type* __tb;
3611 value_type* __te;
3612 if (__i >= 0)
3613 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003614 __i = _VSTD::min(__i, static_cast<int>(__n));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003615 __sb = __begin_ + __i;
3616 __tb = __r.__begin_;
3617 __te = __r.__begin_ + (__n - __i);
3618 }
3619 else
3620 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003621 __i = _VSTD::min(-__i, static_cast<int>(__n));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003622 __sb = __begin_;
3623 __tb = __r.__begin_ + __i;
3624 __te = __r.__begin_ + __n;
3625 }
3626 for (; __r.__end_ != __tb; ++__r.__end_)
3627 ::new (__r.__end_) value_type();
3628 for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
3629 ::new (__r.__end_) value_type(*__sb);
3630 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
3631 ::new (__r.__end_) value_type();
3632 }
3633 return __r;
3634}
3635
3636template <class _Tp>
3637valarray<_Tp>
3638valarray<_Tp>::cshift(int __i) const
3639{
3640 valarray<value_type> __r;
3641 size_t __n = size();
3642 if (__n)
3643 {
3644 __r.__begin_ =
3645 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003646 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003647 __i %= static_cast<int>(__n);
3648 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
3649 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
3650 ::new (__r.__end_) value_type(*__s);
3651 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
3652 ::new (__r.__end_) value_type(*__s);
3653 }
3654 return __r;
3655}
3656
3657template <class _Tp>
3658valarray<_Tp>
3659valarray<_Tp>::apply(value_type __f(value_type)) const
3660{
3661 valarray<value_type> __r;
3662 size_t __n = size();
3663 if (__n)
3664 {
3665 __r.__begin_ =
3666 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003667 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003668 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3669 ::new (__r.__end_) value_type(__f(*__p));
3670 }
3671 return __r;
3672}
3673
3674template <class _Tp>
3675valarray<_Tp>
3676valarray<_Tp>::apply(value_type __f(const value_type&)) const
3677{
3678 valarray<value_type> __r;
3679 size_t __n = size();
3680 if (__n)
3681 {
3682 __r.__begin_ =
3683 __r.__end_ =
Richard Smith73c1fce2014-06-04 19:54:15 +00003684 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003685 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3686 ::new (__r.__end_) value_type(__f(*__p));
3687 }
3688 return __r;
3689}
3690
3691template <class _Tp>
3692void
3693valarray<_Tp>::resize(size_t __n, value_type __x)
3694{
3695 if (__begin_ != nullptr)
3696 {
3697 while (__end_ != __begin_)
3698 (--__end_)->~value_type();
Eric Fiselier32b19c32017-01-07 03:01:24 +00003699 _VSTD::__libcpp_deallocate(__begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003700 __begin_ = __end_ = nullptr;
3701 }
3702 if (__n)
3703 {
Richard Smith73c1fce2014-06-04 19:54:15 +00003704 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003705#ifndef _LIBCPP_NO_EXCEPTIONS
3706 try
3707 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003708#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003709 for (; __n; --__n, ++__end_)
3710 ::new (__end_) value_type(__x);
3711#ifndef _LIBCPP_NO_EXCEPTIONS
3712 }
3713 catch (...)
3714 {
3715 resize(0);
3716 throw;
3717 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003718#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003719 }
3720}
3721
3722template<class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003723inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003724void
Howard Hinnantbd143082012-07-21 00:51:28 +00003725swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003726{
3727 __x.swap(__y);
3728}
3729
3730template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003731inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003732typename enable_if
3733<
3734 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3735 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
3736>::type
3737operator*(const _Expr1& __x, const _Expr2& __y)
3738{
3739 typedef typename _Expr1::value_type value_type;
3740 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
3741 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
3742}
3743
3744template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003745inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003746typename enable_if
3747<
3748 __is_val_expr<_Expr>::value,
3749 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3750 _Expr, __scalar_expr<typename _Expr::value_type> > >
3751>::type
3752operator*(const _Expr& __x, const typename _Expr::value_type& __y)
3753{
3754 typedef typename _Expr::value_type value_type;
3755 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3756 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3757 __x, __scalar_expr<value_type>(__y, __x.size())));
3758}
3759
3760template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003761inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003762typename enable_if
3763<
3764 __is_val_expr<_Expr>::value,
3765 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3766 __scalar_expr<typename _Expr::value_type>, _Expr> >
3767>::type
3768operator*(const typename _Expr::value_type& __x, const _Expr& __y)
3769{
3770 typedef typename _Expr::value_type value_type;
3771 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3772 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3773 __scalar_expr<value_type>(__x, __y.size()), __y));
3774}
3775
3776template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003777inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003778typename enable_if
3779<
3780 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3781 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
3782>::type
3783operator/(const _Expr1& __x, const _Expr2& __y)
3784{
3785 typedef typename _Expr1::value_type value_type;
3786 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
3787 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
3788}
3789
3790template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003791inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003792typename enable_if
3793<
3794 __is_val_expr<_Expr>::value,
3795 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3796 _Expr, __scalar_expr<typename _Expr::value_type> > >
3797>::type
3798operator/(const _Expr& __x, const typename _Expr::value_type& __y)
3799{
3800 typedef typename _Expr::value_type value_type;
3801 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3802 return __val_expr<_Op>(_Op(divides<value_type>(),
3803 __x, __scalar_expr<value_type>(__y, __x.size())));
3804}
3805
3806template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003807inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003808typename enable_if
3809<
3810 __is_val_expr<_Expr>::value,
3811 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3812 __scalar_expr<typename _Expr::value_type>, _Expr> >
3813>::type
3814operator/(const typename _Expr::value_type& __x, const _Expr& __y)
3815{
3816 typedef typename _Expr::value_type value_type;
3817 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3818 return __val_expr<_Op>(_Op(divides<value_type>(),
3819 __scalar_expr<value_type>(__x, __y.size()), __y));
3820}
3821
3822template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003823inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003824typename enable_if
3825<
3826 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3827 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3828>::type
3829operator%(const _Expr1& __x, const _Expr2& __y)
3830{
3831 typedef typename _Expr1::value_type value_type;
3832 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
3833 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
3834}
3835
3836template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003837inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003838typename enable_if
3839<
3840 __is_val_expr<_Expr>::value,
3841 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3842 _Expr, __scalar_expr<typename _Expr::value_type> > >
3843>::type
3844operator%(const _Expr& __x, const typename _Expr::value_type& __y)
3845{
3846 typedef typename _Expr::value_type value_type;
3847 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3848 return __val_expr<_Op>(_Op(modulus<value_type>(),
3849 __x, __scalar_expr<value_type>(__y, __x.size())));
3850}
3851
3852template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003853inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003854typename enable_if
3855<
3856 __is_val_expr<_Expr>::value,
3857 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3858 __scalar_expr<typename _Expr::value_type>, _Expr> >
3859>::type
3860operator%(const typename _Expr::value_type& __x, const _Expr& __y)
3861{
3862 typedef typename _Expr::value_type value_type;
3863 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3864 return __val_expr<_Op>(_Op(modulus<value_type>(),
3865 __scalar_expr<value_type>(__x, __y.size()), __y));
3866}
3867
3868template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003869inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003870typename enable_if
3871<
3872 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3873 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3874>::type
3875operator+(const _Expr1& __x, const _Expr2& __y)
3876{
3877 typedef typename _Expr1::value_type value_type;
3878 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
3879 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
3880}
3881
3882template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003883inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003884typename enable_if
3885<
3886 __is_val_expr<_Expr>::value,
3887 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3888 _Expr, __scalar_expr<typename _Expr::value_type> > >
3889>::type
3890operator+(const _Expr& __x, const typename _Expr::value_type& __y)
3891{
3892 typedef typename _Expr::value_type value_type;
3893 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3894 return __val_expr<_Op>(_Op(plus<value_type>(),
3895 __x, __scalar_expr<value_type>(__y, __x.size())));
3896}
3897
3898template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003899inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003900typename enable_if
3901<
3902 __is_val_expr<_Expr>::value,
3903 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3904 __scalar_expr<typename _Expr::value_type>, _Expr> >
3905>::type
3906operator+(const typename _Expr::value_type& __x, const _Expr& __y)
3907{
3908 typedef typename _Expr::value_type value_type;
3909 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3910 return __val_expr<_Op>(_Op(plus<value_type>(),
3911 __scalar_expr<value_type>(__x, __y.size()), __y));
3912}
3913
3914template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003915inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003916typename enable_if
3917<
3918 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3919 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3920>::type
3921operator-(const _Expr1& __x, const _Expr2& __y)
3922{
3923 typedef typename _Expr1::value_type value_type;
3924 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
3925 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
3926}
3927
3928template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003929inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003930typename enable_if
3931<
3932 __is_val_expr<_Expr>::value,
3933 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3934 _Expr, __scalar_expr<typename _Expr::value_type> > >
3935>::type
3936operator-(const _Expr& __x, const typename _Expr::value_type& __y)
3937{
3938 typedef typename _Expr::value_type value_type;
3939 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3940 return __val_expr<_Op>(_Op(minus<value_type>(),
3941 __x, __scalar_expr<value_type>(__y, __x.size())));
3942}
3943
3944template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003945inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003946typename enable_if
3947<
3948 __is_val_expr<_Expr>::value,
3949 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3950 __scalar_expr<typename _Expr::value_type>, _Expr> >
3951>::type
3952operator-(const typename _Expr::value_type& __x, const _Expr& __y)
3953{
3954 typedef typename _Expr::value_type value_type;
3955 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3956 return __val_expr<_Op>(_Op(minus<value_type>(),
3957 __scalar_expr<value_type>(__x, __y.size()), __y));
3958}
3959
3960template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003961inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003962typename enable_if
3963<
3964 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3965 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
3966>::type
3967operator^(const _Expr1& __x, const _Expr2& __y)
3968{
3969 typedef typename _Expr1::value_type value_type;
3970 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
3971 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
3972}
3973
3974template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003975inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003976typename enable_if
3977<
3978 __is_val_expr<_Expr>::value,
3979 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
3980 _Expr, __scalar_expr<typename _Expr::value_type> > >
3981>::type
3982operator^(const _Expr& __x, const typename _Expr::value_type& __y)
3983{
3984 typedef typename _Expr::value_type value_type;
3985 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3986 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
3987 __x, __scalar_expr<value_type>(__y, __x.size())));
3988}
3989
3990template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003991inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003992typename enable_if
3993<
3994 __is_val_expr<_Expr>::value,
3995 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
3996 __scalar_expr<typename _Expr::value_type>, _Expr> >
3997>::type
3998operator^(const typename _Expr::value_type& __x, const _Expr& __y)
3999{
4000 typedef typename _Expr::value_type value_type;
4001 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4002 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
4003 __scalar_expr<value_type>(__x, __y.size()), __y));
4004}
4005
4006template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004007inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004008typename enable_if
4009<
4010 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4011 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4012>::type
4013operator&(const _Expr1& __x, const _Expr2& __y)
4014{
4015 typedef typename _Expr1::value_type value_type;
4016 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
4017 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
4018}
4019
4020template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004021inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004022typename enable_if
4023<
4024 __is_val_expr<_Expr>::value,
4025 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4026 _Expr, __scalar_expr<typename _Expr::value_type> > >
4027>::type
4028operator&(const _Expr& __x, const typename _Expr::value_type& __y)
4029{
4030 typedef typename _Expr::value_type value_type;
4031 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4032 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4033 __x, __scalar_expr<value_type>(__y, __x.size())));
4034}
4035
4036template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004037inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004038typename enable_if
4039<
4040 __is_val_expr<_Expr>::value,
4041 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4042 __scalar_expr<typename _Expr::value_type>, _Expr> >
4043>::type
4044operator&(const typename _Expr::value_type& __x, const _Expr& __y)
4045{
4046 typedef typename _Expr::value_type value_type;
4047 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4048 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4049 __scalar_expr<value_type>(__x, __y.size()), __y));
4050}
4051
4052template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004053inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004054typename enable_if
4055<
4056 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4057 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4058>::type
4059operator|(const _Expr1& __x, const _Expr2& __y)
4060{
4061 typedef typename _Expr1::value_type value_type;
4062 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
4063 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
4064}
4065
4066template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004067inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004068typename enable_if
4069<
4070 __is_val_expr<_Expr>::value,
4071 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4072 _Expr, __scalar_expr<typename _Expr::value_type> > >
4073>::type
4074operator|(const _Expr& __x, const typename _Expr::value_type& __y)
4075{
4076 typedef typename _Expr::value_type value_type;
4077 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4078 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4079 __x, __scalar_expr<value_type>(__y, __x.size())));
4080}
4081
4082template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004083inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004084typename enable_if
4085<
4086 __is_val_expr<_Expr>::value,
4087 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4088 __scalar_expr<typename _Expr::value_type>, _Expr> >
4089>::type
4090operator|(const typename _Expr::value_type& __x, const _Expr& __y)
4091{
4092 typedef typename _Expr::value_type value_type;
4093 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4094 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4095 __scalar_expr<value_type>(__x, __y.size()), __y));
4096}
4097
4098template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004099inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004100typename enable_if
4101<
4102 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4103 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
4104>::type
4105operator<<(const _Expr1& __x, const _Expr2& __y)
4106{
4107 typedef typename _Expr1::value_type value_type;
4108 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
4109 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
4110}
4111
4112template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004113inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004114typename enable_if
4115<
4116 __is_val_expr<_Expr>::value,
4117 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4118 _Expr, __scalar_expr<typename _Expr::value_type> > >
4119>::type
4120operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
4121{
4122 typedef typename _Expr::value_type value_type;
4123 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4124 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4125 __x, __scalar_expr<value_type>(__y, __x.size())));
4126}
4127
4128template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004129inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004130typename enable_if
4131<
4132 __is_val_expr<_Expr>::value,
4133 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4134 __scalar_expr<typename _Expr::value_type>, _Expr> >
4135>::type
4136operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
4137{
4138 typedef typename _Expr::value_type value_type;
4139 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4140 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4141 __scalar_expr<value_type>(__x, __y.size()), __y));
4142}
4143
4144template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004145inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004146typename enable_if
4147<
4148 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4149 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
4150>::type
4151operator>>(const _Expr1& __x, const _Expr2& __y)
4152{
4153 typedef typename _Expr1::value_type value_type;
4154 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
4155 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
4156}
4157
4158template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004159inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004160typename enable_if
4161<
4162 __is_val_expr<_Expr>::value,
4163 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4164 _Expr, __scalar_expr<typename _Expr::value_type> > >
4165>::type
4166operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
4167{
4168 typedef typename _Expr::value_type value_type;
4169 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4170 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4171 __x, __scalar_expr<value_type>(__y, __x.size())));
4172}
4173
4174template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004175inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004176typename enable_if
4177<
4178 __is_val_expr<_Expr>::value,
4179 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4180 __scalar_expr<typename _Expr::value_type>, _Expr> >
4181>::type
4182operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
4183{
4184 typedef typename _Expr::value_type value_type;
4185 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4186 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4187 __scalar_expr<value_type>(__x, __y.size()), __y));
4188}
4189
4190template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004191inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004192typename enable_if
4193<
4194 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4195 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4196>::type
4197operator&&(const _Expr1& __x, const _Expr2& __y)
4198{
4199 typedef typename _Expr1::value_type value_type;
4200 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
4201 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
4202}
4203
4204template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004205inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004206typename enable_if
4207<
4208 __is_val_expr<_Expr>::value,
4209 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4210 _Expr, __scalar_expr<typename _Expr::value_type> > >
4211>::type
4212operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
4213{
4214 typedef typename _Expr::value_type value_type;
4215 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4216 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4217 __x, __scalar_expr<value_type>(__y, __x.size())));
4218}
4219
4220template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004221inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004222typename enable_if
4223<
4224 __is_val_expr<_Expr>::value,
4225 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4226 __scalar_expr<typename _Expr::value_type>, _Expr> >
4227>::type
4228operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
4229{
4230 typedef typename _Expr::value_type value_type;
4231 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4232 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4233 __scalar_expr<value_type>(__x, __y.size()), __y));
4234}
4235
4236template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004237inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004238typename enable_if
4239<
4240 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4241 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4242>::type
4243operator||(const _Expr1& __x, const _Expr2& __y)
4244{
4245 typedef typename _Expr1::value_type value_type;
4246 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
4247 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
4248}
4249
4250template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004251inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004252typename enable_if
4253<
4254 __is_val_expr<_Expr>::value,
4255 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4256 _Expr, __scalar_expr<typename _Expr::value_type> > >
4257>::type
4258operator||(const _Expr& __x, const typename _Expr::value_type& __y)
4259{
4260 typedef typename _Expr::value_type value_type;
4261 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4262 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4263 __x, __scalar_expr<value_type>(__y, __x.size())));
4264}
4265
4266template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004267inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004268typename enable_if
4269<
4270 __is_val_expr<_Expr>::value,
4271 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4272 __scalar_expr<typename _Expr::value_type>, _Expr> >
4273>::type
4274operator||(const typename _Expr::value_type& __x, const _Expr& __y)
4275{
4276 typedef typename _Expr::value_type value_type;
4277 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4278 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4279 __scalar_expr<value_type>(__x, __y.size()), __y));
4280}
4281
4282template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004283inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004284typename enable_if
4285<
4286 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4287 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4288>::type
4289operator==(const _Expr1& __x, const _Expr2& __y)
4290{
4291 typedef typename _Expr1::value_type value_type;
4292 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
4293 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
4294}
4295
4296template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004297inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004298typename enable_if
4299<
4300 __is_val_expr<_Expr>::value,
4301 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4302 _Expr, __scalar_expr<typename _Expr::value_type> > >
4303>::type
4304operator==(const _Expr& __x, const typename _Expr::value_type& __y)
4305{
4306 typedef typename _Expr::value_type value_type;
4307 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4308 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4309 __x, __scalar_expr<value_type>(__y, __x.size())));
4310}
4311
4312template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004313inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004314typename enable_if
4315<
4316 __is_val_expr<_Expr>::value,
4317 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4318 __scalar_expr<typename _Expr::value_type>, _Expr> >
4319>::type
4320operator==(const typename _Expr::value_type& __x, const _Expr& __y)
4321{
4322 typedef typename _Expr::value_type value_type;
4323 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4324 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4325 __scalar_expr<value_type>(__x, __y.size()), __y));
4326}
4327
4328template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004329inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004330typename enable_if
4331<
4332 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4333 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4334>::type
4335operator!=(const _Expr1& __x, const _Expr2& __y)
4336{
4337 typedef typename _Expr1::value_type value_type;
4338 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
4339 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
4340}
4341
4342template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004343inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004344typename enable_if
4345<
4346 __is_val_expr<_Expr>::value,
4347 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4348 _Expr, __scalar_expr<typename _Expr::value_type> > >
4349>::type
4350operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
4351{
4352 typedef typename _Expr::value_type value_type;
4353 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4354 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4355 __x, __scalar_expr<value_type>(__y, __x.size())));
4356}
4357
4358template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004359inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004360typename enable_if
4361<
4362 __is_val_expr<_Expr>::value,
4363 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4364 __scalar_expr<typename _Expr::value_type>, _Expr> >
4365>::type
4366operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
4367{
4368 typedef typename _Expr::value_type value_type;
4369 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4370 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4371 __scalar_expr<value_type>(__x, __y.size()), __y));
4372}
4373
4374template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004375inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004376typename enable_if
4377<
4378 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4379 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
4380>::type
4381operator<(const _Expr1& __x, const _Expr2& __y)
4382{
4383 typedef typename _Expr1::value_type value_type;
4384 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
4385 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
4386}
4387
4388template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004389inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004390typename enable_if
4391<
4392 __is_val_expr<_Expr>::value,
4393 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4394 _Expr, __scalar_expr<typename _Expr::value_type> > >
4395>::type
4396operator<(const _Expr& __x, const typename _Expr::value_type& __y)
4397{
4398 typedef typename _Expr::value_type value_type;
4399 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4400 return __val_expr<_Op>(_Op(less<value_type>(),
4401 __x, __scalar_expr<value_type>(__y, __x.size())));
4402}
4403
4404template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004405inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004406typename enable_if
4407<
4408 __is_val_expr<_Expr>::value,
4409 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4410 __scalar_expr<typename _Expr::value_type>, _Expr> >
4411>::type
4412operator<(const typename _Expr::value_type& __x, const _Expr& __y)
4413{
4414 typedef typename _Expr::value_type value_type;
4415 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4416 return __val_expr<_Op>(_Op(less<value_type>(),
4417 __scalar_expr<value_type>(__x, __y.size()), __y));
4418}
4419
4420template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004421inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004422typename enable_if
4423<
4424 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4425 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
4426>::type
4427operator>(const _Expr1& __x, const _Expr2& __y)
4428{
4429 typedef typename _Expr1::value_type value_type;
4430 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
4431 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
4432}
4433
4434template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004435inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004436typename enable_if
4437<
4438 __is_val_expr<_Expr>::value,
4439 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4440 _Expr, __scalar_expr<typename _Expr::value_type> > >
4441>::type
4442operator>(const _Expr& __x, const typename _Expr::value_type& __y)
4443{
4444 typedef typename _Expr::value_type value_type;
4445 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4446 return __val_expr<_Op>(_Op(greater<value_type>(),
4447 __x, __scalar_expr<value_type>(__y, __x.size())));
4448}
4449
4450template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004451inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004452typename enable_if
4453<
4454 __is_val_expr<_Expr>::value,
4455 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4456 __scalar_expr<typename _Expr::value_type>, _Expr> >
4457>::type
4458operator>(const typename _Expr::value_type& __x, const _Expr& __y)
4459{
4460 typedef typename _Expr::value_type value_type;
4461 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4462 return __val_expr<_Op>(_Op(greater<value_type>(),
4463 __scalar_expr<value_type>(__x, __y.size()), __y));
4464}
4465
4466template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004467inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004468typename enable_if
4469<
4470 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4471 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4472>::type
4473operator<=(const _Expr1& __x, const _Expr2& __y)
4474{
4475 typedef typename _Expr1::value_type value_type;
4476 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
4477 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
4478}
4479
4480template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004481inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004482typename enable_if
4483<
4484 __is_val_expr<_Expr>::value,
4485 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4486 _Expr, __scalar_expr<typename _Expr::value_type> > >
4487>::type
4488operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
4489{
4490 typedef typename _Expr::value_type value_type;
4491 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4492 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4493 __x, __scalar_expr<value_type>(__y, __x.size())));
4494}
4495
4496template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004497inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004498typename enable_if
4499<
4500 __is_val_expr<_Expr>::value,
4501 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4502 __scalar_expr<typename _Expr::value_type>, _Expr> >
4503>::type
4504operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
4505{
4506 typedef typename _Expr::value_type value_type;
4507 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4508 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4509 __scalar_expr<value_type>(__x, __y.size()), __y));
4510}
4511
4512template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004513inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004514typename enable_if
4515<
4516 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4517 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4518>::type
4519operator>=(const _Expr1& __x, const _Expr2& __y)
4520{
4521 typedef typename _Expr1::value_type value_type;
4522 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
4523 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
4524}
4525
4526template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004527inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004528typename enable_if
4529<
4530 __is_val_expr<_Expr>::value,
4531 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4532 _Expr, __scalar_expr<typename _Expr::value_type> > >
4533>::type
4534operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
4535{
4536 typedef typename _Expr::value_type value_type;
4537 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4538 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4539 __x, __scalar_expr<value_type>(__y, __x.size())));
4540}
4541
4542template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004543inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004544typename enable_if
4545<
4546 __is_val_expr<_Expr>::value,
4547 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4548 __scalar_expr<typename _Expr::value_type>, _Expr> >
4549>::type
4550operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
4551{
4552 typedef typename _Expr::value_type value_type;
4553 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4554 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4555 __scalar_expr<value_type>(__x, __y.size()), __y));
4556}
4557
4558template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004559inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004560typename enable_if
4561<
4562 __is_val_expr<_Expr>::value,
4563 __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
4564>::type
4565abs(const _Expr& __x)
4566{
4567 typedef typename _Expr::value_type value_type;
4568 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
4569 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
4570}
4571
4572template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004573inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004574typename enable_if
4575<
4576 __is_val_expr<_Expr>::value,
4577 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
4578>::type
4579acos(const _Expr& __x)
4580{
4581 typedef typename _Expr::value_type value_type;
4582 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
4583 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
4584}
4585
4586template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004587inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004588typename enable_if
4589<
4590 __is_val_expr<_Expr>::value,
4591 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
4592>::type
4593asin(const _Expr& __x)
4594{
4595 typedef typename _Expr::value_type value_type;
4596 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
4597 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
4598}
4599
4600template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004601inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004602typename enable_if
4603<
4604 __is_val_expr<_Expr>::value,
4605 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
4606>::type
4607atan(const _Expr& __x)
4608{
4609 typedef typename _Expr::value_type value_type;
4610 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
4611 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
4612}
4613
4614template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004615inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004616typename enable_if
4617<
4618 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4619 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4620>::type
4621atan2(const _Expr1& __x, const _Expr2& __y)
4622{
4623 typedef typename _Expr1::value_type value_type;
4624 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
4625 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
4626}
4627
4628template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004629inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004630typename enable_if
4631<
4632 __is_val_expr<_Expr>::value,
4633 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4634 _Expr, __scalar_expr<typename _Expr::value_type> > >
4635>::type
4636atan2(const _Expr& __x, const typename _Expr::value_type& __y)
4637{
4638 typedef typename _Expr::value_type value_type;
4639 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4640 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4641 __x, __scalar_expr<value_type>(__y, __x.size())));
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<__atan2_expr<typename _Expr::value_type>,
4650 __scalar_expr<typename _Expr::value_type>, _Expr> >
4651>::type
4652atan2(const typename _Expr::value_type& __x, const _Expr& __y)
4653{
4654 typedef typename _Expr::value_type value_type;
4655 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4656 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4657 __scalar_expr<value_type>(__x, __y.size()), __y));
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<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
4666>::type
4667cos(const _Expr& __x)
4668{
4669 typedef typename _Expr::value_type value_type;
4670 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
4671 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
4672}
4673
4674template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004675inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004676typename enable_if
4677<
4678 __is_val_expr<_Expr>::value,
4679 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
4680>::type
4681cosh(const _Expr& __x)
4682{
4683 typedef typename _Expr::value_type value_type;
4684 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
4685 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
4686}
4687
4688template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004689inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004690typename enable_if
4691<
4692 __is_val_expr<_Expr>::value,
4693 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
4694>::type
4695exp(const _Expr& __x)
4696{
4697 typedef typename _Expr::value_type value_type;
4698 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
4699 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
4700}
4701
4702template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004703inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004704typename enable_if
4705<
4706 __is_val_expr<_Expr>::value,
4707 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
4708>::type
4709log(const _Expr& __x)
4710{
4711 typedef typename _Expr::value_type value_type;
4712 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
4713 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
4714}
4715
4716template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004717inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004718typename enable_if
4719<
4720 __is_val_expr<_Expr>::value,
4721 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
4722>::type
4723log10(const _Expr& __x)
4724{
4725 typedef typename _Expr::value_type value_type;
4726 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
4727 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
4728}
4729
4730template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004731inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004732typename enable_if
4733<
4734 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4735 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4736>::type
4737pow(const _Expr1& __x, const _Expr2& __y)
4738{
4739 typedef typename _Expr1::value_type value_type;
4740 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
4741 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
4742}
4743
4744template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004745inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004746typename enable_if
4747<
4748 __is_val_expr<_Expr>::value,
4749 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4750 _Expr, __scalar_expr<typename _Expr::value_type> > >
4751>::type
4752pow(const _Expr& __x, const typename _Expr::value_type& __y)
4753{
4754 typedef typename _Expr::value_type value_type;
4755 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4756 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4757 __x, __scalar_expr<value_type>(__y, __x.size())));
4758}
4759
4760template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004761inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004762typename enable_if
4763<
4764 __is_val_expr<_Expr>::value,
4765 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4766 __scalar_expr<typename _Expr::value_type>, _Expr> >
4767>::type
4768pow(const typename _Expr::value_type& __x, const _Expr& __y)
4769{
4770 typedef typename _Expr::value_type value_type;
4771 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4772 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4773 __scalar_expr<value_type>(__x, __y.size()), __y));
4774}
4775
4776template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004777inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004778typename enable_if
4779<
4780 __is_val_expr<_Expr>::value,
4781 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
4782>::type
4783sin(const _Expr& __x)
4784{
4785 typedef typename _Expr::value_type value_type;
4786 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
4787 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
4788}
4789
4790template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004791inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004792typename enable_if
4793<
4794 __is_val_expr<_Expr>::value,
4795 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
4796>::type
4797sinh(const _Expr& __x)
4798{
4799 typedef typename _Expr::value_type value_type;
4800 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
4801 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
4802}
4803
4804template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004805inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004806typename enable_if
4807<
4808 __is_val_expr<_Expr>::value,
4809 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
4810>::type
4811sqrt(const _Expr& __x)
4812{
4813 typedef typename _Expr::value_type value_type;
4814 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
4815 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
4816}
4817
4818template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004819inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004820typename enable_if
4821<
4822 __is_val_expr<_Expr>::value,
4823 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
4824>::type
4825tan(const _Expr& __x)
4826{
4827 typedef typename _Expr::value_type value_type;
4828 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
4829 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
4830}
4831
4832template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004833inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004834typename enable_if
4835<
4836 __is_val_expr<_Expr>::value,
4837 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
4838>::type
4839tanh(const _Expr& __x)
4840{
4841 typedef typename _Expr::value_type value_type;
4842 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
4843 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
4844}
4845
4846template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004847inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004848_Tp*
4849begin(valarray<_Tp>& __v)
4850{
4851 return __v.__begin_;
4852}
4853
4854template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004855inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004856const _Tp*
4857begin(const valarray<_Tp>& __v)
4858{
4859 return __v.__begin_;
4860}
4861
4862template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004863inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004864_Tp*
4865end(valarray<_Tp>& __v)
4866{
4867 return __v.__end_;
4868}
4869
4870template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004871inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004872const _Tp*
4873end(const valarray<_Tp>& __v)
4874{
4875 return __v.__end_;
4876}
4877
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004878_LIBCPP_END_NAMESPACE_STD
4879
4880#endif // _LIBCPP_VALARRAY