blob: d7a173cf6fb09a2cffb90100d5b930813acfa264 [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);
32 valarray(valarray&& v);
33 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);
42 valarray& operator=(valarray&& v);
43 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:
94 void swap(valarray& v);
95
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
234template<class T> void swap(valarray<T>& x, valarray<T>& y);
235
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>
348
349#pragma GCC system_header
350
351_LIBCPP_BEGIN_NAMESPACE_STD
352
353template<class _Tp> class valarray;
354
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000355class _LIBCPP_VISIBLE slice
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000356{
357 size_t __start_;
358 size_t __size_;
359 size_t __stride_;
360public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000361 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000362 slice()
363 : __start_(0),
364 __size_(0),
365 __stride_(0)
366 {}
367
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000368 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000369 slice(size_t __start, size_t __size, size_t __stride)
370 : __start_(__start),
371 __size_(__size),
372 __stride_(__stride)
373 {}
374
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000375 _LIBCPP_INLINE_VISIBILITY size_t start() const {return __start_;}
376 _LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;}
377 _LIBCPP_INLINE_VISIBILITY size_t stride() const {return __stride_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000378};
379
380template <class _Tp> class slice_array;
381class gslice;
382template <class _Tp> class gslice_array;
383template <class _Tp> class mask_array;
384template <class _Tp> class indirect_array;
385
386template <class _Tp>
387_Tp*
388begin(valarray<_Tp>& __v);
389
390template <class _Tp>
391const _Tp*
392begin(const valarray<_Tp>& __v);
393
394template <class _Tp>
395_Tp*
396end(valarray<_Tp>& __v);
397
398template <class _Tp>
399const _Tp*
400end(const valarray<_Tp>& __v);
401
402template <class _Op, class _A0>
403struct _UnaryOp
404{
405 typedef typename _Op::result_type result_type;
406 typedef typename _A0::value_type value_type;
407
408 _Op __op_;
409 _A0 __a0_;
410
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000411 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000412 _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {}
413
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000414 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000415 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
416
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000417 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000418 size_t size() const {return __a0_.size();}
419};
420
421template <class _Op, class _A0, class _A1>
422struct _BinaryOp
423{
424 typedef typename _Op::result_type result_type;
425 typedef typename _A0::value_type value_type;
426
427 _Op __op_;
428 _A0 __a0_;
429 _A1 __a1_;
430
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000431 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000432 _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1)
433 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
434
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000435 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000436 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
437
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000438 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439 size_t size() const {return __a0_.size();}
440};
441
442template <class _Tp>
443class __scalar_expr
444{
445public:
446 typedef _Tp value_type;
447 typedef const _Tp& result_type;
448private:
449 const value_type& __t_;
450 size_t __s_;
451public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000452 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000453 explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {}
454
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000456 result_type operator[](size_t) const {return __t_;}
457
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459 size_t size() const {return __s_;}
460};
461
462template <class _Tp>
463struct __unary_plus : unary_function<_Tp, _Tp>
464{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000466 _Tp operator()(const _Tp& __x) const
467 {return +__x;}
468};
469
470template <class _Tp>
471struct __bit_not : unary_function<_Tp, _Tp>
472{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000474 _Tp operator()(const _Tp& __x) const
475 {return ~__x;}
476};
477
478template <class _Tp>
479struct __bit_shift_left : binary_function<_Tp, _Tp, _Tp>
480{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000482 _Tp operator()(const _Tp& __x, const _Tp& __y) const
483 {return __x << __y;}
484};
485
486template <class _Tp>
487struct __bit_shift_right : binary_function<_Tp, _Tp, _Tp>
488{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000489 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000490 _Tp operator()(const _Tp& __x, const _Tp& __y) const
491 {return __x >> __y;}
492};
493
494template <class _Tp, class _F>
495struct __apply_expr : unary_function<_Tp, _Tp>
496{
497private:
498 _F __f_;
499public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000501 explicit __apply_expr(_F __f) : __f_(__f) {}
502
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000503 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504 _Tp operator()(const _Tp& __x) const
505 {return __f_(__x);}
506};
507
508template <class _Tp>
509struct __abs_expr : unary_function<_Tp, _Tp>
510{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000512 _Tp operator()(const _Tp& __x) const
513 {return abs(__x);}
514};
515
516template <class _Tp>
517struct __acos_expr : unary_function<_Tp, _Tp>
518{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000520 _Tp operator()(const _Tp& __x) const
521 {return acos(__x);}
522};
523
524template <class _Tp>
525struct __asin_expr : unary_function<_Tp, _Tp>
526{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528 _Tp operator()(const _Tp& __x) const
529 {return asin(__x);}
530};
531
532template <class _Tp>
533struct __atan_expr : unary_function<_Tp, _Tp>
534{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000536 _Tp operator()(const _Tp& __x) const
537 {return atan(__x);}
538};
539
540template <class _Tp>
541struct __atan2_expr : binary_function<_Tp, _Tp, _Tp>
542{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000544 _Tp operator()(const _Tp& __x, const _Tp& __y) const
545 {return atan2(__x, __y);}
546};
547
548template <class _Tp>
549struct __cos_expr : unary_function<_Tp, _Tp>
550{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000552 _Tp operator()(const _Tp& __x) const
553 {return cos(__x);}
554};
555
556template <class _Tp>
557struct __cosh_expr : unary_function<_Tp, _Tp>
558{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000560 _Tp operator()(const _Tp& __x) const
561 {return cosh(__x);}
562};
563
564template <class _Tp>
565struct __exp_expr : unary_function<_Tp, _Tp>
566{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000568 _Tp operator()(const _Tp& __x) const
569 {return exp(__x);}
570};
571
572template <class _Tp>
573struct __log_expr : unary_function<_Tp, _Tp>
574{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000576 _Tp operator()(const _Tp& __x) const
577 {return log(__x);}
578};
579
580template <class _Tp>
581struct __log10_expr : unary_function<_Tp, _Tp>
582{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000584 _Tp operator()(const _Tp& __x) const
585 {return log10(__x);}
586};
587
588template <class _Tp>
589struct __pow_expr : binary_function<_Tp, _Tp, _Tp>
590{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000592 _Tp operator()(const _Tp& __x, const _Tp& __y) const
593 {return pow(__x, __y);}
594};
595
596template <class _Tp>
597struct __sin_expr : unary_function<_Tp, _Tp>
598{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000600 _Tp operator()(const _Tp& __x) const
601 {return sin(__x);}
602};
603
604template <class _Tp>
605struct __sinh_expr : unary_function<_Tp, _Tp>
606{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000608 _Tp operator()(const _Tp& __x) const
609 {return sinh(__x);}
610};
611
612template <class _Tp>
613struct __sqrt_expr : unary_function<_Tp, _Tp>
614{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000615 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000616 _Tp operator()(const _Tp& __x) const
617 {return sqrt(__x);}
618};
619
620template <class _Tp>
621struct __tan_expr : unary_function<_Tp, _Tp>
622{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000624 _Tp operator()(const _Tp& __x) const
625 {return tan(__x);}
626};
627
628template <class _Tp>
629struct __tanh_expr : unary_function<_Tp, _Tp>
630{
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000632 _Tp operator()(const _Tp& __x) const
633 {return tanh(__x);}
634};
635
636template <class _ValExpr>
637class __slice_expr
638{
639 typedef typename remove_reference<_ValExpr>::type _RmExpr;
640public:
641 typedef typename _RmExpr::value_type value_type;
642 typedef value_type result_type;
643
644private:
645 _ValExpr __expr_;
646 size_t __start_;
647 size_t __size_;
648 size_t __stride_;
649
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000651 __slice_expr(const slice& __sl, const _RmExpr& __e)
652 : __expr_(__e),
653 __start_(__sl.start()),
654 __size_(__sl.size()),
655 __stride_(__sl.stride())
656 {}
657public:
658
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000659 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000660 result_type operator[](size_t __i) const
661 {return __expr_[__start_ + __i * __stride_];}
662
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000663 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000664 size_t size() const {return __size_;}
665
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000666 template <class> friend class _LIBCPP_VISIBLE valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000667};
668
669template <class _ValExpr>
670class __mask_expr;
671
672template <class _ValExpr>
673class __indirect_expr;
674
675template <class _ValExpr>
676class __shift_expr
677{
678 typedef typename remove_reference<_ValExpr>::type _RmExpr;
679public:
680 typedef typename _RmExpr::value_type value_type;
681 typedef value_type result_type;
682
683private:
684 _ValExpr __expr_;
685 size_t __size_;
686 ptrdiff_t __ul_;
687 ptrdiff_t __sn_;
688 ptrdiff_t __n_;
689 static const ptrdiff_t _N = static_cast<ptrdiff_t>(
690 sizeof(ptrdiff_t) * __CHAR_BIT__ - 1);
691
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000693 __shift_expr(int __n, const _RmExpr& __e)
694 : __expr_(__e),
695 __size_(__e.size()),
696 __n_(__n)
697 {
698 ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _N);
699 __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _N);
700 __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n);
701 }
702public:
703
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000704 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000705 result_type operator[](size_t __j) const
706 {
707 ptrdiff_t __i = static_cast<size_t>(__j);
708 ptrdiff_t __m = (__sn_ * __i - __ul_) >> _N;
709 return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
710 }
711
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713 size_t size() const {return __size_;}
714
715 template <class> friend class __val_expr;
716};
717
718template <class _ValExpr>
719class __cshift_expr
720{
721 typedef typename remove_reference<_ValExpr>::type _RmExpr;
722public:
723 typedef typename _RmExpr::value_type value_type;
724 typedef value_type result_type;
725
726private:
727 _ValExpr __expr_;
728 size_t __size_;
729 size_t __m_;
730 size_t __o1_;
731 size_t __o2_;
732
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000734 __cshift_expr(int __n, const _RmExpr& __e)
735 : __expr_(__e),
736 __size_(__e.size())
737 {
738 __n %= static_cast<int>(__size_);
739 if (__n >= 0)
740 {
741 __m_ = __size_ - __n;
742 __o1_ = __n;
743 __o2_ = __n - __size_;
744 }
745 else
746 {
747 __m_ = -__n;
748 __o1_ = __n + __size_;
749 __o2_ = __n;
750 }
751 }
752public:
753
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000754 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000755 result_type operator[](size_t __i) const
756 {
757 if (__i < __m_)
758 return __expr_[__i + __o1_];
759 return __expr_[__i + __o2_];
760 }
761
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000762 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000763 size_t size() const {return __size_;}
764
765 template <class> friend class __val_expr;
766};
767
768template<class _ValExpr>
769class __val_expr;
770
771template<class _ValExpr>
772struct __is_val_expr : false_type {};
773
774template<class _ValExpr>
775struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
776
777template<class _Tp>
778struct __is_val_expr<valarray<_Tp> > : true_type {};
779
780template<class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000781class _LIBCPP_VISIBLE valarray
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000782{
783public:
784 typedef _Tp value_type;
785 typedef _Tp result_type;
786
787private:
788 value_type* __begin_;
789 value_type* __end_;
790
791public:
792 // construct/destroy:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000793 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000794 valarray() : __begin_(0), __end_(0) {}
795 explicit valarray(size_t __n);
796 valarray(const value_type& __x, size_t __n);
797 valarray(const value_type* __p, size_t __n);
798 valarray(const valarray& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000799#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000800 valarray(valarray&& __v);
801 valarray(initializer_list<value_type> __il);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000802#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000803 valarray(const slice_array<value_type>& __sa);
804 valarray(const gslice_array<value_type>& __ga);
805 valarray(const mask_array<value_type>& __ma);
806 valarray(const indirect_array<value_type>& __ia);
807 ~valarray();
808
809 // assignment:
810 valarray& operator=(const valarray& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000811#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000812 valarray& operator=(valarray&& __v);
813 valarray& operator=(initializer_list<value_type>);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000814#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000815 valarray& operator=(const value_type& __x);
816 valarray& operator=(const slice_array<value_type>& __sa);
817 valarray& operator=(const gslice_array<value_type>& __ga);
818 valarray& operator=(const mask_array<value_type>& __ma);
819 valarray& operator=(const indirect_array<value_type>& __ia);
Howard Hinnantdb866632011-07-27 23:19:59 +0000820 template <class _ValExpr>
821 valarray& operator=(const __val_expr<_ValExpr>& __v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000822
823 // element access:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000824 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000825 const value_type& operator[](size_t __i) const {return __begin_[__i];}
826
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000828 value_type& operator[](size_t __i) {return __begin_[__i];}
829
830 // subset operations:
831 __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const;
832 slice_array<value_type> operator[](slice __s);
833 __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
834 gslice_array<value_type> operator[](const gslice& __gs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000835#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000836 __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
837 gslice_array<value_type> operator[](gslice&& __gs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000838#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000839 __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const;
840 mask_array<value_type> operator[](const valarray<bool>& __vb);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000841#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000842 __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const;
843 mask_array<value_type> operator[](valarray<bool>&& __vb);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000844#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000845 __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
846 indirect_array<value_type> operator[](const valarray<size_t>& __vs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000847#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000848 __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
849 indirect_array<value_type> operator[](valarray<size_t>&& __vs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000850#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000851
852 // unary operators:
853 valarray operator+() const;
854 valarray operator-() const;
855 valarray operator~() const;
856 valarray<bool> operator!() const;
857
858 // computed assignment:
859 valarray& operator*= (const value_type& __x);
860 valarray& operator/= (const value_type& __x);
861 valarray& operator%= (const value_type& __x);
862 valarray& operator+= (const value_type& __x);
863 valarray& operator-= (const value_type& __x);
864 valarray& operator^= (const value_type& __x);
865 valarray& operator&= (const value_type& __x);
866 valarray& operator|= (const value_type& __x);
867 valarray& operator<<=(const value_type& __x);
868 valarray& operator>>=(const value_type& __x);
869
870 template <class _Expr>
871 typename enable_if
872 <
873 __is_val_expr<_Expr>::value,
874 valarray&
875 >::type
876 operator*= (const _Expr& __v);
877
878 template <class _Expr>
879 typename enable_if
880 <
881 __is_val_expr<_Expr>::value,
882 valarray&
883 >::type
884 operator/= (const _Expr& __v);
885
886 template <class _Expr>
887 typename enable_if
888 <
889 __is_val_expr<_Expr>::value,
890 valarray&
891 >::type
892 operator%= (const _Expr& __v);
893
894 template <class _Expr>
895 typename enable_if
896 <
897 __is_val_expr<_Expr>::value,
898 valarray&
899 >::type
900 operator+= (const _Expr& __v);
901
902 template <class _Expr>
903 typename enable_if
904 <
905 __is_val_expr<_Expr>::value,
906 valarray&
907 >::type
908 operator-= (const _Expr& __v);
909
910 template <class _Expr>
911 typename enable_if
912 <
913 __is_val_expr<_Expr>::value,
914 valarray&
915 >::type
916 operator^= (const _Expr& __v);
917
918 template <class _Expr>
919 typename enable_if
920 <
921 __is_val_expr<_Expr>::value,
922 valarray&
923 >::type
924 operator|= (const _Expr& __v);
925
926 template <class _Expr>
927 typename enable_if
928 <
929 __is_val_expr<_Expr>::value,
930 valarray&
931 >::type
932 operator&= (const _Expr& __v);
933
934 template <class _Expr>
935 typename enable_if
936 <
937 __is_val_expr<_Expr>::value,
938 valarray&
939 >::type
940 operator<<= (const _Expr& __v);
941
942 template <class _Expr>
943 typename enable_if
944 <
945 __is_val_expr<_Expr>::value,
946 valarray&
947 >::type
948 operator>>= (const _Expr& __v);
949
950 // member functions:
951 void swap(valarray& __v);
952
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000954 size_t size() const {return __end_ - __begin_;}
955
956 value_type sum() const;
957 value_type min() const;
958 value_type max() const;
959
960 valarray shift (int __i) const;
961 valarray cshift(int __i) const;
962 valarray apply(value_type __f(value_type)) const;
963 valarray apply(value_type __f(const value_type&)) const;
964 void resize(size_t __n, value_type __x = value_type());
965
966private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000967 template <class> friend class _LIBCPP_VISIBLE valarray;
968 template <class> friend class _LIBCPP_VISIBLE slice_array;
969 template <class> friend class _LIBCPP_VISIBLE gslice_array;
970 template <class> friend class _LIBCPP_VISIBLE mask_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000971 template <class> friend class __mask_expr;
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000972 template <class> friend class _LIBCPP_VISIBLE indirect_array;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000973 template <class> friend class __indirect_expr;
974 template <class> friend class __val_expr;
975
976 template <class _Up>
977 friend
978 _Up*
979 begin(valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +0000980
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000981 template <class _Up>
982 friend
983 const _Up*
984 begin(const valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +0000985
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000986 template <class _Up>
987 friend
988 _Up*
989 end(valarray<_Up>& __v);
Howard Hinnant324bb032010-08-22 00:02:43 +0000990
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000991 template <class _Up>
992 friend
993 const _Up*
994 end(const valarray<_Up>& __v);
995};
996
997template <class _Op, class _Tp>
998struct _UnaryOp<_Op, valarray<_Tp> >
999{
1000 typedef typename _Op::result_type result_type;
1001 typedef _Tp value_type;
1002
1003 _Op __op_;
1004 const valarray<_Tp>& __a0_;
1005
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001007 _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
1008
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001009 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001010 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
1011
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001012 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001013 size_t size() const {return __a0_.size();}
1014};
1015
1016template <class _Op, class _Tp, class _A1>
1017struct _BinaryOp<_Op, valarray<_Tp>, _A1>
1018{
1019 typedef typename _Op::result_type result_type;
1020 typedef _Tp value_type;
1021
1022 _Op __op_;
1023 const valarray<_Tp>& __a0_;
1024 _A1 __a1_;
1025
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001026 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001027 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
1028 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1029
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001030 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001031 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1032
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001033 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001034 size_t size() const {return __a0_.size();}
1035};
1036
1037template <class _Op, class _A0, class _Tp>
1038struct _BinaryOp<_Op, _A0, valarray<_Tp> >
1039{
1040 typedef typename _Op::result_type result_type;
1041 typedef _Tp value_type;
1042
1043 _Op __op_;
1044 _A0 __a0_;
1045 const valarray<_Tp>& __a1_;
1046
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001047 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001048 _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
1049 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1050
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001051 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001052 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1053
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001054 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001055 size_t size() const {return __a0_.size();}
1056};
1057
1058template <class _Op, class _Tp>
1059struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> >
1060{
1061 typedef typename _Op::result_type result_type;
1062 typedef _Tp value_type;
1063
1064 _Op __op_;
1065 const valarray<_Tp>& __a0_;
1066 const valarray<_Tp>& __a1_;
1067
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001068 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001069 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
1070 : __op_(__op), __a0_(__a0), __a1_(__a1) {}
1071
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001072 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001073 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
1074
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001075 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001076 size_t size() const {return __a0_.size();}
1077};
1078
1079// slice_array
1080
1081template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001082class _LIBCPP_VISIBLE slice_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001083{
1084public:
1085 typedef _Tp value_type;
1086
1087private:
1088 value_type* __vp_;
1089 size_t __size_;
1090 size_t __stride_;
1091
1092public:
1093 template <class _Expr>
1094 typename enable_if
1095 <
1096 __is_val_expr<_Expr>::value,
1097 void
1098 >::type
1099 operator=(const _Expr& __v) const;
1100
1101 template <class _Expr>
1102 typename enable_if
1103 <
1104 __is_val_expr<_Expr>::value,
1105 void
1106 >::type
1107 operator*=(const _Expr& __v) const;
1108
1109 template <class _Expr>
1110 typename enable_if
1111 <
1112 __is_val_expr<_Expr>::value,
1113 void
1114 >::type
1115 operator/=(const _Expr& __v) const;
1116
1117 template <class _Expr>
1118 typename enable_if
1119 <
1120 __is_val_expr<_Expr>::value,
1121 void
1122 >::type
1123 operator%=(const _Expr& __v) const;
1124
1125 template <class _Expr>
1126 typename enable_if
1127 <
1128 __is_val_expr<_Expr>::value,
1129 void
1130 >::type
1131 operator+=(const _Expr& __v) const;
1132
1133 template <class _Expr>
1134 typename enable_if
1135 <
1136 __is_val_expr<_Expr>::value,
1137 void
1138 >::type
1139 operator-=(const _Expr& __v) const;
1140
1141 template <class _Expr>
1142 typename enable_if
1143 <
1144 __is_val_expr<_Expr>::value,
1145 void
1146 >::type
1147 operator^=(const _Expr& __v) const;
1148
1149 template <class _Expr>
1150 typename enable_if
1151 <
1152 __is_val_expr<_Expr>::value,
1153 void
1154 >::type
1155 operator&=(const _Expr& __v) const;
1156
1157 template <class _Expr>
1158 typename enable_if
1159 <
1160 __is_val_expr<_Expr>::value,
1161 void
1162 >::type
1163 operator|=(const _Expr& __v) const;
1164
1165 template <class _Expr>
1166 typename enable_if
1167 <
1168 __is_val_expr<_Expr>::value,
1169 void
1170 >::type
1171 operator<<=(const _Expr& __v) const;
1172
1173 template <class _Expr>
1174 typename enable_if
1175 <
1176 __is_val_expr<_Expr>::value,
1177 void
1178 >::type
1179 operator>>=(const _Expr& __v) const;
1180
1181 const slice_array& operator=(const slice_array& __sa) const;
1182
1183 void operator=(const value_type& __x) const;
1184
1185private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001186 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001187 slice_array(const slice& __sl, const valarray<value_type>& __v)
1188 : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())),
1189 __size_(__sl.size()),
1190 __stride_(__sl.stride())
1191 {}
1192
1193 template <class> friend class valarray;
1194 template <class> friend class sliceExpr;
1195};
1196
1197template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001198inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001199const slice_array<_Tp>&
1200slice_array<_Tp>::operator=(const slice_array& __sa) const
1201{
1202 value_type* __t = __vp_;
1203 const value_type* __s = __sa.__vp_;
1204 for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
1205 *__t = *__s;
1206}
1207
1208template <class _Tp>
1209template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001210inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001211typename enable_if
1212<
1213 __is_val_expr<_Expr>::value,
1214 void
1215>::type
1216slice_array<_Tp>::operator=(const _Expr& __v) const
1217{
1218 value_type* __t = __vp_;
1219 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1220 *__t = __v[__i];
1221}
1222
1223template <class _Tp>
1224template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001225inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001226typename enable_if
1227<
1228 __is_val_expr<_Expr>::value,
1229 void
1230>::type
1231slice_array<_Tp>::operator*=(const _Expr& __v) const
1232{
1233 value_type* __t = __vp_;
1234 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1235 *__t *= __v[__i];
1236}
1237
1238template <class _Tp>
1239template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001240inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001241typename enable_if
1242<
1243 __is_val_expr<_Expr>::value,
1244 void
1245>::type
1246slice_array<_Tp>::operator/=(const _Expr& __v) const
1247{
1248 value_type* __t = __vp_;
1249 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1250 *__t /= __v[__i];
1251}
1252
1253template <class _Tp>
1254template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001255inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001256typename enable_if
1257<
1258 __is_val_expr<_Expr>::value,
1259 void
1260>::type
1261slice_array<_Tp>::operator%=(const _Expr& __v) const
1262{
1263 value_type* __t = __vp_;
1264 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1265 *__t %= __v[__i];
1266}
1267
1268template <class _Tp>
1269template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001270inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001271typename enable_if
1272<
1273 __is_val_expr<_Expr>::value,
1274 void
1275>::type
1276slice_array<_Tp>::operator+=(const _Expr& __v) const
1277{
1278 value_type* __t = __vp_;
1279 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1280 *__t += __v[__i];
1281}
1282
1283template <class _Tp>
1284template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001285inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001286typename enable_if
1287<
1288 __is_val_expr<_Expr>::value,
1289 void
1290>::type
1291slice_array<_Tp>::operator-=(const _Expr& __v) const
1292{
1293 value_type* __t = __vp_;
1294 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1295 *__t -= __v[__i];
1296}
1297
1298template <class _Tp>
1299template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001300inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001301typename enable_if
1302<
1303 __is_val_expr<_Expr>::value,
1304 void
1305>::type
1306slice_array<_Tp>::operator^=(const _Expr& __v) const
1307{
1308 value_type* __t = __vp_;
1309 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1310 *__t ^= __v[__i];
1311}
1312
1313template <class _Tp>
1314template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001315inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001316typename enable_if
1317<
1318 __is_val_expr<_Expr>::value,
1319 void
1320>::type
1321slice_array<_Tp>::operator&=(const _Expr& __v) const
1322{
1323 value_type* __t = __vp_;
1324 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1325 *__t &= __v[__i];
1326}
1327
1328template <class _Tp>
1329template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001330inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001331typename enable_if
1332<
1333 __is_val_expr<_Expr>::value,
1334 void
1335>::type
1336slice_array<_Tp>::operator|=(const _Expr& __v) const
1337{
1338 value_type* __t = __vp_;
1339 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1340 *__t |= __v[__i];
1341}
1342
1343template <class _Tp>
1344template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001345inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001346typename enable_if
1347<
1348 __is_val_expr<_Expr>::value,
1349 void
1350>::type
1351slice_array<_Tp>::operator<<=(const _Expr& __v) const
1352{
1353 value_type* __t = __vp_;
1354 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1355 *__t <<= __v[__i];
1356}
1357
1358template <class _Tp>
1359template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001360inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001361typename enable_if
1362<
1363 __is_val_expr<_Expr>::value,
1364 void
1365>::type
1366slice_array<_Tp>::operator>>=(const _Expr& __v) const
1367{
1368 value_type* __t = __vp_;
1369 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
1370 *__t >>= __v[__i];
1371}
1372
1373template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001374inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001375void
1376slice_array<_Tp>::operator=(const value_type& __x) const
1377{
1378 value_type* __t = __vp_;
1379 for (size_t __n = __size_; __n; --__n, __t += __stride_)
1380 *__t = __x;
1381}
1382
1383// gslice
1384
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001385class _LIBCPP_VISIBLE gslice
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001386{
1387 valarray<size_t> __size_;
1388 valarray<size_t> __stride_;
1389 valarray<size_t> __1d_;
Howard Hinnant324bb032010-08-22 00:02:43 +00001390
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001391public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001392 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001393 gslice() {}
1394
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001395 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001396 gslice(size_t __start, const valarray<size_t>& __size,
1397 const valarray<size_t>& __stride)
1398 : __size_(__size),
1399 __stride_(__stride)
1400 {__init(__start);}
1401
Howard Hinnant73d21a42010-09-04 23:28:19 +00001402#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001403
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001404 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001405 gslice(size_t __start, const valarray<size_t>& __size,
1406 valarray<size_t>&& __stride)
1407 : __size_(__size),
1408 __stride_(move(__stride))
1409 {__init(__start);}
1410
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001411 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001412 gslice(size_t __start, valarray<size_t>&& __size,
1413 const valarray<size_t>& __stride)
1414 : __size_(move(__size)),
1415 __stride_(__stride)
1416 {__init(__start);}
1417
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001418 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001419 gslice(size_t __start, valarray<size_t>&& __size,
1420 valarray<size_t>&& __stride)
1421 : __size_(move(__size)),
1422 __stride_(move(__stride))
1423 {__init(__start);}
1424
Howard Hinnant73d21a42010-09-04 23:28:19 +00001425#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001426
1427// gslice(const gslice&) = default;
1428// gslice(gslice&&) = default;
1429// gslice& operator=(const gslice&) = default;
1430// gslice& operator=(gslice&&) = default;
1431
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001432 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001433 size_t start() const {return __1d_.size() ? __1d_[0] : 0;}
1434
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001435 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001436 valarray<size_t> size() const {return __size_;}
1437
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001438 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001439 valarray<size_t> stride() const {return __stride_;}
1440
1441private:
1442 void __init(size_t __start);
1443
1444 template <class> friend class gslice_array;
1445 template <class> friend class valarray;
1446 template <class> friend class __val_expr;
1447};
1448
1449// gslice_array
1450
1451template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001452class _LIBCPP_VISIBLE gslice_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001453{
1454public:
1455 typedef _Tp value_type;
1456
1457private:
1458 value_type* __vp_;
1459 valarray<size_t> __1d_;
1460
1461public:
1462 template <class _Expr>
1463 typename enable_if
1464 <
1465 __is_val_expr<_Expr>::value,
1466 void
1467 >::type
1468 operator=(const _Expr& __v) const;
1469
1470 template <class _Expr>
1471 typename enable_if
1472 <
1473 __is_val_expr<_Expr>::value,
1474 void
1475 >::type
1476 operator*=(const _Expr& __v) const;
1477
1478 template <class _Expr>
1479 typename enable_if
1480 <
1481 __is_val_expr<_Expr>::value,
1482 void
1483 >::type
1484 operator/=(const _Expr& __v) const;
1485
1486 template <class _Expr>
1487 typename enable_if
1488 <
1489 __is_val_expr<_Expr>::value,
1490 void
1491 >::type
1492 operator%=(const _Expr& __v) const;
1493
1494 template <class _Expr>
1495 typename enable_if
1496 <
1497 __is_val_expr<_Expr>::value,
1498 void
1499 >::type
1500 operator+=(const _Expr& __v) const;
1501
1502 template <class _Expr>
1503 typename enable_if
1504 <
1505 __is_val_expr<_Expr>::value,
1506 void
1507 >::type
1508 operator-=(const _Expr& __v) const;
1509
1510 template <class _Expr>
1511 typename enable_if
1512 <
1513 __is_val_expr<_Expr>::value,
1514 void
1515 >::type
1516 operator^=(const _Expr& __v) const;
1517
1518 template <class _Expr>
1519 typename enable_if
1520 <
1521 __is_val_expr<_Expr>::value,
1522 void
1523 >::type
1524 operator&=(const _Expr& __v) const;
1525
1526 template <class _Expr>
1527 typename enable_if
1528 <
1529 __is_val_expr<_Expr>::value,
1530 void
1531 >::type
1532 operator|=(const _Expr& __v) const;
1533
1534 template <class _Expr>
1535 typename enable_if
1536 <
1537 __is_val_expr<_Expr>::value,
1538 void
1539 >::type
1540 operator<<=(const _Expr& __v) const;
1541
1542 template <class _Expr>
1543 typename enable_if
1544 <
1545 __is_val_expr<_Expr>::value,
1546 void
1547 >::type
1548 operator>>=(const _Expr& __v) const;
1549
1550 const gslice_array& operator=(const gslice_array& __ga) const;
1551
1552 void operator=(const value_type& __x) const;
1553
1554// gslice_array(const gslice_array&) = default;
1555// gslice_array(gslice_array&&) = default;
1556// gslice_array& operator=(const gslice_array&) = default;
1557// gslice_array& operator=(gslice_array&&) = default;
1558
1559private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001561 gslice_array(const gslice& __gs, const valarray<value_type>& __v)
1562 : __vp_(const_cast<value_type*>(__v.__begin_)),
1563 __1d_(__gs.__1d_)
1564 {}
1565
Howard Hinnant73d21a42010-09-04 23:28:19 +00001566#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001567
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001569 gslice_array(gslice&& __gs, const valarray<value_type>& __v)
1570 : __vp_(const_cast<value_type*>(__v.__begin_)),
1571 __1d_(move(__gs.__1d_))
1572 {}
1573
Howard Hinnant73d21a42010-09-04 23:28:19 +00001574#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001575
1576 template <class> friend class valarray;
1577};
1578
1579template <class _Tp>
1580template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001581inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001582typename enable_if
1583<
1584 __is_val_expr<_Expr>::value,
1585 void
1586>::type
1587gslice_array<_Tp>::operator=(const _Expr& __v) const
1588{
1589 typedef const size_t* _Ip;
1590 size_t __j = 0;
1591 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1592 __vp_[*__i] = __v[__j];
1593}
1594
1595template <class _Tp>
1596template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001597inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001598typename enable_if
1599<
1600 __is_val_expr<_Expr>::value,
1601 void
1602>::type
1603gslice_array<_Tp>::operator*=(const _Expr& __v) const
1604{
1605 typedef const size_t* _Ip;
1606 size_t __j = 0;
1607 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1608 __vp_[*__i] *= __v[__j];
1609}
1610
1611template <class _Tp>
1612template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001613inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001614typename enable_if
1615<
1616 __is_val_expr<_Expr>::value,
1617 void
1618>::type
1619gslice_array<_Tp>::operator/=(const _Expr& __v) const
1620{
1621 typedef const size_t* _Ip;
1622 size_t __j = 0;
1623 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1624 __vp_[*__i] /= __v[__j];
1625}
1626
1627template <class _Tp>
1628template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001629inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001630typename enable_if
1631<
1632 __is_val_expr<_Expr>::value,
1633 void
1634>::type
1635gslice_array<_Tp>::operator%=(const _Expr& __v) const
1636{
1637 typedef const size_t* _Ip;
1638 size_t __j = 0;
1639 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1640 __vp_[*__i] %= __v[__j];
1641}
1642
1643template <class _Tp>
1644template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001645inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001646typename enable_if
1647<
1648 __is_val_expr<_Expr>::value,
1649 void
1650>::type
1651gslice_array<_Tp>::operator+=(const _Expr& __v) const
1652{
1653 typedef const size_t* _Ip;
1654 size_t __j = 0;
1655 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1656 __vp_[*__i] += __v[__j];
1657}
1658
1659template <class _Tp>
1660template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001661inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001662typename enable_if
1663<
1664 __is_val_expr<_Expr>::value,
1665 void
1666>::type
1667gslice_array<_Tp>::operator-=(const _Expr& __v) const
1668{
1669 typedef const size_t* _Ip;
1670 size_t __j = 0;
1671 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1672 __vp_[*__i] -= __v[__j];
1673}
1674
1675template <class _Tp>
1676template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001677inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001678typename enable_if
1679<
1680 __is_val_expr<_Expr>::value,
1681 void
1682>::type
1683gslice_array<_Tp>::operator^=(const _Expr& __v) const
1684{
1685 typedef const size_t* _Ip;
1686 size_t __j = 0;
1687 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1688 __vp_[*__i] ^= __v[__j];
1689}
1690
1691template <class _Tp>
1692template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001693inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001694typename enable_if
1695<
1696 __is_val_expr<_Expr>::value,
1697 void
1698>::type
1699gslice_array<_Tp>::operator&=(const _Expr& __v) const
1700{
1701 typedef const size_t* _Ip;
1702 size_t __j = 0;
1703 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1704 __vp_[*__i] &= __v[__j];
1705}
1706
1707template <class _Tp>
1708template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001709inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001710typename enable_if
1711<
1712 __is_val_expr<_Expr>::value,
1713 void
1714>::type
1715gslice_array<_Tp>::operator|=(const _Expr& __v) const
1716{
1717 typedef const size_t* _Ip;
1718 size_t __j = 0;
1719 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1720 __vp_[*__i] |= __v[__j];
1721}
1722
1723template <class _Tp>
1724template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001725inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001726typename enable_if
1727<
1728 __is_val_expr<_Expr>::value,
1729 void
1730>::type
1731gslice_array<_Tp>::operator<<=(const _Expr& __v) const
1732{
1733 typedef const size_t* _Ip;
1734 size_t __j = 0;
1735 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1736 __vp_[*__i] <<= __v[__j];
1737}
1738
1739template <class _Tp>
1740template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001741inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001742typename enable_if
1743<
1744 __is_val_expr<_Expr>::value,
1745 void
1746>::type
1747gslice_array<_Tp>::operator>>=(const _Expr& __v) const
1748{
1749 typedef const size_t* _Ip;
1750 size_t __j = 0;
1751 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
1752 __vp_[*__i] >>= __v[__j];
1753}
1754
1755template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001756inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001757const gslice_array<_Tp>&
1758gslice_array<_Tp>::operator=(const gslice_array& __ga) const
1759{
1760 typedef const size_t* _Ip;
1761 const value_type* __s = __ga.__vp_;
1762 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_;
1763 __i != __e; ++__i, ++__j)
1764 __vp_[*__i] = __s[*__j];
1765 return *this;
1766}
1767
1768template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001769inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001770void
1771gslice_array<_Tp>::operator=(const value_type& __x) const
1772{
1773 typedef const size_t* _Ip;
1774 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
1775 __vp_[*__i] = __x;
1776}
1777
1778// mask_array
1779
1780template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001781class _LIBCPP_VISIBLE mask_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001782{
1783public:
1784 typedef _Tp value_type;
1785
1786private:
1787 value_type* __vp_;
1788 valarray<size_t> __1d_;
1789
1790public:
1791 template <class _Expr>
1792 typename enable_if
1793 <
1794 __is_val_expr<_Expr>::value,
1795 void
1796 >::type
1797 operator=(const _Expr& __v) const;
1798
1799 template <class _Expr>
1800 typename enable_if
1801 <
1802 __is_val_expr<_Expr>::value,
1803 void
1804 >::type
1805 operator*=(const _Expr& __v) const;
1806
1807 template <class _Expr>
1808 typename enable_if
1809 <
1810 __is_val_expr<_Expr>::value,
1811 void
1812 >::type
1813 operator/=(const _Expr& __v) const;
1814
1815 template <class _Expr>
1816 typename enable_if
1817 <
1818 __is_val_expr<_Expr>::value,
1819 void
1820 >::type
1821 operator%=(const _Expr& __v) const;
1822
1823 template <class _Expr>
1824 typename enable_if
1825 <
1826 __is_val_expr<_Expr>::value,
1827 void
1828 >::type
1829 operator+=(const _Expr& __v) const;
1830
1831 template <class _Expr>
1832 typename enable_if
1833 <
1834 __is_val_expr<_Expr>::value,
1835 void
1836 >::type
1837 operator-=(const _Expr& __v) const;
1838
1839 template <class _Expr>
1840 typename enable_if
1841 <
1842 __is_val_expr<_Expr>::value,
1843 void
1844 >::type
1845 operator^=(const _Expr& __v) const;
1846
1847 template <class _Expr>
1848 typename enable_if
1849 <
1850 __is_val_expr<_Expr>::value,
1851 void
1852 >::type
1853 operator&=(const _Expr& __v) const;
1854
1855 template <class _Expr>
1856 typename enable_if
1857 <
1858 __is_val_expr<_Expr>::value,
1859 void
1860 >::type
1861 operator|=(const _Expr& __v) const;
1862
1863 template <class _Expr>
1864 typename enable_if
1865 <
1866 __is_val_expr<_Expr>::value,
1867 void
1868 >::type
1869 operator<<=(const _Expr& __v) const;
1870
1871 template <class _Expr>
1872 typename enable_if
1873 <
1874 __is_val_expr<_Expr>::value,
1875 void
1876 >::type
1877 operator>>=(const _Expr& __v) const;
1878
1879 const mask_array& operator=(const mask_array& __ma) const;
1880
1881 void operator=(const value_type& __x) const;
1882
1883// mask_array(const mask_array&) = default;
1884// mask_array(mask_array&&) = default;
1885// mask_array& operator=(const mask_array&) = default;
1886// mask_array& operator=(mask_array&&) = default;
1887
1888private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001889 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001890 mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
1891 : __vp_(const_cast<value_type*>(__v.__begin_)),
1892 __1d_(count(__vb.__begin_, __vb.__end_, true))
1893 {
1894 size_t __j = 0;
1895 for (size_t __i = 0; __i < __vb.size(); ++__i)
1896 if (__vb[__i])
1897 __1d_[__j++] = __i;
1898 }
1899
1900 template <class> friend class valarray;
1901};
1902
1903template <class _Tp>
1904template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001905inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001906typename enable_if
1907<
1908 __is_val_expr<_Expr>::value,
1909 void
1910>::type
1911mask_array<_Tp>::operator=(const _Expr& __v) const
1912{
1913 size_t __n = __1d_.size();
1914 for (size_t __i = 0; __i < __n; ++__i)
1915 __vp_[__1d_[__i]] = __v[__i];
1916}
1917
1918template <class _Tp>
1919template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001920inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001921typename enable_if
1922<
1923 __is_val_expr<_Expr>::value,
1924 void
1925>::type
1926mask_array<_Tp>::operator*=(const _Expr& __v) const
1927{
1928 size_t __n = __1d_.size();
1929 for (size_t __i = 0; __i < __n; ++__i)
1930 __vp_[__1d_[__i]] *= __v[__i];
1931}
1932
1933template <class _Tp>
1934template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001935inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001936typename enable_if
1937<
1938 __is_val_expr<_Expr>::value,
1939 void
1940>::type
1941mask_array<_Tp>::operator/=(const _Expr& __v) const
1942{
1943 size_t __n = __1d_.size();
1944 for (size_t __i = 0; __i < __n; ++__i)
1945 __vp_[__1d_[__i]] /= __v[__i];
1946}
1947
1948template <class _Tp>
1949template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001950inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001951typename enable_if
1952<
1953 __is_val_expr<_Expr>::value,
1954 void
1955>::type
1956mask_array<_Tp>::operator%=(const _Expr& __v) const
1957{
1958 size_t __n = __1d_.size();
1959 for (size_t __i = 0; __i < __n; ++__i)
1960 __vp_[__1d_[__i]] %= __v[__i];
1961}
1962
1963template <class _Tp>
1964template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001965inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001966typename enable_if
1967<
1968 __is_val_expr<_Expr>::value,
1969 void
1970>::type
1971mask_array<_Tp>::operator+=(const _Expr& __v) const
1972{
1973 size_t __n = __1d_.size();
1974 for (size_t __i = 0; __i < __n; ++__i)
1975 __vp_[__1d_[__i]] += __v[__i];
1976}
1977
1978template <class _Tp>
1979template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001980inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001981typename enable_if
1982<
1983 __is_val_expr<_Expr>::value,
1984 void
1985>::type
1986mask_array<_Tp>::operator-=(const _Expr& __v) const
1987{
1988 size_t __n = __1d_.size();
1989 for (size_t __i = 0; __i < __n; ++__i)
1990 __vp_[__1d_[__i]] -= __v[__i];
1991}
1992
1993template <class _Tp>
1994template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001995inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001996typename enable_if
1997<
1998 __is_val_expr<_Expr>::value,
1999 void
2000>::type
2001mask_array<_Tp>::operator^=(const _Expr& __v) const
2002{
2003 size_t __n = __1d_.size();
2004 for (size_t __i = 0; __i < __n; ++__i)
2005 __vp_[__1d_[__i]] ^= __v[__i];
2006}
2007
2008template <class _Tp>
2009template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002010inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002011typename enable_if
2012<
2013 __is_val_expr<_Expr>::value,
2014 void
2015>::type
2016mask_array<_Tp>::operator&=(const _Expr& __v) const
2017{
2018 size_t __n = __1d_.size();
2019 for (size_t __i = 0; __i < __n; ++__i)
2020 __vp_[__1d_[__i]] &= __v[__i];
2021}
2022
2023template <class _Tp>
2024template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002025inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002026typename enable_if
2027<
2028 __is_val_expr<_Expr>::value,
2029 void
2030>::type
2031mask_array<_Tp>::operator|=(const _Expr& __v) const
2032{
2033 size_t __n = __1d_.size();
2034 for (size_t __i = 0; __i < __n; ++__i)
2035 __vp_[__1d_[__i]] |= __v[__i];
2036}
2037
2038template <class _Tp>
2039template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002040inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002041typename enable_if
2042<
2043 __is_val_expr<_Expr>::value,
2044 void
2045>::type
2046mask_array<_Tp>::operator<<=(const _Expr& __v) const
2047{
2048 size_t __n = __1d_.size();
2049 for (size_t __i = 0; __i < __n; ++__i)
2050 __vp_[__1d_[__i]] <<= __v[__i];
2051}
2052
2053template <class _Tp>
2054template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002055inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002056typename enable_if
2057<
2058 __is_val_expr<_Expr>::value,
2059 void
2060>::type
2061mask_array<_Tp>::operator>>=(const _Expr& __v) const
2062{
2063 size_t __n = __1d_.size();
2064 for (size_t __i = 0; __i < __n; ++__i)
2065 __vp_[__1d_[__i]] >>= __v[__i];
2066}
2067
2068template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002069inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002070const mask_array<_Tp>&
2071mask_array<_Tp>::operator=(const mask_array& __ma) const
2072{
2073 size_t __n = __1d_.size();
2074 for (size_t __i = 0; __i < __n; ++__i)
2075 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
2076}
2077
2078template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002079inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002080void
2081mask_array<_Tp>::operator=(const value_type& __x) const
2082{
2083 size_t __n = __1d_.size();
2084 for (size_t __i = 0; __i < __n; ++__i)
2085 __vp_[__1d_[__i]] = __x;
2086}
2087
2088template <class _ValExpr>
2089class __mask_expr
2090{
2091 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2092public:
2093 typedef typename _RmExpr::value_type value_type;
2094 typedef value_type result_type;
2095
2096private:
2097 _ValExpr __expr_;
2098 valarray<size_t> __1d_;
2099
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002101 __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
2102 : __expr_(__e),
2103 __1d_(count(__vb.__begin_, __vb.__end_, true))
2104 {
2105 size_t __j = 0;
2106 for (size_t __i = 0; __i < __vb.size(); ++__i)
2107 if (__vb[__i])
2108 __1d_[__j++] = __i;
2109 }
2110
2111public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002112 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002113 result_type operator[](size_t __i) const
2114 {return __expr_[__1d_[__i]];}
2115
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002116 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002117 size_t size() const {return __1d_.size();}
2118
2119 template <class> friend class valarray;
2120};
2121
2122// indirect_array
2123
2124template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002125class _LIBCPP_VISIBLE indirect_array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002126{
2127public:
2128 typedef _Tp value_type;
2129
2130private:
2131 value_type* __vp_;
2132 valarray<size_t> __1d_;
2133
2134public:
2135 template <class _Expr>
2136 typename enable_if
2137 <
2138 __is_val_expr<_Expr>::value,
2139 void
2140 >::type
2141 operator=(const _Expr& __v) const;
2142
2143 template <class _Expr>
2144 typename enable_if
2145 <
2146 __is_val_expr<_Expr>::value,
2147 void
2148 >::type
2149 operator*=(const _Expr& __v) const;
2150
2151 template <class _Expr>
2152 typename enable_if
2153 <
2154 __is_val_expr<_Expr>::value,
2155 void
2156 >::type
2157 operator/=(const _Expr& __v) const;
2158
2159 template <class _Expr>
2160 typename enable_if
2161 <
2162 __is_val_expr<_Expr>::value,
2163 void
2164 >::type
2165 operator%=(const _Expr& __v) const;
2166
2167 template <class _Expr>
2168 typename enable_if
2169 <
2170 __is_val_expr<_Expr>::value,
2171 void
2172 >::type
2173 operator+=(const _Expr& __v) const;
2174
2175 template <class _Expr>
2176 typename enable_if
2177 <
2178 __is_val_expr<_Expr>::value,
2179 void
2180 >::type
2181 operator-=(const _Expr& __v) const;
2182
2183 template <class _Expr>
2184 typename enable_if
2185 <
2186 __is_val_expr<_Expr>::value,
2187 void
2188 >::type
2189 operator^=(const _Expr& __v) const;
2190
2191 template <class _Expr>
2192 typename enable_if
2193 <
2194 __is_val_expr<_Expr>::value,
2195 void
2196 >::type
2197 operator&=(const _Expr& __v) const;
2198
2199 template <class _Expr>
2200 typename enable_if
2201 <
2202 __is_val_expr<_Expr>::value,
2203 void
2204 >::type
2205 operator|=(const _Expr& __v) const;
2206
2207 template <class _Expr>
2208 typename enable_if
2209 <
2210 __is_val_expr<_Expr>::value,
2211 void
2212 >::type
2213 operator<<=(const _Expr& __v) const;
2214
2215 template <class _Expr>
2216 typename enable_if
2217 <
2218 __is_val_expr<_Expr>::value,
2219 void
2220 >::type
2221 operator>>=(const _Expr& __v) const;
2222
2223 const indirect_array& operator=(const indirect_array& __ia) const;
2224
2225 void operator=(const value_type& __x) const;
2226
2227// indirect_array(const indirect_array&) = default;
2228// indirect_array(indirect_array&&) = default;
2229// indirect_array& operator=(const indirect_array&) = default;
2230// indirect_array& operator=(indirect_array&&) = default;
2231
2232private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002233 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002234 indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
2235 : __vp_(const_cast<value_type*>(__v.__begin_)),
2236 __1d_(__ia)
2237 {}
2238
Howard Hinnant73d21a42010-09-04 23:28:19 +00002239#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002240
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002241 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002242 indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
2243 : __vp_(const_cast<value_type*>(__v.__begin_)),
2244 __1d_(move(__ia))
2245 {}
2246
Howard Hinnant73d21a42010-09-04 23:28:19 +00002247#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002248
2249 template <class> friend class valarray;
2250};
2251
2252template <class _Tp>
2253template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002254inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002255typename enable_if
2256<
2257 __is_val_expr<_Expr>::value,
2258 void
2259>::type
2260indirect_array<_Tp>::operator=(const _Expr& __v) const
2261{
2262 size_t __n = __1d_.size();
2263 for (size_t __i = 0; __i < __n; ++__i)
2264 __vp_[__1d_[__i]] = __v[__i];
2265}
2266
2267template <class _Tp>
2268template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002269inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002270typename enable_if
2271<
2272 __is_val_expr<_Expr>::value,
2273 void
2274>::type
2275indirect_array<_Tp>::operator*=(const _Expr& __v) const
2276{
2277 size_t __n = __1d_.size();
2278 for (size_t __i = 0; __i < __n; ++__i)
2279 __vp_[__1d_[__i]] *= __v[__i];
2280}
2281
2282template <class _Tp>
2283template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002284inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002285typename enable_if
2286<
2287 __is_val_expr<_Expr>::value,
2288 void
2289>::type
2290indirect_array<_Tp>::operator/=(const _Expr& __v) const
2291{
2292 size_t __n = __1d_.size();
2293 for (size_t __i = 0; __i < __n; ++__i)
2294 __vp_[__1d_[__i]] /= __v[__i];
2295}
2296
2297template <class _Tp>
2298template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002299inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002300typename enable_if
2301<
2302 __is_val_expr<_Expr>::value,
2303 void
2304>::type
2305indirect_array<_Tp>::operator%=(const _Expr& __v) const
2306{
2307 size_t __n = __1d_.size();
2308 for (size_t __i = 0; __i < __n; ++__i)
2309 __vp_[__1d_[__i]] %= __v[__i];
2310}
2311
2312template <class _Tp>
2313template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002314inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002315typename enable_if
2316<
2317 __is_val_expr<_Expr>::value,
2318 void
2319>::type
2320indirect_array<_Tp>::operator+=(const _Expr& __v) const
2321{
2322 size_t __n = __1d_.size();
2323 for (size_t __i = 0; __i < __n; ++__i)
2324 __vp_[__1d_[__i]] += __v[__i];
2325}
2326
2327template <class _Tp>
2328template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002329inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002330typename enable_if
2331<
2332 __is_val_expr<_Expr>::value,
2333 void
2334>::type
2335indirect_array<_Tp>::operator-=(const _Expr& __v) const
2336{
2337 size_t __n = __1d_.size();
2338 for (size_t __i = 0; __i < __n; ++__i)
2339 __vp_[__1d_[__i]] -= __v[__i];
2340}
2341
2342template <class _Tp>
2343template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002344inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002345typename enable_if
2346<
2347 __is_val_expr<_Expr>::value,
2348 void
2349>::type
2350indirect_array<_Tp>::operator^=(const _Expr& __v) const
2351{
2352 size_t __n = __1d_.size();
2353 for (size_t __i = 0; __i < __n; ++__i)
2354 __vp_[__1d_[__i]] ^= __v[__i];
2355}
2356
2357template <class _Tp>
2358template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002359inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002360typename enable_if
2361<
2362 __is_val_expr<_Expr>::value,
2363 void
2364>::type
2365indirect_array<_Tp>::operator&=(const _Expr& __v) const
2366{
2367 size_t __n = __1d_.size();
2368 for (size_t __i = 0; __i < __n; ++__i)
2369 __vp_[__1d_[__i]] &= __v[__i];
2370}
2371
2372template <class _Tp>
2373template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002374inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002375typename enable_if
2376<
2377 __is_val_expr<_Expr>::value,
2378 void
2379>::type
2380indirect_array<_Tp>::operator|=(const _Expr& __v) const
2381{
2382 size_t __n = __1d_.size();
2383 for (size_t __i = 0; __i < __n; ++__i)
2384 __vp_[__1d_[__i]] |= __v[__i];
2385}
2386
2387template <class _Tp>
2388template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002389inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002390typename enable_if
2391<
2392 __is_val_expr<_Expr>::value,
2393 void
2394>::type
2395indirect_array<_Tp>::operator<<=(const _Expr& __v) const
2396{
2397 size_t __n = __1d_.size();
2398 for (size_t __i = 0; __i < __n; ++__i)
2399 __vp_[__1d_[__i]] <<= __v[__i];
2400}
2401
2402template <class _Tp>
2403template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002404inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002405typename enable_if
2406<
2407 __is_val_expr<_Expr>::value,
2408 void
2409>::type
2410indirect_array<_Tp>::operator>>=(const _Expr& __v) const
2411{
2412 size_t __n = __1d_.size();
2413 for (size_t __i = 0; __i < __n; ++__i)
2414 __vp_[__1d_[__i]] >>= __v[__i];
2415}
2416
2417template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002418inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002419const indirect_array<_Tp>&
2420indirect_array<_Tp>::operator=(const indirect_array& __ia) const
2421{
2422 typedef const size_t* _Ip;
2423 const value_type* __s = __ia.__vp_;
2424 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_;
2425 __i != __e; ++__i, ++__j)
2426 __vp_[*__i] = __s[*__j];
2427 return *this;
2428}
2429
2430template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002431inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002432void
2433indirect_array<_Tp>::operator=(const value_type& __x) const
2434{
2435 typedef const size_t* _Ip;
2436 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
2437 __vp_[*__i] = __x;
2438}
2439
2440template <class _ValExpr>
2441class __indirect_expr
2442{
2443 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2444public:
2445 typedef typename _RmExpr::value_type value_type;
2446 typedef value_type result_type;
2447
2448private:
2449 _ValExpr __expr_;
2450 valarray<size_t> __1d_;
2451
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002452 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002453 __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e)
2454 : __expr_(__e),
2455 __1d_(__ia)
2456 {}
2457
Howard Hinnant73d21a42010-09-04 23:28:19 +00002458#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002459
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002460 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002461 __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
2462 : __expr_(__e),
2463 __1d_(move(__ia))
2464 {}
2465
Howard Hinnant73d21a42010-09-04 23:28:19 +00002466#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002467
2468public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002470 result_type operator[](size_t __i) const
2471 {return __expr_[__1d_[__i]];}
2472
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002474 size_t size() const {return __1d_.size();}
2475
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002476 template <class> friend class _LIBCPP_VISIBLE valarray;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002477};
2478
2479template<class _ValExpr>
2480class __val_expr
2481{
2482 typedef typename remove_reference<_ValExpr>::type _RmExpr;
2483
2484 _ValExpr __expr_;
2485public:
2486 typedef typename _RmExpr::value_type value_type;
2487 typedef typename _RmExpr::result_type result_type;
2488
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002489 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002490 explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
2491
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002493 result_type operator[](size_t __i) const
2494 {return __expr_[__i];}
2495
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002496 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002497 __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
2498 {return __val_expr<__slice_expr<_ValExpr> >(__expr_, __s);}
2499
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002501 __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const
2502 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __gs.__1d_);}
2503
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002504 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002505 __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
2506 {return __val_expr<__mask_expr<_ValExpr> >(__expr_, __vb);}
2507
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002509 __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
2510 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __vs);}
2511
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002513 __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
2514 operator+() const
2515 {
2516 typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
2517 return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
2518 }
2519
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002521 __val_expr<_UnaryOp<negate<value_type>, _ValExpr> >
2522 operator-() const
2523 {
2524 typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
2525 return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
2526 }
2527
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002529 __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> >
2530 operator~() const
2531 {
2532 typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
2533 return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
2534 }
2535
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002537 __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> >
2538 operator!() const
2539 {
2540 typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
2541 return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
2542 }
2543
2544 operator valarray<result_type>() const;
2545
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002546 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002547 size_t size() const {return __expr_.size();}
2548
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002550 result_type sum() const
2551 {
2552 size_t __n = __expr_.size();
2553 result_type __r = __n ? __expr_[0] : result_type();
2554 for (size_t __i = 1; __i < __n; ++__i)
2555 __r += __expr_[__i];
2556 return __r;
2557 }
2558
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002560 result_type min() const
2561 {
2562 size_t __n = size();
2563 result_type __r = __n ? (*this)[0] : result_type();
2564 for (size_t __i = 1; __i < __n; ++__i)
2565 {
2566 result_type __x = __expr_[__i];
2567 if (__x < __r)
2568 __r = __x;
2569 }
2570 return __r;
2571 }
2572
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002573 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002574 result_type max() const
2575 {
2576 size_t __n = size();
2577 result_type __r = __n ? (*this)[0] : result_type();
2578 for (size_t __i = 1; __i < __n; ++__i)
2579 {
2580 result_type __x = __expr_[__i];
2581 if (__r < __x)
2582 __r = __x;
2583 }
2584 return __r;
2585 }
2586
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002588 __val_expr<__shift_expr<_ValExpr> > shift (int __i) const
2589 {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));}
2590
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002592 __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const
2593 {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));}
2594
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002596 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> >
2597 apply(value_type __f(value_type)) const
2598 {
2599 typedef __apply_expr<value_type, value_type(*)(value_type)> _Op;
2600 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2601 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2602 }
2603
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002605 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> >
2606 apply(value_type __f(const value_type&)) const
2607 {
2608 typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op;
2609 typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
2610 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
2611 }
2612};
2613
2614template<class _ValExpr>
2615__val_expr<_ValExpr>::operator valarray<result_type>() const
2616{
2617 valarray<result_type> __r;
2618 size_t __n = __expr_.size();
2619 if (__n)
2620 {
2621 __r.__begin_ =
2622 __r.__end_ =
2623 static_cast<result_type*>(::operator new(__n * sizeof(result_type)));
2624 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
2625 ::new (__r.__end_) result_type(__expr_[__i]);
2626 }
2627 return __r;
2628}
2629
2630// valarray
2631
2632template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002633inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002634valarray<_Tp>::valarray(size_t __n)
2635 : __begin_(0),
2636 __end_(0)
2637{
2638 resize(__n);
2639}
2640
2641template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002642inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002643valarray<_Tp>::valarray(const value_type& __x, size_t __n)
2644 : __begin_(0),
2645 __end_(0)
2646{
2647 resize(__n, __x);
2648}
2649
2650template <class _Tp>
2651valarray<_Tp>::valarray(const value_type* __p, size_t __n)
2652 : __begin_(0),
2653 __end_(0)
2654{
2655 if (__n)
2656 {
2657 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2658#ifndef _LIBCPP_NO_EXCEPTIONS
2659 try
2660 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002661#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002662 for (; __n; ++__end_, ++__p, --__n)
2663 ::new (__end_) value_type(*__p);
2664#ifndef _LIBCPP_NO_EXCEPTIONS
2665 }
2666 catch (...)
2667 {
2668 resize(0);
2669 throw;
2670 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002671#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002672 }
2673}
2674
2675template <class _Tp>
2676valarray<_Tp>::valarray(const valarray& __v)
2677 : __begin_(0),
2678 __end_(0)
2679{
2680 if (__v.size())
2681 {
2682 __begin_ = __end_ = static_cast<value_type*>(::operator new(__v.size() * sizeof(value_type)));
2683#ifndef _LIBCPP_NO_EXCEPTIONS
2684 try
2685 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002686#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002687 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
2688 ::new (__end_) value_type(*__p);
2689#ifndef _LIBCPP_NO_EXCEPTIONS
2690 }
2691 catch (...)
2692 {
2693 resize(0);
2694 throw;
2695 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002696#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002697 }
2698}
2699
Howard Hinnant73d21a42010-09-04 23:28:19 +00002700#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002701
2702template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002703inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002704valarray<_Tp>::valarray(valarray&& __v)
2705 : __begin_(__v.__begin_),
2706 __end_(__v.__end_)
2707{
2708 __v.__begin_ = __v.__end_ = nullptr;
2709}
2710
2711template <class _Tp>
2712valarray<_Tp>::valarray(initializer_list<value_type> __il)
2713 : __begin_(0),
2714 __end_(0)
2715{
2716 size_t __n = __il.size();
2717 if (__n)
2718 {
2719 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2720#ifndef _LIBCPP_NO_EXCEPTIONS
2721 try
2722 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002723#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002724 for (const value_type* __p = __il.begin(); __n; ++__end_, ++__p, --__n)
2725 ::new (__end_) value_type(*__p);
2726#ifndef _LIBCPP_NO_EXCEPTIONS
2727 }
2728 catch (...)
2729 {
2730 resize(0);
2731 throw;
2732 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002733#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002734 }
2735}
2736
Howard Hinnant73d21a42010-09-04 23:28:19 +00002737#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002738
2739template <class _Tp>
2740valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
2741 : __begin_(0),
2742 __end_(0)
2743{
2744 size_t __n = __sa.__size_;
2745 if (__n)
2746 {
2747 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2748#ifndef _LIBCPP_NO_EXCEPTIONS
2749 try
2750 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002751#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002752 for (const value_type* __p = __sa.__vp_; __n; ++__end_, __p += __sa.__stride_, --__n)
2753 ::new (__end_) value_type(*__p);
2754#ifndef _LIBCPP_NO_EXCEPTIONS
2755 }
2756 catch (...)
2757 {
2758 resize(0);
2759 throw;
2760 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002761#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002762 }
2763}
2764
2765template <class _Tp>
2766valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
2767 : __begin_(0),
2768 __end_(0)
2769{
2770 size_t __n = __ga.__1d_.size();
2771 if (__n)
2772 {
2773 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2774#ifndef _LIBCPP_NO_EXCEPTIONS
2775 try
2776 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002777#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002778 typedef const size_t* _Ip;
2779 const value_type* __s = __ga.__vp_;
2780 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2781 __i != __e; ++__i, ++__end_)
2782 ::new (__end_) value_type(__s[*__i]);
2783#ifndef _LIBCPP_NO_EXCEPTIONS
2784 }
2785 catch (...)
2786 {
2787 resize(0);
2788 throw;
2789 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002790#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002791 }
2792}
2793
2794template <class _Tp>
2795valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
2796 : __begin_(0),
2797 __end_(0)
2798{
2799 size_t __n = __ma.__1d_.size();
2800 if (__n)
2801 {
2802 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2803#ifndef _LIBCPP_NO_EXCEPTIONS
2804 try
2805 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002806#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002807 typedef const size_t* _Ip;
2808 const value_type* __s = __ma.__vp_;
2809 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2810 __i != __e; ++__i, ++__end_)
2811 ::new (__end_) value_type(__s[*__i]);
2812#ifndef _LIBCPP_NO_EXCEPTIONS
2813 }
2814 catch (...)
2815 {
2816 resize(0);
2817 throw;
2818 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002819#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002820 }
2821}
2822
2823template <class _Tp>
2824valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
2825 : __begin_(0),
2826 __end_(0)
2827{
2828 size_t __n = __ia.__1d_.size();
2829 if (__n)
2830 {
2831 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
2832#ifndef _LIBCPP_NO_EXCEPTIONS
2833 try
2834 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002835#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002836 typedef const size_t* _Ip;
2837 const value_type* __s = __ia.__vp_;
2838 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2839 __i != __e; ++__i, ++__end_)
2840 ::new (__end_) value_type(__s[*__i]);
2841#ifndef _LIBCPP_NO_EXCEPTIONS
2842 }
2843 catch (...)
2844 {
2845 resize(0);
2846 throw;
2847 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002848#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002849 }
2850}
2851
2852template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002853inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002854valarray<_Tp>::~valarray()
2855{
2856 resize(0);
2857}
2858
2859template <class _Tp>
2860valarray<_Tp>&
2861valarray<_Tp>::operator=(const valarray& __v)
2862{
2863 if (this != &__v)
2864 {
2865 if (size() != __v.size())
2866 resize(__v.size());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002867 _VSTD::copy(__v.__begin_, __v.__end_, __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002868 }
2869 return *this;
2870}
2871
Howard Hinnant73d21a42010-09-04 23:28:19 +00002872#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002873
2874template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002875inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002876valarray<_Tp>&
2877valarray<_Tp>::operator=(valarray&& __v)
2878{
2879 resize(0);
2880 __begin_ = __v.__begin_;
2881 __end_ = __v.__end_;
2882 __v.__begin_ = nullptr;
2883 __v.__end_ = nullptr;
2884 return *this;
2885}
2886
2887template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002888inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002889valarray<_Tp>&
2890valarray<_Tp>::operator=(initializer_list<value_type> __il)
2891{
2892 if (size() != __il.size())
2893 resize(__il.size());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002894 _VSTD::copy(__il.begin(), __il.end(), __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002895 return *this;
2896}
2897
Howard Hinnant73d21a42010-09-04 23:28:19 +00002898#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002899
2900template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002901inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002902valarray<_Tp>&
2903valarray<_Tp>::operator=(const value_type& __x)
2904{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002905 _VSTD::fill(__begin_, __end_, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002906 return *this;
2907}
2908
2909template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002910inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002911valarray<_Tp>&
2912valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
2913{
2914 value_type* __t = __begin_;
2915 const value_type* __s = __sa.__vp_;
2916 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
2917 *__t = *__s;
2918 return *this;
2919}
2920
2921template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002922inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002923valarray<_Tp>&
2924valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
2925{
2926 typedef const size_t* _Ip;
2927 value_type* __t = __begin_;
2928 const value_type* __s = __ga.__vp_;
2929 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
2930 __i != __e; ++__i, ++__t)
2931 *__t = __s[*__i];
2932 return *this;
2933}
2934
2935template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002936inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002937valarray<_Tp>&
2938valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
2939{
2940 typedef const size_t* _Ip;
2941 value_type* __t = __begin_;
2942 const value_type* __s = __ma.__vp_;
2943 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
2944 __i != __e; ++__i, ++__t)
2945 *__t = __s[*__i];
2946 return *this;
2947}
2948
2949template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002950inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002951valarray<_Tp>&
2952valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
2953{
2954 typedef const size_t* _Ip;
2955 value_type* __t = __begin_;
2956 const value_type* __s = __ia.__vp_;
2957 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
2958 __i != __e; ++__i, ++__t)
2959 *__t = __s[*__i];
2960 return *this;
2961}
2962
2963template <class _Tp>
Howard Hinnantdb866632011-07-27 23:19:59 +00002964template <class _ValExpr>
2965inline _LIBCPP_INLINE_VISIBILITY
2966valarray<_Tp>&
2967valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
2968{
2969 size_t __n = __v.size();
2970 if (size() != __n)
2971 resize(__n);
2972 value_type* __t = __begin_;
2973 for (size_t __i = 0; __i != __n; ++__t, ++__i)
2974 *__t = result_type(__v[__i]);
2975 return *this;
2976}
2977
2978template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002979inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002980__val_expr<__slice_expr<const valarray<_Tp>&> >
2981valarray<_Tp>::operator[](slice __s) const
2982{
2983 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
2984}
2985
2986template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002987inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002988slice_array<_Tp>
2989valarray<_Tp>::operator[](slice __s)
2990{
2991 return slice_array<value_type>(__s, *this);
2992}
2993
2994template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002995inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002996__val_expr<__indirect_expr<const valarray<_Tp>&> >
2997valarray<_Tp>::operator[](const gslice& __gs) const
2998{
2999 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
3000}
3001
3002template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003003inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003004gslice_array<_Tp>
3005valarray<_Tp>::operator[](const gslice& __gs)
3006{
3007 return gslice_array<value_type>(__gs, *this);
3008}
3009
Howard Hinnant73d21a42010-09-04 23:28:19 +00003010#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003011
3012template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003013inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003014__val_expr<__indirect_expr<const valarray<_Tp>&> >
3015valarray<_Tp>::operator[](gslice&& __gs) const
3016{
3017 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
3018}
3019
3020template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003021inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003022gslice_array<_Tp>
3023valarray<_Tp>::operator[](gslice&& __gs)
3024{
3025 return gslice_array<value_type>(move(__gs), *this);
3026}
3027
Howard Hinnant73d21a42010-09-04 23:28:19 +00003028#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003029
3030template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003031inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003032__val_expr<__mask_expr<const valarray<_Tp>&> >
3033valarray<_Tp>::operator[](const valarray<bool>& __vb) const
3034{
3035 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
3036}
3037
3038template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003039inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003040mask_array<_Tp>
3041valarray<_Tp>::operator[](const valarray<bool>& __vb)
3042{
3043 return mask_array<value_type>(__vb, *this);
3044}
3045
Howard Hinnant73d21a42010-09-04 23:28:19 +00003046#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003047
3048template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003049inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003050__val_expr<__mask_expr<const valarray<_Tp>&> >
3051valarray<_Tp>::operator[](valarray<bool>&& __vb) const
3052{
3053 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
3054}
3055
3056template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003057inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003058mask_array<_Tp>
3059valarray<_Tp>::operator[](valarray<bool>&& __vb)
3060{
3061 return mask_array<value_type>(move(__vb), *this);
3062}
3063
Howard Hinnant73d21a42010-09-04 23:28:19 +00003064#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003065
3066template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003067inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003068__val_expr<__indirect_expr<const valarray<_Tp>&> >
3069valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
3070{
3071 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
3072}
3073
3074template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003075inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003076indirect_array<_Tp>
3077valarray<_Tp>::operator[](const valarray<size_t>& __vs)
3078{
3079 return indirect_array<value_type>(__vs, *this);
3080}
3081
Howard Hinnant73d21a42010-09-04 23:28:19 +00003082#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003083
3084template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003085inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003086__val_expr<__indirect_expr<const valarray<_Tp>&> >
3087valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
3088{
3089 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
3090}
3091
3092template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003093inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003094indirect_array<_Tp>
3095valarray<_Tp>::operator[](valarray<size_t>&& __vs)
3096{
3097 return indirect_array<value_type>(move(__vs), *this);
3098}
3099
Howard Hinnant73d21a42010-09-04 23:28:19 +00003100#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003101
3102template <class _Tp>
3103valarray<_Tp>
3104valarray<_Tp>::operator+() const
3105{
3106 valarray<value_type> __r;
3107 size_t __n = size();
3108 if (__n)
3109 {
3110 __r.__begin_ =
3111 __r.__end_ =
3112 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3113 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3114 ::new (__r.__end_) value_type(+*__p);
3115 }
3116 return __r;
3117}
3118
3119template <class _Tp>
3120valarray<_Tp>
3121valarray<_Tp>::operator-() const
3122{
3123 valarray<value_type> __r;
3124 size_t __n = size();
3125 if (__n)
3126 {
3127 __r.__begin_ =
3128 __r.__end_ =
3129 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3130 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3131 ::new (__r.__end_) value_type(-*__p);
3132 }
3133 return __r;
3134}
3135
3136template <class _Tp>
3137valarray<_Tp>
3138valarray<_Tp>::operator~() const
3139{
3140 valarray<value_type> __r;
3141 size_t __n = size();
3142 if (__n)
3143 {
3144 __r.__begin_ =
3145 __r.__end_ =
3146 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3147 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3148 ::new (__r.__end_) value_type(~*__p);
3149 }
3150 return __r;
3151}
3152
3153template <class _Tp>
3154valarray<bool>
3155valarray<_Tp>::operator!() const
3156{
3157 valarray<bool> __r;
3158 size_t __n = size();
3159 if (__n)
3160 {
3161 __r.__begin_ =
3162 __r.__end_ =
3163 static_cast<bool*>(::operator new(__n * sizeof(bool)));
3164 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3165 ::new (__r.__end_) bool(!*__p);
3166 }
3167 return __r;
3168}
3169
3170template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003171inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003172valarray<_Tp>&
3173valarray<_Tp>::operator*=(const value_type& __x)
3174{
3175 for (value_type* __p = __begin_; __p != __end_; ++__p)
3176 *__p *= __x;
3177 return *this;
3178}
3179
3180template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003181inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003182valarray<_Tp>&
3183valarray<_Tp>::operator/=(const value_type& __x)
3184{
3185 for (value_type* __p = __begin_; __p != __end_; ++__p)
3186 *__p /= __x;
3187 return *this;
3188}
3189
3190template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003191inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003192valarray<_Tp>&
3193valarray<_Tp>::operator%=(const value_type& __x)
3194{
3195 for (value_type* __p = __begin_; __p != __end_; ++__p)
3196 *__p %= __x;
3197 return *this;
3198}
3199
3200template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003201inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003202valarray<_Tp>&
3203valarray<_Tp>::operator+=(const value_type& __x)
3204{
3205 for (value_type* __p = __begin_; __p != __end_; ++__p)
3206 *__p += __x;
3207 return *this;
3208}
3209
3210template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003211inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003212valarray<_Tp>&
3213valarray<_Tp>::operator-=(const value_type& __x)
3214{
3215 for (value_type* __p = __begin_; __p != __end_; ++__p)
3216 *__p -= __x;
3217 return *this;
3218}
3219
3220template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003221inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003222valarray<_Tp>&
3223valarray<_Tp>::operator^=(const value_type& __x)
3224{
3225 for (value_type* __p = __begin_; __p != __end_; ++__p)
3226 *__p ^= __x;
3227 return *this;
3228}
3229
3230template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003231inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003232valarray<_Tp>&
3233valarray<_Tp>::operator&=(const value_type& __x)
3234{
3235 for (value_type* __p = __begin_; __p != __end_; ++__p)
3236 *__p &= __x;
3237 return *this;
3238}
3239
3240template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003241inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003242valarray<_Tp>&
3243valarray<_Tp>::operator|=(const value_type& __x)
3244{
3245 for (value_type* __p = __begin_; __p != __end_; ++__p)
3246 *__p |= __x;
3247 return *this;
3248}
3249
3250template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003251inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003252valarray<_Tp>&
3253valarray<_Tp>::operator<<=(const value_type& __x)
3254{
3255 for (value_type* __p = __begin_; __p != __end_; ++__p)
3256 *__p <<= __x;
3257 return *this;
3258}
3259
3260template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003261inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003262valarray<_Tp>&
3263valarray<_Tp>::operator>>=(const value_type& __x)
3264{
3265 for (value_type* __p = __begin_; __p != __end_; ++__p)
3266 *__p >>= __x;
3267 return *this;
3268}
3269
3270template <class _Tp>
3271template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003272inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003273typename enable_if
3274<
3275 __is_val_expr<_Expr>::value,
3276 valarray<_Tp>&
3277>::type
3278valarray<_Tp>::operator*=(const _Expr& __v)
3279{
3280 size_t __i = 0;
3281 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3282 *__t *= __v[__i];
3283 return *this;
3284}
3285
3286template <class _Tp>
3287template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003288inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003289typename enable_if
3290<
3291 __is_val_expr<_Expr>::value,
3292 valarray<_Tp>&
3293>::type
3294valarray<_Tp>::operator/=(const _Expr& __v)
3295{
3296 size_t __i = 0;
3297 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3298 *__t /= __v[__i];
3299 return *this;
3300}
3301
3302template <class _Tp>
3303template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003304inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003305typename enable_if
3306<
3307 __is_val_expr<_Expr>::value,
3308 valarray<_Tp>&
3309>::type
3310valarray<_Tp>::operator%=(const _Expr& __v)
3311{
3312 size_t __i = 0;
3313 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3314 *__t %= __v[__i];
3315 return *this;
3316}
3317
3318template <class _Tp>
3319template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003320inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003321typename enable_if
3322<
3323 __is_val_expr<_Expr>::value,
3324 valarray<_Tp>&
3325>::type
3326valarray<_Tp>::operator+=(const _Expr& __v)
3327{
3328 size_t __i = 0;
3329 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3330 *__t += __v[__i];
3331 return *this;
3332}
3333
3334template <class _Tp>
3335template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003336inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003337typename enable_if
3338<
3339 __is_val_expr<_Expr>::value,
3340 valarray<_Tp>&
3341>::type
3342valarray<_Tp>::operator-=(const _Expr& __v)
3343{
3344 size_t __i = 0;
3345 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3346 *__t -= __v[__i];
3347 return *this;
3348}
3349
3350template <class _Tp>
3351template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003352inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003353typename enable_if
3354<
3355 __is_val_expr<_Expr>::value,
3356 valarray<_Tp>&
3357>::type
3358valarray<_Tp>::operator^=(const _Expr& __v)
3359{
3360 size_t __i = 0;
3361 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3362 *__t ^= __v[__i];
3363 return *this;
3364}
3365
3366template <class _Tp>
3367template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003368inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003369typename enable_if
3370<
3371 __is_val_expr<_Expr>::value,
3372 valarray<_Tp>&
3373>::type
3374valarray<_Tp>::operator|=(const _Expr& __v)
3375{
3376 size_t __i = 0;
3377 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3378 *__t |= __v[__i];
3379 return *this;
3380}
3381
3382template <class _Tp>
3383template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003384inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003385typename enable_if
3386<
3387 __is_val_expr<_Expr>::value,
3388 valarray<_Tp>&
3389>::type
3390valarray<_Tp>::operator&=(const _Expr& __v)
3391{
3392 size_t __i = 0;
3393 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3394 *__t &= __v[__i];
3395 return *this;
3396}
3397
3398template <class _Tp>
3399template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003400inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003401typename enable_if
3402<
3403 __is_val_expr<_Expr>::value,
3404 valarray<_Tp>&
3405>::type
3406valarray<_Tp>::operator<<=(const _Expr& __v)
3407{
3408 size_t __i = 0;
3409 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3410 *__t <<= __v[__i];
3411 return *this;
3412}
3413
3414template <class _Tp>
3415template <class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003416inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003417typename enable_if
3418<
3419 __is_val_expr<_Expr>::value,
3420 valarray<_Tp>&
3421>::type
3422valarray<_Tp>::operator>>=(const _Expr& __v)
3423{
3424 size_t __i = 0;
3425 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
3426 *__t >>= __v[__i];
3427 return *this;
3428}
3429
3430template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003431inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003432void
3433valarray<_Tp>::swap(valarray& __v)
3434{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003435 _VSTD::swap(__begin_, __v.__begin_);
3436 _VSTD::swap(__end_, __v.__end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003437}
3438
3439template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003440inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003441_Tp
3442valarray<_Tp>::sum() const
3443{
3444 if (__begin_ == __end_)
3445 return value_type();
3446 const value_type* __p = __begin_;
3447 _Tp __r = *__p;
3448 for (++__p; __p != __end_; ++__p)
3449 __r += *__p;
3450 return __r;
3451}
3452
3453template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003454inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003455_Tp
3456valarray<_Tp>::min() const
3457{
3458 if (__begin_ == __end_)
3459 return value_type();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003460 return *_VSTD::min_element(__begin_, __end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003461}
3462
3463template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003464inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003465_Tp
3466valarray<_Tp>::max() const
3467{
3468 if (__begin_ == __end_)
3469 return value_type();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003470 return *_VSTD::max_element(__begin_, __end_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003471}
3472
3473template <class _Tp>
3474valarray<_Tp>
3475valarray<_Tp>::shift(int __i) const
3476{
3477 valarray<value_type> __r;
3478 size_t __n = size();
3479 if (__n)
3480 {
3481 __r.__begin_ =
3482 __r.__end_ =
3483 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3484 const value_type* __sb;
3485 value_type* __tb;
3486 value_type* __te;
3487 if (__i >= 0)
3488 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003489 __i = _VSTD::min(__i, static_cast<int>(__n));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003490 __sb = __begin_ + __i;
3491 __tb = __r.__begin_;
3492 __te = __r.__begin_ + (__n - __i);
3493 }
3494 else
3495 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003496 __i = _VSTD::min(-__i, static_cast<int>(__n));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003497 __sb = __begin_;
3498 __tb = __r.__begin_ + __i;
3499 __te = __r.__begin_ + __n;
3500 }
3501 for (; __r.__end_ != __tb; ++__r.__end_)
3502 ::new (__r.__end_) value_type();
3503 for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
3504 ::new (__r.__end_) value_type(*__sb);
3505 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
3506 ::new (__r.__end_) value_type();
3507 }
3508 return __r;
3509}
3510
3511template <class _Tp>
3512valarray<_Tp>
3513valarray<_Tp>::cshift(int __i) const
3514{
3515 valarray<value_type> __r;
3516 size_t __n = size();
3517 if (__n)
3518 {
3519 __r.__begin_ =
3520 __r.__end_ =
3521 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3522 __i %= static_cast<int>(__n);
3523 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
3524 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
3525 ::new (__r.__end_) value_type(*__s);
3526 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
3527 ::new (__r.__end_) value_type(*__s);
3528 }
3529 return __r;
3530}
3531
3532template <class _Tp>
3533valarray<_Tp>
3534valarray<_Tp>::apply(value_type __f(value_type)) const
3535{
3536 valarray<value_type> __r;
3537 size_t __n = size();
3538 if (__n)
3539 {
3540 __r.__begin_ =
3541 __r.__end_ =
3542 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3543 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3544 ::new (__r.__end_) value_type(__f(*__p));
3545 }
3546 return __r;
3547}
3548
3549template <class _Tp>
3550valarray<_Tp>
3551valarray<_Tp>::apply(value_type __f(const value_type&)) const
3552{
3553 valarray<value_type> __r;
3554 size_t __n = size();
3555 if (__n)
3556 {
3557 __r.__begin_ =
3558 __r.__end_ =
3559 static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3560 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
3561 ::new (__r.__end_) value_type(__f(*__p));
3562 }
3563 return __r;
3564}
3565
3566template <class _Tp>
3567void
3568valarray<_Tp>::resize(size_t __n, value_type __x)
3569{
3570 if (__begin_ != nullptr)
3571 {
3572 while (__end_ != __begin_)
3573 (--__end_)->~value_type();
3574 ::operator delete(__begin_);
3575 __begin_ = __end_ = nullptr;
3576 }
3577 if (__n)
3578 {
3579 __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
3580#ifndef _LIBCPP_NO_EXCEPTIONS
3581 try
3582 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003583#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003584 for (; __n; --__n, ++__end_)
3585 ::new (__end_) value_type(__x);
3586#ifndef _LIBCPP_NO_EXCEPTIONS
3587 }
3588 catch (...)
3589 {
3590 resize(0);
3591 throw;
3592 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003593#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003594 }
3595}
3596
3597template<class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003598inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003599void
3600swap(valarray<_Tp>& __x, valarray<_Tp>& __y)
3601{
3602 __x.swap(__y);
3603}
3604
3605template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003606inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003607typename enable_if
3608<
3609 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3610 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
3611>::type
3612operator*(const _Expr1& __x, const _Expr2& __y)
3613{
3614 typedef typename _Expr1::value_type value_type;
3615 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
3616 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
3617}
3618
3619template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003620inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003621typename enable_if
3622<
3623 __is_val_expr<_Expr>::value,
3624 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3625 _Expr, __scalar_expr<typename _Expr::value_type> > >
3626>::type
3627operator*(const _Expr& __x, const typename _Expr::value_type& __y)
3628{
3629 typedef typename _Expr::value_type value_type;
3630 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3631 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3632 __x, __scalar_expr<value_type>(__y, __x.size())));
3633}
3634
3635template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003636inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003637typename enable_if
3638<
3639 __is_val_expr<_Expr>::value,
3640 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
3641 __scalar_expr<typename _Expr::value_type>, _Expr> >
3642>::type
3643operator*(const typename _Expr::value_type& __x, const _Expr& __y)
3644{
3645 typedef typename _Expr::value_type value_type;
3646 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3647 return __val_expr<_Op>(_Op(multiplies<value_type>(),
3648 __scalar_expr<value_type>(__x, __y.size()), __y));
3649}
3650
3651template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003652inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003653typename enable_if
3654<
3655 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3656 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
3657>::type
3658operator/(const _Expr1& __x, const _Expr2& __y)
3659{
3660 typedef typename _Expr1::value_type value_type;
3661 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
3662 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
3663}
3664
3665template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003666inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003667typename enable_if
3668<
3669 __is_val_expr<_Expr>::value,
3670 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3671 _Expr, __scalar_expr<typename _Expr::value_type> > >
3672>::type
3673operator/(const _Expr& __x, const typename _Expr::value_type& __y)
3674{
3675 typedef typename _Expr::value_type value_type;
3676 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3677 return __val_expr<_Op>(_Op(divides<value_type>(),
3678 __x, __scalar_expr<value_type>(__y, __x.size())));
3679}
3680
3681template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003682inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003683typename enable_if
3684<
3685 __is_val_expr<_Expr>::value,
3686 __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
3687 __scalar_expr<typename _Expr::value_type>, _Expr> >
3688>::type
3689operator/(const typename _Expr::value_type& __x, const _Expr& __y)
3690{
3691 typedef typename _Expr::value_type value_type;
3692 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3693 return __val_expr<_Op>(_Op(divides<value_type>(),
3694 __scalar_expr<value_type>(__x, __y.size()), __y));
3695}
3696
3697template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003698inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003699typename enable_if
3700<
3701 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3702 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3703>::type
3704operator%(const _Expr1& __x, const _Expr2& __y)
3705{
3706 typedef typename _Expr1::value_type value_type;
3707 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
3708 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
3709}
3710
3711template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003712inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003713typename enable_if
3714<
3715 __is_val_expr<_Expr>::value,
3716 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3717 _Expr, __scalar_expr<typename _Expr::value_type> > >
3718>::type
3719operator%(const _Expr& __x, const typename _Expr::value_type& __y)
3720{
3721 typedef typename _Expr::value_type value_type;
3722 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3723 return __val_expr<_Op>(_Op(modulus<value_type>(),
3724 __x, __scalar_expr<value_type>(__y, __x.size())));
3725}
3726
3727template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003728inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003729typename enable_if
3730<
3731 __is_val_expr<_Expr>::value,
3732 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
3733 __scalar_expr<typename _Expr::value_type>, _Expr> >
3734>::type
3735operator%(const typename _Expr::value_type& __x, const _Expr& __y)
3736{
3737 typedef typename _Expr::value_type value_type;
3738 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3739 return __val_expr<_Op>(_Op(modulus<value_type>(),
3740 __scalar_expr<value_type>(__x, __y.size()), __y));
3741}
3742
3743template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003744inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003745typename enable_if
3746<
3747 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
3748 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3749>::type
3750operator+(const _Expr1& __x, const _Expr2& __y)
3751{
3752 typedef typename _Expr1::value_type value_type;
3753 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
3754 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
3755}
3756
3757template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003758inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003759typename enable_if
3760<
3761 __is_val_expr<_Expr>::value,
3762 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3763 _Expr, __scalar_expr<typename _Expr::value_type> > >
3764>::type
3765operator+(const _Expr& __x, const typename _Expr::value_type& __y)
3766{
3767 typedef typename _Expr::value_type value_type;
3768 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3769 return __val_expr<_Op>(_Op(plus<value_type>(),
3770 __x, __scalar_expr<value_type>(__y, __x.size())));
3771}
3772
3773template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003774inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003775typename enable_if
3776<
3777 __is_val_expr<_Expr>::value,
3778 __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
3779 __scalar_expr<typename _Expr::value_type>, _Expr> >
3780>::type
3781operator+(const typename _Expr::value_type& __x, const _Expr& __y)
3782{
3783 typedef typename _Expr::value_type value_type;
3784 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3785 return __val_expr<_Op>(_Op(plus<value_type>(),
3786 __scalar_expr<value_type>(__x, __y.size()), __y));
3787}
3788
3789template<class _Expr1, class _Expr2>
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<_Expr1>::value && __is_val_expr<_Expr2>::value,
3794 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
3795>::type
3796operator-(const _Expr1& __x, const _Expr2& __y)
3797{
3798 typedef typename _Expr1::value_type value_type;
3799 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
3800 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
3801}
3802
3803template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003804inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003805typename enable_if
3806<
3807 __is_val_expr<_Expr>::value,
3808 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3809 _Expr, __scalar_expr<typename _Expr::value_type> > >
3810>::type
3811operator-(const _Expr& __x, const typename _Expr::value_type& __y)
3812{
3813 typedef typename _Expr::value_type value_type;
3814 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3815 return __val_expr<_Op>(_Op(minus<value_type>(),
3816 __x, __scalar_expr<value_type>(__y, __x.size())));
3817}
3818
3819template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003820inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003821typename enable_if
3822<
3823 __is_val_expr<_Expr>::value,
3824 __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
3825 __scalar_expr<typename _Expr::value_type>, _Expr> >
3826>::type
3827operator-(const typename _Expr::value_type& __x, const _Expr& __y)
3828{
3829 typedef typename _Expr::value_type value_type;
3830 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3831 return __val_expr<_Op>(_Op(minus<value_type>(),
3832 __scalar_expr<value_type>(__x, __y.size()), __y));
3833}
3834
3835template<class _Expr1, class _Expr2>
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<_Expr1>::value && __is_val_expr<_Expr2>::value,
3840 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
3841>::type
3842operator^(const _Expr1& __x, const _Expr2& __y)
3843{
3844 typedef typename _Expr1::value_type value_type;
3845 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
3846 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
3847}
3848
3849template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003850inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003851typename enable_if
3852<
3853 __is_val_expr<_Expr>::value,
3854 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
3855 _Expr, __scalar_expr<typename _Expr::value_type> > >
3856>::type
3857operator^(const _Expr& __x, const typename _Expr::value_type& __y)
3858{
3859 typedef typename _Expr::value_type value_type;
3860 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3861 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
3862 __x, __scalar_expr<value_type>(__y, __x.size())));
3863}
3864
3865template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003866inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003867typename enable_if
3868<
3869 __is_val_expr<_Expr>::value,
3870 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
3871 __scalar_expr<typename _Expr::value_type>, _Expr> >
3872>::type
3873operator^(const typename _Expr::value_type& __x, const _Expr& __y)
3874{
3875 typedef typename _Expr::value_type value_type;
3876 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3877 return __val_expr<_Op>(_Op(bit_xor<value_type>(),
3878 __scalar_expr<value_type>(__x, __y.size()), __y));
3879}
3880
3881template<class _Expr1, class _Expr2>
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<_Expr1>::value && __is_val_expr<_Expr2>::value,
3886 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
3887>::type
3888operator&(const _Expr1& __x, const _Expr2& __y)
3889{
3890 typedef typename _Expr1::value_type value_type;
3891 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
3892 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
3893}
3894
3895template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003896inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003897typename enable_if
3898<
3899 __is_val_expr<_Expr>::value,
3900 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
3901 _Expr, __scalar_expr<typename _Expr::value_type> > >
3902>::type
3903operator&(const _Expr& __x, const typename _Expr::value_type& __y)
3904{
3905 typedef typename _Expr::value_type value_type;
3906 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3907 return __val_expr<_Op>(_Op(bit_and<value_type>(),
3908 __x, __scalar_expr<value_type>(__y, __x.size())));
3909}
3910
3911template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003912inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003913typename enable_if
3914<
3915 __is_val_expr<_Expr>::value,
3916 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
3917 __scalar_expr<typename _Expr::value_type>, _Expr> >
3918>::type
3919operator&(const typename _Expr::value_type& __x, const _Expr& __y)
3920{
3921 typedef typename _Expr::value_type value_type;
3922 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3923 return __val_expr<_Op>(_Op(bit_and<value_type>(),
3924 __scalar_expr<value_type>(__x, __y.size()), __y));
3925}
3926
3927template<class _Expr1, class _Expr2>
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<_Expr1>::value && __is_val_expr<_Expr2>::value,
3932 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
3933>::type
3934operator|(const _Expr1& __x, const _Expr2& __y)
3935{
3936 typedef typename _Expr1::value_type value_type;
3937 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
3938 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
3939}
3940
3941template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003942inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003943typename enable_if
3944<
3945 __is_val_expr<_Expr>::value,
3946 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
3947 _Expr, __scalar_expr<typename _Expr::value_type> > >
3948>::type
3949operator|(const _Expr& __x, const typename _Expr::value_type& __y)
3950{
3951 typedef typename _Expr::value_type value_type;
3952 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3953 return __val_expr<_Op>(_Op(bit_or<value_type>(),
3954 __x, __scalar_expr<value_type>(__y, __x.size())));
3955}
3956
3957template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003958inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003959typename enable_if
3960<
3961 __is_val_expr<_Expr>::value,
3962 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
3963 __scalar_expr<typename _Expr::value_type>, _Expr> >
3964>::type
3965operator|(const typename _Expr::value_type& __x, const _Expr& __y)
3966{
3967 typedef typename _Expr::value_type value_type;
3968 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
3969 return __val_expr<_Op>(_Op(bit_or<value_type>(),
3970 __scalar_expr<value_type>(__x, __y.size()), __y));
3971}
3972
3973template<class _Expr1, class _Expr2>
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<_Expr1>::value && __is_val_expr<_Expr2>::value,
3978 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
3979>::type
3980operator<<(const _Expr1& __x, const _Expr2& __y)
3981{
3982 typedef typename _Expr1::value_type value_type;
3983 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
3984 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
3985}
3986
3987template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003988inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003989typename enable_if
3990<
3991 __is_val_expr<_Expr>::value,
3992 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
3993 _Expr, __scalar_expr<typename _Expr::value_type> > >
3994>::type
3995operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
3996{
3997 typedef typename _Expr::value_type value_type;
3998 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
3999 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4000 __x, __scalar_expr<value_type>(__y, __x.size())));
4001}
4002
4003template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004004inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004005typename enable_if
4006<
4007 __is_val_expr<_Expr>::value,
4008 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
4009 __scalar_expr<typename _Expr::value_type>, _Expr> >
4010>::type
4011operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
4012{
4013 typedef typename _Expr::value_type value_type;
4014 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4015 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
4016 __scalar_expr<value_type>(__x, __y.size()), __y));
4017}
4018
4019template<class _Expr1, class _Expr2>
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<_Expr1>::value && __is_val_expr<_Expr2>::value,
4024 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
4025>::type
4026operator>>(const _Expr1& __x, const _Expr2& __y)
4027{
4028 typedef typename _Expr1::value_type value_type;
4029 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
4030 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
4031}
4032
4033template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004034inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004035typename enable_if
4036<
4037 __is_val_expr<_Expr>::value,
4038 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4039 _Expr, __scalar_expr<typename _Expr::value_type> > >
4040>::type
4041operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
4042{
4043 typedef typename _Expr::value_type value_type;
4044 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4045 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4046 __x, __scalar_expr<value_type>(__y, __x.size())));
4047}
4048
4049template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004050inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004051typename enable_if
4052<
4053 __is_val_expr<_Expr>::value,
4054 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
4055 __scalar_expr<typename _Expr::value_type>, _Expr> >
4056>::type
4057operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
4058{
4059 typedef typename _Expr::value_type value_type;
4060 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4061 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
4062 __scalar_expr<value_type>(__x, __y.size()), __y));
4063}
4064
4065template<class _Expr1, class _Expr2>
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<_Expr1>::value && __is_val_expr<_Expr2>::value,
4070 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
4071>::type
4072operator&&(const _Expr1& __x, const _Expr2& __y)
4073{
4074 typedef typename _Expr1::value_type value_type;
4075 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
4076 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
4077}
4078
4079template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004080inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004081typename enable_if
4082<
4083 __is_val_expr<_Expr>::value,
4084 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4085 _Expr, __scalar_expr<typename _Expr::value_type> > >
4086>::type
4087operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
4088{
4089 typedef typename _Expr::value_type value_type;
4090 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4091 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4092 __x, __scalar_expr<value_type>(__y, __x.size())));
4093}
4094
4095template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004096inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004097typename enable_if
4098<
4099 __is_val_expr<_Expr>::value,
4100 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
4101 __scalar_expr<typename _Expr::value_type>, _Expr> >
4102>::type
4103operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
4104{
4105 typedef typename _Expr::value_type value_type;
4106 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4107 return __val_expr<_Op>(_Op(logical_and<value_type>(),
4108 __scalar_expr<value_type>(__x, __y.size()), __y));
4109}
4110
4111template<class _Expr1, class _Expr2>
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<_Expr1>::value && __is_val_expr<_Expr2>::value,
4116 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
4117>::type
4118operator||(const _Expr1& __x, const _Expr2& __y)
4119{
4120 typedef typename _Expr1::value_type value_type;
4121 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
4122 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
4123}
4124
4125template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004126inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004127typename enable_if
4128<
4129 __is_val_expr<_Expr>::value,
4130 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4131 _Expr, __scalar_expr<typename _Expr::value_type> > >
4132>::type
4133operator||(const _Expr& __x, const typename _Expr::value_type& __y)
4134{
4135 typedef typename _Expr::value_type value_type;
4136 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4137 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4138 __x, __scalar_expr<value_type>(__y, __x.size())));
4139}
4140
4141template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004142inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004143typename enable_if
4144<
4145 __is_val_expr<_Expr>::value,
4146 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
4147 __scalar_expr<typename _Expr::value_type>, _Expr> >
4148>::type
4149operator||(const typename _Expr::value_type& __x, const _Expr& __y)
4150{
4151 typedef typename _Expr::value_type value_type;
4152 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4153 return __val_expr<_Op>(_Op(logical_or<value_type>(),
4154 __scalar_expr<value_type>(__x, __y.size()), __y));
4155}
4156
4157template<class _Expr1, class _Expr2>
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<_Expr1>::value && __is_val_expr<_Expr2>::value,
4162 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4163>::type
4164operator==(const _Expr1& __x, const _Expr2& __y)
4165{
4166 typedef typename _Expr1::value_type value_type;
4167 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
4168 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
4169}
4170
4171template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004172inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004173typename enable_if
4174<
4175 __is_val_expr<_Expr>::value,
4176 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4177 _Expr, __scalar_expr<typename _Expr::value_type> > >
4178>::type
4179operator==(const _Expr& __x, const typename _Expr::value_type& __y)
4180{
4181 typedef typename _Expr::value_type value_type;
4182 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4183 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4184 __x, __scalar_expr<value_type>(__y, __x.size())));
4185}
4186
4187template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004188inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004189typename enable_if
4190<
4191 __is_val_expr<_Expr>::value,
4192 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
4193 __scalar_expr<typename _Expr::value_type>, _Expr> >
4194>::type
4195operator==(const typename _Expr::value_type& __x, const _Expr& __y)
4196{
4197 typedef typename _Expr::value_type value_type;
4198 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4199 return __val_expr<_Op>(_Op(equal_to<value_type>(),
4200 __scalar_expr<value_type>(__x, __y.size()), __y));
4201}
4202
4203template<class _Expr1, class _Expr2>
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<_Expr1>::value && __is_val_expr<_Expr2>::value,
4208 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
4209>::type
4210operator!=(const _Expr1& __x, const _Expr2& __y)
4211{
4212 typedef typename _Expr1::value_type value_type;
4213 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
4214 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
4215}
4216
4217template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004218inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004219typename enable_if
4220<
4221 __is_val_expr<_Expr>::value,
4222 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4223 _Expr, __scalar_expr<typename _Expr::value_type> > >
4224>::type
4225operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
4226{
4227 typedef typename _Expr::value_type value_type;
4228 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4229 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4230 __x, __scalar_expr<value_type>(__y, __x.size())));
4231}
4232
4233template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004234inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004235typename enable_if
4236<
4237 __is_val_expr<_Expr>::value,
4238 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
4239 __scalar_expr<typename _Expr::value_type>, _Expr> >
4240>::type
4241operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
4242{
4243 typedef typename _Expr::value_type value_type;
4244 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4245 return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
4246 __scalar_expr<value_type>(__x, __y.size()), __y));
4247}
4248
4249template<class _Expr1, class _Expr2>
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<_Expr1>::value && __is_val_expr<_Expr2>::value,
4254 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
4255>::type
4256operator<(const _Expr1& __x, const _Expr2& __y)
4257{
4258 typedef typename _Expr1::value_type value_type;
4259 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
4260 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
4261}
4262
4263template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004264inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004265typename enable_if
4266<
4267 __is_val_expr<_Expr>::value,
4268 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4269 _Expr, __scalar_expr<typename _Expr::value_type> > >
4270>::type
4271operator<(const _Expr& __x, const typename _Expr::value_type& __y)
4272{
4273 typedef typename _Expr::value_type value_type;
4274 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4275 return __val_expr<_Op>(_Op(less<value_type>(),
4276 __x, __scalar_expr<value_type>(__y, __x.size())));
4277}
4278
4279template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004280inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004281typename enable_if
4282<
4283 __is_val_expr<_Expr>::value,
4284 __val_expr<_BinaryOp<less<typename _Expr::value_type>,
4285 __scalar_expr<typename _Expr::value_type>, _Expr> >
4286>::type
4287operator<(const typename _Expr::value_type& __x, const _Expr& __y)
4288{
4289 typedef typename _Expr::value_type value_type;
4290 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4291 return __val_expr<_Op>(_Op(less<value_type>(),
4292 __scalar_expr<value_type>(__x, __y.size()), __y));
4293}
4294
4295template<class _Expr1, class _Expr2>
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<_Expr1>::value && __is_val_expr<_Expr2>::value,
4300 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
4301>::type
4302operator>(const _Expr1& __x, const _Expr2& __y)
4303{
4304 typedef typename _Expr1::value_type value_type;
4305 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
4306 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
4307}
4308
4309template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004310inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004311typename enable_if
4312<
4313 __is_val_expr<_Expr>::value,
4314 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4315 _Expr, __scalar_expr<typename _Expr::value_type> > >
4316>::type
4317operator>(const _Expr& __x, const typename _Expr::value_type& __y)
4318{
4319 typedef typename _Expr::value_type value_type;
4320 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4321 return __val_expr<_Op>(_Op(greater<value_type>(),
4322 __x, __scalar_expr<value_type>(__y, __x.size())));
4323}
4324
4325template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004326inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004327typename enable_if
4328<
4329 __is_val_expr<_Expr>::value,
4330 __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
4331 __scalar_expr<typename _Expr::value_type>, _Expr> >
4332>::type
4333operator>(const typename _Expr::value_type& __x, const _Expr& __y)
4334{
4335 typedef typename _Expr::value_type value_type;
4336 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4337 return __val_expr<_Op>(_Op(greater<value_type>(),
4338 __scalar_expr<value_type>(__x, __y.size()), __y));
4339}
4340
4341template<class _Expr1, class _Expr2>
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<_Expr1>::value && __is_val_expr<_Expr2>::value,
4346 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4347>::type
4348operator<=(const _Expr1& __x, const _Expr2& __y)
4349{
4350 typedef typename _Expr1::value_type value_type;
4351 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
4352 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
4353}
4354
4355template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004356inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004357typename enable_if
4358<
4359 __is_val_expr<_Expr>::value,
4360 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4361 _Expr, __scalar_expr<typename _Expr::value_type> > >
4362>::type
4363operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
4364{
4365 typedef typename _Expr::value_type value_type;
4366 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4367 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4368 __x, __scalar_expr<value_type>(__y, __x.size())));
4369}
4370
4371template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004372inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004373typename enable_if
4374<
4375 __is_val_expr<_Expr>::value,
4376 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
4377 __scalar_expr<typename _Expr::value_type>, _Expr> >
4378>::type
4379operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
4380{
4381 typedef typename _Expr::value_type value_type;
4382 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4383 return __val_expr<_Op>(_Op(less_equal<value_type>(),
4384 __scalar_expr<value_type>(__x, __y.size()), __y));
4385}
4386
4387template<class _Expr1, class _Expr2>
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<_Expr1>::value && __is_val_expr<_Expr2>::value,
4392 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
4393>::type
4394operator>=(const _Expr1& __x, const _Expr2& __y)
4395{
4396 typedef typename _Expr1::value_type value_type;
4397 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
4398 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
4399}
4400
4401template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004402inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004403typename enable_if
4404<
4405 __is_val_expr<_Expr>::value,
4406 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4407 _Expr, __scalar_expr<typename _Expr::value_type> > >
4408>::type
4409operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
4410{
4411 typedef typename _Expr::value_type value_type;
4412 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4413 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4414 __x, __scalar_expr<value_type>(__y, __x.size())));
4415}
4416
4417template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004418inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004419typename enable_if
4420<
4421 __is_val_expr<_Expr>::value,
4422 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
4423 __scalar_expr<typename _Expr::value_type>, _Expr> >
4424>::type
4425operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
4426{
4427 typedef typename _Expr::value_type value_type;
4428 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4429 return __val_expr<_Op>(_Op(greater_equal<value_type>(),
4430 __scalar_expr<value_type>(__x, __y.size()), __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<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
4439>::type
4440abs(const _Expr& __x)
4441{
4442 typedef typename _Expr::value_type value_type;
4443 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
4444 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
4445}
4446
4447template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004448inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004449typename enable_if
4450<
4451 __is_val_expr<_Expr>::value,
4452 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
4453>::type
4454acos(const _Expr& __x)
4455{
4456 typedef typename _Expr::value_type value_type;
4457 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
4458 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
4459}
4460
4461template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004462inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004463typename enable_if
4464<
4465 __is_val_expr<_Expr>::value,
4466 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
4467>::type
4468asin(const _Expr& __x)
4469{
4470 typedef typename _Expr::value_type value_type;
4471 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
4472 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
4473}
4474
4475template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004476inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004477typename enable_if
4478<
4479 __is_val_expr<_Expr>::value,
4480 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
4481>::type
4482atan(const _Expr& __x)
4483{
4484 typedef typename _Expr::value_type value_type;
4485 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
4486 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
4487}
4488
4489template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004490inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004491typename enable_if
4492<
4493 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4494 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4495>::type
4496atan2(const _Expr1& __x, const _Expr2& __y)
4497{
4498 typedef typename _Expr1::value_type value_type;
4499 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
4500 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
4501}
4502
4503template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004504inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004505typename enable_if
4506<
4507 __is_val_expr<_Expr>::value,
4508 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4509 _Expr, __scalar_expr<typename _Expr::value_type> > >
4510>::type
4511atan2(const _Expr& __x, const typename _Expr::value_type& __y)
4512{
4513 typedef typename _Expr::value_type value_type;
4514 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4515 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4516 __x, __scalar_expr<value_type>(__y, __x.size())));
4517}
4518
4519template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004520inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004521typename enable_if
4522<
4523 __is_val_expr<_Expr>::value,
4524 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
4525 __scalar_expr<typename _Expr::value_type>, _Expr> >
4526>::type
4527atan2(const typename _Expr::value_type& __x, const _Expr& __y)
4528{
4529 typedef typename _Expr::value_type value_type;
4530 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4531 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
4532 __scalar_expr<value_type>(__x, __y.size()), __y));
4533}
4534
4535template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004536inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004537typename enable_if
4538<
4539 __is_val_expr<_Expr>::value,
4540 __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
4541>::type
4542cos(const _Expr& __x)
4543{
4544 typedef typename _Expr::value_type value_type;
4545 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
4546 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
4547}
4548
4549template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004550inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004551typename enable_if
4552<
4553 __is_val_expr<_Expr>::value,
4554 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
4555>::type
4556cosh(const _Expr& __x)
4557{
4558 typedef typename _Expr::value_type value_type;
4559 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
4560 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
4561}
4562
4563template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004564inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004565typename enable_if
4566<
4567 __is_val_expr<_Expr>::value,
4568 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
4569>::type
4570exp(const _Expr& __x)
4571{
4572 typedef typename _Expr::value_type value_type;
4573 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
4574 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
4575}
4576
4577template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004578inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004579typename enable_if
4580<
4581 __is_val_expr<_Expr>::value,
4582 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
4583>::type
4584log(const _Expr& __x)
4585{
4586 typedef typename _Expr::value_type value_type;
4587 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
4588 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
4589}
4590
4591template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004592inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004593typename enable_if
4594<
4595 __is_val_expr<_Expr>::value,
4596 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
4597>::type
4598log10(const _Expr& __x)
4599{
4600 typedef typename _Expr::value_type value_type;
4601 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
4602 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
4603}
4604
4605template<class _Expr1, class _Expr2>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004606inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004607typename enable_if
4608<
4609 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
4610 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
4611>::type
4612pow(const _Expr1& __x, const _Expr2& __y)
4613{
4614 typedef typename _Expr1::value_type value_type;
4615 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
4616 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
4617}
4618
4619template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004620inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004621typename enable_if
4622<
4623 __is_val_expr<_Expr>::value,
4624 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4625 _Expr, __scalar_expr<typename _Expr::value_type> > >
4626>::type
4627pow(const _Expr& __x, const typename _Expr::value_type& __y)
4628{
4629 typedef typename _Expr::value_type value_type;
4630 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
4631 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4632 __x, __scalar_expr<value_type>(__y, __x.size())));
4633}
4634
4635template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004636inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004637typename enable_if
4638<
4639 __is_val_expr<_Expr>::value,
4640 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
4641 __scalar_expr<typename _Expr::value_type>, _Expr> >
4642>::type
4643pow(const typename _Expr::value_type& __x, const _Expr& __y)
4644{
4645 typedef typename _Expr::value_type value_type;
4646 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
4647 return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
4648 __scalar_expr<value_type>(__x, __y.size()), __y));
4649}
4650
4651template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004652inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004653typename enable_if
4654<
4655 __is_val_expr<_Expr>::value,
4656 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
4657>::type
4658sin(const _Expr& __x)
4659{
4660 typedef typename _Expr::value_type value_type;
4661 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
4662 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
4663}
4664
4665template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004666inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004667typename enable_if
4668<
4669 __is_val_expr<_Expr>::value,
4670 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
4671>::type
4672sinh(const _Expr& __x)
4673{
4674 typedef typename _Expr::value_type value_type;
4675 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
4676 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
4677}
4678
4679template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004680inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004681typename enable_if
4682<
4683 __is_val_expr<_Expr>::value,
4684 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
4685>::type
4686sqrt(const _Expr& __x)
4687{
4688 typedef typename _Expr::value_type value_type;
4689 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
4690 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
4691}
4692
4693template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004694inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004695typename enable_if
4696<
4697 __is_val_expr<_Expr>::value,
4698 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
4699>::type
4700tan(const _Expr& __x)
4701{
4702 typedef typename _Expr::value_type value_type;
4703 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
4704 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
4705}
4706
4707template<class _Expr>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004708inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004709typename enable_if
4710<
4711 __is_val_expr<_Expr>::value,
4712 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
4713>::type
4714tanh(const _Expr& __x)
4715{
4716 typedef typename _Expr::value_type value_type;
4717 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
4718 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
4719}
4720
4721template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004722inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004723_Tp*
4724begin(valarray<_Tp>& __v)
4725{
4726 return __v.__begin_;
4727}
4728
4729template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004730inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004731const _Tp*
4732begin(const valarray<_Tp>& __v)
4733{
4734 return __v.__begin_;
4735}
4736
4737template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004738inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004739_Tp*
4740end(valarray<_Tp>& __v)
4741{
4742 return __v.__end_;
4743}
4744
4745template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00004746inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004747const _Tp*
4748end(const valarray<_Tp>& __v)
4749{
4750 return __v.__end_;
4751}
4752
4753extern template valarray<size_t>::valarray(size_t);
4754extern template valarray<size_t>::~valarray();
4755extern template void valarray<size_t>::resize(size_t, size_t);
4756
4757_LIBCPP_END_NAMESPACE_STD
4758
4759#endif // _LIBCPP_VALARRAY