1 | // -*- C++ -*- |
2 | //===----------------------------------------------------------------------===// |
3 | // |
4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
5 | // See https://llvm.org/LICENSE.txt for license information. |
6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
7 | // |
8 | //===----------------------------------------------------------------------===// |
9 | |
10 | #ifndef _LIBCPP_VALARRAY |
11 | #define _LIBCPP_VALARRAY |
12 | |
13 | /* |
14 | valarray synopsis |
15 | |
16 | namespace std |
17 | { |
18 | |
19 | template<class T> |
20 | class valarray |
21 | { |
22 | public: |
23 | typedef T value_type; |
24 | |
25 | // construct/destroy: |
26 | valarray(); |
27 | explicit valarray(size_t n); |
28 | valarray(const value_type& x, size_t n); |
29 | valarray(const value_type* px, size_t n); |
30 | valarray(const valarray& v); |
31 | valarray(valarray&& v) noexcept; |
32 | valarray(const slice_array<value_type>& sa); |
33 | valarray(const gslice_array<value_type>& ga); |
34 | valarray(const mask_array<value_type>& ma); |
35 | valarray(const indirect_array<value_type>& ia); |
36 | valarray(initializer_list<value_type> il); |
37 | ~valarray(); |
38 | |
39 | // assignment: |
40 | valarray& operator=(const valarray& v); |
41 | valarray& operator=(valarray&& v) noexcept; |
42 | valarray& operator=(initializer_list<value_type> il); |
43 | valarray& operator=(const value_type& x); |
44 | valarray& operator=(const slice_array<value_type>& sa); |
45 | valarray& operator=(const gslice_array<value_type>& ga); |
46 | valarray& operator=(const mask_array<value_type>& ma); |
47 | valarray& operator=(const indirect_array<value_type>& ia); |
48 | |
49 | // element access: |
50 | const value_type& operator[](size_t i) const; |
51 | value_type& operator[](size_t i); |
52 | |
53 | // subset operations: |
54 | valarray operator[](slice s) const; |
55 | slice_array<value_type> operator[](slice s); |
56 | valarray operator[](const gslice& gs) const; |
57 | gslice_array<value_type> operator[](const gslice& gs); |
58 | valarray operator[](const valarray<bool>& vb) const; |
59 | mask_array<value_type> operator[](const valarray<bool>& vb); |
60 | valarray operator[](const valarray<size_t>& vs) const; |
61 | indirect_array<value_type> operator[](const valarray<size_t>& vs); |
62 | |
63 | // unary operators: |
64 | valarray operator+() const; |
65 | valarray operator-() const; |
66 | valarray operator~() const; |
67 | valarray<bool> operator!() const; |
68 | |
69 | // computed assignment: |
70 | valarray& operator*= (const value_type& x); |
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 | |
81 | valarray& operator*= (const valarray& v); |
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 | |
92 | // member functions: |
93 | void swap(valarray& v) noexcept; |
94 | |
95 | size_t size() const; |
96 | |
97 | value_type sum() const; |
98 | value_type min() const; |
99 | value_type max() const; |
100 | |
101 | valarray shift (int i) const; |
102 | valarray cshift(int i) const; |
103 | valarray apply(value_type f(value_type)) const; |
104 | valarray apply(value_type f(const value_type&)) const; |
105 | void resize(size_t n, value_type x = value_type()); |
106 | }; |
107 | |
108 | template<class T, size_t cnt> valarray(const T(&)[cnt], size_t) -> valarray<T>; |
109 | |
110 | class slice |
111 | { |
112 | public: |
113 | slice(); |
114 | slice(size_t start, size_t size, size_t stride); |
115 | |
116 | size_t start() const; |
117 | size_t size() const; |
118 | size_t stride() const; |
119 | |
120 | friend bool operator==(const slice& x, const slice& y); // since C++20 |
121 | }; |
122 | |
123 | template <class T> |
124 | class slice_array |
125 | { |
126 | public: |
127 | typedef T value_type; |
128 | |
129 | const slice_array& operator=(const slice_array& sa) 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 | void operator|= (const valarray<value_type>& v) const; |
139 | void operator<<=(const valarray<value_type>& v) const; |
140 | void operator>>=(const valarray<value_type>& v) const; |
141 | |
142 | void operator=(const value_type& x) const; |
143 | void operator=(const valarray<T>& val_arr) const; |
144 | |
145 | slice_array() = delete; |
146 | }; |
147 | |
148 | class gslice |
149 | { |
150 | public: |
151 | gslice(); |
152 | gslice(size_t start, const valarray<size_t>& size, |
153 | const valarray<size_t>& stride); |
154 | |
155 | size_t start() const; |
156 | valarray<size_t> size() const; |
157 | valarray<size_t> stride() const; |
158 | }; |
159 | |
160 | template <class T> |
161 | class gslice_array |
162 | { |
163 | public: |
164 | typedef T value_type; |
165 | |
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 | void operator&= (const valarray<value_type>& v) const; |
174 | void operator|= (const valarray<value_type>& v) const; |
175 | void operator<<=(const valarray<value_type>& v) const; |
176 | void operator>>=(const valarray<value_type>& v) const; |
177 | |
178 | gslice_array(const gslice_array& ga); |
179 | ~gslice_array(); |
180 | const gslice_array& operator=(const gslice_array& ga) const; |
181 | void operator=(const value_type& x) const; |
182 | |
183 | gslice_array() = delete; |
184 | }; |
185 | |
186 | template <class T> |
187 | class mask_array |
188 | { |
189 | public: |
190 | typedef T value_type; |
191 | |
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 | void operator&= (const valarray<value_type>& v) const; |
200 | void operator|= (const valarray<value_type>& v) const; |
201 | void operator<<=(const valarray<value_type>& v) const; |
202 | void operator>>=(const valarray<value_type>& v) const; |
203 | |
204 | mask_array(const mask_array& ma); |
205 | ~mask_array(); |
206 | const mask_array& operator=(const mask_array& ma) const; |
207 | void operator=(const value_type& x) const; |
208 | |
209 | mask_array() = delete; |
210 | }; |
211 | |
212 | template <class T> |
213 | class indirect_array |
214 | { |
215 | public: |
216 | typedef T value_type; |
217 | |
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 | void operator&= (const valarray<value_type>& v) const; |
226 | void operator|= (const valarray<value_type>& v) const; |
227 | void operator<<=(const valarray<value_type>& v) const; |
228 | void operator>>=(const valarray<value_type>& v) const; |
229 | |
230 | indirect_array(const indirect_array& ia); |
231 | ~indirect_array(); |
232 | const indirect_array& operator=(const indirect_array& ia) const; |
233 | void operator=(const value_type& x) const; |
234 | |
235 | indirect_array() = delete; |
236 | }; |
237 | |
238 | template<class T> void swap(valarray<T>& x, valarray<T>& y) noexcept; |
239 | |
240 | template<class T> valarray<T> operator* (const valarray<T>& x, const valarray<T>& y); |
241 | template<class T> valarray<T> operator* (const valarray<T>& x, const T& y); |
242 | template<class T> valarray<T> operator* (const T& x, const valarray<T>& y); |
243 | |
244 | template<class T> valarray<T> operator/ (const valarray<T>& x, const valarray<T>& y); |
245 | template<class T> valarray<T> operator/ (const valarray<T>& x, const T& y); |
246 | template<class T> valarray<T> operator/ (const T& x, const valarray<T>& y); |
247 | |
248 | template<class T> valarray<T> operator% (const valarray<T>& x, const valarray<T>& y); |
249 | template<class T> valarray<T> operator% (const valarray<T>& x, const T& y); |
250 | template<class T> valarray<T> operator% (const T& x, const valarray<T>& y); |
251 | |
252 | template<class T> valarray<T> operator+ (const valarray<T>& x, const valarray<T>& y); |
253 | template<class T> valarray<T> operator+ (const valarray<T>& x, const T& y); |
254 | template<class T> valarray<T> operator+ (const T& x, const valarray<T>& y); |
255 | |
256 | template<class T> valarray<T> operator- (const valarray<T>& x, const valarray<T>& y); |
257 | template<class T> valarray<T> operator- (const valarray<T>& x, const T& y); |
258 | template<class T> valarray<T> operator- (const T& x, const valarray<T>& y); |
259 | |
260 | template<class T> valarray<T> operator^ (const valarray<T>& x, const valarray<T>& y); |
261 | template<class T> valarray<T> operator^ (const valarray<T>& x, const T& y); |
262 | template<class T> valarray<T> operator^ (const T& x, const valarray<T>& y); |
263 | |
264 | template<class T> valarray<T> operator& (const valarray<T>& x, const valarray<T>& y); |
265 | template<class T> valarray<T> operator& (const valarray<T>& x, const T& y); |
266 | template<class T> valarray<T> operator& (const T& x, const valarray<T>& y); |
267 | |
268 | template<class T> valarray<T> operator| (const valarray<T>& x, const valarray<T>& y); |
269 | template<class T> valarray<T> operator| (const valarray<T>& x, const T& y); |
270 | template<class T> valarray<T> operator| (const T& x, const valarray<T>& y); |
271 | |
272 | template<class T> valarray<T> operator<<(const valarray<T>& x, const valarray<T>& y); |
273 | template<class T> valarray<T> operator<<(const valarray<T>& x, const T& y); |
274 | template<class T> valarray<T> operator<<(const T& x, const valarray<T>& y); |
275 | |
276 | template<class T> valarray<T> operator>>(const valarray<T>& x, const valarray<T>& y); |
277 | template<class T> valarray<T> operator>>(const valarray<T>& x, const T& y); |
278 | template<class T> valarray<T> operator>>(const T& x, const valarray<T>& y); |
279 | |
280 | template<class T> valarray<bool> operator&&(const valarray<T>& x, const valarray<T>& y); |
281 | template<class T> valarray<bool> operator&&(const valarray<T>& x, const T& y); |
282 | template<class T> valarray<bool> operator&&(const T& x, const valarray<T>& y); |
283 | |
284 | template<class T> valarray<bool> operator||(const valarray<T>& x, const valarray<T>& y); |
285 | template<class T> valarray<bool> operator||(const valarray<T>& x, const T& y); |
286 | template<class T> valarray<bool> operator||(const T& x, const valarray<T>& y); |
287 | |
288 | template<class T> valarray<bool> operator==(const valarray<T>& x, const valarray<T>& y); |
289 | template<class T> valarray<bool> operator==(const valarray<T>& x, const T& y); |
290 | template<class T> valarray<bool> operator==(const T& x, const valarray<T>& y); |
291 | |
292 | template<class T> valarray<bool> operator!=(const valarray<T>& x, const valarray<T>& y); |
293 | template<class T> valarray<bool> operator!=(const valarray<T>& x, const T& y); |
294 | template<class T> valarray<bool> operator!=(const T& x, const valarray<T>& y); |
295 | |
296 | template<class T> valarray<bool> operator< (const valarray<T>& x, const valarray<T>& y); |
297 | template<class T> valarray<bool> operator< (const valarray<T>& x, const T& y); |
298 | template<class T> valarray<bool> operator< (const T& x, const valarray<T>& y); |
299 | |
300 | template<class T> valarray<bool> operator> (const valarray<T>& x, const valarray<T>& y); |
301 | template<class T> valarray<bool> operator> (const valarray<T>& x, const T& y); |
302 | template<class T> valarray<bool> operator> (const T& x, const valarray<T>& y); |
303 | |
304 | template<class T> valarray<bool> operator<=(const valarray<T>& x, const valarray<T>& y); |
305 | template<class T> valarray<bool> operator<=(const valarray<T>& x, const T& y); |
306 | template<class T> valarray<bool> operator<=(const T& x, const valarray<T>& y); |
307 | |
308 | template<class T> valarray<bool> operator>=(const valarray<T>& x, const valarray<T>& y); |
309 | template<class T> valarray<bool> operator>=(const valarray<T>& x, const T& y); |
310 | template<class T> valarray<bool> operator>=(const T& x, const valarray<T>& y); |
311 | |
312 | template<class T> valarray<T> abs (const valarray<T>& x); |
313 | template<class T> valarray<T> acos (const valarray<T>& x); |
314 | template<class T> valarray<T> asin (const valarray<T>& x); |
315 | template<class T> valarray<T> atan (const valarray<T>& x); |
316 | |
317 | template<class T> valarray<T> atan2(const valarray<T>& x, const valarray<T>& y); |
318 | template<class T> valarray<T> atan2(const valarray<T>& x, const T& y); |
319 | template<class T> valarray<T> atan2(const T& x, const valarray<T>& y); |
320 | |
321 | template<class T> valarray<T> cos (const valarray<T>& x); |
322 | template<class T> valarray<T> cosh (const valarray<T>& x); |
323 | template<class T> valarray<T> exp (const valarray<T>& x); |
324 | template<class T> valarray<T> log (const valarray<T>& x); |
325 | template<class T> valarray<T> log10(const valarray<T>& x); |
326 | |
327 | template<class T> valarray<T> pow(const valarray<T>& x, const valarray<T>& y); |
328 | template<class T> valarray<T> pow(const valarray<T>& x, const T& y); |
329 | template<class T> valarray<T> pow(const T& x, const valarray<T>& y); |
330 | |
331 | template<class T> valarray<T> sin (const valarray<T>& x); |
332 | template<class T> valarray<T> sinh (const valarray<T>& x); |
333 | template<class T> valarray<T> sqrt (const valarray<T>& x); |
334 | template<class T> valarray<T> tan (const valarray<T>& x); |
335 | template<class T> valarray<T> tanh (const valarray<T>& x); |
336 | |
337 | template <class T> unspecified1 begin(valarray<T>& v); |
338 | template <class T> unspecified2 begin(const valarray<T>& v); |
339 | template <class T> unspecified1 end(valarray<T>& v); |
340 | template <class T> unspecified2 end(const valarray<T>& v); |
341 | |
342 | } // std |
343 | |
344 | */ |
345 | |
346 | #include <__algorithm/copy.h> |
347 | #include <__algorithm/count.h> |
348 | #include <__algorithm/fill.h> |
349 | #include <__algorithm/max_element.h> |
350 | #include <__algorithm/min.h> |
351 | #include <__algorithm/min_element.h> |
352 | #include <__algorithm/unwrap_iter.h> |
353 | #include <__assert> |
354 | #include <__config> |
355 | #include <__functional/operations.h> |
356 | #include <__memory/addressof.h> |
357 | #include <__memory/allocator.h> |
358 | #include <__memory/uninitialized_algorithms.h> |
359 | #include <__type_traits/decay.h> |
360 | #include <__type_traits/remove_reference.h> |
361 | #include <__utility/move.h> |
362 | #include <__utility/swap.h> |
363 | #include <cmath> |
364 | #include <cstddef> |
365 | #include <new> |
366 | #include <version> |
367 | |
368 | // standard-mandated includes |
369 | |
370 | // [valarray.syn] |
371 | #include <initializer_list> |
372 | |
373 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
374 | # pragma GCC system_header |
375 | #endif |
376 | |
377 | _LIBCPP_PUSH_MACROS |
378 | #include <__undef_macros> |
379 | |
380 | _LIBCPP_BEGIN_NAMESPACE_STD |
381 | |
382 | template <class _Tp> |
383 | class _LIBCPP_TEMPLATE_VIS valarray; |
384 | |
385 | class _LIBCPP_TEMPLATE_VIS slice { |
386 | size_t __start_; |
387 | size_t __size_; |
388 | size_t __stride_; |
389 | |
390 | public: |
391 | _LIBCPP_HIDE_FROM_ABI slice() : __start_(0), __size_(0), __stride_(0) {} |
392 | |
393 | _LIBCPP_HIDE_FROM_ABI slice(size_t __start, size_t __size, size_t __stride) |
394 | : __start_(__start), __size_(__size), __stride_(__stride) {} |
395 | |
396 | _LIBCPP_HIDE_FROM_ABI size_t start() const { return __start_; } |
397 | _LIBCPP_HIDE_FROM_ABI size_t size() const { return __size_; } |
398 | _LIBCPP_HIDE_FROM_ABI size_t stride() const { return __stride_; } |
399 | |
400 | #if _LIBCPP_STD_VER >= 20 |
401 | |
402 | _LIBCPP_HIDE_FROM_ABI friend bool operator==(const slice& __x, const slice& __y) { |
403 | return __x.start() == __y.start() && __x.size() == __y.size() && __x.stride() == __y.stride(); |
404 | } |
405 | |
406 | #endif |
407 | }; |
408 | |
409 | template <class _Tp> |
410 | class _LIBCPP_TEMPLATE_VIS slice_array; |
411 | class _LIBCPP_EXPORTED_FROM_ABI gslice; |
412 | template <class _Tp> |
413 | class _LIBCPP_TEMPLATE_VIS gslice_array; |
414 | template <class _Tp> |
415 | class _LIBCPP_TEMPLATE_VIS mask_array; |
416 | template <class _Tp> |
417 | class _LIBCPP_TEMPLATE_VIS indirect_array; |
418 | |
419 | template <class _Tp> |
420 | _LIBCPP_HIDE_FROM_ABI _Tp* begin(valarray<_Tp>& __v); |
421 | |
422 | template <class _Tp> |
423 | _LIBCPP_HIDE_FROM_ABI const _Tp* begin(const valarray<_Tp>& __v); |
424 | |
425 | template <class _Tp> |
426 | _LIBCPP_HIDE_FROM_ABI _Tp* end(valarray<_Tp>& __v); |
427 | |
428 | template <class _Tp> |
429 | _LIBCPP_HIDE_FROM_ABI const _Tp* end(const valarray<_Tp>& __v); |
430 | |
431 | template <class _Op, class _A0> |
432 | struct _UnaryOp { |
433 | typedef typename _Op::__result_type __result_type; |
434 | using value_type = __decay_t<__result_type>; |
435 | |
436 | _Op __op_; |
437 | _A0 __a0_; |
438 | |
439 | _LIBCPP_HIDE_FROM_ABI _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {} |
440 | |
441 | _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i]); } |
442 | |
443 | _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); } |
444 | }; |
445 | |
446 | template <class _Op, class _A0, class _A1> |
447 | struct _BinaryOp { |
448 | typedef typename _Op::__result_type __result_type; |
449 | using value_type = __decay_t<__result_type>; |
450 | |
451 | _Op __op_; |
452 | _A0 __a0_; |
453 | _A1 __a1_; |
454 | |
455 | _LIBCPP_HIDE_FROM_ABI _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1) |
456 | : __op_(__op), __a0_(__a0), __a1_(__a1) {} |
457 | |
458 | _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i], __a1_[__i]); } |
459 | |
460 | _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); } |
461 | }; |
462 | |
463 | template <class _Tp> |
464 | class __scalar_expr { |
465 | public: |
466 | typedef _Tp value_type; |
467 | typedef const _Tp& __result_type; |
468 | |
469 | private: |
470 | const value_type& __t_; |
471 | size_t __s_; |
472 | |
473 | public: |
474 | _LIBCPP_HIDE_FROM_ABI explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {} |
475 | |
476 | _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t) const { return __t_; } |
477 | |
478 | _LIBCPP_HIDE_FROM_ABI size_t size() const { return __s_; } |
479 | }; |
480 | |
481 | template <class _Tp> |
482 | struct __unary_plus { |
483 | typedef _Tp __result_type; |
484 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return +__x; } |
485 | }; |
486 | |
487 | template <class _Tp> |
488 | struct __bit_not { |
489 | typedef _Tp __result_type; |
490 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return ~__x; } |
491 | }; |
492 | |
493 | template <class _Tp> |
494 | struct __bit_shift_left { |
495 | typedef _Tp __result_type; |
496 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x << __y; } |
497 | }; |
498 | |
499 | template <class _Tp> |
500 | struct __bit_shift_right { |
501 | typedef _Tp __result_type; |
502 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x >> __y; } |
503 | }; |
504 | |
505 | template <class _Tp, class _Fp> |
506 | struct __apply_expr { |
507 | private: |
508 | _Fp __f_; |
509 | |
510 | public: |
511 | typedef _Tp __result_type; |
512 | |
513 | _LIBCPP_HIDE_FROM_ABI explicit __apply_expr(_Fp __f) : __f_(__f) {} |
514 | |
515 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return __f_(__x); } |
516 | }; |
517 | |
518 | template <class _Tp> |
519 | struct __abs_expr { |
520 | typedef _Tp __result_type; |
521 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::abs(__x); } |
522 | }; |
523 | |
524 | template <class _Tp> |
525 | struct __acos_expr { |
526 | typedef _Tp __result_type; |
527 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::acos(__x); } |
528 | }; |
529 | |
530 | template <class _Tp> |
531 | struct __asin_expr { |
532 | typedef _Tp __result_type; |
533 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::asin(__x); } |
534 | }; |
535 | |
536 | template <class _Tp> |
537 | struct __atan_expr { |
538 | typedef _Tp __result_type; |
539 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::atan(__x); } |
540 | }; |
541 | |
542 | template <class _Tp> |
543 | struct __atan2_expr { |
544 | typedef _Tp __result_type; |
545 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return std::atan2(__x, __y); } |
546 | }; |
547 | |
548 | template <class _Tp> |
549 | struct __cos_expr { |
550 | typedef _Tp __result_type; |
551 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::cos(__x); } |
552 | }; |
553 | |
554 | template <class _Tp> |
555 | struct __cosh_expr { |
556 | typedef _Tp __result_type; |
557 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::cosh(__x); } |
558 | }; |
559 | |
560 | template <class _Tp> |
561 | struct __exp_expr { |
562 | typedef _Tp __result_type; |
563 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::exp(__x); } |
564 | }; |
565 | |
566 | template <class _Tp> |
567 | struct __log_expr { |
568 | typedef _Tp __result_type; |
569 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::log(__x); } |
570 | }; |
571 | |
572 | template <class _Tp> |
573 | struct __log10_expr { |
574 | typedef _Tp __result_type; |
575 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::log10(__x); } |
576 | }; |
577 | |
578 | template <class _Tp> |
579 | struct __pow_expr { |
580 | typedef _Tp __result_type; |
581 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return std::pow(__x, __y); } |
582 | }; |
583 | |
584 | template <class _Tp> |
585 | struct __sin_expr { |
586 | typedef _Tp __result_type; |
587 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::sin(__x); } |
588 | }; |
589 | |
590 | template <class _Tp> |
591 | struct __sinh_expr { |
592 | typedef _Tp __result_type; |
593 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::sinh(__x); } |
594 | }; |
595 | |
596 | template <class _Tp> |
597 | struct __sqrt_expr { |
598 | typedef _Tp __result_type; |
599 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::sqrt(__x); } |
600 | }; |
601 | |
602 | template <class _Tp> |
603 | struct __tan_expr { |
604 | typedef _Tp __result_type; |
605 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::tan(__x); } |
606 | }; |
607 | |
608 | template <class _Tp> |
609 | struct __tanh_expr { |
610 | typedef _Tp __result_type; |
611 | _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::tanh(__x); } |
612 | }; |
613 | |
614 | template <class _ValExpr> |
615 | class __slice_expr { |
616 | typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr; |
617 | |
618 | public: |
619 | typedef typename _RmExpr::value_type value_type; |
620 | typedef value_type __result_type; |
621 | |
622 | private: |
623 | _ValExpr __expr_; |
624 | size_t __start_; |
625 | size_t __size_; |
626 | size_t __stride_; |
627 | |
628 | _LIBCPP_HIDE_FROM_ABI __slice_expr(const slice& __sl, const _RmExpr& __e) |
629 | : __expr_(__e), __start_(__sl.start()), __size_(__sl.size()), __stride_(__sl.stride()) {} |
630 | |
631 | public: |
632 | _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __expr_[__start_ + __i * __stride_]; } |
633 | |
634 | _LIBCPP_HIDE_FROM_ABI size_t size() const { return __size_; } |
635 | |
636 | template <class> |
637 | friend class __val_expr; |
638 | template <class> |
639 | friend class _LIBCPP_TEMPLATE_VIS valarray; |
640 | }; |
641 | |
642 | template <class _ValExpr> |
643 | class __mask_expr; |
644 | |
645 | template <class _ValExpr> |
646 | class __indirect_expr; |
647 | |
648 | template <class _ValExpr> |
649 | class __shift_expr { |
650 | typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr; |
651 | |
652 | public: |
653 | typedef typename _RmExpr::value_type value_type; |
654 | typedef value_type __result_type; |
655 | |
656 | private: |
657 | _ValExpr __expr_; |
658 | size_t __size_; |
659 | ptrdiff_t __ul_; |
660 | ptrdiff_t __sn_; |
661 | ptrdiff_t __n_; |
662 | static const ptrdiff_t _Np = static_cast<ptrdiff_t>(sizeof(ptrdiff_t) * __CHAR_BIT__ - 1); |
663 | |
664 | _LIBCPP_HIDE_FROM_ABI __shift_expr(int __n, const _RmExpr& __e) : __expr_(__e), __size_(__e.size()), __n_(__n) { |
665 | ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _Np); |
666 | __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _Np); |
667 | __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n); |
668 | } |
669 | |
670 | public: |
671 | _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __j) const { |
672 | ptrdiff_t __i = static_cast<ptrdiff_t>(__j); |
673 | ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np; |
674 | return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m); |
675 | } |
676 | |
677 | _LIBCPP_HIDE_FROM_ABI size_t size() const { return __size_; } |
678 | |
679 | template <class> |
680 | friend class __val_expr; |
681 | }; |
682 | |
683 | template <class _ValExpr> |
684 | class __cshift_expr { |
685 | typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr; |
686 | |
687 | public: |
688 | typedef typename _RmExpr::value_type value_type; |
689 | typedef value_type __result_type; |
690 | |
691 | private: |
692 | _ValExpr __expr_; |
693 | size_t __size_; |
694 | size_t __m_; |
695 | size_t __o1_; |
696 | size_t __o2_; |
697 | |
698 | _LIBCPP_HIDE_FROM_ABI __cshift_expr(int __n, const _RmExpr& __e) : __expr_(__e), __size_(__e.size()) { |
699 | __n %= static_cast<int>(__size_); |
700 | if (__n >= 0) { |
701 | __m_ = __size_ - __n; |
702 | __o1_ = __n; |
703 | __o2_ = __n - __size_; |
704 | } else { |
705 | __m_ = -__n; |
706 | __o1_ = __n + __size_; |
707 | __o2_ = __n; |
708 | } |
709 | } |
710 | |
711 | public: |
712 | _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { |
713 | if (__i < __m_) |
714 | return __expr_[__i + __o1_]; |
715 | return __expr_[__i + __o2_]; |
716 | } |
717 | |
718 | _LIBCPP_HIDE_FROM_ABI size_t size() const { return __size_; } |
719 | |
720 | template <class> |
721 | friend class __val_expr; |
722 | }; |
723 | |
724 | template <class _ValExpr> |
725 | class __val_expr; |
726 | |
727 | template <class _ValExpr> |
728 | struct __is_val_expr : false_type {}; |
729 | |
730 | template <class _ValExpr> |
731 | struct __is_val_expr<__val_expr<_ValExpr> > : true_type {}; |
732 | |
733 | template <class _Tp> |
734 | struct __is_val_expr<valarray<_Tp> > : true_type {}; |
735 | |
736 | template <class _Tp> |
737 | struct __is_val_expr<slice_array<_Tp> > : true_type {}; |
738 | |
739 | template <class _Tp> |
740 | struct __is_val_expr<gslice_array<_Tp> > : true_type {}; |
741 | |
742 | template <class _Tp> |
743 | struct __is_val_expr<mask_array<_Tp> > : true_type {}; |
744 | |
745 | template <class _Tp> |
746 | struct __is_val_expr<indirect_array<_Tp> > : true_type {}; |
747 | |
748 | // The functions using a __val_expr access the elements by their index. |
749 | // valarray and the libc++ lazy proxies have an operator[]. The |
750 | // Standard proxy array's don't have this operator, instead they have a |
751 | // implementation specific accessor |
752 | // __get(size_t) |
753 | // |
754 | // The functions use the non-member function |
755 | // __get(__val_expr, size_t) |
756 | // |
757 | // If the __val_expr is a specialization of __val_expr_use_member_functions it |
758 | // uses the __val_expr's member function |
759 | // __get(size_t) |
760 | // else it uses the __val_expr's member function |
761 | // operator[](size_t) |
762 | template <class _ValExpr> |
763 | struct __val_expr_use_member_functions; |
764 | |
765 | template <class> |
766 | struct __val_expr_use_member_functions : false_type {}; |
767 | |
768 | template <class _Tp> |
769 | struct __val_expr_use_member_functions<slice_array<_Tp> > : true_type {}; |
770 | |
771 | template <class _Tp> |
772 | struct __val_expr_use_member_functions<gslice_array<_Tp> > : true_type {}; |
773 | |
774 | template <class _Tp> |
775 | struct __val_expr_use_member_functions<mask_array<_Tp> > : true_type {}; |
776 | |
777 | template <class _Tp> |
778 | struct __val_expr_use_member_functions<indirect_array<_Tp> > : true_type {}; |
779 | |
780 | template <class _Tp> |
781 | class _LIBCPP_TEMPLATE_VIS valarray { |
782 | public: |
783 | typedef _Tp value_type; |
784 | typedef _Tp __result_type; |
785 | |
786 | private: |
787 | value_type* __begin_; |
788 | value_type* __end_; |
789 | |
790 | public: |
791 | // construct/destroy: |
792 | _LIBCPP_HIDE_FROM_ABI valarray() : __begin_(nullptr), __end_(nullptr) {} |
793 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 explicit valarray(size_t __n); |
794 | _LIBCPP_HIDE_FROM_ABI valarray(const value_type& __x, size_t __n); |
795 | valarray(const value_type* __p, size_t __n); |
796 | valarray(const valarray& __v); |
797 | #ifndef _LIBCPP_CXX03_LANG |
798 | _LIBCPP_HIDE_FROM_ABI valarray(valarray&& __v) _NOEXCEPT; |
799 | valarray(initializer_list<value_type> __il); |
800 | #endif // _LIBCPP_CXX03_LANG |
801 | valarray(const slice_array<value_type>& __sa); |
802 | valarray(const gslice_array<value_type>& __ga); |
803 | valarray(const mask_array<value_type>& __ma); |
804 | valarray(const indirect_array<value_type>& __ia); |
805 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 ~valarray(); |
806 | |
807 | // assignment: |
808 | valarray& operator=(const valarray& __v); |
809 | #ifndef _LIBCPP_CXX03_LANG |
810 | _LIBCPP_HIDE_FROM_ABI valarray& operator=(valarray&& __v) _NOEXCEPT; |
811 | _LIBCPP_HIDE_FROM_ABI valarray& operator=(initializer_list<value_type>); |
812 | #endif // _LIBCPP_CXX03_LANG |
813 | _LIBCPP_HIDE_FROM_ABI valarray& operator=(const value_type& __x); |
814 | _LIBCPP_HIDE_FROM_ABI valarray& operator=(const slice_array<value_type>& __sa); |
815 | _LIBCPP_HIDE_FROM_ABI valarray& operator=(const gslice_array<value_type>& __ga); |
816 | _LIBCPP_HIDE_FROM_ABI valarray& operator=(const mask_array<value_type>& __ma); |
817 | _LIBCPP_HIDE_FROM_ABI valarray& operator=(const indirect_array<value_type>& __ia); |
818 | template <class _ValExpr> |
819 | _LIBCPP_HIDE_FROM_ABI valarray& operator=(const __val_expr<_ValExpr>& __v); |
820 | |
821 | // element access: |
822 | _LIBCPP_HIDE_FROM_ABI const value_type& operator[](size_t __i) const { return __begin_[__i]; } |
823 | |
824 | _LIBCPP_HIDE_FROM_ABI value_type& operator[](size_t __i) { return __begin_[__i]; } |
825 | |
826 | // subset operations: |
827 | _LIBCPP_HIDE_FROM_ABI __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const; |
828 | _LIBCPP_HIDE_FROM_ABI slice_array<value_type> operator[](slice __s); |
829 | _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const; |
830 | _LIBCPP_HIDE_FROM_ABI gslice_array<value_type> operator[](const gslice& __gs); |
831 | #ifndef _LIBCPP_CXX03_LANG |
832 | _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const; |
833 | _LIBCPP_HIDE_FROM_ABI gslice_array<value_type> operator[](gslice&& __gs); |
834 | #endif // _LIBCPP_CXX03_LANG |
835 | _LIBCPP_HIDE_FROM_ABI __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const; |
836 | _LIBCPP_HIDE_FROM_ABI mask_array<value_type> operator[](const valarray<bool>& __vb); |
837 | #ifndef _LIBCPP_CXX03_LANG |
838 | _LIBCPP_HIDE_FROM_ABI __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const; |
839 | _LIBCPP_HIDE_FROM_ABI mask_array<value_type> operator[](valarray<bool>&& __vb); |
840 | #endif // _LIBCPP_CXX03_LANG |
841 | _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const; |
842 | _LIBCPP_HIDE_FROM_ABI indirect_array<value_type> operator[](const valarray<size_t>& __vs); |
843 | #ifndef _LIBCPP_CXX03_LANG |
844 | _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const; |
845 | _LIBCPP_HIDE_FROM_ABI indirect_array<value_type> operator[](valarray<size_t>&& __vs); |
846 | #endif // _LIBCPP_CXX03_LANG |
847 | |
848 | // unary operators: |
849 | _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__unary_plus<_Tp>, const valarray&> > operator+() const; |
850 | _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<negate<_Tp>, const valarray&> > operator-() const; |
851 | _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__bit_not<_Tp>, const valarray&> > operator~() const; |
852 | _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<logical_not<_Tp>, const valarray&> > operator!() const; |
853 | |
854 | // computed assignment: |
855 | _LIBCPP_HIDE_FROM_ABI valarray& operator*=(const value_type& __x); |
856 | _LIBCPP_HIDE_FROM_ABI valarray& operator/=(const value_type& __x); |
857 | _LIBCPP_HIDE_FROM_ABI valarray& operator%=(const value_type& __x); |
858 | _LIBCPP_HIDE_FROM_ABI valarray& operator+=(const value_type& __x); |
859 | _LIBCPP_HIDE_FROM_ABI valarray& operator-=(const value_type& __x); |
860 | _LIBCPP_HIDE_FROM_ABI valarray& operator^=(const value_type& __x); |
861 | _LIBCPP_HIDE_FROM_ABI valarray& operator&=(const value_type& __x); |
862 | _LIBCPP_HIDE_FROM_ABI valarray& operator|=(const value_type& __x); |
863 | _LIBCPP_HIDE_FROM_ABI valarray& operator<<=(const value_type& __x); |
864 | _LIBCPP_HIDE_FROM_ABI valarray& operator>>=(const value_type& __x); |
865 | |
866 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
867 | _LIBCPP_HIDE_FROM_ABI valarray& operator*=(const _Expr& __v); |
868 | |
869 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
870 | _LIBCPP_HIDE_FROM_ABI valarray& operator/=(const _Expr& __v); |
871 | |
872 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
873 | _LIBCPP_HIDE_FROM_ABI valarray& operator%=(const _Expr& __v); |
874 | |
875 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
876 | _LIBCPP_HIDE_FROM_ABI valarray& operator+=(const _Expr& __v); |
877 | |
878 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
879 | _LIBCPP_HIDE_FROM_ABI valarray& operator-=(const _Expr& __v); |
880 | |
881 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
882 | _LIBCPP_HIDE_FROM_ABI valarray& operator^=(const _Expr& __v); |
883 | |
884 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
885 | _LIBCPP_HIDE_FROM_ABI valarray& operator|=(const _Expr& __v); |
886 | |
887 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
888 | _LIBCPP_HIDE_FROM_ABI valarray& operator&=(const _Expr& __v); |
889 | |
890 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
891 | _LIBCPP_HIDE_FROM_ABI valarray& operator<<=(const _Expr& __v); |
892 | |
893 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
894 | _LIBCPP_HIDE_FROM_ABI valarray& operator>>=(const _Expr& __v); |
895 | |
896 | // member functions: |
897 | _LIBCPP_HIDE_FROM_ABI void swap(valarray& __v) _NOEXCEPT; |
898 | |
899 | _LIBCPP_HIDE_FROM_ABI size_t size() const { return static_cast<size_t>(__end_ - __begin_); } |
900 | |
901 | _LIBCPP_HIDE_FROM_ABI value_type sum() const; |
902 | _LIBCPP_HIDE_FROM_ABI value_type min() const; |
903 | _LIBCPP_HIDE_FROM_ABI value_type max() const; |
904 | |
905 | valarray shift(int __i) const; |
906 | valarray cshift(int __i) const; |
907 | valarray apply(value_type __f(value_type)) const; |
908 | valarray apply(value_type __f(const value_type&)) const; |
909 | void resize(size_t __n, value_type __x = value_type()); |
910 | |
911 | private: |
912 | template <class> |
913 | friend class _LIBCPP_TEMPLATE_VIS valarray; |
914 | template <class> |
915 | friend class _LIBCPP_TEMPLATE_VIS slice_array; |
916 | template <class> |
917 | friend class _LIBCPP_TEMPLATE_VIS gslice_array; |
918 | template <class> |
919 | friend class _LIBCPP_TEMPLATE_VIS mask_array; |
920 | template <class> |
921 | friend class __mask_expr; |
922 | template <class> |
923 | friend class _LIBCPP_TEMPLATE_VIS indirect_array; |
924 | template <class> |
925 | friend class __indirect_expr; |
926 | template <class> |
927 | friend class __val_expr; |
928 | |
929 | template <class _Up> |
930 | friend _Up* begin(valarray<_Up>& __v); |
931 | |
932 | template <class _Up> |
933 | friend const _Up* begin(const valarray<_Up>& __v); |
934 | |
935 | template <class _Up> |
936 | friend _Up* end(valarray<_Up>& __v); |
937 | |
938 | template <class _Up> |
939 | friend const _Up* end(const valarray<_Up>& __v); |
940 | |
941 | _LIBCPP_HIDE_FROM_ABI void __clear(size_t __capacity); |
942 | valarray& __assign_range(const value_type* __f, const value_type* __l); |
943 | }; |
944 | |
945 | #if _LIBCPP_STD_VER >= 17 |
946 | template <class _Tp, size_t _Size> |
947 | valarray(const _Tp (&)[_Size], size_t) -> valarray<_Tp>; |
948 | #endif |
949 | |
950 | template <class _Expr, |
951 | __enable_if_t<__is_val_expr<_Expr>::value && __val_expr_use_member_functions<_Expr>::value, int> = 0> |
952 | _LIBCPP_HIDE_FROM_ABI typename _Expr::value_type __get(const _Expr& __v, size_t __i) { |
953 | return __v.__get(__i); |
954 | } |
955 | |
956 | template <class _Expr, |
957 | __enable_if_t<__is_val_expr<_Expr>::value && !__val_expr_use_member_functions<_Expr>::value, int> = 0> |
958 | _LIBCPP_HIDE_FROM_ABI typename _Expr::value_type __get(const _Expr& __v, size_t __i) { |
959 | return __v[__i]; |
960 | } |
961 | |
962 | extern template _LIBCPP_EXPORTED_FROM_ABI void valarray<size_t>::resize(size_t, size_t); |
963 | |
964 | template <class _Op, class _Tp> |
965 | struct _UnaryOp<_Op, valarray<_Tp> > { |
966 | typedef typename _Op::__result_type __result_type; |
967 | using value_type = __decay_t<__result_type>; |
968 | |
969 | _Op __op_; |
970 | const valarray<_Tp>& __a0_; |
971 | |
972 | _LIBCPP_HIDE_FROM_ABI _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {} |
973 | |
974 | _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i]); } |
975 | |
976 | _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); } |
977 | }; |
978 | |
979 | template <class _Op, class _Tp, class _A1> |
980 | struct _BinaryOp<_Op, valarray<_Tp>, _A1> { |
981 | typedef typename _Op::__result_type __result_type; |
982 | using value_type = __decay_t<__result_type>; |
983 | |
984 | _Op __op_; |
985 | const valarray<_Tp>& __a0_; |
986 | _A1 __a1_; |
987 | |
988 | _LIBCPP_HIDE_FROM_ABI _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1) |
989 | : __op_(__op), __a0_(__a0), __a1_(__a1) {} |
990 | |
991 | _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i], __a1_[__i]); } |
992 | |
993 | _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); } |
994 | }; |
995 | |
996 | template <class _Op, class _A0, class _Tp> |
997 | struct _BinaryOp<_Op, _A0, valarray<_Tp> > { |
998 | typedef typename _Op::__result_type __result_type; |
999 | using value_type = __decay_t<__result_type>; |
1000 | |
1001 | _Op __op_; |
1002 | _A0 __a0_; |
1003 | const valarray<_Tp>& __a1_; |
1004 | |
1005 | _LIBCPP_HIDE_FROM_ABI _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1) |
1006 | : __op_(__op), __a0_(__a0), __a1_(__a1) {} |
1007 | |
1008 | _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i], __a1_[__i]); } |
1009 | |
1010 | _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); } |
1011 | }; |
1012 | |
1013 | template <class _Op, class _Tp> |
1014 | struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> > { |
1015 | typedef typename _Op::__result_type __result_type; |
1016 | using value_type = __decay_t<__result_type>; |
1017 | |
1018 | _Op __op_; |
1019 | const valarray<_Tp>& __a0_; |
1020 | const valarray<_Tp>& __a1_; |
1021 | |
1022 | _LIBCPP_HIDE_FROM_ABI _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1) |
1023 | : __op_(__op), __a0_(__a0), __a1_(__a1) {} |
1024 | |
1025 | _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i], __a1_[__i]); } |
1026 | |
1027 | _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); } |
1028 | }; |
1029 | |
1030 | // slice_array |
1031 | |
1032 | template <class _Tp> |
1033 | class _LIBCPP_TEMPLATE_VIS slice_array { |
1034 | public: |
1035 | typedef _Tp value_type; |
1036 | |
1037 | private: |
1038 | value_type* __vp_; |
1039 | size_t __size_; |
1040 | size_t __stride_; |
1041 | |
1042 | public: |
1043 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1044 | void _LIBCPP_HIDE_FROM_ABI operator=(const _Expr& __v) const; |
1045 | |
1046 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1047 | void _LIBCPP_HIDE_FROM_ABI operator*=(const _Expr& __v) const; |
1048 | |
1049 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1050 | void _LIBCPP_HIDE_FROM_ABI operator/=(const _Expr& __v) const; |
1051 | |
1052 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1053 | void _LIBCPP_HIDE_FROM_ABI operator%=(const _Expr& __v) const; |
1054 | |
1055 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1056 | void _LIBCPP_HIDE_FROM_ABI operator+=(const _Expr& __v) const; |
1057 | |
1058 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1059 | void _LIBCPP_HIDE_FROM_ABI operator-=(const _Expr& __v) const; |
1060 | |
1061 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1062 | void _LIBCPP_HIDE_FROM_ABI operator^=(const _Expr& __v) const; |
1063 | |
1064 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1065 | void _LIBCPP_HIDE_FROM_ABI operator&=(const _Expr& __v) const; |
1066 | |
1067 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1068 | void _LIBCPP_HIDE_FROM_ABI operator|=(const _Expr& __v) const; |
1069 | |
1070 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1071 | void _LIBCPP_HIDE_FROM_ABI operator<<=(const _Expr& __v) const; |
1072 | |
1073 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1074 | void _LIBCPP_HIDE_FROM_ABI operator>>=(const _Expr& __v) const; |
1075 | |
1076 | slice_array(slice_array const&) = default; |
1077 | |
1078 | _LIBCPP_HIDE_FROM_ABI const slice_array& operator=(const slice_array& __sa) const; |
1079 | |
1080 | _LIBCPP_HIDE_FROM_ABI void operator=(const value_type& __x) const; |
1081 | |
1082 | _LIBCPP_HIDE_FROM_ABI void operator=(const valarray<value_type>& __va) const; |
1083 | |
1084 | // Behaves like __val_expr::operator[], which returns by value. |
1085 | _LIBCPP_HIDE_FROM_ABI value_type __get(size_t __i) const { |
1086 | _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __size_, "slice_array.__get() index out of bounds" ); |
1087 | return __vp_[__i * __stride_]; |
1088 | } |
1089 | |
1090 | private: |
1091 | _LIBCPP_HIDE_FROM_ABI slice_array(const slice& __sl, const valarray<value_type>& __v) |
1092 | : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())), __size_(__sl.size()), __stride_(__sl.stride()) {} |
1093 | |
1094 | template <class> |
1095 | friend class valarray; |
1096 | }; |
1097 | |
1098 | template <class _Tp> |
1099 | inline const slice_array<_Tp>& slice_array<_Tp>::operator=(const slice_array& __sa) const { |
1100 | value_type* __t = __vp_; |
1101 | const value_type* __s = __sa.__vp_; |
1102 | for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_) |
1103 | *__t = *__s; |
1104 | return *this; |
1105 | } |
1106 | |
1107 | template <class _Tp> |
1108 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1109 | inline void slice_array<_Tp>::operator=(const _Expr& __v) const { |
1110 | value_type* __t = __vp_; |
1111 | for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) |
1112 | *__t = __v[__i]; |
1113 | } |
1114 | |
1115 | template <class _Tp> |
1116 | inline void slice_array<_Tp>::operator=(const valarray<value_type>& __va) const { |
1117 | value_type* __t = __vp_; |
1118 | for (size_t __i = 0; __i < __va.size(); ++__i, __t += __stride_) |
1119 | *__t = __va[__i]; |
1120 | } |
1121 | |
1122 | template <class _Tp> |
1123 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1124 | inline void slice_array<_Tp>::operator*=(const _Expr& __v) const { |
1125 | value_type* __t = __vp_; |
1126 | for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) |
1127 | *__t *= __v[__i]; |
1128 | } |
1129 | |
1130 | template <class _Tp> |
1131 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1132 | inline void slice_array<_Tp>::operator/=(const _Expr& __v) const { |
1133 | value_type* __t = __vp_; |
1134 | for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) |
1135 | *__t /= __v[__i]; |
1136 | } |
1137 | |
1138 | template <class _Tp> |
1139 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1140 | inline void slice_array<_Tp>::operator%=(const _Expr& __v) const { |
1141 | value_type* __t = __vp_; |
1142 | for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) |
1143 | *__t %= __v[__i]; |
1144 | } |
1145 | |
1146 | template <class _Tp> |
1147 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1148 | inline void slice_array<_Tp>::operator+=(const _Expr& __v) const { |
1149 | value_type* __t = __vp_; |
1150 | for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) |
1151 | *__t += __v[__i]; |
1152 | } |
1153 | |
1154 | template <class _Tp> |
1155 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1156 | inline void slice_array<_Tp>::operator-=(const _Expr& __v) const { |
1157 | value_type* __t = __vp_; |
1158 | for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) |
1159 | *__t -= __v[__i]; |
1160 | } |
1161 | |
1162 | template <class _Tp> |
1163 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1164 | inline void slice_array<_Tp>::operator^=(const _Expr& __v) const { |
1165 | value_type* __t = __vp_; |
1166 | for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) |
1167 | *__t ^= __v[__i]; |
1168 | } |
1169 | |
1170 | template <class _Tp> |
1171 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1172 | inline void slice_array<_Tp>::operator&=(const _Expr& __v) const { |
1173 | value_type* __t = __vp_; |
1174 | for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) |
1175 | *__t &= __v[__i]; |
1176 | } |
1177 | |
1178 | template <class _Tp> |
1179 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1180 | inline void slice_array<_Tp>::operator|=(const _Expr& __v) const { |
1181 | value_type* __t = __vp_; |
1182 | for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) |
1183 | *__t |= __v[__i]; |
1184 | } |
1185 | |
1186 | template <class _Tp> |
1187 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1188 | inline void slice_array<_Tp>::operator<<=(const _Expr& __v) const { |
1189 | value_type* __t = __vp_; |
1190 | for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) |
1191 | *__t <<= __v[__i]; |
1192 | } |
1193 | |
1194 | template <class _Tp> |
1195 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1196 | inline void slice_array<_Tp>::operator>>=(const _Expr& __v) const { |
1197 | value_type* __t = __vp_; |
1198 | for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) |
1199 | *__t >>= __v[__i]; |
1200 | } |
1201 | |
1202 | template <class _Tp> |
1203 | inline void slice_array<_Tp>::operator=(const value_type& __x) const { |
1204 | value_type* __t = __vp_; |
1205 | for (size_t __n = __size_; __n; --__n, __t += __stride_) |
1206 | *__t = __x; |
1207 | } |
1208 | |
1209 | // gslice |
1210 | |
1211 | class _LIBCPP_EXPORTED_FROM_ABI gslice { |
1212 | valarray<size_t> __size_; |
1213 | valarray<size_t> __stride_; |
1214 | valarray<size_t> __1d_; |
1215 | |
1216 | public: |
1217 | _LIBCPP_HIDE_FROM_ABI gslice() {} |
1218 | |
1219 | _LIBCPP_HIDE_FROM_ABI gslice(size_t __start, const valarray<size_t>& __size, const valarray<size_t>& __stride) |
1220 | : __size_(__size), __stride_(__stride) { |
1221 | __init(__start); |
1222 | } |
1223 | |
1224 | #ifndef _LIBCPP_CXX03_LANG |
1225 | |
1226 | _LIBCPP_HIDE_FROM_ABI gslice(size_t __start, const valarray<size_t>& __size, valarray<size_t>&& __stride) |
1227 | : __size_(__size), __stride_(std::move(__stride)) { |
1228 | __init(__start); |
1229 | } |
1230 | |
1231 | _LIBCPP_HIDE_FROM_ABI gslice(size_t __start, valarray<size_t>&& __size, const valarray<size_t>& __stride) |
1232 | : __size_(std::move(__size)), __stride_(__stride) { |
1233 | __init(__start); |
1234 | } |
1235 | |
1236 | _LIBCPP_HIDE_FROM_ABI gslice(size_t __start, valarray<size_t>&& __size, valarray<size_t>&& __stride) |
1237 | : __size_(std::move(__size)), __stride_(std::move(__stride)) { |
1238 | __init(__start); |
1239 | } |
1240 | |
1241 | #endif // _LIBCPP_CXX03_LANG |
1242 | |
1243 | _LIBCPP_HIDE_FROM_ABI size_t start() const { return __1d_.size() ? __1d_[0] : 0; } |
1244 | |
1245 | _LIBCPP_HIDE_FROM_ABI valarray<size_t> size() const { return __size_; } |
1246 | |
1247 | _LIBCPP_HIDE_FROM_ABI valarray<size_t> stride() const { return __stride_; } |
1248 | |
1249 | private: |
1250 | void __init(size_t __start); |
1251 | |
1252 | template <class> |
1253 | friend class gslice_array; |
1254 | template <class> |
1255 | friend class valarray; |
1256 | template <class> |
1257 | friend class __val_expr; |
1258 | }; |
1259 | |
1260 | // gslice_array |
1261 | |
1262 | template <class _Tp> |
1263 | class _LIBCPP_TEMPLATE_VIS gslice_array { |
1264 | public: |
1265 | typedef _Tp value_type; |
1266 | |
1267 | private: |
1268 | value_type* __vp_; |
1269 | valarray<size_t> __1d_; |
1270 | |
1271 | public: |
1272 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1273 | void _LIBCPP_HIDE_FROM_ABI operator=(const _Expr& __v) const; |
1274 | |
1275 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1276 | void _LIBCPP_HIDE_FROM_ABI operator*=(const _Expr& __v) const; |
1277 | |
1278 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1279 | void _LIBCPP_HIDE_FROM_ABI operator/=(const _Expr& __v) const; |
1280 | |
1281 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1282 | void _LIBCPP_HIDE_FROM_ABI operator%=(const _Expr& __v) const; |
1283 | |
1284 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1285 | void _LIBCPP_HIDE_FROM_ABI operator+=(const _Expr& __v) const; |
1286 | |
1287 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1288 | void _LIBCPP_HIDE_FROM_ABI operator-=(const _Expr& __v) const; |
1289 | |
1290 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1291 | void _LIBCPP_HIDE_FROM_ABI operator^=(const _Expr& __v) const; |
1292 | |
1293 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1294 | void _LIBCPP_HIDE_FROM_ABI operator&=(const _Expr& __v) const; |
1295 | |
1296 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1297 | void _LIBCPP_HIDE_FROM_ABI operator|=(const _Expr& __v) const; |
1298 | |
1299 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1300 | void _LIBCPP_HIDE_FROM_ABI operator<<=(const _Expr& __v) const; |
1301 | |
1302 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1303 | void _LIBCPP_HIDE_FROM_ABI operator>>=(const _Expr& __v) const; |
1304 | |
1305 | _LIBCPP_HIDE_FROM_ABI const gslice_array& operator=(const gslice_array& __ga) const; |
1306 | |
1307 | _LIBCPP_HIDE_FROM_ABI void operator=(const value_type& __x) const; |
1308 | |
1309 | gslice_array(const gslice_array&) = default; |
1310 | |
1311 | // Behaves like __val_expr::operator[], which returns by value. |
1312 | _LIBCPP_HIDE_FROM_ABI value_type __get(size_t __i) const { |
1313 | _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __1d_.size(), "gslice_array.__get() index out of bounds" ); |
1314 | return __vp_[__1d_[__i]]; |
1315 | } |
1316 | |
1317 | private: |
1318 | gslice_array(const gslice& __gs, const valarray<value_type>& __v) |
1319 | : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(__gs.__1d_) {} |
1320 | |
1321 | #ifndef _LIBCPP_CXX03_LANG |
1322 | gslice_array(gslice&& __gs, const valarray<value_type>& __v) |
1323 | : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(std::move(__gs.__1d_)) {} |
1324 | #endif // _LIBCPP_CXX03_LANG |
1325 | |
1326 | template <class> |
1327 | friend class valarray; |
1328 | }; |
1329 | |
1330 | template <class _Tp> |
1331 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1332 | inline void gslice_array<_Tp>::operator=(const _Expr& __v) const { |
1333 | typedef const size_t* _Ip; |
1334 | size_t __j = 0; |
1335 | for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) |
1336 | __vp_[*__i] = __v[__j]; |
1337 | } |
1338 | |
1339 | template <class _Tp> |
1340 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1341 | inline void gslice_array<_Tp>::operator*=(const _Expr& __v) const { |
1342 | typedef const size_t* _Ip; |
1343 | size_t __j = 0; |
1344 | for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) |
1345 | __vp_[*__i] *= __v[__j]; |
1346 | } |
1347 | |
1348 | template <class _Tp> |
1349 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1350 | inline void gslice_array<_Tp>::operator/=(const _Expr& __v) const { |
1351 | typedef const size_t* _Ip; |
1352 | size_t __j = 0; |
1353 | for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) |
1354 | __vp_[*__i] /= __v[__j]; |
1355 | } |
1356 | |
1357 | template <class _Tp> |
1358 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1359 | inline void gslice_array<_Tp>::operator%=(const _Expr& __v) const { |
1360 | typedef const size_t* _Ip; |
1361 | size_t __j = 0; |
1362 | for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) |
1363 | __vp_[*__i] %= __v[__j]; |
1364 | } |
1365 | |
1366 | template <class _Tp> |
1367 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1368 | inline void gslice_array<_Tp>::operator+=(const _Expr& __v) const { |
1369 | typedef const size_t* _Ip; |
1370 | size_t __j = 0; |
1371 | for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) |
1372 | __vp_[*__i] += __v[__j]; |
1373 | } |
1374 | |
1375 | template <class _Tp> |
1376 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1377 | inline void gslice_array<_Tp>::operator-=(const _Expr& __v) const { |
1378 | typedef const size_t* _Ip; |
1379 | size_t __j = 0; |
1380 | for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) |
1381 | __vp_[*__i] -= __v[__j]; |
1382 | } |
1383 | |
1384 | template <class _Tp> |
1385 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1386 | inline void gslice_array<_Tp>::operator^=(const _Expr& __v) const { |
1387 | typedef const size_t* _Ip; |
1388 | size_t __j = 0; |
1389 | for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) |
1390 | __vp_[*__i] ^= __v[__j]; |
1391 | } |
1392 | |
1393 | template <class _Tp> |
1394 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1395 | inline void gslice_array<_Tp>::operator&=(const _Expr& __v) const { |
1396 | typedef const size_t* _Ip; |
1397 | size_t __j = 0; |
1398 | for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) |
1399 | __vp_[*__i] &= __v[__j]; |
1400 | } |
1401 | |
1402 | template <class _Tp> |
1403 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1404 | inline void gslice_array<_Tp>::operator|=(const _Expr& __v) const { |
1405 | typedef const size_t* _Ip; |
1406 | size_t __j = 0; |
1407 | for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) |
1408 | __vp_[*__i] |= __v[__j]; |
1409 | } |
1410 | |
1411 | template <class _Tp> |
1412 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1413 | inline void gslice_array<_Tp>::operator<<=(const _Expr& __v) const { |
1414 | typedef const size_t* _Ip; |
1415 | size_t __j = 0; |
1416 | for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) |
1417 | __vp_[*__i] <<= __v[__j]; |
1418 | } |
1419 | |
1420 | template <class _Tp> |
1421 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1422 | inline void gslice_array<_Tp>::operator>>=(const _Expr& __v) const { |
1423 | typedef const size_t* _Ip; |
1424 | size_t __j = 0; |
1425 | for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) |
1426 | __vp_[*__i] >>= __v[__j]; |
1427 | } |
1428 | |
1429 | template <class _Tp> |
1430 | inline const gslice_array<_Tp>& gslice_array<_Tp>::operator=(const gslice_array& __ga) const { |
1431 | typedef const size_t* _Ip; |
1432 | const value_type* __s = __ga.__vp_; |
1433 | for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_; __i != __e; ++__i, ++__j) |
1434 | __vp_[*__i] = __s[*__j]; |
1435 | return *this; |
1436 | } |
1437 | |
1438 | template <class _Tp> |
1439 | inline void gslice_array<_Tp>::operator=(const value_type& __x) const { |
1440 | typedef const size_t* _Ip; |
1441 | for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i) |
1442 | __vp_[*__i] = __x; |
1443 | } |
1444 | |
1445 | // mask_array |
1446 | |
1447 | template <class _Tp> |
1448 | class _LIBCPP_TEMPLATE_VIS mask_array { |
1449 | public: |
1450 | typedef _Tp value_type; |
1451 | |
1452 | private: |
1453 | value_type* __vp_; |
1454 | valarray<size_t> __1d_; |
1455 | |
1456 | public: |
1457 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1458 | void _LIBCPP_HIDE_FROM_ABI operator=(const _Expr& __v) const; |
1459 | |
1460 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1461 | void _LIBCPP_HIDE_FROM_ABI operator*=(const _Expr& __v) const; |
1462 | |
1463 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1464 | void _LIBCPP_HIDE_FROM_ABI operator/=(const _Expr& __v) const; |
1465 | |
1466 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1467 | void _LIBCPP_HIDE_FROM_ABI operator%=(const _Expr& __v) const; |
1468 | |
1469 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1470 | void _LIBCPP_HIDE_FROM_ABI operator+=(const _Expr& __v) const; |
1471 | |
1472 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1473 | void _LIBCPP_HIDE_FROM_ABI operator-=(const _Expr& __v) const; |
1474 | |
1475 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1476 | void _LIBCPP_HIDE_FROM_ABI operator^=(const _Expr& __v) const; |
1477 | |
1478 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1479 | void _LIBCPP_HIDE_FROM_ABI operator&=(const _Expr& __v) const; |
1480 | |
1481 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1482 | void _LIBCPP_HIDE_FROM_ABI operator|=(const _Expr& __v) const; |
1483 | |
1484 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1485 | void _LIBCPP_HIDE_FROM_ABI operator<<=(const _Expr& __v) const; |
1486 | |
1487 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1488 | void _LIBCPP_HIDE_FROM_ABI operator>>=(const _Expr& __v) const; |
1489 | |
1490 | mask_array(const mask_array&) = default; |
1491 | |
1492 | _LIBCPP_HIDE_FROM_ABI const mask_array& operator=(const mask_array& __ma) const; |
1493 | |
1494 | _LIBCPP_HIDE_FROM_ABI void operator=(const value_type& __x) const; |
1495 | |
1496 | // Behaves like __val_expr::operator[], which returns by value. |
1497 | _LIBCPP_HIDE_FROM_ABI value_type __get(size_t __i) const { |
1498 | _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __1d_.size(), "mask_array.__get() index out of bounds" ); |
1499 | return __vp_[__1d_[__i]]; |
1500 | } |
1501 | |
1502 | private: |
1503 | _LIBCPP_HIDE_FROM_ABI mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v) |
1504 | : __vp_(const_cast<value_type*>(__v.__begin_)), |
1505 | __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true))) { |
1506 | size_t __j = 0; |
1507 | for (size_t __i = 0; __i < __vb.size(); ++__i) |
1508 | if (__vb[__i]) |
1509 | __1d_[__j++] = __i; |
1510 | } |
1511 | |
1512 | template <class> |
1513 | friend class valarray; |
1514 | }; |
1515 | |
1516 | template <class _Tp> |
1517 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1518 | inline void mask_array<_Tp>::operator=(const _Expr& __v) const { |
1519 | size_t __n = __1d_.size(); |
1520 | for (size_t __i = 0; __i < __n; ++__i) |
1521 | __vp_[__1d_[__i]] = __v[__i]; |
1522 | } |
1523 | |
1524 | template <class _Tp> |
1525 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1526 | inline void mask_array<_Tp>::operator*=(const _Expr& __v) const { |
1527 | size_t __n = __1d_.size(); |
1528 | for (size_t __i = 0; __i < __n; ++__i) |
1529 | __vp_[__1d_[__i]] *= __v[__i]; |
1530 | } |
1531 | |
1532 | template <class _Tp> |
1533 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1534 | inline void mask_array<_Tp>::operator/=(const _Expr& __v) const { |
1535 | size_t __n = __1d_.size(); |
1536 | for (size_t __i = 0; __i < __n; ++__i) |
1537 | __vp_[__1d_[__i]] /= __v[__i]; |
1538 | } |
1539 | |
1540 | template <class _Tp> |
1541 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1542 | inline void mask_array<_Tp>::operator%=(const _Expr& __v) const { |
1543 | size_t __n = __1d_.size(); |
1544 | for (size_t __i = 0; __i < __n; ++__i) |
1545 | __vp_[__1d_[__i]] %= __v[__i]; |
1546 | } |
1547 | |
1548 | template <class _Tp> |
1549 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1550 | inline void mask_array<_Tp>::operator+=(const _Expr& __v) const { |
1551 | size_t __n = __1d_.size(); |
1552 | for (size_t __i = 0; __i < __n; ++__i) |
1553 | __vp_[__1d_[__i]] += __v[__i]; |
1554 | } |
1555 | |
1556 | template <class _Tp> |
1557 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1558 | inline void mask_array<_Tp>::operator-=(const _Expr& __v) const { |
1559 | size_t __n = __1d_.size(); |
1560 | for (size_t __i = 0; __i < __n; ++__i) |
1561 | __vp_[__1d_[__i]] -= __v[__i]; |
1562 | } |
1563 | |
1564 | template <class _Tp> |
1565 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1566 | inline void mask_array<_Tp>::operator^=(const _Expr& __v) const { |
1567 | size_t __n = __1d_.size(); |
1568 | for (size_t __i = 0; __i < __n; ++__i) |
1569 | __vp_[__1d_[__i]] ^= __v[__i]; |
1570 | } |
1571 | |
1572 | template <class _Tp> |
1573 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1574 | inline void mask_array<_Tp>::operator&=(const _Expr& __v) const { |
1575 | size_t __n = __1d_.size(); |
1576 | for (size_t __i = 0; __i < __n; ++__i) |
1577 | __vp_[__1d_[__i]] &= __v[__i]; |
1578 | } |
1579 | |
1580 | template <class _Tp> |
1581 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1582 | inline void mask_array<_Tp>::operator|=(const _Expr& __v) const { |
1583 | size_t __n = __1d_.size(); |
1584 | for (size_t __i = 0; __i < __n; ++__i) |
1585 | __vp_[__1d_[__i]] |= __v[__i]; |
1586 | } |
1587 | |
1588 | template <class _Tp> |
1589 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1590 | inline void mask_array<_Tp>::operator<<=(const _Expr& __v) const { |
1591 | size_t __n = __1d_.size(); |
1592 | for (size_t __i = 0; __i < __n; ++__i) |
1593 | __vp_[__1d_[__i]] <<= __v[__i]; |
1594 | } |
1595 | |
1596 | template <class _Tp> |
1597 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1598 | inline void mask_array<_Tp>::operator>>=(const _Expr& __v) const { |
1599 | size_t __n = __1d_.size(); |
1600 | for (size_t __i = 0; __i < __n; ++__i) |
1601 | __vp_[__1d_[__i]] >>= __v[__i]; |
1602 | } |
1603 | |
1604 | template <class _Tp> |
1605 | inline const mask_array<_Tp>& mask_array<_Tp>::operator=(const mask_array& __ma) const { |
1606 | size_t __n = __1d_.size(); |
1607 | for (size_t __i = 0; __i < __n; ++__i) |
1608 | __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]]; |
1609 | return *this; |
1610 | } |
1611 | |
1612 | template <class _Tp> |
1613 | inline void mask_array<_Tp>::operator=(const value_type& __x) const { |
1614 | size_t __n = __1d_.size(); |
1615 | for (size_t __i = 0; __i < __n; ++__i) |
1616 | __vp_[__1d_[__i]] = __x; |
1617 | } |
1618 | |
1619 | template <class _ValExpr> |
1620 | class __mask_expr { |
1621 | typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr; |
1622 | |
1623 | public: |
1624 | typedef typename _RmExpr::value_type value_type; |
1625 | typedef value_type __result_type; |
1626 | |
1627 | private: |
1628 | _ValExpr __expr_; |
1629 | valarray<size_t> __1d_; |
1630 | |
1631 | _LIBCPP_HIDE_FROM_ABI __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e) |
1632 | : __expr_(__e), __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true))) { |
1633 | size_t __j = 0; |
1634 | for (size_t __i = 0; __i < __vb.size(); ++__i) |
1635 | if (__vb[__i]) |
1636 | __1d_[__j++] = __i; |
1637 | } |
1638 | |
1639 | public: |
1640 | _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __expr_[__1d_[__i]]; } |
1641 | |
1642 | _LIBCPP_HIDE_FROM_ABI size_t size() const { return __1d_.size(); } |
1643 | |
1644 | template <class> |
1645 | friend class __val_expr; |
1646 | template <class> |
1647 | friend class valarray; |
1648 | }; |
1649 | |
1650 | // indirect_array |
1651 | |
1652 | template <class _Tp> |
1653 | class _LIBCPP_TEMPLATE_VIS indirect_array { |
1654 | public: |
1655 | typedef _Tp value_type; |
1656 | |
1657 | private: |
1658 | value_type* __vp_; |
1659 | valarray<size_t> __1d_; |
1660 | |
1661 | public: |
1662 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1663 | void _LIBCPP_HIDE_FROM_ABI operator=(const _Expr& __v) const; |
1664 | |
1665 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1666 | void _LIBCPP_HIDE_FROM_ABI operator*=(const _Expr& __v) const; |
1667 | |
1668 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1669 | void _LIBCPP_HIDE_FROM_ABI operator/=(const _Expr& __v) const; |
1670 | |
1671 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1672 | void _LIBCPP_HIDE_FROM_ABI operator%=(const _Expr& __v) const; |
1673 | |
1674 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1675 | void _LIBCPP_HIDE_FROM_ABI operator+=(const _Expr& __v) const; |
1676 | |
1677 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1678 | void _LIBCPP_HIDE_FROM_ABI operator-=(const _Expr& __v) const; |
1679 | |
1680 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1681 | void _LIBCPP_HIDE_FROM_ABI operator^=(const _Expr& __v) const; |
1682 | |
1683 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1684 | void _LIBCPP_HIDE_FROM_ABI operator&=(const _Expr& __v) const; |
1685 | |
1686 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1687 | void _LIBCPP_HIDE_FROM_ABI operator|=(const _Expr& __v) const; |
1688 | |
1689 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1690 | void _LIBCPP_HIDE_FROM_ABI operator<<=(const _Expr& __v) const; |
1691 | |
1692 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
1693 | void _LIBCPP_HIDE_FROM_ABI operator>>=(const _Expr& __v) const; |
1694 | |
1695 | indirect_array(const indirect_array&) = default; |
1696 | |
1697 | _LIBCPP_HIDE_FROM_ABI const indirect_array& operator=(const indirect_array& __ia) const; |
1698 | |
1699 | _LIBCPP_HIDE_FROM_ABI void operator=(const value_type& __x) const; |
1700 | |
1701 | // Behaves like __val_expr::operator[], which returns by value. |
1702 | _LIBCPP_HIDE_FROM_ABI value_type __get(size_t __i) const { |
1703 | _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __1d_.size(), "indirect_array.__get() index out of bounds" ); |
1704 | return __vp_[__1d_[__i]]; |
1705 | } |
1706 | |
1707 | private: |
1708 | _LIBCPP_HIDE_FROM_ABI indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v) |
1709 | : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(__ia) {} |
1710 | |
1711 | #ifndef _LIBCPP_CXX03_LANG |
1712 | |
1713 | _LIBCPP_HIDE_FROM_ABI indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v) |
1714 | : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(std::move(__ia)) {} |
1715 | |
1716 | #endif // _LIBCPP_CXX03_LANG |
1717 | |
1718 | template <class> |
1719 | friend class valarray; |
1720 | }; |
1721 | |
1722 | template <class _Tp> |
1723 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1724 | inline void indirect_array<_Tp>::operator=(const _Expr& __v) const { |
1725 | size_t __n = __1d_.size(); |
1726 | for (size_t __i = 0; __i < __n; ++__i) |
1727 | __vp_[__1d_[__i]] = __v[__i]; |
1728 | } |
1729 | |
1730 | template <class _Tp> |
1731 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1732 | inline void indirect_array<_Tp>::operator*=(const _Expr& __v) const { |
1733 | size_t __n = __1d_.size(); |
1734 | for (size_t __i = 0; __i < __n; ++__i) |
1735 | __vp_[__1d_[__i]] *= __v[__i]; |
1736 | } |
1737 | |
1738 | template <class _Tp> |
1739 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1740 | inline void indirect_array<_Tp>::operator/=(const _Expr& __v) const { |
1741 | size_t __n = __1d_.size(); |
1742 | for (size_t __i = 0; __i < __n; ++__i) |
1743 | __vp_[__1d_[__i]] /= __v[__i]; |
1744 | } |
1745 | |
1746 | template <class _Tp> |
1747 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1748 | inline void indirect_array<_Tp>::operator%=(const _Expr& __v) const { |
1749 | size_t __n = __1d_.size(); |
1750 | for (size_t __i = 0; __i < __n; ++__i) |
1751 | __vp_[__1d_[__i]] %= __v[__i]; |
1752 | } |
1753 | |
1754 | template <class _Tp> |
1755 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1756 | inline void indirect_array<_Tp>::operator+=(const _Expr& __v) const { |
1757 | size_t __n = __1d_.size(); |
1758 | for (size_t __i = 0; __i < __n; ++__i) |
1759 | __vp_[__1d_[__i]] += __v[__i]; |
1760 | } |
1761 | |
1762 | template <class _Tp> |
1763 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1764 | inline void indirect_array<_Tp>::operator-=(const _Expr& __v) const { |
1765 | size_t __n = __1d_.size(); |
1766 | for (size_t __i = 0; __i < __n; ++__i) |
1767 | __vp_[__1d_[__i]] -= __v[__i]; |
1768 | } |
1769 | |
1770 | template <class _Tp> |
1771 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1772 | inline void indirect_array<_Tp>::operator^=(const _Expr& __v) const { |
1773 | size_t __n = __1d_.size(); |
1774 | for (size_t __i = 0; __i < __n; ++__i) |
1775 | __vp_[__1d_[__i]] ^= __v[__i]; |
1776 | } |
1777 | |
1778 | template <class _Tp> |
1779 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1780 | inline void indirect_array<_Tp>::operator&=(const _Expr& __v) const { |
1781 | size_t __n = __1d_.size(); |
1782 | for (size_t __i = 0; __i < __n; ++__i) |
1783 | __vp_[__1d_[__i]] &= __v[__i]; |
1784 | } |
1785 | |
1786 | template <class _Tp> |
1787 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1788 | inline void indirect_array<_Tp>::operator|=(const _Expr& __v) const { |
1789 | size_t __n = __1d_.size(); |
1790 | for (size_t __i = 0; __i < __n; ++__i) |
1791 | __vp_[__1d_[__i]] |= __v[__i]; |
1792 | } |
1793 | |
1794 | template <class _Tp> |
1795 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1796 | inline void indirect_array<_Tp>::operator<<=(const _Expr& __v) const { |
1797 | size_t __n = __1d_.size(); |
1798 | for (size_t __i = 0; __i < __n; ++__i) |
1799 | __vp_[__1d_[__i]] <<= __v[__i]; |
1800 | } |
1801 | |
1802 | template <class _Tp> |
1803 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
1804 | inline void indirect_array<_Tp>::operator>>=(const _Expr& __v) const { |
1805 | size_t __n = __1d_.size(); |
1806 | for (size_t __i = 0; __i < __n; ++__i) |
1807 | __vp_[__1d_[__i]] >>= __v[__i]; |
1808 | } |
1809 | |
1810 | template <class _Tp> |
1811 | inline const indirect_array<_Tp>& indirect_array<_Tp>::operator=(const indirect_array& __ia) const { |
1812 | typedef const size_t* _Ip; |
1813 | const value_type* __s = __ia.__vp_; |
1814 | for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_; __i != __e; ++__i, ++__j) |
1815 | __vp_[*__i] = __s[*__j]; |
1816 | return *this; |
1817 | } |
1818 | |
1819 | template <class _Tp> |
1820 | inline void indirect_array<_Tp>::operator=(const value_type& __x) const { |
1821 | typedef const size_t* _Ip; |
1822 | for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i) |
1823 | __vp_[*__i] = __x; |
1824 | } |
1825 | |
1826 | template <class _ValExpr> |
1827 | class __indirect_expr { |
1828 | typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr; |
1829 | |
1830 | public: |
1831 | typedef typename _RmExpr::value_type value_type; |
1832 | typedef value_type __result_type; |
1833 | |
1834 | private: |
1835 | _ValExpr __expr_; |
1836 | valarray<size_t> __1d_; |
1837 | |
1838 | _LIBCPP_HIDE_FROM_ABI __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e) : __expr_(__e), __1d_(__ia) {} |
1839 | |
1840 | #ifndef _LIBCPP_CXX03_LANG |
1841 | |
1842 | _LIBCPP_HIDE_FROM_ABI __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e) |
1843 | : __expr_(__e), __1d_(std::move(__ia)) {} |
1844 | |
1845 | #endif // _LIBCPP_CXX03_LANG |
1846 | |
1847 | public: |
1848 | _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __expr_[__1d_[__i]]; } |
1849 | |
1850 | _LIBCPP_HIDE_FROM_ABI size_t size() const { return __1d_.size(); } |
1851 | |
1852 | template <class> |
1853 | friend class __val_expr; |
1854 | template <class> |
1855 | friend class _LIBCPP_TEMPLATE_VIS valarray; |
1856 | }; |
1857 | |
1858 | template <class _ValExpr> |
1859 | class __val_expr { |
1860 | typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr; |
1861 | |
1862 | _ValExpr __expr_; |
1863 | |
1864 | public: |
1865 | typedef typename _RmExpr::value_type value_type; |
1866 | typedef typename _RmExpr::__result_type __result_type; |
1867 | |
1868 | _LIBCPP_HIDE_FROM_ABI explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {} |
1869 | |
1870 | _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __expr_[__i]; } |
1871 | |
1872 | _LIBCPP_HIDE_FROM_ABI __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const { |
1873 | typedef __slice_expr<_ValExpr> _NewExpr; |
1874 | return __val_expr< _NewExpr >(_NewExpr(__s, __expr_)); |
1875 | } |
1876 | |
1877 | _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const { |
1878 | typedef __indirect_expr<_ValExpr> _NewExpr; |
1879 | return __val_expr<_NewExpr >(_NewExpr(__gs.__1d_, __expr_)); |
1880 | } |
1881 | |
1882 | _LIBCPP_HIDE_FROM_ABI __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const { |
1883 | typedef __mask_expr<_ValExpr> _NewExpr; |
1884 | return __val_expr< _NewExpr >(_NewExpr(__vb, __expr_)); |
1885 | } |
1886 | |
1887 | _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const { |
1888 | typedef __indirect_expr<_ValExpr> _NewExpr; |
1889 | return __val_expr< _NewExpr >(_NewExpr(__vs, __expr_)); |
1890 | } |
1891 | |
1892 | _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> > operator+() const { |
1893 | typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr; |
1894 | return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_)); |
1895 | } |
1896 | |
1897 | _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<negate<value_type>, _ValExpr> > operator-() const { |
1898 | typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr; |
1899 | return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_)); |
1900 | } |
1901 | |
1902 | _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> > operator~() const { |
1903 | typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr; |
1904 | return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_)); |
1905 | } |
1906 | |
1907 | _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> > operator!() const { |
1908 | typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr; |
1909 | return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_)); |
1910 | } |
1911 | |
1912 | operator valarray<__result_type>() const; |
1913 | |
1914 | _LIBCPP_HIDE_FROM_ABI size_t size() const { return __expr_.size(); } |
1915 | |
1916 | _LIBCPP_HIDE_FROM_ABI __result_type sum() const { |
1917 | size_t __n = __expr_.size(); |
1918 | __result_type __r = __n ? __expr_[0] : __result_type(); |
1919 | for (size_t __i = 1; __i < __n; ++__i) |
1920 | __r += __expr_[__i]; |
1921 | return __r; |
1922 | } |
1923 | |
1924 | _LIBCPP_HIDE_FROM_ABI __result_type min() const { |
1925 | size_t __n = size(); |
1926 | __result_type __r = __n ? (*this)[0] : __result_type(); |
1927 | for (size_t __i = 1; __i < __n; ++__i) { |
1928 | __result_type __x = __expr_[__i]; |
1929 | if (__x < __r) |
1930 | __r = __x; |
1931 | } |
1932 | return __r; |
1933 | } |
1934 | |
1935 | _LIBCPP_HIDE_FROM_ABI __result_type max() const { |
1936 | size_t __n = size(); |
1937 | __result_type __r = __n ? (*this)[0] : __result_type(); |
1938 | for (size_t __i = 1; __i < __n; ++__i) { |
1939 | __result_type __x = __expr_[__i]; |
1940 | if (__r < __x) |
1941 | __r = __x; |
1942 | } |
1943 | return __r; |
1944 | } |
1945 | |
1946 | _LIBCPP_HIDE_FROM_ABI __val_expr<__shift_expr<_ValExpr> > shift(int __i) const { |
1947 | return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_)); |
1948 | } |
1949 | |
1950 | _LIBCPP_HIDE_FROM_ABI __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const { |
1951 | return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_)); |
1952 | } |
1953 | |
1954 | _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__apply_expr<value_type, value_type (*)(value_type)>, _ValExpr> > |
1955 | apply(value_type __f(value_type)) const { |
1956 | typedef __apply_expr<value_type, value_type (*)(value_type)> _Op; |
1957 | typedef _UnaryOp<_Op, _ValExpr> _NewExpr; |
1958 | return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_)); |
1959 | } |
1960 | |
1961 | _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__apply_expr<value_type, value_type (*)(const value_type&)>, _ValExpr> > |
1962 | apply(value_type __f(const value_type&)) const { |
1963 | typedef __apply_expr<value_type, value_type (*)(const value_type&)> _Op; |
1964 | typedef _UnaryOp<_Op, _ValExpr> _NewExpr; |
1965 | return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_)); |
1966 | } |
1967 | }; |
1968 | |
1969 | template <class _ValExpr> |
1970 | __val_expr<_ValExpr>::operator valarray<__val_expr::__result_type>() const { |
1971 | valarray<__result_type> __r; |
1972 | size_t __n = __expr_.size(); |
1973 | if (__n) { |
1974 | __r.__begin_ = __r.__end_ = allocator<__result_type>().allocate(__n); |
1975 | for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i) |
1976 | ::new ((void*)__r.__end_) __result_type(__expr_[__i]); |
1977 | } |
1978 | return __r; |
1979 | } |
1980 | |
1981 | // valarray |
1982 | |
1983 | template <class _Tp> |
1984 | inline valarray<_Tp>::valarray(size_t __n) : __begin_(nullptr), __end_(nullptr) { |
1985 | if (__n) { |
1986 | __begin_ = __end_ = allocator<value_type>().allocate(__n); |
1987 | #ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
1988 | try { |
1989 | #endif // _LIBCPP_HAS_NO_EXCEPTIONS |
1990 | for (size_t __n_left = __n; __n_left; --__n_left, ++__end_) |
1991 | ::new ((void*)__end_) value_type(); |
1992 | #ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
1993 | } catch (...) { |
1994 | __clear(__n); |
1995 | throw; |
1996 | } |
1997 | #endif // _LIBCPP_HAS_NO_EXCEPTIONS |
1998 | } |
1999 | } |
2000 | |
2001 | template <class _Tp> |
2002 | inline valarray<_Tp>::valarray(const value_type& __x, size_t __n) : __begin_(nullptr), __end_(nullptr) { |
2003 | resize(__n, __x); |
2004 | } |
2005 | |
2006 | template <class _Tp> |
2007 | valarray<_Tp>::valarray(const value_type* __p, size_t __n) : __begin_(nullptr), __end_(nullptr) { |
2008 | if (__n) { |
2009 | __begin_ = __end_ = allocator<value_type>().allocate(__n); |
2010 | #ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
2011 | try { |
2012 | #endif // _LIBCPP_HAS_NO_EXCEPTIONS |
2013 | for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left) |
2014 | ::new ((void*)__end_) value_type(*__p); |
2015 | #ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
2016 | } catch (...) { |
2017 | __clear(__n); |
2018 | throw; |
2019 | } |
2020 | #endif // _LIBCPP_HAS_NO_EXCEPTIONS |
2021 | } |
2022 | } |
2023 | |
2024 | template <class _Tp> |
2025 | valarray<_Tp>::valarray(const valarray& __v) : __begin_(nullptr), __end_(nullptr) { |
2026 | if (__v.size()) { |
2027 | __begin_ = __end_ = allocator<value_type>().allocate(__v.size()); |
2028 | #ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
2029 | try { |
2030 | #endif // _LIBCPP_HAS_NO_EXCEPTIONS |
2031 | for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p) |
2032 | ::new ((void*)__end_) value_type(*__p); |
2033 | #ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
2034 | } catch (...) { |
2035 | __clear(__v.size()); |
2036 | throw; |
2037 | } |
2038 | #endif // _LIBCPP_HAS_NO_EXCEPTIONS |
2039 | } |
2040 | } |
2041 | |
2042 | #ifndef _LIBCPP_CXX03_LANG |
2043 | |
2044 | template <class _Tp> |
2045 | inline valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT : __begin_(__v.__begin_), __end_(__v.__end_) { |
2046 | __v.__begin_ = __v.__end_ = nullptr; |
2047 | } |
2048 | |
2049 | template <class _Tp> |
2050 | valarray<_Tp>::valarray(initializer_list<value_type> __il) : __begin_(nullptr), __end_(nullptr) { |
2051 | const size_t __n = __il.size(); |
2052 | if (__n) { |
2053 | __begin_ = __end_ = allocator<value_type>().allocate(__n); |
2054 | # ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
2055 | try { |
2056 | # endif // _LIBCPP_HAS_NO_EXCEPTIONS |
2057 | size_t __n_left = __n; |
2058 | for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left) |
2059 | ::new ((void*)__end_) value_type(*__p); |
2060 | # ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
2061 | } catch (...) { |
2062 | __clear(__n); |
2063 | throw; |
2064 | } |
2065 | # endif // _LIBCPP_HAS_NO_EXCEPTIONS |
2066 | } |
2067 | } |
2068 | |
2069 | #endif // _LIBCPP_CXX03_LANG |
2070 | |
2071 | template <class _Tp> |
2072 | valarray<_Tp>::valarray(const slice_array<value_type>& __sa) : __begin_(nullptr), __end_(nullptr) { |
2073 | const size_t __n = __sa.__size_; |
2074 | if (__n) { |
2075 | __begin_ = __end_ = allocator<value_type>().allocate(__n); |
2076 | #ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
2077 | try { |
2078 | #endif // _LIBCPP_HAS_NO_EXCEPTIONS |
2079 | size_t __n_left = __n; |
2080 | for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left) |
2081 | ::new ((void*)__end_) value_type(*__p); |
2082 | #ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
2083 | } catch (...) { |
2084 | __clear(__n); |
2085 | throw; |
2086 | } |
2087 | #endif // _LIBCPP_HAS_NO_EXCEPTIONS |
2088 | } |
2089 | } |
2090 | |
2091 | template <class _Tp> |
2092 | valarray<_Tp>::valarray(const gslice_array<value_type>& __ga) : __begin_(nullptr), __end_(nullptr) { |
2093 | const size_t __n = __ga.__1d_.size(); |
2094 | if (__n) { |
2095 | __begin_ = __end_ = allocator<value_type>().allocate(__n); |
2096 | #ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
2097 | try { |
2098 | #endif // _LIBCPP_HAS_NO_EXCEPTIONS |
2099 | typedef const size_t* _Ip; |
2100 | const value_type* __s = __ga.__vp_; |
2101 | for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; __i != __e; ++__i, ++__end_) |
2102 | ::new ((void*)__end_) value_type(__s[*__i]); |
2103 | #ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
2104 | } catch (...) { |
2105 | __clear(__n); |
2106 | throw; |
2107 | } |
2108 | #endif // _LIBCPP_HAS_NO_EXCEPTIONS |
2109 | } |
2110 | } |
2111 | |
2112 | template <class _Tp> |
2113 | valarray<_Tp>::valarray(const mask_array<value_type>& __ma) : __begin_(nullptr), __end_(nullptr) { |
2114 | const size_t __n = __ma.__1d_.size(); |
2115 | if (__n) { |
2116 | __begin_ = __end_ = allocator<value_type>().allocate(__n); |
2117 | #ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
2118 | try { |
2119 | #endif // _LIBCPP_HAS_NO_EXCEPTIONS |
2120 | typedef const size_t* _Ip; |
2121 | const value_type* __s = __ma.__vp_; |
2122 | for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; __i != __e; ++__i, ++__end_) |
2123 | ::new ((void*)__end_) value_type(__s[*__i]); |
2124 | #ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
2125 | } catch (...) { |
2126 | __clear(__n); |
2127 | throw; |
2128 | } |
2129 | #endif // _LIBCPP_HAS_NO_EXCEPTIONS |
2130 | } |
2131 | } |
2132 | |
2133 | template <class _Tp> |
2134 | valarray<_Tp>::valarray(const indirect_array<value_type>& __ia) : __begin_(nullptr), __end_(nullptr) { |
2135 | const size_t __n = __ia.__1d_.size(); |
2136 | if (__n) { |
2137 | __begin_ = __end_ = allocator<value_type>().allocate(__n); |
2138 | #ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
2139 | try { |
2140 | #endif // _LIBCPP_HAS_NO_EXCEPTIONS |
2141 | typedef const size_t* _Ip; |
2142 | const value_type* __s = __ia.__vp_; |
2143 | for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; __i != __e; ++__i, ++__end_) |
2144 | ::new ((void*)__end_) value_type(__s[*__i]); |
2145 | #ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
2146 | } catch (...) { |
2147 | __clear(__n); |
2148 | throw; |
2149 | } |
2150 | #endif // _LIBCPP_HAS_NO_EXCEPTIONS |
2151 | } |
2152 | } |
2153 | |
2154 | template <class _Tp> |
2155 | inline valarray<_Tp>::~valarray() { |
2156 | __clear(size()); |
2157 | } |
2158 | |
2159 | template <class _Tp> |
2160 | valarray<_Tp>& valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l) { |
2161 | size_t __n = __l - __f; |
2162 | if (size() != __n) { |
2163 | __clear(size()); |
2164 | __begin_ = allocator<value_type>().allocate(__n); |
2165 | __end_ = __begin_ + __n; |
2166 | std::uninitialized_copy(__f, __l, __begin_); |
2167 | } else { |
2168 | std::copy(__f, __l, __begin_); |
2169 | } |
2170 | return *this; |
2171 | } |
2172 | |
2173 | template <class _Tp> |
2174 | valarray<_Tp>& valarray<_Tp>::operator=(const valarray& __v) { |
2175 | if (this != std::addressof(__v)) |
2176 | return __assign_range(__v.__begin_, __v.__end_); |
2177 | return *this; |
2178 | } |
2179 | |
2180 | #ifndef _LIBCPP_CXX03_LANG |
2181 | |
2182 | template <class _Tp> |
2183 | inline valarray<_Tp>& valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT { |
2184 | __clear(size()); |
2185 | __begin_ = __v.__begin_; |
2186 | __end_ = __v.__end_; |
2187 | __v.__begin_ = nullptr; |
2188 | __v.__end_ = nullptr; |
2189 | return *this; |
2190 | } |
2191 | |
2192 | template <class _Tp> |
2193 | inline valarray<_Tp>& valarray<_Tp>::operator=(initializer_list<value_type> __il) { |
2194 | return __assign_range(__il.begin(), __il.end()); |
2195 | } |
2196 | |
2197 | #endif // _LIBCPP_CXX03_LANG |
2198 | |
2199 | template <class _Tp> |
2200 | inline valarray<_Tp>& valarray<_Tp>::operator=(const value_type& __x) { |
2201 | std::fill(__begin_, __end_, __x); |
2202 | return *this; |
2203 | } |
2204 | |
2205 | template <class _Tp> |
2206 | inline valarray<_Tp>& valarray<_Tp>::operator=(const slice_array<value_type>& __sa) { |
2207 | value_type* __t = __begin_; |
2208 | const value_type* __s = __sa.__vp_; |
2209 | for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t) |
2210 | *__t = *__s; |
2211 | return *this; |
2212 | } |
2213 | |
2214 | template <class _Tp> |
2215 | inline valarray<_Tp>& valarray<_Tp>::operator=(const gslice_array<value_type>& __ga) { |
2216 | typedef const size_t* _Ip; |
2217 | value_type* __t = __begin_; |
2218 | const value_type* __s = __ga.__vp_; |
2219 | for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; __i != __e; ++__i, ++__t) |
2220 | *__t = __s[*__i]; |
2221 | return *this; |
2222 | } |
2223 | |
2224 | template <class _Tp> |
2225 | inline valarray<_Tp>& valarray<_Tp>::operator=(const mask_array<value_type>& __ma) { |
2226 | typedef const size_t* _Ip; |
2227 | value_type* __t = __begin_; |
2228 | const value_type* __s = __ma.__vp_; |
2229 | for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; __i != __e; ++__i, ++__t) |
2230 | *__t = __s[*__i]; |
2231 | return *this; |
2232 | } |
2233 | |
2234 | template <class _Tp> |
2235 | inline valarray<_Tp>& valarray<_Tp>::operator=(const indirect_array<value_type>& __ia) { |
2236 | typedef const size_t* _Ip; |
2237 | value_type* __t = __begin_; |
2238 | const value_type* __s = __ia.__vp_; |
2239 | for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; __i != __e; ++__i, ++__t) |
2240 | *__t = __s[*__i]; |
2241 | return *this; |
2242 | } |
2243 | |
2244 | template <class _Tp> |
2245 | template <class _ValExpr> |
2246 | inline valarray<_Tp>& valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v) { |
2247 | size_t __n = __v.size(); |
2248 | if (size() != __n) |
2249 | resize(__n); |
2250 | value_type* __t = __begin_; |
2251 | for (size_t __i = 0; __i != __n; ++__t, ++__i) |
2252 | *__t = __result_type(__v[__i]); |
2253 | return *this; |
2254 | } |
2255 | |
2256 | template <class _Tp> |
2257 | inline __val_expr<__slice_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](slice __s) const { |
2258 | return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this)); |
2259 | } |
2260 | |
2261 | template <class _Tp> |
2262 | inline slice_array<_Tp> valarray<_Tp>::operator[](slice __s) { |
2263 | return slice_array<value_type>(__s, *this); |
2264 | } |
2265 | |
2266 | template <class _Tp> |
2267 | inline __val_expr<__indirect_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](const gslice& __gs) const { |
2268 | return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this)); |
2269 | } |
2270 | |
2271 | template <class _Tp> |
2272 | inline gslice_array<_Tp> valarray<_Tp>::operator[](const gslice& __gs) { |
2273 | return gslice_array<value_type>(__gs, *this); |
2274 | } |
2275 | |
2276 | #ifndef _LIBCPP_CXX03_LANG |
2277 | |
2278 | template <class _Tp> |
2279 | inline __val_expr<__indirect_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](gslice&& __gs) const { |
2280 | return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(std::move(__gs.__1d_), *this)); |
2281 | } |
2282 | |
2283 | template <class _Tp> |
2284 | inline gslice_array<_Tp> valarray<_Tp>::operator[](gslice&& __gs) { |
2285 | return gslice_array<value_type>(std::move(__gs), *this); |
2286 | } |
2287 | |
2288 | #endif // _LIBCPP_CXX03_LANG |
2289 | |
2290 | template <class _Tp> |
2291 | inline __val_expr<__mask_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](const valarray<bool>& __vb) const { |
2292 | return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this)); |
2293 | } |
2294 | |
2295 | template <class _Tp> |
2296 | inline mask_array<_Tp> valarray<_Tp>::operator[](const valarray<bool>& __vb) { |
2297 | return mask_array<value_type>(__vb, *this); |
2298 | } |
2299 | |
2300 | #ifndef _LIBCPP_CXX03_LANG |
2301 | |
2302 | template <class _Tp> |
2303 | inline __val_expr<__mask_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](valarray<bool>&& __vb) const { |
2304 | return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(std::move(__vb), *this)); |
2305 | } |
2306 | |
2307 | template <class _Tp> |
2308 | inline mask_array<_Tp> valarray<_Tp>::operator[](valarray<bool>&& __vb) { |
2309 | return mask_array<value_type>(std::move(__vb), *this); |
2310 | } |
2311 | |
2312 | #endif // _LIBCPP_CXX03_LANG |
2313 | |
2314 | template <class _Tp> |
2315 | inline __val_expr<__indirect_expr<const valarray<_Tp>&> > |
2316 | valarray<_Tp>::operator[](const valarray<size_t>& __vs) const { |
2317 | return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this)); |
2318 | } |
2319 | |
2320 | template <class _Tp> |
2321 | inline indirect_array<_Tp> valarray<_Tp>::operator[](const valarray<size_t>& __vs) { |
2322 | return indirect_array<value_type>(__vs, *this); |
2323 | } |
2324 | |
2325 | #ifndef _LIBCPP_CXX03_LANG |
2326 | |
2327 | template <class _Tp> |
2328 | inline __val_expr<__indirect_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](valarray<size_t>&& __vs) const { |
2329 | return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(std::move(__vs), *this)); |
2330 | } |
2331 | |
2332 | template <class _Tp> |
2333 | inline indirect_array<_Tp> valarray<_Tp>::operator[](valarray<size_t>&& __vs) { |
2334 | return indirect_array<value_type>(std::move(__vs), *this); |
2335 | } |
2336 | |
2337 | #endif // _LIBCPP_CXX03_LANG |
2338 | |
2339 | template <class _Tp> |
2340 | inline __val_expr<_UnaryOp<__unary_plus<_Tp>, const valarray<_Tp>&> > valarray<_Tp>::operator+() const { |
2341 | using _Op = _UnaryOp<__unary_plus<_Tp>, const valarray<_Tp>&>; |
2342 | return __val_expr<_Op>(_Op(__unary_plus<_Tp>(), *this)); |
2343 | } |
2344 | |
2345 | template <class _Tp> |
2346 | inline __val_expr<_UnaryOp<negate<_Tp>, const valarray<_Tp>&> > valarray<_Tp>::operator-() const { |
2347 | using _Op = _UnaryOp<negate<_Tp>, const valarray<_Tp>&>; |
2348 | return __val_expr<_Op>(_Op(negate<_Tp>(), *this)); |
2349 | } |
2350 | |
2351 | template <class _Tp> |
2352 | inline __val_expr<_UnaryOp<__bit_not<_Tp>, const valarray<_Tp>&> > valarray<_Tp>::operator~() const { |
2353 | using _Op = _UnaryOp<__bit_not<_Tp>, const valarray<_Tp>&>; |
2354 | return __val_expr<_Op>(_Op(__bit_not<_Tp>(), *this)); |
2355 | } |
2356 | |
2357 | template <class _Tp> |
2358 | inline __val_expr<_UnaryOp<logical_not<_Tp>, const valarray<_Tp>&> > valarray<_Tp>::operator!() const { |
2359 | using _Op = _UnaryOp<logical_not<_Tp>, const valarray<_Tp>&>; |
2360 | return __val_expr<_Op>(_Op(logical_not<_Tp>(), *this)); |
2361 | } |
2362 | |
2363 | template <class _Tp> |
2364 | inline valarray<_Tp>& valarray<_Tp>::operator*=(const value_type& __x) { |
2365 | for (value_type* __p = __begin_; __p != __end_; ++__p) |
2366 | *__p *= __x; |
2367 | return *this; |
2368 | } |
2369 | |
2370 | template <class _Tp> |
2371 | inline valarray<_Tp>& valarray<_Tp>::operator/=(const value_type& __x) { |
2372 | for (value_type* __p = __begin_; __p != __end_; ++__p) |
2373 | *__p /= __x; |
2374 | return *this; |
2375 | } |
2376 | |
2377 | template <class _Tp> |
2378 | inline valarray<_Tp>& valarray<_Tp>::operator%=(const value_type& __x) { |
2379 | for (value_type* __p = __begin_; __p != __end_; ++__p) |
2380 | *__p %= __x; |
2381 | return *this; |
2382 | } |
2383 | |
2384 | template <class _Tp> |
2385 | inline valarray<_Tp>& valarray<_Tp>::operator+=(const value_type& __x) { |
2386 | for (value_type* __p = __begin_; __p != __end_; ++__p) |
2387 | *__p += __x; |
2388 | return *this; |
2389 | } |
2390 | |
2391 | template <class _Tp> |
2392 | inline valarray<_Tp>& valarray<_Tp>::operator-=(const value_type& __x) { |
2393 | for (value_type* __p = __begin_; __p != __end_; ++__p) |
2394 | *__p -= __x; |
2395 | return *this; |
2396 | } |
2397 | |
2398 | template <class _Tp> |
2399 | inline valarray<_Tp>& valarray<_Tp>::operator^=(const value_type& __x) { |
2400 | for (value_type* __p = __begin_; __p != __end_; ++__p) |
2401 | *__p ^= __x; |
2402 | return *this; |
2403 | } |
2404 | |
2405 | template <class _Tp> |
2406 | inline valarray<_Tp>& valarray<_Tp>::operator&=(const value_type& __x) { |
2407 | for (value_type* __p = __begin_; __p != __end_; ++__p) |
2408 | *__p &= __x; |
2409 | return *this; |
2410 | } |
2411 | |
2412 | template <class _Tp> |
2413 | inline valarray<_Tp>& valarray<_Tp>::operator|=(const value_type& __x) { |
2414 | for (value_type* __p = __begin_; __p != __end_; ++__p) |
2415 | *__p |= __x; |
2416 | return *this; |
2417 | } |
2418 | |
2419 | template <class _Tp> |
2420 | inline valarray<_Tp>& valarray<_Tp>::operator<<=(const value_type& __x) { |
2421 | for (value_type* __p = __begin_; __p != __end_; ++__p) |
2422 | *__p <<= __x; |
2423 | return *this; |
2424 | } |
2425 | |
2426 | template <class _Tp> |
2427 | inline valarray<_Tp>& valarray<_Tp>::operator>>=(const value_type& __x) { |
2428 | for (value_type* __p = __begin_; __p != __end_; ++__p) |
2429 | *__p >>= __x; |
2430 | return *this; |
2431 | } |
2432 | |
2433 | template <class _Tp> |
2434 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
2435 | inline valarray<_Tp>& valarray<_Tp>::operator*=(const _Expr& __v) { |
2436 | size_t __i = 0; |
2437 | for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i) |
2438 | *__t *= std::__get(__v, __i); |
2439 | return *this; |
2440 | } |
2441 | |
2442 | template <class _Tp> |
2443 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
2444 | inline valarray<_Tp>& valarray<_Tp>::operator/=(const _Expr& __v) { |
2445 | size_t __i = 0; |
2446 | for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i) |
2447 | *__t /= std::__get(__v, __i); |
2448 | return *this; |
2449 | } |
2450 | |
2451 | template <class _Tp> |
2452 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
2453 | inline valarray<_Tp>& valarray<_Tp>::operator%=(const _Expr& __v) { |
2454 | size_t __i = 0; |
2455 | for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i) |
2456 | *__t %= std::__get(__v, __i); |
2457 | return *this; |
2458 | } |
2459 | |
2460 | template <class _Tp> |
2461 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
2462 | inline valarray<_Tp>& valarray<_Tp>::operator+=(const _Expr& __v) { |
2463 | size_t __i = 0; |
2464 | for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i) |
2465 | *__t += std::__get(__v, __i); |
2466 | return *this; |
2467 | } |
2468 | |
2469 | template <class _Tp> |
2470 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
2471 | inline valarray<_Tp>& valarray<_Tp>::operator-=(const _Expr& __v) { |
2472 | size_t __i = 0; |
2473 | for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i) |
2474 | *__t -= std::__get(__v, __i); |
2475 | return *this; |
2476 | } |
2477 | |
2478 | template <class _Tp> |
2479 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
2480 | inline valarray<_Tp>& valarray<_Tp>::operator^=(const _Expr& __v) { |
2481 | size_t __i = 0; |
2482 | for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i) |
2483 | *__t ^= std::__get(__v, __i); |
2484 | return *this; |
2485 | } |
2486 | |
2487 | template <class _Tp> |
2488 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
2489 | inline valarray<_Tp>& valarray<_Tp>::operator|=(const _Expr& __v) { |
2490 | size_t __i = 0; |
2491 | for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i) |
2492 | *__t |= std::__get(__v, __i); |
2493 | return *this; |
2494 | } |
2495 | |
2496 | template <class _Tp> |
2497 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
2498 | inline valarray<_Tp>& valarray<_Tp>::operator&=(const _Expr& __v) { |
2499 | size_t __i = 0; |
2500 | for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i) |
2501 | *__t &= std::__get(__v, __i); |
2502 | return *this; |
2503 | } |
2504 | |
2505 | template <class _Tp> |
2506 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
2507 | inline valarray<_Tp>& valarray<_Tp>::operator<<=(const _Expr& __v) { |
2508 | size_t __i = 0; |
2509 | for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i) |
2510 | *__t <<= std::__get(__v, __i); |
2511 | return *this; |
2512 | } |
2513 | |
2514 | template <class _Tp> |
2515 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> > |
2516 | inline valarray<_Tp>& valarray<_Tp>::operator>>=(const _Expr& __v) { |
2517 | size_t __i = 0; |
2518 | for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i) |
2519 | *__t >>= std::__get(__v, __i); |
2520 | return *this; |
2521 | } |
2522 | |
2523 | template <class _Tp> |
2524 | inline void valarray<_Tp>::swap(valarray& __v) _NOEXCEPT { |
2525 | std::swap(__begin_, __v.__begin_); |
2526 | std::swap(__end_, __v.__end_); |
2527 | } |
2528 | |
2529 | template <class _Tp> |
2530 | inline _Tp valarray<_Tp>::sum() const { |
2531 | if (__begin_ == __end_) |
2532 | return value_type(); |
2533 | const value_type* __p = __begin_; |
2534 | _Tp __r = *__p; |
2535 | for (++__p; __p != __end_; ++__p) |
2536 | __r += *__p; |
2537 | return __r; |
2538 | } |
2539 | |
2540 | template <class _Tp> |
2541 | inline _Tp valarray<_Tp>::min() const { |
2542 | if (__begin_ == __end_) |
2543 | return value_type(); |
2544 | return *std::min_element(__begin_, __end_); |
2545 | } |
2546 | |
2547 | template <class _Tp> |
2548 | inline _Tp valarray<_Tp>::max() const { |
2549 | if (__begin_ == __end_) |
2550 | return value_type(); |
2551 | return *std::max_element(__begin_, __end_); |
2552 | } |
2553 | |
2554 | template <class _Tp> |
2555 | valarray<_Tp> valarray<_Tp>::shift(int __i) const { |
2556 | valarray<value_type> __r; |
2557 | size_t __n = size(); |
2558 | if (__n) { |
2559 | __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n); |
2560 | const value_type* __sb; |
2561 | value_type* __tb; |
2562 | value_type* __te; |
2563 | if (__i >= 0) { |
2564 | __i = std::min(__i, static_cast<int>(__n)); |
2565 | __sb = __begin_ + __i; |
2566 | __tb = __r.__begin_; |
2567 | __te = __r.__begin_ + (__n - __i); |
2568 | } else { |
2569 | __i = std::min(-__i, static_cast<int>(__n)); |
2570 | __sb = __begin_; |
2571 | __tb = __r.__begin_ + __i; |
2572 | __te = __r.__begin_ + __n; |
2573 | } |
2574 | for (; __r.__end_ != __tb; ++__r.__end_) |
2575 | ::new ((void*)__r.__end_) value_type(); |
2576 | for (; __r.__end_ != __te; ++__r.__end_, ++__sb) |
2577 | ::new ((void*)__r.__end_) value_type(*__sb); |
2578 | for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_) |
2579 | ::new ((void*)__r.__end_) value_type(); |
2580 | } |
2581 | return __r; |
2582 | } |
2583 | |
2584 | template <class _Tp> |
2585 | valarray<_Tp> valarray<_Tp>::cshift(int __i) const { |
2586 | valarray<value_type> __r; |
2587 | size_t __n = size(); |
2588 | if (__n) { |
2589 | __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n); |
2590 | __i %= static_cast<int>(__n); |
2591 | const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i; |
2592 | for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s) |
2593 | ::new ((void*)__r.__end_) value_type(*__s); |
2594 | for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s) |
2595 | ::new ((void*)__r.__end_) value_type(*__s); |
2596 | } |
2597 | return __r; |
2598 | } |
2599 | |
2600 | template <class _Tp> |
2601 | valarray<_Tp> valarray<_Tp>::apply(value_type __f(value_type)) const { |
2602 | valarray<value_type> __r; |
2603 | size_t __n = size(); |
2604 | if (__n) { |
2605 | __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n); |
2606 | for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) |
2607 | ::new ((void*)__r.__end_) value_type(__f(*__p)); |
2608 | } |
2609 | return __r; |
2610 | } |
2611 | |
2612 | template <class _Tp> |
2613 | valarray<_Tp> valarray<_Tp>::apply(value_type __f(const value_type&)) const { |
2614 | valarray<value_type> __r; |
2615 | size_t __n = size(); |
2616 | if (__n) { |
2617 | __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n); |
2618 | for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) |
2619 | ::new ((void*)__r.__end_) value_type(__f(*__p)); |
2620 | } |
2621 | return __r; |
2622 | } |
2623 | |
2624 | template <class _Tp> |
2625 | inline void valarray<_Tp>::__clear(size_t __capacity) { |
2626 | if (__begin_ != nullptr) { |
2627 | while (__end_ != __begin_) |
2628 | (--__end_)->~value_type(); |
2629 | allocator<value_type>().deallocate(__begin_, __capacity); |
2630 | __begin_ = __end_ = nullptr; |
2631 | } |
2632 | } |
2633 | |
2634 | template <class _Tp> |
2635 | void valarray<_Tp>::resize(size_t __n, value_type __x) { |
2636 | __clear(size()); |
2637 | if (__n) { |
2638 | __begin_ = __end_ = allocator<value_type>().allocate(__n); |
2639 | #ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
2640 | try { |
2641 | #endif // _LIBCPP_HAS_NO_EXCEPTIONS |
2642 | for (size_t __n_left = __n; __n_left; --__n_left, ++__end_) |
2643 | ::new ((void*)__end_) value_type(__x); |
2644 | #ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
2645 | } catch (...) { |
2646 | __clear(__n); |
2647 | throw; |
2648 | } |
2649 | #endif // _LIBCPP_HAS_NO_EXCEPTIONS |
2650 | } |
2651 | } |
2652 | |
2653 | template <class _Tp> |
2654 | inline _LIBCPP_HIDE_FROM_ABI void swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT { |
2655 | __x.swap(__y); |
2656 | } |
2657 | |
2658 | template <class _Expr1, |
2659 | class _Expr2, |
2660 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
2661 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> > |
2662 | operator*(const _Expr1& __x, const _Expr2& __y) { |
2663 | typedef typename _Expr1::value_type value_type; |
2664 | typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op; |
2665 | return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y)); |
2666 | } |
2667 | |
2668 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2669 | inline _LIBCPP_HIDE_FROM_ABI |
2670 | __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
2671 | operator*(const _Expr& __x, const typename _Expr::value_type& __y) { |
2672 | typedef typename _Expr::value_type value_type; |
2673 | typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
2674 | return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
2675 | } |
2676 | |
2677 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2678 | inline _LIBCPP_HIDE_FROM_ABI |
2679 | __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
2680 | operator*(const typename _Expr::value_type& __x, const _Expr& __y) { |
2681 | typedef typename _Expr::value_type value_type; |
2682 | typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
2683 | return __val_expr<_Op>(_Op(multiplies<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
2684 | } |
2685 | |
2686 | template <class _Expr1, |
2687 | class _Expr2, |
2688 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
2689 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> > |
2690 | operator/(const _Expr1& __x, const _Expr2& __y) { |
2691 | typedef typename _Expr1::value_type value_type; |
2692 | typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op; |
2693 | return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y)); |
2694 | } |
2695 | |
2696 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2697 | inline _LIBCPP_HIDE_FROM_ABI |
2698 | __val_expr<_BinaryOp<divides<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
2699 | operator/(const _Expr& __x, const typename _Expr::value_type& __y) { |
2700 | typedef typename _Expr::value_type value_type; |
2701 | typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
2702 | return __val_expr<_Op>(_Op(divides<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
2703 | } |
2704 | |
2705 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2706 | inline _LIBCPP_HIDE_FROM_ABI |
2707 | __val_expr<_BinaryOp<divides<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
2708 | operator/(const typename _Expr::value_type& __x, const _Expr& __y) { |
2709 | typedef typename _Expr::value_type value_type; |
2710 | typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
2711 | return __val_expr<_Op>(_Op(divides<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
2712 | } |
2713 | |
2714 | template <class _Expr1, |
2715 | class _Expr2, |
2716 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
2717 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> > |
2718 | operator%(const _Expr1& __x, const _Expr2& __y) { |
2719 | typedef typename _Expr1::value_type value_type; |
2720 | typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op; |
2721 | return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y)); |
2722 | } |
2723 | |
2724 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2725 | inline _LIBCPP_HIDE_FROM_ABI |
2726 | __val_expr<_BinaryOp<modulus<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
2727 | operator%(const _Expr& __x, const typename _Expr::value_type& __y) { |
2728 | typedef typename _Expr::value_type value_type; |
2729 | typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
2730 | return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
2731 | } |
2732 | |
2733 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2734 | inline _LIBCPP_HIDE_FROM_ABI |
2735 | __val_expr<_BinaryOp<modulus<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
2736 | operator%(const typename _Expr::value_type& __x, const _Expr& __y) { |
2737 | typedef typename _Expr::value_type value_type; |
2738 | typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
2739 | return __val_expr<_Op>(_Op(modulus<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
2740 | } |
2741 | |
2742 | template <class _Expr1, |
2743 | class _Expr2, |
2744 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
2745 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> > |
2746 | operator+(const _Expr1& __x, const _Expr2& __y) { |
2747 | typedef typename _Expr1::value_type value_type; |
2748 | typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op; |
2749 | return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y)); |
2750 | } |
2751 | |
2752 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2753 | inline _LIBCPP_HIDE_FROM_ABI |
2754 | __val_expr<_BinaryOp<plus<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
2755 | operator+(const _Expr& __x, const typename _Expr::value_type& __y) { |
2756 | typedef typename _Expr::value_type value_type; |
2757 | typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
2758 | return __val_expr<_Op>(_Op(plus<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
2759 | } |
2760 | |
2761 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2762 | inline _LIBCPP_HIDE_FROM_ABI |
2763 | __val_expr<_BinaryOp<plus<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
2764 | operator+(const typename _Expr::value_type& __x, const _Expr& __y) { |
2765 | typedef typename _Expr::value_type value_type; |
2766 | typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
2767 | return __val_expr<_Op>(_Op(plus<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
2768 | } |
2769 | |
2770 | template <class _Expr1, |
2771 | class _Expr2, |
2772 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
2773 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> > |
2774 | operator-(const _Expr1& __x, const _Expr2& __y) { |
2775 | typedef typename _Expr1::value_type value_type; |
2776 | typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op; |
2777 | return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y)); |
2778 | } |
2779 | |
2780 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2781 | inline _LIBCPP_HIDE_FROM_ABI |
2782 | __val_expr<_BinaryOp<minus<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
2783 | operator-(const _Expr& __x, const typename _Expr::value_type& __y) { |
2784 | typedef typename _Expr::value_type value_type; |
2785 | typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
2786 | return __val_expr<_Op>(_Op(minus<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
2787 | } |
2788 | |
2789 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2790 | inline _LIBCPP_HIDE_FROM_ABI |
2791 | __val_expr<_BinaryOp<minus<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
2792 | operator-(const typename _Expr::value_type& __x, const _Expr& __y) { |
2793 | typedef typename _Expr::value_type value_type; |
2794 | typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
2795 | return __val_expr<_Op>(_Op(minus<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
2796 | } |
2797 | |
2798 | template <class _Expr1, |
2799 | class _Expr2, |
2800 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
2801 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> > |
2802 | operator^(const _Expr1& __x, const _Expr2& __y) { |
2803 | typedef typename _Expr1::value_type value_type; |
2804 | typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op; |
2805 | return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y)); |
2806 | } |
2807 | |
2808 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2809 | inline _LIBCPP_HIDE_FROM_ABI |
2810 | __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
2811 | operator^(const _Expr& __x, const typename _Expr::value_type& __y) { |
2812 | typedef typename _Expr::value_type value_type; |
2813 | typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
2814 | return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
2815 | } |
2816 | |
2817 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2818 | inline _LIBCPP_HIDE_FROM_ABI |
2819 | __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
2820 | operator^(const typename _Expr::value_type& __x, const _Expr& __y) { |
2821 | typedef typename _Expr::value_type value_type; |
2822 | typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
2823 | return __val_expr<_Op>(_Op(bit_xor<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
2824 | } |
2825 | |
2826 | template <class _Expr1, |
2827 | class _Expr2, |
2828 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
2829 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> > |
2830 | operator&(const _Expr1& __x, const _Expr2& __y) { |
2831 | typedef typename _Expr1::value_type value_type; |
2832 | typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op; |
2833 | return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y)); |
2834 | } |
2835 | |
2836 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2837 | inline _LIBCPP_HIDE_FROM_ABI |
2838 | __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
2839 | operator&(const _Expr& __x, const typename _Expr::value_type& __y) { |
2840 | typedef typename _Expr::value_type value_type; |
2841 | typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
2842 | return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
2843 | } |
2844 | |
2845 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2846 | inline _LIBCPP_HIDE_FROM_ABI |
2847 | __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
2848 | operator&(const typename _Expr::value_type& __x, const _Expr& __y) { |
2849 | typedef typename _Expr::value_type value_type; |
2850 | typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
2851 | return __val_expr<_Op>(_Op(bit_and<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
2852 | } |
2853 | |
2854 | template <class _Expr1, |
2855 | class _Expr2, |
2856 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
2857 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> > |
2858 | operator|(const _Expr1& __x, const _Expr2& __y) { |
2859 | typedef typename _Expr1::value_type value_type; |
2860 | typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op; |
2861 | return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y)); |
2862 | } |
2863 | |
2864 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2865 | inline _LIBCPP_HIDE_FROM_ABI |
2866 | __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
2867 | operator|(const _Expr& __x, const typename _Expr::value_type& __y) { |
2868 | typedef typename _Expr::value_type value_type; |
2869 | typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
2870 | return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
2871 | } |
2872 | |
2873 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2874 | inline _LIBCPP_HIDE_FROM_ABI |
2875 | __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
2876 | operator|(const typename _Expr::value_type& __x, const _Expr& __y) { |
2877 | typedef typename _Expr::value_type value_type; |
2878 | typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
2879 | return __val_expr<_Op>(_Op(bit_or<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
2880 | } |
2881 | |
2882 | template <class _Expr1, |
2883 | class _Expr2, |
2884 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
2885 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> > |
2886 | operator<<(const _Expr1& __x, const _Expr2& __y) { |
2887 | typedef typename _Expr1::value_type value_type; |
2888 | typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op; |
2889 | return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y)); |
2890 | } |
2891 | |
2892 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2893 | inline _LIBCPP_HIDE_FROM_ABI |
2894 | __val_expr< _BinaryOp<__bit_shift_left<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
2895 | operator<<(const _Expr& __x, const typename _Expr::value_type& __y) { |
2896 | typedef typename _Expr::value_type value_type; |
2897 | typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
2898 | return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
2899 | } |
2900 | |
2901 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2902 | inline _LIBCPP_HIDE_FROM_ABI |
2903 | __val_expr< _BinaryOp<__bit_shift_left<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
2904 | operator<<(const typename _Expr::value_type& __x, const _Expr& __y) { |
2905 | typedef typename _Expr::value_type value_type; |
2906 | typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
2907 | return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
2908 | } |
2909 | |
2910 | template <class _Expr1, |
2911 | class _Expr2, |
2912 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
2913 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> > |
2914 | operator>>(const _Expr1& __x, const _Expr2& __y) { |
2915 | typedef typename _Expr1::value_type value_type; |
2916 | typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op; |
2917 | return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y)); |
2918 | } |
2919 | |
2920 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2921 | inline _LIBCPP_HIDE_FROM_ABI __val_expr< |
2922 | _BinaryOp<__bit_shift_right<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
2923 | operator>>(const _Expr& __x, const typename _Expr::value_type& __y) { |
2924 | typedef typename _Expr::value_type value_type; |
2925 | typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
2926 | return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
2927 | } |
2928 | |
2929 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2930 | inline _LIBCPP_HIDE_FROM_ABI |
2931 | __val_expr< _BinaryOp<__bit_shift_right<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
2932 | operator>>(const typename _Expr::value_type& __x, const _Expr& __y) { |
2933 | typedef typename _Expr::value_type value_type; |
2934 | typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
2935 | return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
2936 | } |
2937 | |
2938 | template <class _Expr1, |
2939 | class _Expr2, |
2940 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
2941 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> > |
2942 | operator&&(const _Expr1& __x, const _Expr2& __y) { |
2943 | typedef typename _Expr1::value_type value_type; |
2944 | typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op; |
2945 | return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y)); |
2946 | } |
2947 | |
2948 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2949 | inline _LIBCPP_HIDE_FROM_ABI |
2950 | __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
2951 | operator&&(const _Expr& __x, const typename _Expr::value_type& __y) { |
2952 | typedef typename _Expr::value_type value_type; |
2953 | typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
2954 | return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
2955 | } |
2956 | |
2957 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2958 | inline _LIBCPP_HIDE_FROM_ABI |
2959 | __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
2960 | operator&&(const typename _Expr::value_type& __x, const _Expr& __y) { |
2961 | typedef typename _Expr::value_type value_type; |
2962 | typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
2963 | return __val_expr<_Op>(_Op(logical_and<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
2964 | } |
2965 | |
2966 | template <class _Expr1, |
2967 | class _Expr2, |
2968 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
2969 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> > |
2970 | operator||(const _Expr1& __x, const _Expr2& __y) { |
2971 | typedef typename _Expr1::value_type value_type; |
2972 | typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op; |
2973 | return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y)); |
2974 | } |
2975 | |
2976 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2977 | inline _LIBCPP_HIDE_FROM_ABI |
2978 | __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
2979 | operator||(const _Expr& __x, const typename _Expr::value_type& __y) { |
2980 | typedef typename _Expr::value_type value_type; |
2981 | typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
2982 | return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
2983 | } |
2984 | |
2985 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
2986 | inline _LIBCPP_HIDE_FROM_ABI |
2987 | __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
2988 | operator||(const typename _Expr::value_type& __x, const _Expr& __y) { |
2989 | typedef typename _Expr::value_type value_type; |
2990 | typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
2991 | return __val_expr<_Op>(_Op(logical_or<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
2992 | } |
2993 | |
2994 | template <class _Expr1, |
2995 | class _Expr2, |
2996 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
2997 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> > |
2998 | operator==(const _Expr1& __x, const _Expr2& __y) { |
2999 | typedef typename _Expr1::value_type value_type; |
3000 | typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op; |
3001 | return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y)); |
3002 | } |
3003 | |
3004 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3005 | inline _LIBCPP_HIDE_FROM_ABI |
3006 | __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
3007 | operator==(const _Expr& __x, const typename _Expr::value_type& __y) { |
3008 | typedef typename _Expr::value_type value_type; |
3009 | typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
3010 | return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
3011 | } |
3012 | |
3013 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3014 | inline _LIBCPP_HIDE_FROM_ABI |
3015 | __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
3016 | operator==(const typename _Expr::value_type& __x, const _Expr& __y) { |
3017 | typedef typename _Expr::value_type value_type; |
3018 | typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
3019 | return __val_expr<_Op>(_Op(equal_to<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
3020 | } |
3021 | |
3022 | template <class _Expr1, |
3023 | class _Expr2, |
3024 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
3025 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> > |
3026 | operator!=(const _Expr1& __x, const _Expr2& __y) { |
3027 | typedef typename _Expr1::value_type value_type; |
3028 | typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op; |
3029 | return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y)); |
3030 | } |
3031 | |
3032 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3033 | inline _LIBCPP_HIDE_FROM_ABI |
3034 | __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
3035 | operator!=(const _Expr& __x, const typename _Expr::value_type& __y) { |
3036 | typedef typename _Expr::value_type value_type; |
3037 | typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
3038 | return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
3039 | } |
3040 | |
3041 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3042 | inline _LIBCPP_HIDE_FROM_ABI |
3043 | __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
3044 | operator!=(const typename _Expr::value_type& __x, const _Expr& __y) { |
3045 | typedef typename _Expr::value_type value_type; |
3046 | typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
3047 | return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
3048 | } |
3049 | |
3050 | template <class _Expr1, |
3051 | class _Expr2, |
3052 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
3053 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> > |
3054 | operator<(const _Expr1& __x, const _Expr2& __y) { |
3055 | typedef typename _Expr1::value_type value_type; |
3056 | typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op; |
3057 | return __val_expr<_Op>(_Op(less<value_type>(), __x, __y)); |
3058 | } |
3059 | |
3060 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3061 | inline _LIBCPP_HIDE_FROM_ABI |
3062 | __val_expr<_BinaryOp<less<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
3063 | operator<(const _Expr& __x, const typename _Expr::value_type& __y) { |
3064 | typedef typename _Expr::value_type value_type; |
3065 | typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
3066 | return __val_expr<_Op>(_Op(less<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
3067 | } |
3068 | |
3069 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3070 | inline _LIBCPP_HIDE_FROM_ABI |
3071 | __val_expr<_BinaryOp<less<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
3072 | operator<(const typename _Expr::value_type& __x, const _Expr& __y) { |
3073 | typedef typename _Expr::value_type value_type; |
3074 | typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
3075 | return __val_expr<_Op>(_Op(less<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
3076 | } |
3077 | |
3078 | template <class _Expr1, |
3079 | class _Expr2, |
3080 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
3081 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> > |
3082 | operator>(const _Expr1& __x, const _Expr2& __y) { |
3083 | typedef typename _Expr1::value_type value_type; |
3084 | typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op; |
3085 | return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y)); |
3086 | } |
3087 | |
3088 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3089 | inline _LIBCPP_HIDE_FROM_ABI |
3090 | __val_expr<_BinaryOp<greater<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
3091 | operator>(const _Expr& __x, const typename _Expr::value_type& __y) { |
3092 | typedef typename _Expr::value_type value_type; |
3093 | typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
3094 | return __val_expr<_Op>(_Op(greater<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
3095 | } |
3096 | |
3097 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3098 | inline _LIBCPP_HIDE_FROM_ABI |
3099 | __val_expr<_BinaryOp<greater<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
3100 | operator>(const typename _Expr::value_type& __x, const _Expr& __y) { |
3101 | typedef typename _Expr::value_type value_type; |
3102 | typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
3103 | return __val_expr<_Op>(_Op(greater<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
3104 | } |
3105 | |
3106 | template <class _Expr1, |
3107 | class _Expr2, |
3108 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
3109 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> > |
3110 | operator<=(const _Expr1& __x, const _Expr2& __y) { |
3111 | typedef typename _Expr1::value_type value_type; |
3112 | typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op; |
3113 | return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y)); |
3114 | } |
3115 | |
3116 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3117 | inline _LIBCPP_HIDE_FROM_ABI |
3118 | __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
3119 | operator<=(const _Expr& __x, const typename _Expr::value_type& __y) { |
3120 | typedef typename _Expr::value_type value_type; |
3121 | typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
3122 | return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
3123 | } |
3124 | |
3125 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3126 | inline _LIBCPP_HIDE_FROM_ABI |
3127 | __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
3128 | operator<=(const typename _Expr::value_type& __x, const _Expr& __y) { |
3129 | typedef typename _Expr::value_type value_type; |
3130 | typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
3131 | return __val_expr<_Op>(_Op(less_equal<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
3132 | } |
3133 | |
3134 | template <class _Expr1, |
3135 | class _Expr2, |
3136 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
3137 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> > |
3138 | operator>=(const _Expr1& __x, const _Expr2& __y) { |
3139 | typedef typename _Expr1::value_type value_type; |
3140 | typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op; |
3141 | return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y)); |
3142 | } |
3143 | |
3144 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3145 | inline _LIBCPP_HIDE_FROM_ABI |
3146 | __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
3147 | operator>=(const _Expr& __x, const typename _Expr::value_type& __y) { |
3148 | typedef typename _Expr::value_type value_type; |
3149 | typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
3150 | return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
3151 | } |
3152 | |
3153 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3154 | inline _LIBCPP_HIDE_FROM_ABI |
3155 | __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
3156 | operator>=(const typename _Expr::value_type& __x, const _Expr& __y) { |
3157 | typedef typename _Expr::value_type value_type; |
3158 | typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
3159 | return __val_expr<_Op>(_Op(greater_equal<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
3160 | } |
3161 | |
3162 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3163 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> > |
3164 | abs(const _Expr& __x) { |
3165 | typedef typename _Expr::value_type value_type; |
3166 | typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op; |
3167 | return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x)); |
3168 | } |
3169 | |
3170 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3171 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> > |
3172 | acos(const _Expr& __x) { |
3173 | typedef typename _Expr::value_type value_type; |
3174 | typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op; |
3175 | return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x)); |
3176 | } |
3177 | |
3178 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3179 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> > |
3180 | asin(const _Expr& __x) { |
3181 | typedef typename _Expr::value_type value_type; |
3182 | typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op; |
3183 | return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x)); |
3184 | } |
3185 | |
3186 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3187 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> > |
3188 | atan(const _Expr& __x) { |
3189 | typedef typename _Expr::value_type value_type; |
3190 | typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op; |
3191 | return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x)); |
3192 | } |
3193 | |
3194 | template <class _Expr1, |
3195 | class _Expr2, |
3196 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
3197 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> > |
3198 | atan2(const _Expr1& __x, const _Expr2& __y) { |
3199 | typedef typename _Expr1::value_type value_type; |
3200 | typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op; |
3201 | return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y)); |
3202 | } |
3203 | |
3204 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3205 | inline _LIBCPP_HIDE_FROM_ABI |
3206 | __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
3207 | atan2(const _Expr& __x, const typename _Expr::value_type& __y) { |
3208 | typedef typename _Expr::value_type value_type; |
3209 | typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
3210 | return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
3211 | } |
3212 | |
3213 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3214 | inline _LIBCPP_HIDE_FROM_ABI |
3215 | __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
3216 | atan2(const typename _Expr::value_type& __x, const _Expr& __y) { |
3217 | typedef typename _Expr::value_type value_type; |
3218 | typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
3219 | return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
3220 | } |
3221 | |
3222 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3223 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> > |
3224 | cos(const _Expr& __x) { |
3225 | typedef typename _Expr::value_type value_type; |
3226 | typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op; |
3227 | return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x)); |
3228 | } |
3229 | |
3230 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3231 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> > |
3232 | cosh(const _Expr& __x) { |
3233 | typedef typename _Expr::value_type value_type; |
3234 | typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op; |
3235 | return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x)); |
3236 | } |
3237 | |
3238 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3239 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> > |
3240 | exp(const _Expr& __x) { |
3241 | typedef typename _Expr::value_type value_type; |
3242 | typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op; |
3243 | return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x)); |
3244 | } |
3245 | |
3246 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3247 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> > |
3248 | log(const _Expr& __x) { |
3249 | typedef typename _Expr::value_type value_type; |
3250 | typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op; |
3251 | return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x)); |
3252 | } |
3253 | |
3254 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3255 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> > |
3256 | log10(const _Expr& __x) { |
3257 | typedef typename _Expr::value_type value_type; |
3258 | typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op; |
3259 | return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x)); |
3260 | } |
3261 | |
3262 | template <class _Expr1, |
3263 | class _Expr2, |
3264 | __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0> |
3265 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> > |
3266 | pow(const _Expr1& __x, const _Expr2& __y) { |
3267 | typedef typename _Expr1::value_type value_type; |
3268 | typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op; |
3269 | return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y)); |
3270 | } |
3271 | |
3272 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3273 | inline _LIBCPP_HIDE_FROM_ABI |
3274 | __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > > |
3275 | pow(const _Expr& __x, const typename _Expr::value_type& __y) { |
3276 | typedef typename _Expr::value_type value_type; |
3277 | typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op; |
3278 | return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size()))); |
3279 | } |
3280 | |
3281 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3282 | inline _LIBCPP_HIDE_FROM_ABI |
3283 | __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> > |
3284 | pow(const typename _Expr::value_type& __x, const _Expr& __y) { |
3285 | typedef typename _Expr::value_type value_type; |
3286 | typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op; |
3287 | return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y)); |
3288 | } |
3289 | |
3290 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3291 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> > |
3292 | sin(const _Expr& __x) { |
3293 | typedef typename _Expr::value_type value_type; |
3294 | typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op; |
3295 | return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x)); |
3296 | } |
3297 | |
3298 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3299 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> > |
3300 | sinh(const _Expr& __x) { |
3301 | typedef typename _Expr::value_type value_type; |
3302 | typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op; |
3303 | return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x)); |
3304 | } |
3305 | |
3306 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3307 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> > |
3308 | sqrt(const _Expr& __x) { |
3309 | typedef typename _Expr::value_type value_type; |
3310 | typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op; |
3311 | return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x)); |
3312 | } |
3313 | |
3314 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3315 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> > |
3316 | tan(const _Expr& __x) { |
3317 | typedef typename _Expr::value_type value_type; |
3318 | typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op; |
3319 | return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x)); |
3320 | } |
3321 | |
3322 | template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0> |
3323 | inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> > |
3324 | tanh(const _Expr& __x) { |
3325 | typedef typename _Expr::value_type value_type; |
3326 | typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op; |
3327 | return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x)); |
3328 | } |
3329 | |
3330 | template <class _Tp> |
3331 | inline _LIBCPP_HIDE_FROM_ABI _Tp* begin(valarray<_Tp>& __v) { |
3332 | return __v.__begin_; |
3333 | } |
3334 | |
3335 | template <class _Tp> |
3336 | inline _LIBCPP_HIDE_FROM_ABI const _Tp* begin(const valarray<_Tp>& __v) { |
3337 | return __v.__begin_; |
3338 | } |
3339 | |
3340 | template <class _Tp> |
3341 | inline _LIBCPP_HIDE_FROM_ABI _Tp* end(valarray<_Tp>& __v) { |
3342 | return __v.__end_; |
3343 | } |
3344 | |
3345 | template <class _Tp> |
3346 | inline _LIBCPP_HIDE_FROM_ABI const _Tp* end(const valarray<_Tp>& __v) { |
3347 | return __v.__end_; |
3348 | } |
3349 | |
3350 | _LIBCPP_END_NAMESPACE_STD |
3351 | |
3352 | _LIBCPP_POP_MACROS |
3353 | |
3354 | #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
3355 | # include <algorithm> |
3356 | # include <concepts> |
3357 | # include <cstdlib> |
3358 | # include <cstring> |
3359 | # include <functional> |
3360 | # include <stdexcept> |
3361 | # include <type_traits> |
3362 | #endif |
3363 | |
3364 | #endif // _LIBCPP_VALARRAY |
3365 | |