blob: 8d3892ad35d91f11c4c4ed4b9c85bcce2ba5e4fd [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 Hinnant08e17472011-10-17 20:05:10 +0000350#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000351#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000352#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000353
Eric Fiselier018a3d52017-05-31 22:07:49 +0000354_LIBCPP_PUSH_MACROS
355#include <__undef_macros>
356
357
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000358_LIBCPP_BEGIN_NAMESPACE_STD
359
Eric Fiselierc3589a82017-01-04 23:56:00 +0000360template<class _Tp> class _LIBCPP_TEMPLATE_VIS valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361
Eric Fiselierc3589a82017-01-04 23:56:00 +0000362class _LIBCPP_TEMPLATE_VIS slice
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000363{
364 size_t __start_;
365 size_t __size_;
366 size_t __stride_;
367public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000368 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000369 slice()
370 : __start_(0),
371 __size_(0),
372 __stride_(0)
373 {}
374
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000375 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000376 slice(size_t __start, size_t __size, size_t __stride)
377 : __start_(__start),
378 __size_(__size),
379 __stride_(__stride)
380 {}
381
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000382 _LIBCPP_INLINE_VISIBILITY size_t start() const {return __start_;}
383 _LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;}
384 _LIBCPP_INLINE_VISIBILITY size_t stride() const {return __stride_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000385};
386
Eric Fiselierc3589a82017-01-04 23:56:00 +0000387template <class _Tp> class _LIBCPP_TEMPLATE_VIS slice_array;
Howard Hinnant83eade62013-03-06 23:30:19 +0000388class _LIBCPP_TYPE_VIS gslice;
Eric Fiselierc3589a82017-01-04 23:56:00 +0000389template <class _Tp> class _LIBCPP_TEMPLATE_VIS gslice_array;
390template <class _Tp> class _LIBCPP_TEMPLATE_VIS mask_array;
391template <class _Tp> class _LIBCPP_TEMPLATE_VIS indirect_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000392
393template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000394_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000395_Tp*
396begin(valarray<_Tp>& __v);
397
398template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000399_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000400const _Tp*
401begin(const valarray<_Tp>& __v);
402
403template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000404_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000405_Tp*
406end(valarray<_Tp>& __v);
407
408template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000409_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000410const _Tp*
411end(const valarray<_Tp>& __v);
412
413template <class _Op, class _A0>
414struct _UnaryOp
415{
416 typedef typename _Op::result_type result_type;
417 typedef typename _A0::value_type value_type;
418
419 _Op __op_;
420 _A0 __a0_;
421
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000423 _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {}
424
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000425 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000426 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
427
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000429 size_t size() const {return __a0_.size();}
430};
431
432template <class _Op, class _A0, class _A1>
433struct _BinaryOp
434{
435 typedef typename _Op::result_type result_type;
436 typedef typename _A0::value_type value_type;
437
438 _Op __op_;
439 _A0 __a0_;
440 _A1 __a1_;
441
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000442 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000443 _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1)
444 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
445
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000446 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000447 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
448
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000450 size_t size() const {return __a0_.size();}
451};
452
453template <class _Tp>
454class __scalar_expr
455{
456public:
457 typedef _Tp value_type;
458 typedef const _Tp& result_type;
459private:
460 const value_type& __t_;
461 size_t __s_;
462public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000464 explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {}
465
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000467 result_type operator[](size_t) const {return __t_;}
468
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470 size_t size() const {return __s_;}
471};
472
473template <class _Tp>
474struct __unary_plus : unary_function<_Tp, _Tp>
475{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000477 _Tp operator()(const _Tp& __x) const
478 {return +__x;}
479};
480
481template <class _Tp>
482struct __bit_not : unary_function<_Tp, _Tp>
483{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000485 _Tp operator()(const _Tp& __x) const
486 {return ~__x;}
487};
488
489template <class _Tp>
490struct __bit_shift_left : binary_function<_Tp, _Tp, _Tp>
491{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000493 _Tp operator()(const _Tp& __x, const _Tp& __y) const
494 {return __x << __y;}
495};
496
497template <class _Tp>
498struct __bit_shift_right : binary_function<_Tp, _Tp, _Tp>
499{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000501 _Tp operator()(const _Tp& __x, const _Tp& __y) const
502 {return __x >> __y;}
503};
504
Howard Hinnant99968442011-11-29 18:15:50 +0000505template <class _Tp, class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000506struct __apply_expr : unary_function<_Tp, _Tp>
507{
508private:
Howard Hinnant99968442011-11-29 18:15:50 +0000509 _Fp __f_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000510public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +0000512 explicit __apply_expr(_Fp __f) : __f_(__f) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000513
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000515 _Tp operator()(const _Tp& __x) const
516 {return __f_(__x);}
517};
518
519template <class _Tp>
520struct __abs_expr : unary_function<_Tp, _Tp>
521{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000523 _Tp operator()(const _Tp& __x) const
524 {return abs(__x);}
525};
526
527template <class _Tp>
528struct __acos_expr : unary_function<_Tp, _Tp>
529{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000530 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000531 _Tp operator()(const _Tp& __x) const
532 {return acos(__x);}
533};
534
535template <class _Tp>
536struct __asin_expr : unary_function<_Tp, _Tp>
537{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000539 _Tp operator()(const _Tp& __x) const
540 {return asin(__x);}
541};
542
543template <class _Tp>
544struct __atan_expr : unary_function<_Tp, _Tp>
545{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000546 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000547 _Tp operator()(const _Tp& __x) const
548 {return atan(__x);}
549};
550
551template <class _Tp>
552struct __atan2_expr : binary_function<_Tp, _Tp, _Tp>
553{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000555 _Tp operator()(const _Tp& __x, const _Tp& __y) const
556 {return atan2(__x, __y);}
557};
558
559template <class _Tp>
560struct __cos_expr : unary_function<_Tp, _Tp>
561{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000563 _Tp operator()(const _Tp& __x) const
564 {return cos(__x);}
565};
566
567template <class _Tp>
568struct __cosh_expr : unary_function<_Tp, _Tp>
569{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000571 _Tp operator()(const _Tp& __x) const
572 {return cosh(__x);}
573};
574
575template <class _Tp>
576struct __exp_expr : unary_function<_Tp, _Tp>
577{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000579 _Tp operator()(const _Tp& __x) const
580 {return exp(__x);}
581};
582
583template <class _Tp>
584struct __log_expr : unary_function<_Tp, _Tp>
585{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000587 _Tp operator()(const _Tp& __x) const
588 {return log(__x);}
589};
590
591template <class _Tp>
592struct __log10_expr : unary_function<_Tp, _Tp>
593{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000595 _Tp operator()(const _Tp& __x) const
596 {return log10(__x);}
597};
598
599template <class _Tp>
600struct __pow_expr : binary_function<_Tp, _Tp, _Tp>
601{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000603 _Tp operator()(const _Tp& __x, const _Tp& __y) const
604 {return pow(__x, __y);}
605};
606
607template <class _Tp>
608struct __sin_expr : unary_function<_Tp, _Tp>
609{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000611 _Tp operator()(const _Tp& __x) const
612 {return sin(__x);}
613};
614
615template <class _Tp>
616struct __sinh_expr : unary_function<_Tp, _Tp>
617{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000619 _Tp operator()(const _Tp& __x) const
620 {return sinh(__x);}
621};
622
623template <class _Tp>
624struct __sqrt_expr : unary_function<_Tp, _Tp>
625{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000627 _Tp operator()(const _Tp& __x) const
628 {return sqrt(__x);}
629};
630
631template <class _Tp>
632struct __tan_expr : unary_function<_Tp, _Tp>
633{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000635 _Tp operator()(const _Tp& __x) const
636 {return tan(__x);}
637};
638
639template <class _Tp>
640struct __tanh_expr : unary_function<_Tp, _Tp>
641{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000643 _Tp operator()(const _Tp& __x) const
644 {return tanh(__x);}
645};
646
647template <class _ValExpr>
648class __slice_expr
649{
650 typedef typename remove_reference<_ValExpr>::type _RmExpr;
651public:
652 typedef typename _RmExpr::value_type value_type;
653 typedef value_type result_type;
654
655private:
656 _ValExpr __expr_;
657 size_t __start_;
658 size_t __size_;
659 size_t __stride_;
660
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000662 __slice_expr(const slice& __sl, const _RmExpr& __e)
663 : __expr_(__e),
664 __start_(__sl.start()),
665 __size_(__sl.size()),
666 __stride_(__sl.stride())
667 {}
668public:
669
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000670 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000671 result_type operator[](size_t __i) const
672 {return __expr_[__start_ + __i * __stride_];}
673
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000675 size_t size() const {return __size_;}
676
Eric Fiselierc3589a82017-01-04 23:56:00 +0000677 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000678};
679
680template <class _ValExpr>
681class __mask_expr;
682
683template <class _ValExpr>
684class __indirect_expr;
685
686template <class _ValExpr>
687class __shift_expr
688{
689 typedef typename remove_reference<_ValExpr>::type _RmExpr;
690public:
691 typedef typename _RmExpr::value_type value_type;
692 typedef value_type result_type;
693
694private:
695 _ValExpr __expr_;
696 size_t __size_;
697 ptrdiff_t __ul_;
698 ptrdiff_t __sn_;
699 ptrdiff_t __n_;
Howard Hinnant99968442011-11-29 18:15:50 +0000700 static const ptrdiff_t _Np = static_cast<ptrdiff_t>(
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000701 sizeof(ptrdiff_t) * __CHAR_BIT__ - 1);
702
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000704 __shift_expr(int __n, const _RmExpr& __e)
705 : __expr_(__e),
706 __size_(__e.size()),
707 __n_(__n)
708 {
Howard Hinnant99968442011-11-29 18:15:50 +0000709 ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _Np);
710 __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _Np);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711 __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n);
712 }
713public:
714
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000715 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000716 result_type operator[](size_t __j) const
717 {
Howard Hinnantec3773c2011-12-01 20:21:04 +0000718 ptrdiff_t __i = static_cast<ptrdiff_t>(__j);
Howard Hinnant99968442011-11-29 18:15:50 +0000719 ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000720 return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
721 }
722
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000724 size_t size() const {return __size_;}
725
726 template <class> friend class __val_expr;
727};
728
729template <class _ValExpr>
730class __cshift_expr
731{
732 typedef typename remove_reference<_ValExpr>::type _RmExpr;
733public:
734 typedef typename _RmExpr::value_type value_type;
735 typedef value_type result_type;
736
737private:
738 _ValExpr __expr_;
739 size_t __size_;
740 size_t __m_;
741 size_t __o1_;
742 size_t __o2_;
743
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000745 __cshift_expr(int __n, const _RmExpr& __e)
746 : __expr_(__e),
747 __size_(__e.size())
748 {
749 __n %= static_cast<int>(__size_);
750 if (__n >= 0)
751 {
752 __m_ = __size_ - __n;
753 __o1_ = __n;
754 __o2_ = __n - __size_;
755 }
756 else
757 {
758 __m_ = -__n;
759 __o1_ = __n + __size_;
760 __o2_ = __n;
761 }
762 }
763public:
764
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000766 result_type operator[](size_t __i) const
767 {
768 if (__i < __m_)
769 return __expr_[__i + __o1_];
770 return __expr_[__i + __o2_];
771 }
772
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000774 size_t size() const {return __size_;}
775
776 template <class> friend class __val_expr;
777};
778
779template<class _ValExpr>
780class __val_expr;
781
782template<class _ValExpr>
783struct __is_val_expr : false_type {};
784
785template<class _ValExpr>
786struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
787
788template<class _Tp>
789struct __is_val_expr<valarray<_Tp> > : true_type {};
790
791template<class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000792class _LIBCPP_TEMPLATE_VIS valarray
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000793{
794public:
795 typedef _Tp value_type;
796 typedef _Tp result_type;
797
798private:
799 value_type* __begin_;
800 value_type* __end_;
801
802public:
803 // construct/destroy:
Douglas Gregor0855dde2012-05-19 07:14:17 +0000804 _LIBCPP_INLINE_VISIBILITY
805 valarray() : __begin_(0), __end_(0) {}
Eric Fiselierb6a049f2016-09-16 00:13:55 +0000806 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
807 explicit valarray(size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000808 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor0855dde2012-05-19 07:14:17 +0000809 valarray(const value_type& __x, size_t __n);
810 valarray(const value_type* __p, size_t __n);
811 valarray(const valarray& __v);
Eric Fiselier97db5172017-04-19 00:23:45 +0000812#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000813 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd143082012-07-21 00:51:28 +0000814 valarray(valarray&& __v) _NOEXCEPT;
Douglas Gregor0855dde2012-05-19 07:14:17 +0000815 valarray(initializer_list<value_type> __il);
Eric Fiselier97db5172017-04-19 00:23:45 +0000816#endif // _LIBCPP_CXX03_LANG
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);
Eric Fiselier97db5172017-04-19 00:23:45 +0000826#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd143082012-07-21 00:51:28 +0000828 valarray& operator=(valarray&& __v) _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000829 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor0855dde2012-05-19 07:14:17 +0000830 valarray& operator=(initializer_list<value_type>);
Eric Fiselier97db5172017-04-19 00:23:45 +0000831#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000832 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor0855dde2012-05-19 07:14:17 +0000833 valarray& operator=(const value_type& __x);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000835 valarray& operator=(const slice_array<value_type>& __sa);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000837 valarray& operator=(const gslice_array<value_type>& __ga);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000839 valarray& operator=(const mask_array<value_type>& __ma);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000841 valarray& operator=(const indirect_array<value_type>& __ia);
Howard Hinnantdb866632011-07-27 23:19:59 +0000842 template <class _ValExpr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000843 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantdb866632011-07-27 23:19:59 +0000844 valarray& operator=(const __val_expr<_ValExpr>& __v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000845
846 // element access:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000848 const value_type& operator[](size_t __i) const {return __begin_[__i];}
849
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000851 value_type& operator[](size_t __i) {return __begin_[__i];}
852
853 // subset operations:
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000854 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000855 __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000857 slice_array<value_type> operator[](slice __s);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000859 __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000861 gslice_array<value_type> operator[](const gslice& __gs);
Eric Fiselier97db5172017-04-19 00:23:45 +0000862#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000864 __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000866 gslice_array<value_type> operator[](gslice&& __gs);
Eric Fiselier97db5172017-04-19 00:23:45 +0000867#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000868 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000869 __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000871 mask_array<value_type> operator[](const valarray<bool>& __vb);
Eric Fiselier97db5172017-04-19 00:23:45 +0000872#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000874 __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000876 mask_array<value_type> operator[](valarray<bool>&& __vb);
Eric Fiselier97db5172017-04-19 00:23:45 +0000877#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000878 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000879 __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000881 indirect_array<value_type> operator[](const valarray<size_t>& __vs);
Eric Fiselier97db5172017-04-19 00:23:45 +0000882#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000884 __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000886 indirect_array<value_type> operator[](valarray<size_t>&& __vs);
Eric Fiselier97db5172017-04-19 00:23:45 +0000887#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000888
889 // unary operators:
Douglas Gregor0855dde2012-05-19 07:14:17 +0000890 valarray operator+() const;
891 valarray operator-() const;
892 valarray operator~() const;
893 valarray<bool> operator!() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000894
895 // computed assignment:
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000897 valarray& operator*= (const value_type& __x);
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);
916
917 template <class _Expr>
918 typename enable_if
919 <
920 __is_val_expr<_Expr>::value,
921 valarray&
922 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000924 operator*= (const _Expr& __v);
925
926 template <class _Expr>
927 typename enable_if
928 <
929 __is_val_expr<_Expr>::value,
930 valarray&
931 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000932 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000933 operator/= (const _Expr& __v);
934
935 template <class _Expr>
936 typename enable_if
937 <
938 __is_val_expr<_Expr>::value,
939 valarray&
940 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000941 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000942 operator%= (const _Expr& __v);
943
944 template <class _Expr>
945 typename enable_if
946 <
947 __is_val_expr<_Expr>::value,
948 valarray&
949 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000951 operator+= (const _Expr& __v);
952
953 template <class _Expr>
954 typename enable_if
955 <
956 __is_val_expr<_Expr>::value,
957 valarray&
958 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000959 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000960 operator-= (const _Expr& __v);
961
962 template <class _Expr>
963 typename enable_if
964 <
965 __is_val_expr<_Expr>::value,
966 valarray&
967 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000968 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000969 operator^= (const _Expr& __v);
970
971 template <class _Expr>
972 typename enable_if
973 <
974 __is_val_expr<_Expr>::value,
975 valarray&
976 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000977 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000978 operator|= (const _Expr& __v);
979
980 template <class _Expr>
981 typename enable_if
982 <
983 __is_val_expr<_Expr>::value,
984 valarray&
985 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000986 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000987 operator&= (const _Expr& __v);
988
989 template <class _Expr>
990 typename enable_if
991 <
992 __is_val_expr<_Expr>::value,
993 valarray&
994 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000996 operator<<= (const _Expr& __v);
997
998 template <class _Expr>
999 typename enable_if
1000 <
1001 __is_val_expr<_Expr>::value,
1002 valarray&
1003 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001004 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001005 operator>>= (const _Expr& __v);
1006
1007 // member functions:
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd143082012-07-21 00:51:28 +00001009 void swap(valarray& __v) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001010
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001011 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001012 size_t size() const {return static_cast<size_t>(__end_ - __begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001013
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001014 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor0855dde2012-05-19 07:14:17 +00001015 value_type sum() const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001016 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor0855dde2012-05-19 07:14:17 +00001017 value_type min() const;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001018 _LIBCPP_INLINE_VISIBILITY
Douglas Gregor0855dde2012-05-19 07:14:17 +00001019 value_type max() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001020
Douglas Gregor0855dde2012-05-19 07:14:17 +00001021 valarray shift (int __i) const;
1022 valarray cshift(int __i) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001023 valarray apply(value_type __f(value_type)) const;
1024 valarray apply(value_type __f(const value_type&)) const;
1025 void resize(size_t __n, value_type __x = value_type());
1026
1027private:
Eric Fiselierc3589a82017-01-04 23:56:00 +00001028 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
1029 template <class> friend class _LIBCPP_TEMPLATE_VIS slice_array;
1030 template <class> friend class _LIBCPP_TEMPLATE_VIS gslice_array;
1031 template <class> friend class _LIBCPP_TEMPLATE_VIS mask_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001032 template <class> friend class __mask_expr;
Eric Fiselierc3589a82017-01-04 23:56:00 +00001033 template <class> friend class _LIBCPP_TEMPLATE_VIS indirect_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001034 template <class> friend class __indirect_expr;
1035 template <class> friend class __val_expr;
1036
1037 template <class _Up>
1038 friend
1039 _Up*
1040 begin(valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +00001041
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001042 template <class _Up>
1043 friend
1044 const _Up*
1045 begin(const valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +00001046
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001047 template <class _Up>
1048 friend
1049 _Up*
1050 end(valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +00001051
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001052 template <class _Up>
1053 friend
1054 const _Up*
1055 end(const valarray<_Up>& __v);
Mikhail Maltsev171ed212018-02-08 11:33:48 +00001056
1057 void __clear();
1058 valarray& __assign_range(const value_type* __f, const value_type* __l);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001059};
1060
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001061_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::valarray(size_t))
1062_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::~valarray())
1063_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void valarray<size_t>::resize(size_t, size_t))
1064
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001065template <class _Op, class _Tp>
1066struct _UnaryOp<_Op, valarray<_Tp> >
1067{
1068 typedef typename _Op::result_type result_type;
1069 typedef _Tp value_type;
1070
1071 _Op __op_;
1072 const valarray<_Tp>& __a0_;
1073
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001074 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001075 _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
1076
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001077 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001078 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
1079
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001081 size_t size() const {return __a0_.size();}
1082};
1083
1084template <class _Op, class _Tp, class _A1>
1085struct _BinaryOp<_Op, valarray<_Tp>, _A1>
1086{
1087 typedef typename _Op::result_type result_type;
1088 typedef _Tp value_type;
1089
1090 _Op __op_;
1091 const valarray<_Tp>& __a0_;
1092 _A1 __a1_;
1093
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001094 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001095 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
1096 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1097
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001099 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1100
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001102 size_t size() const {return __a0_.size();}
1103};
1104
1105template <class _Op, class _A0, class _Tp>
1106struct _BinaryOp<_Op, _A0, valarray<_Tp> >
1107{
1108 typedef typename _Op::result_type result_type;
1109 typedef _Tp value_type;
1110
1111 _Op __op_;
1112 _A0 __a0_;
1113 const valarray<_Tp>& __a1_;
1114
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001116 _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
1117 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1118
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001119 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001120 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1121
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001123 size_t size() const {return __a0_.size();}
1124};
1125
1126template <class _Op, class _Tp>
1127struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> >
1128{
1129 typedef typename _Op::result_type result_type;
1130 typedef _Tp value_type;
1131
1132 _Op __op_;
1133 const valarray<_Tp>& __a0_;
1134 const valarray<_Tp>& __a1_;
1135
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001136 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001137 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
1138 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1139
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001141 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1142
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001143 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001144 size_t size() const {return __a0_.size();}
1145};
1146
1147// slice_array
1148
1149template <class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +00001150class _LIBCPP_TEMPLATE_VIS slice_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001151{
1152public:
1153 typedef _Tp value_type;
1154
1155private:
1156 value_type* __vp_;
1157 size_t __size_;
1158 size_t __stride_;
1159
1160public:
1161 template <class _Expr>
1162 typename enable_if
1163 <
1164 __is_val_expr<_Expr>::value,
1165 void
1166 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001168 operator=(const _Expr& __v) const;
1169
1170 template <class _Expr>
1171 typename enable_if
1172 <
1173 __is_val_expr<_Expr>::value,
1174 void
1175 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001176 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001177 operator*=(const _Expr& __v) const;
1178
1179 template <class _Expr>
1180 typename enable_if
1181 <
1182 __is_val_expr<_Expr>::value,
1183 void
1184 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001186 operator/=(const _Expr& __v) const;
1187
1188 template <class _Expr>
1189 typename enable_if
1190 <
1191 __is_val_expr<_Expr>::value,
1192 void
1193 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001194 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001195 operator%=(const _Expr& __v) const;
1196
1197 template <class _Expr>
1198 typename enable_if
1199 <
1200 __is_val_expr<_Expr>::value,
1201 void
1202 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001203 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001204 operator+=(const _Expr& __v) const;
1205
1206 template <class _Expr>
1207 typename enable_if
1208 <
1209 __is_val_expr<_Expr>::value,
1210 void
1211 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001212 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001213 operator-=(const _Expr& __v) const;
1214
1215 template <class _Expr>
1216 typename enable_if
1217 <
1218 __is_val_expr<_Expr>::value,
1219 void
1220 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001221 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001222 operator^=(const _Expr& __v) const;
1223
1224 template <class _Expr>
1225 typename enable_if
1226 <
1227 __is_val_expr<_Expr>::value,
1228 void
1229 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001230 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001231 operator&=(const _Expr& __v) const;
1232
1233 template <class _Expr>
1234 typename enable_if
1235 <
1236 __is_val_expr<_Expr>::value,
1237 void
1238 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001239 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001240 operator|=(const _Expr& __v) const;
1241
1242 template <class _Expr>
1243 typename enable_if
1244 <
1245 __is_val_expr<_Expr>::value,
1246 void
1247 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001248 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001249 operator<<=(const _Expr& __v) const;
1250
1251 template <class _Expr>
1252 typename enable_if
1253 <
1254 __is_val_expr<_Expr>::value,
1255 void
1256 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001257 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001258 operator>>=(const _Expr& __v) const;
1259
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001260 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001261 const slice_array& operator=(const slice_array& __sa) const;
1262
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001263 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001264 void operator=(const value_type& __x) const;
1265
1266private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001267 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001268 slice_array(const slice& __sl, const valarray<value_type>& __v)
1269 : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())),
1270 __size_(__sl.size()),
1271 __stride_(__sl.stride())
1272 {}
1273
1274 template <class> friend class valarray;
1275 template <class> friend class sliceExpr;
1276};
1277
1278template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001279inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001280const slice_array<_Tp>&
1281slice_array<_Tp>::operator=(const slice_array& __sa) const
1282{
1283 value_type* __t = __vp_;
1284 const value_type* __s = __sa.__vp_;
1285 for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
1286 *__t = *__s;
Eric Fiselierf4124612014-08-12 00:06:58 +00001287 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001288}
1289
1290template <class _Tp>
1291template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001292inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001293typename enable_if
1294<
1295 __is_val_expr<_Expr>::value,
1296 void
1297>::type
1298slice_array<_Tp>::operator=(const _Expr& __v) const
1299{
1300 value_type* __t = __vp_;
1301 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1302 *__t = __v[__i];
1303}
1304
1305template <class _Tp>
1306template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001307inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001308typename enable_if
1309<
1310 __is_val_expr<_Expr>::value,
1311 void
1312>::type
1313slice_array<_Tp>::operator*=(const _Expr& __v) const
1314{
1315 value_type* __t = __vp_;
1316 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1317 *__t *= __v[__i];
1318}
1319
1320template <class _Tp>
1321template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001322inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001323typename enable_if
1324<
1325 __is_val_expr<_Expr>::value,
1326 void
1327>::type
1328slice_array<_Tp>::operator/=(const _Expr& __v) const
1329{
1330 value_type* __t = __vp_;
1331 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1332 *__t /= __v[__i];
1333}
1334
1335template <class _Tp>
1336template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001337inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001338typename enable_if
1339<
1340 __is_val_expr<_Expr>::value,
1341 void
1342>::type
1343slice_array<_Tp>::operator%=(const _Expr& __v) const
1344{
1345 value_type* __t = __vp_;
1346 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1347 *__t %= __v[__i];
1348}
1349
1350template <class _Tp>
1351template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001352inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001353typename enable_if
1354<
1355 __is_val_expr<_Expr>::value,
1356 void
1357>::type
1358slice_array<_Tp>::operator+=(const _Expr& __v) const
1359{
1360 value_type* __t = __vp_;
1361 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1362 *__t += __v[__i];
1363}
1364
1365template <class _Tp>
1366template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001367inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001368typename enable_if
1369<
1370 __is_val_expr<_Expr>::value,
1371 void
1372>::type
1373slice_array<_Tp>::operator-=(const _Expr& __v) const
1374{
1375 value_type* __t = __vp_;
1376 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1377 *__t -= __v[__i];
1378}
1379
1380template <class _Tp>
1381template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001382inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001383typename enable_if
1384<
1385 __is_val_expr<_Expr>::value,
1386 void
1387>::type
1388slice_array<_Tp>::operator^=(const _Expr& __v) const
1389{
1390 value_type* __t = __vp_;
1391 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1392 *__t ^= __v[__i];
1393}
1394
1395template <class _Tp>
1396template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001397inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001398typename enable_if
1399<
1400 __is_val_expr<_Expr>::value,
1401 void
1402>::type
1403slice_array<_Tp>::operator&=(const _Expr& __v) const
1404{
1405 value_type* __t = __vp_;
1406 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1407 *__t &= __v[__i];
1408}
1409
1410template <class _Tp>
1411template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001412inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001413typename enable_if
1414<
1415 __is_val_expr<_Expr>::value,
1416 void
1417>::type
1418slice_array<_Tp>::operator|=(const _Expr& __v) const
1419{
1420 value_type* __t = __vp_;
1421 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1422 *__t |= __v[__i];
1423}
1424
1425template <class _Tp>
1426template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001427inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001428typename enable_if
1429<
1430 __is_val_expr<_Expr>::value,
1431 void
1432>::type
1433slice_array<_Tp>::operator<<=(const _Expr& __v) const
1434{
1435 value_type* __t = __vp_;
1436 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1437 *__t <<= __v[__i];
1438}
1439
1440template <class _Tp>
1441template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001442inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001443typename enable_if
1444<
1445 __is_val_expr<_Expr>::value,
1446 void
1447>::type
1448slice_array<_Tp>::operator>>=(const _Expr& __v) const
1449{
1450 value_type* __t = __vp_;
1451 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1452 *__t >>= __v[__i];
1453}
1454
1455template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001456inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001457void
1458slice_array<_Tp>::operator=(const value_type& __x) const
1459{
1460 value_type* __t = __vp_;
1461 for (size_t __n = __size_; __n; --__n, __t += __stride_)
1462 *__t = __x;
1463}
1464
1465// gslice
1466
Howard Hinnant83eade62013-03-06 23:30:19 +00001467class _LIBCPP_TYPE_VIS gslice
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001468{
1469 valarray<size_t> __size_;
1470 valarray<size_t> __stride_;
1471 valarray<size_t> __1d_;
Howard Hinnant324bb032010-08-22 00:02:43 +00001472
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001473public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001475 gslice() {}
Douglas Gregor0855dde2012-05-19 07:14:17 +00001476
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001478 gslice(size_t __start, const valarray<size_t>& __size,
1479 const valarray<size_t>& __stride)
1480 : __size_(__size),
1481 __stride_(__stride)
1482 {__init(__start);}
1483
Eric Fiselier97db5172017-04-19 00:23:45 +00001484#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001485
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001486 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001487 gslice(size_t __start, const valarray<size_t>& __size,
1488 valarray<size_t>&& __stride)
1489 : __size_(__size),
1490 __stride_(move(__stride))
1491 {__init(__start);}
1492
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001493 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001494 gslice(size_t __start, valarray<size_t>&& __size,
1495 const valarray<size_t>& __stride)
1496 : __size_(move(__size)),
1497 __stride_(__stride)
1498 {__init(__start);}
1499
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001501 gslice(size_t __start, valarray<size_t>&& __size,
1502 valarray<size_t>&& __stride)
1503 : __size_(move(__size)),
1504 __stride_(move(__stride))
1505 {__init(__start);}
1506
Eric Fiselier97db5172017-04-19 00:23:45 +00001507#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001508
1509// gslice(const gslice&) = default;
1510// gslice(gslice&&) = default;
1511// gslice& operator=(const gslice&) = default;
1512// gslice& operator=(gslice&&) = default;
1513
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001515 size_t start() const {return __1d_.size() ? __1d_[0] : 0;}
1516
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001518 valarray<size_t> size() const {return __size_;}
1519
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001521 valarray<size_t> stride() const {return __stride_;}
1522
1523private:
1524 void __init(size_t __start);
1525
1526 template <class> friend class gslice_array;
1527 template <class> friend class valarray;
1528 template <class> friend class __val_expr;
1529};
1530
1531// gslice_array
1532
1533template <class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +00001534class _LIBCPP_TEMPLATE_VIS gslice_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001535{
1536public:
1537 typedef _Tp value_type;
1538
1539private:
1540 value_type* __vp_;
1541 valarray<size_t> __1d_;
1542
1543public:
1544 template <class _Expr>
1545 typename enable_if
1546 <
1547 __is_val_expr<_Expr>::value,
1548 void
1549 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001551 operator=(const _Expr& __v) const;
1552
1553 template <class _Expr>
1554 typename enable_if
1555 <
1556 __is_val_expr<_Expr>::value,
1557 void
1558 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001560 operator*=(const _Expr& __v) const;
1561
1562 template <class _Expr>
1563 typename enable_if
1564 <
1565 __is_val_expr<_Expr>::value,
1566 void
1567 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001569 operator/=(const _Expr& __v) const;
1570
1571 template <class _Expr>
1572 typename enable_if
1573 <
1574 __is_val_expr<_Expr>::value,
1575 void
1576 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001578 operator%=(const _Expr& __v) const;
1579
1580 template <class _Expr>
1581 typename enable_if
1582 <
1583 __is_val_expr<_Expr>::value,
1584 void
1585 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001587 operator+=(const _Expr& __v) const;
1588
1589 template <class _Expr>
1590 typename enable_if
1591 <
1592 __is_val_expr<_Expr>::value,
1593 void
1594 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001596 operator-=(const _Expr& __v) const;
1597
1598 template <class _Expr>
1599 typename enable_if
1600 <
1601 __is_val_expr<_Expr>::value,
1602 void
1603 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001605 operator^=(const _Expr& __v) const;
1606
1607 template <class _Expr>
1608 typename enable_if
1609 <
1610 __is_val_expr<_Expr>::value,
1611 void
1612 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001613 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001614 operator&=(const _Expr& __v) const;
1615
1616 template <class _Expr>
1617 typename enable_if
1618 <
1619 __is_val_expr<_Expr>::value,
1620 void
1621 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001623 operator|=(const _Expr& __v) const;
1624
1625 template <class _Expr>
1626 typename enable_if
1627 <
1628 __is_val_expr<_Expr>::value,
1629 void
1630 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001632 operator<<=(const _Expr& __v) const;
1633
1634 template <class _Expr>
1635 typename enable_if
1636 <
1637 __is_val_expr<_Expr>::value,
1638 void
1639 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001640 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001641 operator>>=(const _Expr& __v) const;
1642
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001644 const gslice_array& operator=(const gslice_array& __ga) const;
1645
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001646 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001647 void operator=(const value_type& __x) const;
1648
1649// gslice_array(const gslice_array&) = default;
1650// gslice_array(gslice_array&&) = default;
1651// gslice_array& operator=(const gslice_array&) = default;
1652// gslice_array& operator=(gslice_array&&) = default;
1653
1654private:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001655 gslice_array(const gslice& __gs, const valarray<value_type>& __v)
1656 : __vp_(const_cast<value_type*>(__v.__begin_)),
1657 __1d_(__gs.__1d_)
1658 {}
1659
Eric Fiselier97db5172017-04-19 00:23:45 +00001660#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001661 gslice_array(gslice&& __gs, const valarray<value_type>& __v)
1662 : __vp_(const_cast<value_type*>(__v.__begin_)),
1663 __1d_(move(__gs.__1d_))
1664 {}
Eric Fiselier97db5172017-04-19 00:23:45 +00001665#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001666
1667 template <class> friend class valarray;
1668};
1669
1670template <class _Tp>
1671template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001672inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001673typename enable_if
1674<
1675 __is_val_expr<_Expr>::value,
1676 void
1677>::type
1678gslice_array<_Tp>::operator=(const _Expr& __v) const
1679{
1680 typedef const size_t* _Ip;
1681 size_t __j = 0;
1682 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1683 __vp_[*__i] = __v[__j];
1684}
1685
1686template <class _Tp>
1687template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001688inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001689typename enable_if
1690<
1691 __is_val_expr<_Expr>::value,
1692 void
1693>::type
1694gslice_array<_Tp>::operator*=(const _Expr& __v) const
1695{
1696 typedef const size_t* _Ip;
1697 size_t __j = 0;
1698 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1699 __vp_[*__i] *= __v[__j];
1700}
1701
1702template <class _Tp>
1703template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001704inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001705typename enable_if
1706<
1707 __is_val_expr<_Expr>::value,
1708 void
1709>::type
1710gslice_array<_Tp>::operator/=(const _Expr& __v) const
1711{
1712 typedef const size_t* _Ip;
1713 size_t __j = 0;
1714 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1715 __vp_[*__i] /= __v[__j];
1716}
1717
1718template <class _Tp>
1719template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001720inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001721typename enable_if
1722<
1723 __is_val_expr<_Expr>::value,
1724 void
1725>::type
1726gslice_array<_Tp>::operator%=(const _Expr& __v) const
1727{
1728 typedef const size_t* _Ip;
1729 size_t __j = 0;
1730 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1731 __vp_[*__i] %= __v[__j];
1732}
1733
1734template <class _Tp>
1735template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001736inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001737typename enable_if
1738<
1739 __is_val_expr<_Expr>::value,
1740 void
1741>::type
1742gslice_array<_Tp>::operator+=(const _Expr& __v) const
1743{
1744 typedef const size_t* _Ip;
1745 size_t __j = 0;
1746 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1747 __vp_[*__i] += __v[__j];
1748}
1749
1750template <class _Tp>
1751template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001752inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001753typename enable_if
1754<
1755 __is_val_expr<_Expr>::value,
1756 void
1757>::type
1758gslice_array<_Tp>::operator-=(const _Expr& __v) const
1759{
1760 typedef const size_t* _Ip;
1761 size_t __j = 0;
1762 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1763 __vp_[*__i] -= __v[__j];
1764}
1765
1766template <class _Tp>
1767template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001768inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001769typename enable_if
1770<
1771 __is_val_expr<_Expr>::value,
1772 void
1773>::type
1774gslice_array<_Tp>::operator^=(const _Expr& __v) const
1775{
1776 typedef const size_t* _Ip;
1777 size_t __j = 0;
1778 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1779 __vp_[*__i] ^= __v[__j];
1780}
1781
1782template <class _Tp>
1783template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001784inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001785typename enable_if
1786<
1787 __is_val_expr<_Expr>::value,
1788 void
1789>::type
1790gslice_array<_Tp>::operator&=(const _Expr& __v) const
1791{
1792 typedef const size_t* _Ip;
1793 size_t __j = 0;
1794 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1795 __vp_[*__i] &= __v[__j];
1796}
1797
1798template <class _Tp>
1799template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001800inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001801typename enable_if
1802<
1803 __is_val_expr<_Expr>::value,
1804 void
1805>::type
1806gslice_array<_Tp>::operator|=(const _Expr& __v) const
1807{
1808 typedef const size_t* _Ip;
1809 size_t __j = 0;
1810 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1811 __vp_[*__i] |= __v[__j];
1812}
1813
1814template <class _Tp>
1815template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001816inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001817typename enable_if
1818<
1819 __is_val_expr<_Expr>::value,
1820 void
1821>::type
1822gslice_array<_Tp>::operator<<=(const _Expr& __v) const
1823{
1824 typedef const size_t* _Ip;
1825 size_t __j = 0;
1826 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1827 __vp_[*__i] <<= __v[__j];
1828}
1829
1830template <class _Tp>
1831template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001832inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001833typename enable_if
1834<
1835 __is_val_expr<_Expr>::value,
1836 void
1837>::type
1838gslice_array<_Tp>::operator>>=(const _Expr& __v) const
1839{
1840 typedef const size_t* _Ip;
1841 size_t __j = 0;
1842 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1843 __vp_[*__i] >>= __v[__j];
1844}
1845
1846template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001847inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001848const gslice_array<_Tp>&
1849gslice_array<_Tp>::operator=(const gslice_array& __ga) const
1850{
1851 typedef const size_t* _Ip;
1852 const value_type* __s = __ga.__vp_;
1853 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_;
1854 __i != __e; ++__i, ++__j)
1855 __vp_[*__i] = __s[*__j];
1856 return *this;
1857}
1858
1859template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001860inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001861void
1862gslice_array<_Tp>::operator=(const value_type& __x) const
1863{
1864 typedef const size_t* _Ip;
1865 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1866 __vp_[*__i] = __x;
1867}
1868
1869// mask_array
1870
1871template <class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +00001872class _LIBCPP_TEMPLATE_VIS mask_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001873{
1874public:
1875 typedef _Tp value_type;
1876
1877private:
1878 value_type* __vp_;
1879 valarray<size_t> __1d_;
1880
1881public:
1882 template <class _Expr>
1883 typename enable_if
1884 <
1885 __is_val_expr<_Expr>::value,
1886 void
1887 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001889 operator=(const _Expr& __v) const;
1890
1891 template <class _Expr>
1892 typename enable_if
1893 <
1894 __is_val_expr<_Expr>::value,
1895 void
1896 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001898 operator*=(const _Expr& __v) const;
1899
1900 template <class _Expr>
1901 typename enable_if
1902 <
1903 __is_val_expr<_Expr>::value,
1904 void
1905 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001907 operator/=(const _Expr& __v) const;
1908
1909 template <class _Expr>
1910 typename enable_if
1911 <
1912 __is_val_expr<_Expr>::value,
1913 void
1914 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001915 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001916 operator%=(const _Expr& __v) const;
1917
1918 template <class _Expr>
1919 typename enable_if
1920 <
1921 __is_val_expr<_Expr>::value,
1922 void
1923 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001924 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001925 operator+=(const _Expr& __v) const;
1926
1927 template <class _Expr>
1928 typename enable_if
1929 <
1930 __is_val_expr<_Expr>::value,
1931 void
1932 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001934 operator-=(const _Expr& __v) const;
1935
1936 template <class _Expr>
1937 typename enable_if
1938 <
1939 __is_val_expr<_Expr>::value,
1940 void
1941 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001942 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001943 operator^=(const _Expr& __v) const;
1944
1945 template <class _Expr>
1946 typename enable_if
1947 <
1948 __is_val_expr<_Expr>::value,
1949 void
1950 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001951 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001952 operator&=(const _Expr& __v) const;
1953
1954 template <class _Expr>
1955 typename enable_if
1956 <
1957 __is_val_expr<_Expr>::value,
1958 void
1959 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001960 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001961 operator|=(const _Expr& __v) const;
1962
1963 template <class _Expr>
1964 typename enable_if
1965 <
1966 __is_val_expr<_Expr>::value,
1967 void
1968 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001970 operator<<=(const _Expr& __v) const;
1971
1972 template <class _Expr>
1973 typename enable_if
1974 <
1975 __is_val_expr<_Expr>::value,
1976 void
1977 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001979 operator>>=(const _Expr& __v) const;
1980
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001981 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001982 const mask_array& operator=(const mask_array& __ma) const;
1983
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001984 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001985 void operator=(const value_type& __x) const;
1986
1987// mask_array(const mask_array&) = default;
1988// mask_array(mask_array&&) = default;
1989// mask_array& operator=(const mask_array&) = default;
1990// mask_array& operator=(mask_array&&) = default;
1991
1992private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001993 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001994 mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
1995 : __vp_(const_cast<value_type*>(__v.__begin_)),
Howard Hinnantec3773c2011-12-01 20:21:04 +00001996 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001997 {
1998 size_t __j = 0;
1999 for (size_t __i = 0; __i < __vb.size(); ++__i)
2000 if (__vb[__i])
2001 __1d_[__j++] = __i;
2002 }
2003
2004 template <class> friend class valarray;
2005};
2006
2007template <class _Tp>
2008template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002009inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002010typename enable_if
2011<
2012 __is_val_expr<_Expr>::value,
2013 void
2014>::type
2015mask_array<_Tp>::operator=(const _Expr& __v) const
2016{
2017 size_t __n = __1d_.size();
2018 for (size_t __i = 0; __i < __n; ++__i)
2019 __vp_[__1d_[__i]] = __v[__i];
2020}
2021
2022template <class _Tp>
2023template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002024inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002025typename enable_if
2026<
2027 __is_val_expr<_Expr>::value,
2028 void
2029>::type
2030mask_array<_Tp>::operator*=(const _Expr& __v) const
2031{
2032 size_t __n = __1d_.size();
2033 for (size_t __i = 0; __i < __n; ++__i)
2034 __vp_[__1d_[__i]] *= __v[__i];
2035}
2036
2037template <class _Tp>
2038template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002039inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002040typename enable_if
2041<
2042 __is_val_expr<_Expr>::value,
2043 void
2044>::type
2045mask_array<_Tp>::operator/=(const _Expr& __v) const
2046{
2047 size_t __n = __1d_.size();
2048 for (size_t __i = 0; __i < __n; ++__i)
2049 __vp_[__1d_[__i]] /= __v[__i];
2050}
2051
2052template <class _Tp>
2053template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002054inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002055typename enable_if
2056<
2057 __is_val_expr<_Expr>::value,
2058 void
2059>::type
2060mask_array<_Tp>::operator%=(const _Expr& __v) const
2061{
2062 size_t __n = __1d_.size();
2063 for (size_t __i = 0; __i < __n; ++__i)
2064 __vp_[__1d_[__i]] %= __v[__i];
2065}
2066
2067template <class _Tp>
2068template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002069inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002070typename enable_if
2071<
2072 __is_val_expr<_Expr>::value,
2073 void
2074>::type
2075mask_array<_Tp>::operator+=(const _Expr& __v) const
2076{
2077 size_t __n = __1d_.size();
2078 for (size_t __i = 0; __i < __n; ++__i)
2079 __vp_[__1d_[__i]] += __v[__i];
2080}
2081
2082template <class _Tp>
2083template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002084inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002085typename enable_if
2086<
2087 __is_val_expr<_Expr>::value,
2088 void
2089>::type
2090mask_array<_Tp>::operator-=(const _Expr& __v) const
2091{
2092 size_t __n = __1d_.size();
2093 for (size_t __i = 0; __i < __n; ++__i)
2094 __vp_[__1d_[__i]] -= __v[__i];
2095}
2096
2097template <class _Tp>
2098template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002099inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002100typename enable_if
2101<
2102 __is_val_expr<_Expr>::value,
2103 void
2104>::type
2105mask_array<_Tp>::operator^=(const _Expr& __v) const
2106{
2107 size_t __n = __1d_.size();
2108 for (size_t __i = 0; __i < __n; ++__i)
2109 __vp_[__1d_[__i]] ^= __v[__i];
2110}
2111
2112template <class _Tp>
2113template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002114inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002115typename enable_if
2116<
2117 __is_val_expr<_Expr>::value,
2118 void
2119>::type
2120mask_array<_Tp>::operator&=(const _Expr& __v) const
2121{
2122 size_t __n = __1d_.size();
2123 for (size_t __i = 0; __i < __n; ++__i)
2124 __vp_[__1d_[__i]] &= __v[__i];
2125}
2126
2127template <class _Tp>
2128template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002129inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002130typename enable_if
2131<
2132 __is_val_expr<_Expr>::value,
2133 void
2134>::type
2135mask_array<_Tp>::operator|=(const _Expr& __v) const
2136{
2137 size_t __n = __1d_.size();
2138 for (size_t __i = 0; __i < __n; ++__i)
2139 __vp_[__1d_[__i]] |= __v[__i];
2140}
2141
2142template <class _Tp>
2143template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002144inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002145typename enable_if
2146<
2147 __is_val_expr<_Expr>::value,
2148 void
2149>::type
2150mask_array<_Tp>::operator<<=(const _Expr& __v) const
2151{
2152 size_t __n = __1d_.size();
2153 for (size_t __i = 0; __i < __n; ++__i)
2154 __vp_[__1d_[__i]] <<= __v[__i];
2155}
2156
2157template <class _Tp>
2158template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002159inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002160typename enable_if
2161<
2162 __is_val_expr<_Expr>::value,
2163 void
2164>::type
2165mask_array<_Tp>::operator>>=(const _Expr& __v) const
2166{
2167 size_t __n = __1d_.size();
2168 for (size_t __i = 0; __i < __n; ++__i)
2169 __vp_[__1d_[__i]] >>= __v[__i];
2170}
2171
2172template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002173inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002174const mask_array<_Tp>&
2175mask_array<_Tp>::operator=(const mask_array& __ma) const
2176{
2177 size_t __n = __1d_.size();
2178 for (size_t __i = 0; __i < __n; ++__i)
2179 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
Eric Fiselierf4124612014-08-12 00:06:58 +00002180 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002181}
2182
2183template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002184inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002185void
2186mask_array<_Tp>::operator=(const value_type& __x) const
2187{
2188 size_t __n = __1d_.size();
2189 for (size_t __i = 0; __i < __n; ++__i)
2190 __vp_[__1d_[__i]] = __x;
2191}
2192
2193template <class _ValExpr>
2194class __mask_expr
2195{
2196 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2197public:
2198 typedef typename _RmExpr::value_type value_type;
2199 typedef value_type result_type;
2200
2201private:
2202 _ValExpr __expr_;
2203 valarray<size_t> __1d_;
2204
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002205 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002206 __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
2207 : __expr_(__e),
Howard Hinnantec3773c2011-12-01 20:21:04 +00002208 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002209 {
2210 size_t __j = 0;
2211 for (size_t __i = 0; __i < __vb.size(); ++__i)
2212 if (__vb[__i])
2213 __1d_[__j++] = __i;
2214 }
2215
2216public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002217 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002218 result_type operator[](size_t __i) const
2219 {return __expr_[__1d_[__i]];}
2220
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002221 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002222 size_t size() const {return __1d_.size();}
2223
2224 template <class> friend class valarray;
2225};
2226
2227// indirect_array
2228
2229template <class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +00002230class _LIBCPP_TEMPLATE_VIS indirect_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002231{
2232public:
2233 typedef _Tp value_type;
2234
2235private:
2236 value_type* __vp_;
2237 valarray<size_t> __1d_;
2238
2239public:
2240 template <class _Expr>
2241 typename enable_if
2242 <
2243 __is_val_expr<_Expr>::value,
2244 void
2245 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002247 operator=(const _Expr& __v) const;
2248
2249 template <class _Expr>
2250 typename enable_if
2251 <
2252 __is_val_expr<_Expr>::value,
2253 void
2254 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002256 operator*=(const _Expr& __v) const;
2257
2258 template <class _Expr>
2259 typename enable_if
2260 <
2261 __is_val_expr<_Expr>::value,
2262 void
2263 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002264 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002265 operator/=(const _Expr& __v) const;
2266
2267 template <class _Expr>
2268 typename enable_if
2269 <
2270 __is_val_expr<_Expr>::value,
2271 void
2272 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002273 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002274 operator%=(const _Expr& __v) const;
2275
2276 template <class _Expr>
2277 typename enable_if
2278 <
2279 __is_val_expr<_Expr>::value,
2280 void
2281 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002282 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002283 operator+=(const _Expr& __v) const;
2284
2285 template <class _Expr>
2286 typename enable_if
2287 <
2288 __is_val_expr<_Expr>::value,
2289 void
2290 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002292 operator-=(const _Expr& __v) const;
2293
2294 template <class _Expr>
2295 typename enable_if
2296 <
2297 __is_val_expr<_Expr>::value,
2298 void
2299 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002301 operator^=(const _Expr& __v) const;
2302
2303 template <class _Expr>
2304 typename enable_if
2305 <
2306 __is_val_expr<_Expr>::value,
2307 void
2308 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002309 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002310 operator&=(const _Expr& __v) const;
2311
2312 template <class _Expr>
2313 typename enable_if
2314 <
2315 __is_val_expr<_Expr>::value,
2316 void
2317 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002318 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002319 operator|=(const _Expr& __v) const;
2320
2321 template <class _Expr>
2322 typename enable_if
2323 <
2324 __is_val_expr<_Expr>::value,
2325 void
2326 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002327 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002328 operator<<=(const _Expr& __v) const;
2329
2330 template <class _Expr>
2331 typename enable_if
2332 <
2333 __is_val_expr<_Expr>::value,
2334 void
2335 >::type
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002336 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002337 operator>>=(const _Expr& __v) const;
2338
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002339 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002340 const indirect_array& operator=(const indirect_array& __ia) const;
2341
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002342 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002343 void operator=(const value_type& __x) const;
2344
2345// indirect_array(const indirect_array&) = default;
2346// indirect_array(indirect_array&&) = default;
2347// indirect_array& operator=(const indirect_array&) = default;
2348// indirect_array& operator=(indirect_array&&) = default;
2349
2350private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002351 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002352 indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
2353 : __vp_(const_cast<value_type*>(__v.__begin_)),
2354 __1d_(__ia)
2355 {}
2356
Eric Fiselier97db5172017-04-19 00:23:45 +00002357#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002358
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002359 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002360 indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
2361 : __vp_(const_cast<value_type*>(__v.__begin_)),
2362 __1d_(move(__ia))
2363 {}
2364
Eric Fiselier97db5172017-04-19 00:23:45 +00002365#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002366
2367 template <class> friend class valarray;
2368};
2369
2370template <class _Tp>
2371template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002372inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002373typename enable_if
2374<
2375 __is_val_expr<_Expr>::value,
2376 void
2377>::type
2378indirect_array<_Tp>::operator=(const _Expr& __v) const
2379{
2380 size_t __n = __1d_.size();
2381 for (size_t __i = 0; __i < __n; ++__i)
2382 __vp_[__1d_[__i]] = __v[__i];
2383}
2384
2385template <class _Tp>
2386template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002387inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002388typename enable_if
2389<
2390 __is_val_expr<_Expr>::value,
2391 void
2392>::type
2393indirect_array<_Tp>::operator*=(const _Expr& __v) const
2394{
2395 size_t __n = __1d_.size();
2396 for (size_t __i = 0; __i < __n; ++__i)
2397 __vp_[__1d_[__i]] *= __v[__i];
2398}
2399
2400template <class _Tp>
2401template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002402inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002403typename enable_if
2404<
2405 __is_val_expr<_Expr>::value,
2406 void
2407>::type
2408indirect_array<_Tp>::operator/=(const _Expr& __v) const
2409{
2410 size_t __n = __1d_.size();
2411 for (size_t __i = 0; __i < __n; ++__i)
2412 __vp_[__1d_[__i]] /= __v[__i];
2413}
2414
2415template <class _Tp>
2416template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002417inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002418typename enable_if
2419<
2420 __is_val_expr<_Expr>::value,
2421 void
2422>::type
2423indirect_array<_Tp>::operator%=(const _Expr& __v) const
2424{
2425 size_t __n = __1d_.size();
2426 for (size_t __i = 0; __i < __n; ++__i)
2427 __vp_[__1d_[__i]] %= __v[__i];
2428}
2429
2430template <class _Tp>
2431template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002432inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002433typename enable_if
2434<
2435 __is_val_expr<_Expr>::value,
2436 void
2437>::type
2438indirect_array<_Tp>::operator+=(const _Expr& __v) const
2439{
2440 size_t __n = __1d_.size();
2441 for (size_t __i = 0; __i < __n; ++__i)
2442 __vp_[__1d_[__i]] += __v[__i];
2443}
2444
2445template <class _Tp>
2446template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002447inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002448typename enable_if
2449<
2450 __is_val_expr<_Expr>::value,
2451 void
2452>::type
2453indirect_array<_Tp>::operator-=(const _Expr& __v) const
2454{
2455 size_t __n = __1d_.size();
2456 for (size_t __i = 0; __i < __n; ++__i)
2457 __vp_[__1d_[__i]] -= __v[__i];
2458}
2459
2460template <class _Tp>
2461template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002462inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002463typename enable_if
2464<
2465 __is_val_expr<_Expr>::value,
2466 void
2467>::type
2468indirect_array<_Tp>::operator^=(const _Expr& __v) const
2469{
2470 size_t __n = __1d_.size();
2471 for (size_t __i = 0; __i < __n; ++__i)
2472 __vp_[__1d_[__i]] ^= __v[__i];
2473}
2474
2475template <class _Tp>
2476template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002477inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002478typename enable_if
2479<
2480 __is_val_expr<_Expr>::value,
2481 void
2482>::type
2483indirect_array<_Tp>::operator&=(const _Expr& __v) const
2484{
2485 size_t __n = __1d_.size();
2486 for (size_t __i = 0; __i < __n; ++__i)
2487 __vp_[__1d_[__i]] &= __v[__i];
2488}
2489
2490template <class _Tp>
2491template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002492inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002493typename enable_if
2494<
2495 __is_val_expr<_Expr>::value,
2496 void
2497>::type
2498indirect_array<_Tp>::operator|=(const _Expr& __v) const
2499{
2500 size_t __n = __1d_.size();
2501 for (size_t __i = 0; __i < __n; ++__i)
2502 __vp_[__1d_[__i]] |= __v[__i];
2503}
2504
2505template <class _Tp>
2506template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002507inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002508typename enable_if
2509<
2510 __is_val_expr<_Expr>::value,
2511 void
2512>::type
2513indirect_array<_Tp>::operator<<=(const _Expr& __v) const
2514{
2515 size_t __n = __1d_.size();
2516 for (size_t __i = 0; __i < __n; ++__i)
2517 __vp_[__1d_[__i]] <<= __v[__i];
2518}
2519
2520template <class _Tp>
2521template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002522inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002523typename enable_if
2524<
2525 __is_val_expr<_Expr>::value,
2526 void
2527>::type
2528indirect_array<_Tp>::operator>>=(const _Expr& __v) const
2529{
2530 size_t __n = __1d_.size();
2531 for (size_t __i = 0; __i < __n; ++__i)
2532 __vp_[__1d_[__i]] >>= __v[__i];
2533}
2534
2535template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002536inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002537const indirect_array<_Tp>&
2538indirect_array<_Tp>::operator=(const indirect_array& __ia) const
2539{
2540 typedef const size_t* _Ip;
2541 const value_type* __s = __ia.__vp_;
2542 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_;
2543 __i != __e; ++__i, ++__j)
2544 __vp_[*__i] = __s[*__j];
2545 return *this;
2546}
2547
2548template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002549inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002550void
2551indirect_array<_Tp>::operator=(const value_type& __x) const
2552{
2553 typedef const size_t* _Ip;
2554 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
2555 __vp_[*__i] = __x;
2556}
2557
2558template <class _ValExpr>
2559class __indirect_expr
2560{
2561 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2562public:
2563 typedef typename _RmExpr::value_type value_type;
2564 typedef value_type result_type;
2565
2566private:
2567 _ValExpr __expr_;
2568 valarray<size_t> __1d_;
2569
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002571 __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e)
2572 : __expr_(__e),
2573 __1d_(__ia)
2574 {}
2575
Eric Fiselier97db5172017-04-19 00:23:45 +00002576#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002577
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002579 __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
2580 : __expr_(__e),
2581 __1d_(move(__ia))
2582 {}
2583
Eric Fiselier97db5172017-04-19 00:23:45 +00002584#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002585
2586public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002588 result_type operator[](size_t __i) const
2589 {return __expr_[__1d_[__i]];}
2590
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002592 size_t size() const {return __1d_.size();}
2593
Eric Fiselierc3589a82017-01-04 23:56:00 +00002594 template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002595};
2596
2597template<class _ValExpr>
2598class __val_expr
2599{
2600 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2601
2602 _ValExpr __expr_;
2603public:
2604 typedef typename _RmExpr::value_type value_type;
2605 typedef typename _RmExpr::result_type result_type;
2606
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002608 explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
2609
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002611 result_type operator[](size_t __i) const
2612 {return __expr_[__i];}
2613
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002614 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002615 __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
2616 {return __val_expr<__slice_expr<_ValExpr> >(__expr_, __s);}
2617
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002619 __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const
2620 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __gs.__1d_);}
2621
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002623 __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
2624 {return __val_expr<__mask_expr<_ValExpr> >(__expr_, __vb);}
2625
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002627 __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
2628 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __vs);}
2629
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002631 __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
2632 operator+() const
2633 {
2634 typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
2635 return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
2636 }
2637
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002638 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002639 __val_expr<_UnaryOp<negate<value_type>, _ValExpr> >
2640 operator-() const
2641 {
2642 typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
2643 return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
2644 }
2645
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002646 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002647 __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> >
2648 operator~() const
2649 {
2650 typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
2651 return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
2652 }
2653
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002655 __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> >
2656 operator!() const
2657 {
2658 typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
2659 return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
2660 }
2661
2662 operator valarray<result_type>() const;
2663
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002664 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002665 size_t size() const {return __expr_.size();}
2666
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002667 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002668 result_type sum() const
2669 {
2670 size_t __n = __expr_.size();
2671 result_type __r = __n ? __expr_[0] : result_type();
2672 for (size_t __i = 1; __i < __n; ++__i)
2673 __r += __expr_[__i];
2674 return __r;
2675 }
2676
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002678 result_type min() const
2679 {
2680 size_t __n = size();
2681 result_type __r = __n ? (*this)[0] : result_type();
2682 for (size_t __i = 1; __i < __n; ++__i)
2683 {
2684 result_type __x = __expr_[__i];
2685 if (__x < __r)
2686 __r = __x;
2687 }
2688 return __r;
2689 }
2690
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002691 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002692 result_type max() const
2693 {
2694 size_t __n = size();
2695 result_type __r = __n ? (*this)[0] : result_type();
2696 for (size_t __i = 1; __i < __n; ++__i)
2697 {
2698 result_type __x = __expr_[__i];
2699 if (__r < __x)
2700 __r = __x;
2701 }
2702 return __r;
2703 }
2704
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002706 __val_expr<__shift_expr<_ValExpr> > shift (int __i) const
2707 {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));}
2708
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002709 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002710 __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const
2711 {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));}
2712
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002713 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002714 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> >
2715 apply(value_type __f(value_type)) const
2716 {
2717 typedef __apply_expr<value_type, value_type(*)(value_type)> _Op;
2718 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2719 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2720 }
2721
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002723 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> >
2724 apply(value_type __f(const value_type&)) const
2725 {
2726 typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op;
2727 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2728 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2729 }
2730};
2731
2732template<class _ValExpr>
Howard Hinnantd8851432013-09-13 23:27:42 +00002733__val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002734{
2735 valarray<result_type> __r;
2736 size_t __n = __expr_.size();
2737 if (__n)
2738 {
2739 __r.__begin_ =
2740 __r.__end_ =
Eric Fiseliera8312872018-03-22 04:42:56 +00002741 static_cast<result_type*>(
2742 _VSTD::__libcpp_allocate(__n * sizeof(result_type), __alignof(result_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002743 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
2744 ::new (__r.__end_) result_type(__expr_[__i]);
2745 }
2746 return __r;
2747}
2748
2749// valarray
2750
2751template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002752inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002753valarray<_Tp>::valarray(size_t __n)
2754 : __begin_(0),
2755 __end_(0)
2756{
Mikhail Maltsev171ed212018-02-08 11:33:48 +00002757 if (__n)
2758 {
Eric Fiseliera8312872018-03-22 04:42:56 +00002759 __begin_ = __end_ = static_cast<value_type*>(
2760 _VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
Mikhail Maltsev171ed212018-02-08 11:33:48 +00002761#ifndef _LIBCPP_NO_EXCEPTIONS
2762 try
2763 {
2764#endif // _LIBCPP_NO_EXCEPTIONS
2765 for (; __n; --__n, ++__end_)
2766 ::new (__end_) value_type();
2767#ifndef _LIBCPP_NO_EXCEPTIONS
2768 }
2769 catch (...)
2770 {
2771 __clear();
2772 throw;
2773 }
2774#endif // _LIBCPP_NO_EXCEPTIONS
2775 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002776}
2777
2778template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002779inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002780valarray<_Tp>::valarray(const value_type& __x, size_t __n)
2781 : __begin_(0),
2782 __end_(0)
2783{
2784 resize(__n, __x);
2785}
2786
2787template <class _Tp>
2788valarray<_Tp>::valarray(const value_type* __p, size_t __n)
2789 : __begin_(0),
2790 __end_(0)
2791{
2792 if (__n)
2793 {
Eric Fiseliera8312872018-03-22 04:42:56 +00002794 __begin_ = __end_ = static_cast<value_type*>(
2795 _VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002796#ifndef _LIBCPP_NO_EXCEPTIONS
2797 try
2798 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002799#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002800 for (; __n; ++__end_, ++__p, --__n)
2801 ::new (__end_) value_type(*__p);
2802#ifndef _LIBCPP_NO_EXCEPTIONS
2803 }
2804 catch (...)
2805 {
Mikhail Maltsev171ed212018-02-08 11:33:48 +00002806 __clear();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002807 throw;
2808 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002809#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002810 }
2811}
2812
2813template <class _Tp>
2814valarray<_Tp>::valarray(const valarray& __v)
2815 : __begin_(0),
2816 __end_(0)
2817{
2818 if (__v.size())
2819 {
Eric Fiseliera8312872018-03-22 04:42:56 +00002820 __begin_ = __end_ = static_cast<value_type*>(
2821 _VSTD::__libcpp_allocate(__v.size() * sizeof(value_type), __alignof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002822#ifndef _LIBCPP_NO_EXCEPTIONS
2823 try
2824 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002825#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002826 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
2827 ::new (__end_) value_type(*__p);
2828#ifndef _LIBCPP_NO_EXCEPTIONS
2829 }
2830 catch (...)
2831 {
Mikhail Maltsev171ed212018-02-08 11:33:48 +00002832 __clear();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002833 throw;
2834 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002835#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002836 }
2837}
2838
Eric Fiselier97db5172017-04-19 00:23:45 +00002839#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002840
2841template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002842inline
Howard Hinnantbd143082012-07-21 00:51:28 +00002843valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002844 : __begin_(__v.__begin_),
2845 __end_(__v.__end_)
2846{
2847 __v.__begin_ = __v.__end_ = nullptr;
2848}
2849
2850template <class _Tp>
2851valarray<_Tp>::valarray(initializer_list<value_type> __il)
2852 : __begin_(0),
2853 __end_(0)
2854{
2855 size_t __n = __il.size();
2856 if (__n)
2857 {
Eric Fiseliera8312872018-03-22 04:42:56 +00002858 __begin_ = __end_ = static_cast<value_type*>(
2859_VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002860#ifndef _LIBCPP_NO_EXCEPTIONS
2861 try
2862 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002863#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002864 for (const value_type* __p = __il.begin(); __n; ++__end_, ++__p, --__n)
2865 ::new (__end_) value_type(*__p);
2866#ifndef _LIBCPP_NO_EXCEPTIONS
2867 }
2868 catch (...)
2869 {
Mikhail Maltsev171ed212018-02-08 11:33:48 +00002870 __clear();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002871 throw;
2872 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002873#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002874 }
2875}
2876
Eric Fiselier97db5172017-04-19 00:23:45 +00002877#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002878
2879template <class _Tp>
2880valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
2881 : __begin_(0),
2882 __end_(0)
2883{
2884 size_t __n = __sa.__size_;
2885 if (__n)
2886 {
Eric Fiseliera8312872018-03-22 04:42:56 +00002887 __begin_ = __end_ = static_cast<value_type*>(
2888 _VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002889#ifndef _LIBCPP_NO_EXCEPTIONS
2890 try
2891 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002892#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002893 for (const value_type* __p = __sa.__vp_; __n; ++__end_, __p += __sa.__stride_, --__n)
2894 ::new (__end_) value_type(*__p);
2895#ifndef _LIBCPP_NO_EXCEPTIONS
2896 }
2897 catch (...)
2898 {
Mikhail Maltsev171ed212018-02-08 11:33:48 +00002899 __clear();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002900 throw;
2901 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002902#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002903 }
2904}
2905
2906template <class _Tp>
2907valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
2908 : __begin_(0),
2909 __end_(0)
2910{
2911 size_t __n = __ga.__1d_.size();
2912 if (__n)
2913 {
Eric Fiseliera8312872018-03-22 04:42:56 +00002914 __begin_ = __end_ = static_cast<value_type*>(
2915 _VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002916#ifndef _LIBCPP_NO_EXCEPTIONS
2917 try
2918 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002919#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002920 typedef const size_t* _Ip;
2921 const value_type* __s = __ga.__vp_;
2922 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2923 __i != __e; ++__i, ++__end_)
2924 ::new (__end_) value_type(__s[*__i]);
2925#ifndef _LIBCPP_NO_EXCEPTIONS
2926 }
2927 catch (...)
2928 {
Mikhail Maltsev171ed212018-02-08 11:33:48 +00002929 __clear();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002930 throw;
2931 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002932#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002933 }
2934}
2935
2936template <class _Tp>
2937valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
2938 : __begin_(0),
2939 __end_(0)
2940{
2941 size_t __n = __ma.__1d_.size();
2942 if (__n)
2943 {
Eric Fiseliera8312872018-03-22 04:42:56 +00002944 __begin_ = __end_ = static_cast<value_type*>(
2945 _VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002946#ifndef _LIBCPP_NO_EXCEPTIONS
2947 try
2948 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002949#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002950 typedef const size_t* _Ip;
2951 const value_type* __s = __ma.__vp_;
2952 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2953 __i != __e; ++__i, ++__end_)
2954 ::new (__end_) value_type(__s[*__i]);
2955#ifndef _LIBCPP_NO_EXCEPTIONS
2956 }
2957 catch (...)
2958 {
Mikhail Maltsev171ed212018-02-08 11:33:48 +00002959 __clear();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002960 throw;
2961 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002962#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002963 }
2964}
2965
2966template <class _Tp>
2967valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
2968 : __begin_(0),
2969 __end_(0)
2970{
2971 size_t __n = __ia.__1d_.size();
2972 if (__n)
2973 {
Eric Fiseliera8312872018-03-22 04:42:56 +00002974 __begin_ = __end_ = static_cast<value_type*>(
2975 _VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002976#ifndef _LIBCPP_NO_EXCEPTIONS
2977 try
2978 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002979#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002980 typedef const size_t* _Ip;
2981 const value_type* __s = __ia.__vp_;
2982 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2983 __i != __e; ++__i, ++__end_)
2984 ::new (__end_) value_type(__s[*__i]);
2985#ifndef _LIBCPP_NO_EXCEPTIONS
2986 }
2987 catch (...)
2988 {
Mikhail Maltsev171ed212018-02-08 11:33:48 +00002989 __clear();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002990 throw;
2991 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002992#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002993 }
2994}
2995
2996template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002997inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002998valarray<_Tp>::~valarray()
2999{
Mikhail Maltsev171ed212018-02-08 11:33:48 +00003000 __clear();
3001}
3002
3003template <class _Tp>
3004valarray<_Tp>&
3005valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l)
3006{
3007 size_t __n = __l - __f;
3008 if (size() != __n)
3009 {
3010 __clear();
Eric Fiseliera8312872018-03-22 04:42:56 +00003011 __begin_ = static_cast<value_type*>(
3012 _VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
Mikhail Maltsev171ed212018-02-08 11:33:48 +00003013 __end_ = __begin_ + __n;
3014 _VSTD::uninitialized_copy(__f, __l, __begin_);
3015 } else {
3016 _VSTD::copy(__f, __l, __begin_);
3017 }
3018 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003019}
3020
3021template <class _Tp>
3022valarray<_Tp>&
3023valarray<_Tp>::operator=(const valarray& __v)
3024{
3025 if (this != &__v)
Mikhail Maltsev171ed212018-02-08 11:33:48 +00003026 return __assign_range(__v.__begin_, __v.__end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003027 return *this;
3028}
3029
Eric Fiselier97db5172017-04-19 00:23:45 +00003030#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003031
3032template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003033inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003034valarray<_Tp>&
Howard Hinnantbd143082012-07-21 00:51:28 +00003035valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003036{
Mikhail Maltsev171ed212018-02-08 11:33:48 +00003037 __clear();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003038 __begin_ = __v.__begin_;
3039 __end_ = __v.__end_;
3040 __v.__begin_ = nullptr;
3041 __v.__end_ = nullptr;
3042 return *this;
3043}
3044
3045template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003046inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003047valarray<_Tp>&
3048valarray<_Tp>::operator=(initializer_list<value_type> __il)
3049{
Mikhail Maltsev171ed212018-02-08 11:33:48 +00003050 return __assign_range(__il.begin(), __il.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003051}
3052
Eric Fiselier97db5172017-04-19 00:23:45 +00003053#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003054
3055template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003056inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003057valarray<_Tp>&
3058valarray<_Tp>::operator=(const value_type& __x)
3059{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003060 _VSTD::fill(__begin_, __end_, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003061 return *this;
3062}
3063
3064template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003065inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003066valarray<_Tp>&
3067valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
3068{
3069 value_type* __t = __begin_;
3070 const value_type* __s = __sa.__vp_;
3071 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
3072 *__t = *__s;
3073 return *this;
3074}
3075
3076template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003077inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003078valarray<_Tp>&
3079valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
3080{
3081 typedef const size_t* _Ip;
3082 value_type* __t = __begin_;
3083 const value_type* __s = __ga.__vp_;
3084 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
3085 __i != __e; ++__i, ++__t)
3086 *__t = __s[*__i];
3087 return *this;
3088}
3089
3090template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003091inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003092valarray<_Tp>&
3093valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
3094{
3095 typedef const size_t* _Ip;
3096 value_type* __t = __begin_;
3097 const value_type* __s = __ma.__vp_;
3098 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
3099 __i != __e; ++__i, ++__t)
3100 *__t = __s[*__i];
3101 return *this;
3102}
3103
3104template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003105inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003106valarray<_Tp>&
3107valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
3108{
3109 typedef const size_t* _Ip;
3110 value_type* __t = __begin_;
3111 const value_type* __s = __ia.__vp_;
3112 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
3113 __i != __e; ++__i, ++__t)
3114 *__t = __s[*__i];
3115 return *this;
3116}
3117
3118template <class _Tp>
Howard Hinnantdb866632011-07-27 23:19:59 +00003119template <class _ValExpr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003120inline
Howard Hinnantdb866632011-07-27 23:19:59 +00003121valarray<_Tp>&
3122valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
3123{
3124 size_t __n = __v.size();
3125 if (size() != __n)
3126 resize(__n);
3127 value_type* __t = __begin_;
3128 for (size_t __i = 0; __i != __n; ++__t, ++__i)
3129 *__t = result_type(__v[__i]);
3130 return *this;
3131}
3132
3133template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003134inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003135__val_expr<__slice_expr<const valarray<_Tp>&> >
3136valarray<_Tp>::operator[](slice __s) const
3137{
3138 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
3139}
3140
3141template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003142inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003143slice_array<_Tp>
3144valarray<_Tp>::operator[](slice __s)
3145{
3146 return slice_array<value_type>(__s, *this);
3147}
3148
3149template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003150inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003151__val_expr<__indirect_expr<const valarray<_Tp>&> >
3152valarray<_Tp>::operator[](const gslice& __gs) const
3153{
3154 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
3155}
3156
3157template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003158inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003159gslice_array<_Tp>
3160valarray<_Tp>::operator[](const gslice& __gs)
3161{
3162 return gslice_array<value_type>(__gs, *this);
3163}
3164
Eric Fiselier97db5172017-04-19 00:23:45 +00003165#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003166
3167template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003168inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003169__val_expr<__indirect_expr<const valarray<_Tp>&> >
3170valarray<_Tp>::operator[](gslice&& __gs) const
3171{
3172 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
3173}
3174
3175template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003176inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003177gslice_array<_Tp>
3178valarray<_Tp>::operator[](gslice&& __gs)
3179{
3180 return gslice_array<value_type>(move(__gs), *this);
3181}
3182
Eric Fiselier97db5172017-04-19 00:23:45 +00003183#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003184
3185template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003186inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003187__val_expr<__mask_expr<const valarray<_Tp>&> >
3188valarray<_Tp>::operator[](const valarray<bool>& __vb) const
3189{
3190 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
3191}
3192
3193template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003194inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003195mask_array<_Tp>
3196valarray<_Tp>::operator[](const valarray<bool>& __vb)
3197{
3198 return mask_array<value_type>(__vb, *this);
3199}
3200
Eric Fiselier97db5172017-04-19 00:23:45 +00003201#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003202
3203template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003204inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003205__val_expr<__mask_expr<const valarray<_Tp>&> >
3206valarray<_Tp>::operator[](valarray<bool>&& __vb) const
3207{
3208 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
3209}
3210
3211template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003212inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003213mask_array<_Tp>
3214valarray<_Tp>::operator[](valarray<bool>&& __vb)
3215{
3216 return mask_array<value_type>(move(__vb), *this);
3217}
3218
Eric Fiselier97db5172017-04-19 00:23:45 +00003219#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003220
3221template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003222inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003223__val_expr<__indirect_expr<const valarray<_Tp>&> >
3224valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
3225{
3226 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
3227}
3228
3229template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003230inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003231indirect_array<_Tp>
3232valarray<_Tp>::operator[](const valarray<size_t>& __vs)
3233{
3234 return indirect_array<value_type>(__vs, *this);
3235}
3236
Eric Fiselier97db5172017-04-19 00:23:45 +00003237#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003238
3239template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003240inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003241__val_expr<__indirect_expr<const valarray<_Tp>&> >
3242valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
3243{
3244 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
3245}
3246
3247template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003248inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003249indirect_array<_Tp>
3250valarray<_Tp>::operator[](valarray<size_t>&& __vs)
3251{
3252 return indirect_array<value_type>(move(__vs), *this);
3253}
3254
Eric Fiselier97db5172017-04-19 00:23:45 +00003255#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003256
3257template <class _Tp>
3258valarray<_Tp>
3259valarray<_Tp>::operator+() const
3260{
3261 valarray<value_type> __r;
3262 size_t __n = size();
3263 if (__n)
3264 {
3265 __r.__begin_ =
3266 __r.__end_ =
Eric Fiseliera8312872018-03-22 04:42:56 +00003267 static_cast<value_type*>(
3268 _VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003269 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3270 ::new (__r.__end_) value_type(+*__p);
3271 }
3272 return __r;
3273}
3274
3275template <class _Tp>
3276valarray<_Tp>
3277valarray<_Tp>::operator-() const
3278{
3279 valarray<value_type> __r;
3280 size_t __n = size();
3281 if (__n)
3282 {
3283 __r.__begin_ =
3284 __r.__end_ =
Eric Fiseliera8312872018-03-22 04:42:56 +00003285 static_cast<value_type*>(
3286 _VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003287 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3288 ::new (__r.__end_) value_type(-*__p);
3289 }
3290 return __r;
3291}
3292
3293template <class _Tp>
3294valarray<_Tp>
3295valarray<_Tp>::operator~() const
3296{
3297 valarray<value_type> __r;
3298 size_t __n = size();
3299 if (__n)
3300 {
3301 __r.__begin_ =
3302 __r.__end_ =
Eric Fiseliera8312872018-03-22 04:42:56 +00003303 static_cast<value_type*>(
3304 _VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003305 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3306 ::new (__r.__end_) value_type(~*__p);
3307 }
3308 return __r;
3309}
3310
3311template <class _Tp>
3312valarray<bool>
3313valarray<_Tp>::operator!() const
3314{
3315 valarray<bool> __r;
3316 size_t __n = size();
3317 if (__n)
3318 {
3319 __r.__begin_ =
3320 __r.__end_ =
Eric Fiseliera8312872018-03-22 04:42:56 +00003321 static_cast<bool*>(_VSTD::__libcpp_allocate(__n * sizeof(bool), __alignof(bool)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003322 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3323 ::new (__r.__end_) bool(!*__p);
3324 }
3325 return __r;
3326}
3327
3328template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003329inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003330valarray<_Tp>&
3331valarray<_Tp>::operator*=(const value_type& __x)
3332{
3333 for (value_type* __p = __begin_; __p != __end_; ++__p)
3334 *__p *= __x;
3335 return *this;
3336}
3337
3338template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003339inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003340valarray<_Tp>&
3341valarray<_Tp>::operator/=(const value_type& __x)
3342{
3343 for (value_type* __p = __begin_; __p != __end_; ++__p)
3344 *__p /= __x;
3345 return *this;
3346}
3347
3348template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003349inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003350valarray<_Tp>&
3351valarray<_Tp>::operator%=(const value_type& __x)
3352{
3353 for (value_type* __p = __begin_; __p != __end_; ++__p)
3354 *__p %= __x;
3355 return *this;
3356}
3357
3358template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003359inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003360valarray<_Tp>&
3361valarray<_Tp>::operator+=(const value_type& __x)
3362{
3363 for (value_type* __p = __begin_; __p != __end_; ++__p)
3364 *__p += __x;
3365 return *this;
3366}
3367
3368template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003369inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003370valarray<_Tp>&
3371valarray<_Tp>::operator-=(const value_type& __x)
3372{
3373 for (value_type* __p = __begin_; __p != __end_; ++__p)
3374 *__p -= __x;
3375 return *this;
3376}
3377
3378template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003379inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003380valarray<_Tp>&
3381valarray<_Tp>::operator^=(const value_type& __x)
3382{
3383 for (value_type* __p = __begin_; __p != __end_; ++__p)
3384 *__p ^= __x;
3385 return *this;
3386}
3387
3388template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003389inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003390valarray<_Tp>&
3391valarray<_Tp>::operator&=(const value_type& __x)
3392{
3393 for (value_type* __p = __begin_; __p != __end_; ++__p)
3394 *__p &= __x;
3395 return *this;
3396}
3397
3398template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003399inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003400valarray<_Tp>&
3401valarray<_Tp>::operator|=(const value_type& __x)
3402{
3403 for (value_type* __p = __begin_; __p != __end_; ++__p)
3404 *__p |= __x;
3405 return *this;
3406}
3407
3408template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003409inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003410valarray<_Tp>&
3411valarray<_Tp>::operator<<=(const value_type& __x)
3412{
3413 for (value_type* __p = __begin_; __p != __end_; ++__p)
3414 *__p <<= __x;
3415 return *this;
3416}
3417
3418template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003419inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003420valarray<_Tp>&
3421valarray<_Tp>::operator>>=(const value_type& __x)
3422{
3423 for (value_type* __p = __begin_; __p != __end_; ++__p)
3424 *__p >>= __x;
3425 return *this;
3426}
3427
3428template <class _Tp>
3429template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003430inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003431typename enable_if
3432<
3433 __is_val_expr<_Expr>::value,
3434 valarray<_Tp>&
3435>::type
3436valarray<_Tp>::operator*=(const _Expr& __v)
3437{
3438 size_t __i = 0;
3439 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3440 *__t *= __v[__i];
3441 return *this;
3442}
3443
3444template <class _Tp>
3445template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003446inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003447typename enable_if
3448<
3449 __is_val_expr<_Expr>::value,
3450 valarray<_Tp>&
3451>::type
3452valarray<_Tp>::operator/=(const _Expr& __v)
3453{
3454 size_t __i = 0;
3455 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3456 *__t /= __v[__i];
3457 return *this;
3458}
3459
3460template <class _Tp>
3461template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003462inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003463typename enable_if
3464<
3465 __is_val_expr<_Expr>::value,
3466 valarray<_Tp>&
3467>::type
3468valarray<_Tp>::operator%=(const _Expr& __v)
3469{
3470 size_t __i = 0;
3471 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3472 *__t %= __v[__i];
3473 return *this;
3474}
3475
3476template <class _Tp>
3477template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003478inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003479typename enable_if
3480<
3481 __is_val_expr<_Expr>::value,
3482 valarray<_Tp>&
3483>::type
3484valarray<_Tp>::operator+=(const _Expr& __v)
3485{
3486 size_t __i = 0;
3487 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3488 *__t += __v[__i];
3489 return *this;
3490}
3491
3492template <class _Tp>
3493template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003494inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003495typename enable_if
3496<
3497 __is_val_expr<_Expr>::value,
3498 valarray<_Tp>&
3499>::type
3500valarray<_Tp>::operator-=(const _Expr& __v)
3501{
3502 size_t __i = 0;
3503 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3504 *__t -= __v[__i];
3505 return *this;
3506}
3507
3508template <class _Tp>
3509template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003510inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003511typename enable_if
3512<
3513 __is_val_expr<_Expr>::value,
3514 valarray<_Tp>&
3515>::type
3516valarray<_Tp>::operator^=(const _Expr& __v)
3517{
3518 size_t __i = 0;
3519 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3520 *__t ^= __v[__i];
3521 return *this;
3522}
3523
3524template <class _Tp>
3525template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003526inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003527typename enable_if
3528<
3529 __is_val_expr<_Expr>::value,
3530 valarray<_Tp>&
3531>::type
3532valarray<_Tp>::operator|=(const _Expr& __v)
3533{
3534 size_t __i = 0;
3535 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3536 *__t |= __v[__i];
3537 return *this;
3538}
3539
3540template <class _Tp>
3541template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003542inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003543typename enable_if
3544<
3545 __is_val_expr<_Expr>::value,
3546 valarray<_Tp>&
3547>::type
3548valarray<_Tp>::operator&=(const _Expr& __v)
3549{
3550 size_t __i = 0;
3551 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3552 *__t &= __v[__i];
3553 return *this;
3554}
3555
3556template <class _Tp>
3557template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003558inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003559typename enable_if
3560<
3561 __is_val_expr<_Expr>::value,
3562 valarray<_Tp>&
3563>::type
3564valarray<_Tp>::operator<<=(const _Expr& __v)
3565{
3566 size_t __i = 0;
3567 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3568 *__t <<= __v[__i];
3569 return *this;
3570}
3571
3572template <class _Tp>
3573template <class _Expr>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003574inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003575typename enable_if
3576<
3577 __is_val_expr<_Expr>::value,
3578 valarray<_Tp>&
3579>::type
3580valarray<_Tp>::operator>>=(const _Expr& __v)
3581{
3582 size_t __i = 0;
3583 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3584 *__t >>= __v[__i];
3585 return *this;
3586}
3587
3588template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003589inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003590void
Howard Hinnantbd143082012-07-21 00:51:28 +00003591valarray<_Tp>::swap(valarray& __v) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003592{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003593 _VSTD::swap(__begin_, __v.__begin_);
3594 _VSTD::swap(__end_, __v.__end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003595}
3596
3597template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003598inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003599_Tp
3600valarray<_Tp>::sum() const
3601{
3602 if (__begin_ == __end_)
3603 return value_type();
3604 const value_type* __p = __begin_;
3605 _Tp __r = *__p;
3606 for (++__p; __p != __end_; ++__p)
3607 __r += *__p;
3608 return __r;
3609}
3610
3611template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003612inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003613_Tp
3614valarray<_Tp>::min() const
3615{
3616 if (__begin_ == __end_)
3617 return value_type();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003618 return *_VSTD::min_element(__begin_, __end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003619}
3620
3621template <class _Tp>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00003622inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003623_Tp
3624valarray<_Tp>::max() const
3625{
3626 if (__begin_ == __end_)
3627 return value_type();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003628 return *_VSTD::max_element(__begin_, __end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003629}
3630
3631template <class _Tp>
3632valarray<_Tp>
3633valarray<_Tp>::shift(int __i) const
3634{
3635 valarray<value_type> __r;
3636 size_t __n = size();
3637 if (__n)
3638 {
3639 __r.__begin_ =
3640 __r.__end_ =
Eric Fiseliera8312872018-03-22 04:42:56 +00003641 static_cast<value_type*>(
3642 _VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003643 const value_type* __sb;
3644 value_type* __tb;
3645 value_type* __te;
3646 if (__i >= 0)
3647 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003648 __i = _VSTD::min(__i, static_cast<int>(__n));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003649 __sb = __begin_ + __i;
3650 __tb = __r.__begin_;
3651 __te = __r.__begin_ + (__n - __i);
3652 }
3653 else
3654 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003655 __i = _VSTD::min(-__i, static_cast<int>(__n));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003656 __sb = __begin_;
3657 __tb = __r.__begin_ + __i;
3658 __te = __r.__begin_ + __n;
3659 }
3660 for (; __r.__end_ != __tb; ++__r.__end_)
3661 ::new (__r.__end_) value_type();
3662 for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
3663 ::new (__r.__end_) value_type(*__sb);
3664 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
3665 ::new (__r.__end_) value_type();
3666 }
3667 return __r;
3668}
3669
3670template <class _Tp>
3671valarray<_Tp>
3672valarray<_Tp>::cshift(int __i) const
3673{
3674 valarray<value_type> __r;
3675 size_t __n = size();
3676 if (__n)
3677 {
3678 __r.__begin_ =
3679 __r.__end_ =
Eric Fiseliera8312872018-03-22 04:42:56 +00003680 static_cast<value_type*>(
3681 _VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003682 __i %= static_cast<int>(__n);
3683 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
3684 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
3685 ::new (__r.__end_) value_type(*__s);
3686 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
3687 ::new (__r.__end_) value_type(*__s);
3688 }
3689 return __r;
3690}
3691
3692template <class _Tp>
3693valarray<_Tp>
3694valarray<_Tp>::apply(value_type __f(value_type)) const
3695{
3696 valarray<value_type> __r;
3697 size_t __n = size();
3698 if (__n)
3699 {
3700 __r.__begin_ =
3701 __r.__end_ =
Eric Fiseliera8312872018-03-22 04:42:56 +00003702 static_cast<value_type*>(
3703 _VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003704 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3705 ::new (__r.__end_) value_type(__f(*__p));
3706 }
3707 return __r;
3708}
3709
3710template <class _Tp>
3711valarray<_Tp>
3712valarray<_Tp>::apply(value_type __f(const value_type&)) const
3713{
3714 valarray<value_type> __r;
3715 size_t __n = size();
3716 if (__n)
3717 {
3718 __r.__begin_ =
3719 __r.__end_ =
Eric Fiseliera8312872018-03-22 04:42:56 +00003720 static_cast<value_type*>(
3721 _VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003722 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3723 ::new (__r.__end_) value_type(__f(*__p));
3724 }
3725 return __r;
3726}
3727
3728template <class _Tp>
3729void
Mikhail Maltsev171ed212018-02-08 11:33:48 +00003730valarray<_Tp>::__clear()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003731{
3732 if (__begin_ != nullptr)
3733 {
3734 while (__end_ != __begin_)
3735 (--__end_)->~value_type();
Eric Fiseliera8312872018-03-22 04:42:56 +00003736 _VSTD::__libcpp_deallocate(__begin_, __alignof(value_type));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003737 __begin_ = __end_ = nullptr;
3738 }
Mikhail Maltsev171ed212018-02-08 11:33:48 +00003739}
3740
3741template <class _Tp>
3742void
3743valarray<_Tp>::resize(size_t __n, value_type __x)
3744{
3745 __clear();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003746 if (__n)
3747 {
Eric Fiseliera8312872018-03-22 04:42:56 +00003748 __begin_ = __end_ = static_cast<value_type*>(
3749 _VSTD::__libcpp_allocate(__n * sizeof(value_type), __alignof(value_type)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003750#ifndef _LIBCPP_NO_EXCEPTIONS
3751 try
3752 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003753#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003754 for (; __n; --__n, ++__end_)
3755 ::new (__end_) value_type(__x);
3756#ifndef _LIBCPP_NO_EXCEPTIONS
3757 }
3758 catch (...)
3759 {
Mikhail Maltsev171ed212018-02-08 11:33:48 +00003760 __clear();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003761 throw;
3762 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003763#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003764 }
3765}
3766
3767template<class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003768inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003769void
Howard Hinnantbd143082012-07-21 00:51:28 +00003770swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003771{
3772 __x.swap(__y);
3773}
3774
3775template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003776inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003777typename enable_if
3778<
3779 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3780 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
3781>::type
3782operator*(const _Expr1& __x, const _Expr2& __y)
3783{
3784 typedef typename _Expr1::value_type value_type;
3785 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
3786 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
3787}
3788
3789template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003790inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003791typename enable_if
3792<
3793 __is_val_expr<_Expr>::value,
3794 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3795 _Expr, __scalar_expr<typename _Expr::value_type> > >
3796>::type
3797operator*(const _Expr& __x, const typename _Expr::value_type& __y)
3798{
3799 typedef typename _Expr::value_type value_type;
3800 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3801 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3802 __x, __scalar_expr<value_type>(__y, __x.size())));
3803}
3804
3805template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003806inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003807typename enable_if
3808<
3809 __is_val_expr<_Expr>::value,
3810 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3811 __scalar_expr<typename _Expr::value_type>, _Expr> >
3812>::type
3813operator*(const typename _Expr::value_type& __x, const _Expr& __y)
3814{
3815 typedef typename _Expr::value_type value_type;
3816 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3817 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3818 __scalar_expr<value_type>(__x, __y.size()), __y));
3819}
3820
3821template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003822inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003823typename enable_if
3824<
3825 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3826 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
3827>::type
3828operator/(const _Expr1& __x, const _Expr2& __y)
3829{
3830 typedef typename _Expr1::value_type value_type;
3831 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
3832 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
3833}
3834
3835template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003836inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003837typename enable_if
3838<
3839 __is_val_expr<_Expr>::value,
3840 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3841 _Expr, __scalar_expr<typename _Expr::value_type> > >
3842>::type
3843operator/(const _Expr& __x, const typename _Expr::value_type& __y)
3844{
3845 typedef typename _Expr::value_type value_type;
3846 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3847 return __val_expr<_Op>(_Op(divides<value_type>(),
3848 __x, __scalar_expr<value_type>(__y, __x.size())));
3849}
3850
3851template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003852inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003853typename enable_if
3854<
3855 __is_val_expr<_Expr>::value,
3856 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3857 __scalar_expr<typename _Expr::value_type>, _Expr> >
3858>::type
3859operator/(const typename _Expr::value_type& __x, const _Expr& __y)
3860{
3861 typedef typename _Expr::value_type value_type;
3862 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3863 return __val_expr<_Op>(_Op(divides<value_type>(),
3864 __scalar_expr<value_type>(__x, __y.size()), __y));
3865}
3866
3867template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003868inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003869typename enable_if
3870<
3871 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3872 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3873>::type
3874operator%(const _Expr1& __x, const _Expr2& __y)
3875{
3876 typedef typename _Expr1::value_type value_type;
3877 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
3878 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
3879}
3880
3881template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003882inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003883typename enable_if
3884<
3885 __is_val_expr<_Expr>::value,
3886 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3887 _Expr, __scalar_expr<typename _Expr::value_type> > >
3888>::type
3889operator%(const _Expr& __x, const typename _Expr::value_type& __y)
3890{
3891 typedef typename _Expr::value_type value_type;
3892 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3893 return __val_expr<_Op>(_Op(modulus<value_type>(),
3894 __x, __scalar_expr<value_type>(__y, __x.size())));
3895}
3896
3897template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003898inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003899typename enable_if
3900<
3901 __is_val_expr<_Expr>::value,
3902 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3903 __scalar_expr<typename _Expr::value_type>, _Expr> >
3904>::type
3905operator%(const typename _Expr::value_type& __x, const _Expr& __y)
3906{
3907 typedef typename _Expr::value_type value_type;
3908 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3909 return __val_expr<_Op>(_Op(modulus<value_type>(),
3910 __scalar_expr<value_type>(__x, __y.size()), __y));
3911}
3912
3913template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003914inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003915typename enable_if
3916<
3917 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3918 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3919>::type
3920operator+(const _Expr1& __x, const _Expr2& __y)
3921{
3922 typedef typename _Expr1::value_type value_type;
3923 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
3924 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
3925}
3926
3927template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003928inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003929typename enable_if
3930<
3931 __is_val_expr<_Expr>::value,
3932 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3933 _Expr, __scalar_expr<typename _Expr::value_type> > >
3934>::type
3935operator+(const _Expr& __x, const typename _Expr::value_type& __y)
3936{
3937 typedef typename _Expr::value_type value_type;
3938 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3939 return __val_expr<_Op>(_Op(plus<value_type>(),
3940 __x, __scalar_expr<value_type>(__y, __x.size())));
3941}
3942
3943template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003944inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003945typename enable_if
3946<
3947 __is_val_expr<_Expr>::value,
3948 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3949 __scalar_expr<typename _Expr::value_type>, _Expr> >
3950>::type
3951operator+(const typename _Expr::value_type& __x, const _Expr& __y)
3952{
3953 typedef typename _Expr::value_type value_type;
3954 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3955 return __val_expr<_Op>(_Op(plus<value_type>(),
3956 __scalar_expr<value_type>(__x, __y.size()), __y));
3957}
3958
3959template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003960inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003961typename enable_if
3962<
3963 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3964 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3965>::type
3966operator-(const _Expr1& __x, const _Expr2& __y)
3967{
3968 typedef typename _Expr1::value_type value_type;
3969 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
3970 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
3971}
3972
3973template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003974inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003975typename enable_if
3976<
3977 __is_val_expr<_Expr>::value,
3978 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3979 _Expr, __scalar_expr<typename _Expr::value_type> > >
3980>::type
3981operator-(const _Expr& __x, const typename _Expr::value_type& __y)
3982{
3983 typedef typename _Expr::value_type value_type;
3984 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3985 return __val_expr<_Op>(_Op(minus<value_type>(),
3986 __x, __scalar_expr<value_type>(__y, __x.size())));
3987}
3988
3989template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003990inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003991typename enable_if
3992<
3993 __is_val_expr<_Expr>::value,
3994 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3995 __scalar_expr<typename _Expr::value_type>, _Expr> >
3996>::type
3997operator-(const typename _Expr::value_type& __x, const _Expr& __y)
3998{
3999 typedef typename _Expr::value_type value_type;
4000 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4001 return __val_expr<_Op>(_Op(minus<value_type>(),
4002 __scalar_expr<value_type>(__x, __y.size()), __y));
4003}
4004
4005template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004006inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004007typename enable_if
4008<
4009 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4010 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
4011>::type
4012operator^(const _Expr1& __x, const _Expr2& __y)
4013{
4014 typedef typename _Expr1::value_type value_type;
4015 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
4016 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
4017}
4018
4019template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004020inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004021typename enable_if
4022<
4023 __is_val_expr<_Expr>::value,
4024 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
4025 _Expr, __scalar_expr<typename _Expr::value_type> > >
4026>::type
4027operator^(const _Expr& __x, const typename _Expr::value_type& __y)
4028{
4029 typedef typename _Expr::value_type value_type;
4030 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4031 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
4032 __x, __scalar_expr<value_type>(__y, __x.size())));
4033}
4034
4035template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004036inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004037typename enable_if
4038<
4039 __is_val_expr<_Expr>::value,
4040 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
4041 __scalar_expr<typename _Expr::value_type>, _Expr> >
4042>::type
4043operator^(const typename _Expr::value_type& __x, const _Expr& __y)
4044{
4045 typedef typename _Expr::value_type value_type;
4046 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4047 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
4048 __scalar_expr<value_type>(__x, __y.size()), __y));
4049}
4050
4051template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004052inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004053typename enable_if
4054<
4055 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4056 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4057>::type
4058operator&(const _Expr1& __x, const _Expr2& __y)
4059{
4060 typedef typename _Expr1::value_type value_type;
4061 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
4062 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
4063}
4064
4065template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004066inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004067typename enable_if
4068<
4069 __is_val_expr<_Expr>::value,
4070 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4071 _Expr, __scalar_expr<typename _Expr::value_type> > >
4072>::type
4073operator&(const _Expr& __x, const typename _Expr::value_type& __y)
4074{
4075 typedef typename _Expr::value_type value_type;
4076 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4077 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4078 __x, __scalar_expr<value_type>(__y, __x.size())));
4079}
4080
4081template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004082inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004083typename enable_if
4084<
4085 __is_val_expr<_Expr>::value,
4086 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
4087 __scalar_expr<typename _Expr::value_type>, _Expr> >
4088>::type
4089operator&(const typename _Expr::value_type& __x, const _Expr& __y)
4090{
4091 typedef typename _Expr::value_type value_type;
4092 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4093 return __val_expr<_Op>(_Op(bit_and<value_type>(),
4094 __scalar_expr<value_type>(__x, __y.size()), __y));
4095}
4096
4097template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004098inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004099typename enable_if
4100<
4101 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4102 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4103>::type
4104operator|(const _Expr1& __x, const _Expr2& __y)
4105{
4106 typedef typename _Expr1::value_type value_type;
4107 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
4108 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
4109}
4110
4111template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004112inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004113typename enable_if
4114<
4115 __is_val_expr<_Expr>::value,
4116 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4117 _Expr, __scalar_expr<typename _Expr::value_type> > >
4118>::type
4119operator|(const _Expr& __x, const typename _Expr::value_type& __y)
4120{
4121 typedef typename _Expr::value_type value_type;
4122 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4123 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4124 __x, __scalar_expr<value_type>(__y, __x.size())));
4125}
4126
4127template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004128inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004129typename enable_if
4130<
4131 __is_val_expr<_Expr>::value,
4132 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
4133 __scalar_expr<typename _Expr::value_type>, _Expr> >
4134>::type
4135operator|(const typename _Expr::value_type& __x, const _Expr& __y)
4136{
4137 typedef typename _Expr::value_type value_type;
4138 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4139 return __val_expr<_Op>(_Op(bit_or<value_type>(),
4140 __scalar_expr<value_type>(__x, __y.size()), __y));
4141}
4142
4143template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004144inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004145typename enable_if
4146<
4147 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4148 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
4149>::type
4150operator<<(const _Expr1& __x, const _Expr2& __y)
4151{
4152 typedef typename _Expr1::value_type value_type;
4153 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
4154 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
4155}
4156
4157template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004158inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004159typename enable_if
4160<
4161 __is_val_expr<_Expr>::value,
4162 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4163 _Expr, __scalar_expr<typename _Expr::value_type> > >
4164>::type
4165operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
4166{
4167 typedef typename _Expr::value_type value_type;
4168 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4169 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4170 __x, __scalar_expr<value_type>(__y, __x.size())));
4171}
4172
4173template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004174inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004175typename enable_if
4176<
4177 __is_val_expr<_Expr>::value,
4178 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4179 __scalar_expr<typename _Expr::value_type>, _Expr> >
4180>::type
4181operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
4182{
4183 typedef typename _Expr::value_type value_type;
4184 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4185 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4186 __scalar_expr<value_type>(__x, __y.size()), __y));
4187}
4188
4189template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004190inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004191typename enable_if
4192<
4193 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4194 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
4195>::type
4196operator>>(const _Expr1& __x, const _Expr2& __y)
4197{
4198 typedef typename _Expr1::value_type value_type;
4199 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
4200 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
4201}
4202
4203template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004204inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004205typename enable_if
4206<
4207 __is_val_expr<_Expr>::value,
4208 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4209 _Expr, __scalar_expr<typename _Expr::value_type> > >
4210>::type
4211operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
4212{
4213 typedef typename _Expr::value_type value_type;
4214 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4215 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4216 __x, __scalar_expr<value_type>(__y, __x.size())));
4217}
4218
4219template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004220inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004221typename enable_if
4222<
4223 __is_val_expr<_Expr>::value,
4224 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4225 __scalar_expr<typename _Expr::value_type>, _Expr> >
4226>::type
4227operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
4228{
4229 typedef typename _Expr::value_type value_type;
4230 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4231 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4232 __scalar_expr<value_type>(__x, __y.size()), __y));
4233}
4234
4235template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004236inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004237typename enable_if
4238<
4239 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4240 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4241>::type
4242operator&&(const _Expr1& __x, const _Expr2& __y)
4243{
4244 typedef typename _Expr1::value_type value_type;
4245 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
4246 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
4247}
4248
4249template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004250inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004251typename enable_if
4252<
4253 __is_val_expr<_Expr>::value,
4254 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4255 _Expr, __scalar_expr<typename _Expr::value_type> > >
4256>::type
4257operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
4258{
4259 typedef typename _Expr::value_type value_type;
4260 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4261 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4262 __x, __scalar_expr<value_type>(__y, __x.size())));
4263}
4264
4265template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004266inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004267typename enable_if
4268<
4269 __is_val_expr<_Expr>::value,
4270 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4271 __scalar_expr<typename _Expr::value_type>, _Expr> >
4272>::type
4273operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
4274{
4275 typedef typename _Expr::value_type value_type;
4276 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4277 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4278 __scalar_expr<value_type>(__x, __y.size()), __y));
4279}
4280
4281template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004282inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004283typename enable_if
4284<
4285 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4286 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4287>::type
4288operator||(const _Expr1& __x, const _Expr2& __y)
4289{
4290 typedef typename _Expr1::value_type value_type;
4291 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
4292 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
4293}
4294
4295template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004296inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004297typename enable_if
4298<
4299 __is_val_expr<_Expr>::value,
4300 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4301 _Expr, __scalar_expr<typename _Expr::value_type> > >
4302>::type
4303operator||(const _Expr& __x, const typename _Expr::value_type& __y)
4304{
4305 typedef typename _Expr::value_type value_type;
4306 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4307 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4308 __x, __scalar_expr<value_type>(__y, __x.size())));
4309}
4310
4311template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004312inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004313typename enable_if
4314<
4315 __is_val_expr<_Expr>::value,
4316 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4317 __scalar_expr<typename _Expr::value_type>, _Expr> >
4318>::type
4319operator||(const typename _Expr::value_type& __x, const _Expr& __y)
4320{
4321 typedef typename _Expr::value_type value_type;
4322 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4323 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4324 __scalar_expr<value_type>(__x, __y.size()), __y));
4325}
4326
4327template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004328inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004329typename enable_if
4330<
4331 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4332 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4333>::type
4334operator==(const _Expr1& __x, const _Expr2& __y)
4335{
4336 typedef typename _Expr1::value_type value_type;
4337 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
4338 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
4339}
4340
4341template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004342inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004343typename enable_if
4344<
4345 __is_val_expr<_Expr>::value,
4346 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4347 _Expr, __scalar_expr<typename _Expr::value_type> > >
4348>::type
4349operator==(const _Expr& __x, const typename _Expr::value_type& __y)
4350{
4351 typedef typename _Expr::value_type value_type;
4352 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4353 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4354 __x, __scalar_expr<value_type>(__y, __x.size())));
4355}
4356
4357template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004358inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004359typename enable_if
4360<
4361 __is_val_expr<_Expr>::value,
4362 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4363 __scalar_expr<typename _Expr::value_type>, _Expr> >
4364>::type
4365operator==(const typename _Expr::value_type& __x, const _Expr& __y)
4366{
4367 typedef typename _Expr::value_type value_type;
4368 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4369 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4370 __scalar_expr<value_type>(__x, __y.size()), __y));
4371}
4372
4373template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004374inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004375typename enable_if
4376<
4377 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4378 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4379>::type
4380operator!=(const _Expr1& __x, const _Expr2& __y)
4381{
4382 typedef typename _Expr1::value_type value_type;
4383 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
4384 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
4385}
4386
4387template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004388inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004389typename enable_if
4390<
4391 __is_val_expr<_Expr>::value,
4392 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4393 _Expr, __scalar_expr<typename _Expr::value_type> > >
4394>::type
4395operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
4396{
4397 typedef typename _Expr::value_type value_type;
4398 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4399 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4400 __x, __scalar_expr<value_type>(__y, __x.size())));
4401}
4402
4403template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004404inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004405typename enable_if
4406<
4407 __is_val_expr<_Expr>::value,
4408 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4409 __scalar_expr<typename _Expr::value_type>, _Expr> >
4410>::type
4411operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
4412{
4413 typedef typename _Expr::value_type value_type;
4414 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4415 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4416 __scalar_expr<value_type>(__x, __y.size()), __y));
4417}
4418
4419template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004420inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004421typename enable_if
4422<
4423 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4424 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
4425>::type
4426operator<(const _Expr1& __x, const _Expr2& __y)
4427{
4428 typedef typename _Expr1::value_type value_type;
4429 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
4430 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
4431}
4432
4433template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004434inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004435typename enable_if
4436<
4437 __is_val_expr<_Expr>::value,
4438 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4439 _Expr, __scalar_expr<typename _Expr::value_type> > >
4440>::type
4441operator<(const _Expr& __x, const typename _Expr::value_type& __y)
4442{
4443 typedef typename _Expr::value_type value_type;
4444 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4445 return __val_expr<_Op>(_Op(less<value_type>(),
4446 __x, __scalar_expr<value_type>(__y, __x.size())));
4447}
4448
4449template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004450inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004451typename enable_if
4452<
4453 __is_val_expr<_Expr>::value,
4454 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4455 __scalar_expr<typename _Expr::value_type>, _Expr> >
4456>::type
4457operator<(const typename _Expr::value_type& __x, const _Expr& __y)
4458{
4459 typedef typename _Expr::value_type value_type;
4460 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4461 return __val_expr<_Op>(_Op(less<value_type>(),
4462 __scalar_expr<value_type>(__x, __y.size()), __y));
4463}
4464
4465template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004466inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004467typename enable_if
4468<
4469 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4470 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
4471>::type
4472operator>(const _Expr1& __x, const _Expr2& __y)
4473{
4474 typedef typename _Expr1::value_type value_type;
4475 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
4476 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
4477}
4478
4479template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004480inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004481typename enable_if
4482<
4483 __is_val_expr<_Expr>::value,
4484 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4485 _Expr, __scalar_expr<typename _Expr::value_type> > >
4486>::type
4487operator>(const _Expr& __x, const typename _Expr::value_type& __y)
4488{
4489 typedef typename _Expr::value_type value_type;
4490 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4491 return __val_expr<_Op>(_Op(greater<value_type>(),
4492 __x, __scalar_expr<value_type>(__y, __x.size())));
4493}
4494
4495template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004496inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004497typename enable_if
4498<
4499 __is_val_expr<_Expr>::value,
4500 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4501 __scalar_expr<typename _Expr::value_type>, _Expr> >
4502>::type
4503operator>(const typename _Expr::value_type& __x, const _Expr& __y)
4504{
4505 typedef typename _Expr::value_type value_type;
4506 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4507 return __val_expr<_Op>(_Op(greater<value_type>(),
4508 __scalar_expr<value_type>(__x, __y.size()), __y));
4509}
4510
4511template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004512inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004513typename enable_if
4514<
4515 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4516 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4517>::type
4518operator<=(const _Expr1& __x, const _Expr2& __y)
4519{
4520 typedef typename _Expr1::value_type value_type;
4521 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
4522 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
4523}
4524
4525template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004526inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004527typename enable_if
4528<
4529 __is_val_expr<_Expr>::value,
4530 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4531 _Expr, __scalar_expr<typename _Expr::value_type> > >
4532>::type
4533operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
4534{
4535 typedef typename _Expr::value_type value_type;
4536 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4537 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4538 __x, __scalar_expr<value_type>(__y, __x.size())));
4539}
4540
4541template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004542inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004543typename enable_if
4544<
4545 __is_val_expr<_Expr>::value,
4546 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4547 __scalar_expr<typename _Expr::value_type>, _Expr> >
4548>::type
4549operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
4550{
4551 typedef typename _Expr::value_type value_type;
4552 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4553 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4554 __scalar_expr<value_type>(__x, __y.size()), __y));
4555}
4556
4557template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004558inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004559typename enable_if
4560<
4561 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4562 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4563>::type
4564operator>=(const _Expr1& __x, const _Expr2& __y)
4565{
4566 typedef typename _Expr1::value_type value_type;
4567 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
4568 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
4569}
4570
4571template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004572inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004573typename enable_if
4574<
4575 __is_val_expr<_Expr>::value,
4576 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4577 _Expr, __scalar_expr<typename _Expr::value_type> > >
4578>::type
4579operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
4580{
4581 typedef typename _Expr::value_type value_type;
4582 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4583 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4584 __x, __scalar_expr<value_type>(__y, __x.size())));
4585}
4586
4587template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004588inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004589typename enable_if
4590<
4591 __is_val_expr<_Expr>::value,
4592 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4593 __scalar_expr<typename _Expr::value_type>, _Expr> >
4594>::type
4595operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
4596{
4597 typedef typename _Expr::value_type value_type;
4598 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4599 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4600 __scalar_expr<value_type>(__x, __y.size()), __y));
4601}
4602
4603template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004604inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004605typename enable_if
4606<
4607 __is_val_expr<_Expr>::value,
4608 __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
4609>::type
4610abs(const _Expr& __x)
4611{
4612 typedef typename _Expr::value_type value_type;
4613 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
4614 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
4615}
4616
4617template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004618inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004619typename enable_if
4620<
4621 __is_val_expr<_Expr>::value,
4622 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
4623>::type
4624acos(const _Expr& __x)
4625{
4626 typedef typename _Expr::value_type value_type;
4627 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
4628 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
4629}
4630
4631template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004632inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004633typename enable_if
4634<
4635 __is_val_expr<_Expr>::value,
4636 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
4637>::type
4638asin(const _Expr& __x)
4639{
4640 typedef typename _Expr::value_type value_type;
4641 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
4642 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
4643}
4644
4645template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004646inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004647typename enable_if
4648<
4649 __is_val_expr<_Expr>::value,
4650 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
4651>::type
4652atan(const _Expr& __x)
4653{
4654 typedef typename _Expr::value_type value_type;
4655 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
4656 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
4657}
4658
4659template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004660inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004661typename enable_if
4662<
4663 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4664 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4665>::type
4666atan2(const _Expr1& __x, const _Expr2& __y)
4667{
4668 typedef typename _Expr1::value_type value_type;
4669 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
4670 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
4671}
4672
4673template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004674inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004675typename enable_if
4676<
4677 __is_val_expr<_Expr>::value,
4678 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4679 _Expr, __scalar_expr<typename _Expr::value_type> > >
4680>::type
4681atan2(const _Expr& __x, const typename _Expr::value_type& __y)
4682{
4683 typedef typename _Expr::value_type value_type;
4684 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4685 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4686 __x, __scalar_expr<value_type>(__y, __x.size())));
4687}
4688
4689template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004690inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004691typename enable_if
4692<
4693 __is_val_expr<_Expr>::value,
4694 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4695 __scalar_expr<typename _Expr::value_type>, _Expr> >
4696>::type
4697atan2(const typename _Expr::value_type& __x, const _Expr& __y)
4698{
4699 typedef typename _Expr::value_type value_type;
4700 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4701 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4702 __scalar_expr<value_type>(__x, __y.size()), __y));
4703}
4704
4705template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004706inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004707typename enable_if
4708<
4709 __is_val_expr<_Expr>::value,
4710 __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
4711>::type
4712cos(const _Expr& __x)
4713{
4714 typedef typename _Expr::value_type value_type;
4715 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
4716 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
4717}
4718
4719template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004720inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004721typename enable_if
4722<
4723 __is_val_expr<_Expr>::value,
4724 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
4725>::type
4726cosh(const _Expr& __x)
4727{
4728 typedef typename _Expr::value_type value_type;
4729 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
4730 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
4731}
4732
4733template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004734inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004735typename enable_if
4736<
4737 __is_val_expr<_Expr>::value,
4738 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
4739>::type
4740exp(const _Expr& __x)
4741{
4742 typedef typename _Expr::value_type value_type;
4743 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
4744 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
4745}
4746
4747template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004748inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004749typename enable_if
4750<
4751 __is_val_expr<_Expr>::value,
4752 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
4753>::type
4754log(const _Expr& __x)
4755{
4756 typedef typename _Expr::value_type value_type;
4757 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
4758 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
4759}
4760
4761template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004762inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004763typename enable_if
4764<
4765 __is_val_expr<_Expr>::value,
4766 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
4767>::type
4768log10(const _Expr& __x)
4769{
4770 typedef typename _Expr::value_type value_type;
4771 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
4772 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
4773}
4774
4775template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004776inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004777typename enable_if
4778<
4779 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4780 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4781>::type
4782pow(const _Expr1& __x, const _Expr2& __y)
4783{
4784 typedef typename _Expr1::value_type value_type;
4785 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
4786 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
4787}
4788
4789template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004790inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004791typename enable_if
4792<
4793 __is_val_expr<_Expr>::value,
4794 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4795 _Expr, __scalar_expr<typename _Expr::value_type> > >
4796>::type
4797pow(const _Expr& __x, const typename _Expr::value_type& __y)
4798{
4799 typedef typename _Expr::value_type value_type;
4800 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4801 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4802 __x, __scalar_expr<value_type>(__y, __x.size())));
4803}
4804
4805template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004806inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004807typename enable_if
4808<
4809 __is_val_expr<_Expr>::value,
4810 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4811 __scalar_expr<typename _Expr::value_type>, _Expr> >
4812>::type
4813pow(const typename _Expr::value_type& __x, const _Expr& __y)
4814{
4815 typedef typename _Expr::value_type value_type;
4816 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4817 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4818 __scalar_expr<value_type>(__x, __y.size()), __y));
4819}
4820
4821template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004822inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004823typename enable_if
4824<
4825 __is_val_expr<_Expr>::value,
4826 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
4827>::type
4828sin(const _Expr& __x)
4829{
4830 typedef typename _Expr::value_type value_type;
4831 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
4832 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
4833}
4834
4835template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004836inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004837typename enable_if
4838<
4839 __is_val_expr<_Expr>::value,
4840 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
4841>::type
4842sinh(const _Expr& __x)
4843{
4844 typedef typename _Expr::value_type value_type;
4845 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
4846 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
4847}
4848
4849template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004850inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004851typename enable_if
4852<
4853 __is_val_expr<_Expr>::value,
4854 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
4855>::type
4856sqrt(const _Expr& __x)
4857{
4858 typedef typename _Expr::value_type value_type;
4859 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
4860 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
4861}
4862
4863template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004864inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004865typename enable_if
4866<
4867 __is_val_expr<_Expr>::value,
4868 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
4869>::type
4870tan(const _Expr& __x)
4871{
4872 typedef typename _Expr::value_type value_type;
4873 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
4874 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
4875}
4876
4877template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004878inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004879typename enable_if
4880<
4881 __is_val_expr<_Expr>::value,
4882 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
4883>::type
4884tanh(const _Expr& __x)
4885{
4886 typedef typename _Expr::value_type value_type;
4887 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
4888 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
4889}
4890
4891template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004892inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004893_Tp*
4894begin(valarray<_Tp>& __v)
4895{
4896 return __v.__begin_;
4897}
4898
4899template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004900inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004901const _Tp*
4902begin(const valarray<_Tp>& __v)
4903{
4904 return __v.__begin_;
4905}
4906
4907template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004908inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004909_Tp*
4910end(valarray<_Tp>& __v)
4911{
4912 return __v.__end_;
4913}
4914
4915template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004916inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004917const _Tp*
4918end(const valarray<_Tp>& __v)
4919{
4920 return __v.__end_;
4921}
4922
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004923_LIBCPP_END_NAMESPACE_STD
4924
Eric Fiselier018a3d52017-05-31 22:07:49 +00004925_LIBCPP_POP_MACROS
4926
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004927#endif // _LIBCPP_VALARRAY