1 // -*- C++ -*- 2 //===-------------------------- valarray ----------------------------------===// 3 // 4 // The LLVM Compiler Infrastructure 5 // 6 // This file is dual licensed under the MIT and the University of Illinois Open 7 // Source Licenses. See LICENSE.TXT for details. 8 // 9 //===----------------------------------------------------------------------===// 10 11 #ifndef _LIBCPP_VALARRAY 12 #define _LIBCPP_VALARRAY 13 14 /* 15 valarray synopsis 16 17 namespace std 18 { 19 20 template<class T> 21 class valarray 22 { 23 public: 24 typedef T value_type; 25 26 // construct/destroy: 27 valarray(); 28 explicit valarray(size_t n); 29 valarray(const value_type& x, size_t n); 30 valarray(const value_type* px, size_t n); 31 valarray(const valarray& v); 32 valarray(valarray&& v) noexcept; 33 valarray(const slice_array<value_type>& sa); 34 valarray(const gslice_array<value_type>& ga); 35 valarray(const mask_array<value_type>& ma); 36 valarray(const indirect_array<value_type>& ia); 37 valarray(initializer_list<value_type> il); 38 ~valarray(); 39 40 // assignment: 41 valarray& operator=(const valarray& v); 42 valarray& operator=(valarray&& v) noexcept; 43 valarray& operator=(initializer_list<value_type> il); 44 valarray& operator=(const value_type& x); 45 valarray& operator=(const slice_array<value_type>& sa); 46 valarray& operator=(const gslice_array<value_type>& ga); 47 valarray& operator=(const mask_array<value_type>& ma); 48 valarray& operator=(const indirect_array<value_type>& ia); 49 50 // element access: 51 const value_type& operator[](size_t i) const; 52 value_type& operator[](size_t i); 53 54 // subset operations: 55 valarray operator[](slice s) const; 56 slice_array<value_type> operator[](slice s); 57 valarray operator[](const gslice& gs) const; 58 gslice_array<value_type> operator[](const gslice& gs); 59 valarray operator[](const valarray<bool>& vb) const; 60 mask_array<value_type> operator[](const valarray<bool>& vb); 61 valarray operator[](const valarray<size_t>& vs) const; 62 indirect_array<value_type> operator[](const valarray<size_t>& vs); 63 64 // unary operators: 65 valarray operator+() const; 66 valarray operator-() const; 67 valarray operator~() const; 68 valarray<bool> operator!() const; 69 70 // computed assignment: 71 valarray& operator*= (const value_type& x); 72 valarray& operator/= (const value_type& x); 73 valarray& operator%= (const value_type& x); 74 valarray& operator+= (const value_type& x); 75 valarray& operator-= (const value_type& x); 76 valarray& operator^= (const value_type& x); 77 valarray& operator&= (const value_type& x); 78 valarray& operator|= (const value_type& x); 79 valarray& operator<<=(const value_type& x); 80 valarray& operator>>=(const value_type& x); 81 82 valarray& operator*= (const valarray& v); 83 valarray& operator/= (const valarray& v); 84 valarray& operator%= (const valarray& v); 85 valarray& operator+= (const valarray& v); 86 valarray& operator-= (const valarray& v); 87 valarray& operator^= (const valarray& v); 88 valarray& operator|= (const valarray& v); 89 valarray& operator&= (const valarray& v); 90 valarray& operator<<=(const valarray& v); 91 valarray& operator>>=(const valarray& v); 92 93 // member functions: 94 void swap(valarray& v) noexcept; 95 96 size_t size() const; 97 98 value_type sum() const; 99 value_type min() const; 100 value_type max() const; 101 102 valarray shift (int i) const; 103 valarray cshift(int i) const; 104 valarray apply(value_type f(value_type)) const; 105 valarray apply(value_type f(const value_type&)) const; 106 void resize(size_t n, value_type x = value_type()); 107 }; 108 109 class slice 110 { 111 public: 112 slice(); 113 slice(size_t start, size_t size, size_t stride); 114 115 size_t start() const; 116 size_t size() const; 117 size_t stride() const; 118 }; 119 120 template <class T> 121 class slice_array 122 { 123 public: 124 typedef T value_type; 125 126 const slice_array& operator=(const slice_array& sa) const; 127 void operator= (const valarray<value_type>& v) const; 128 void operator*= (const valarray<value_type>& v) const; 129 void operator/= (const valarray<value_type>& v) const; 130 void operator%= (const valarray<value_type>& v) const; 131 void operator+= (const valarray<value_type>& v) const; 132 void operator-= (const valarray<value_type>& v) const; 133 void operator^= (const valarray<value_type>& v) const; 134 void operator&= (const valarray<value_type>& v) const; 135 void operator|= (const valarray<value_type>& v) const; 136 void operator<<=(const valarray<value_type>& v) const; 137 void operator>>=(const valarray<value_type>& v) const; 138 139 void operator=(const value_type& x) const; 140 141 slice_array() = delete; 142 }; 143 144 class gslice 145 { 146 public: 147 gslice(); 148 gslice(size_t start, const valarray<size_t>& size, 149 const valarray<size_t>& stride); 150 151 size_t start() const; 152 valarray<size_t> size() const; 153 valarray<size_t> stride() const; 154 }; 155 156 template <class T> 157 class gslice_array 158 { 159 public: 160 typedef T value_type; 161 162 void operator= (const valarray<value_type>& v) const; 163 void operator*= (const valarray<value_type>& v) const; 164 void operator/= (const valarray<value_type>& v) const; 165 void operator%= (const valarray<value_type>& v) const; 166 void operator+= (const valarray<value_type>& v) const; 167 void operator-= (const valarray<value_type>& v) const; 168 void operator^= (const valarray<value_type>& v) const; 169 void operator&= (const valarray<value_type>& v) const; 170 void operator|= (const valarray<value_type>& v) const; 171 void operator<<=(const valarray<value_type>& v) const; 172 void operator>>=(const valarray<value_type>& v) const; 173 174 gslice_array(const gslice_array& ga); 175 ~gslice_array(); 176 const gslice_array& operator=(const gslice_array& ga) const; 177 void operator=(const value_type& x) const; 178 179 gslice_array() = delete; 180 }; 181 182 template <class T> 183 class mask_array 184 { 185 public: 186 typedef T value_type; 187 188 void operator= (const valarray<value_type>& v) const; 189 void operator*= (const valarray<value_type>& v) const; 190 void operator/= (const valarray<value_type>& v) const; 191 void operator%= (const valarray<value_type>& v) const; 192 void operator+= (const valarray<value_type>& v) const; 193 void operator-= (const valarray<value_type>& v) const; 194 void operator^= (const valarray<value_type>& v) const; 195 void operator&= (const valarray<value_type>& v) const; 196 void operator|= (const valarray<value_type>& v) const; 197 void operator<<=(const valarray<value_type>& v) const; 198 void operator>>=(const valarray<value_type>& v) const; 199 200 mask_array(const mask_array& ma); 201 ~mask_array(); 202 const mask_array& operator=(const mask_array& ma) const; 203 void operator=(const value_type& x) const; 204 205 mask_array() = delete; 206 }; 207 208 template <class T> 209 class indirect_array 210 { 211 public: 212 typedef T value_type; 213 214 void operator= (const valarray<value_type>& v) const; 215 void operator*= (const valarray<value_type>& v) const; 216 void operator/= (const valarray<value_type>& v) const; 217 void operator%= (const valarray<value_type>& v) const; 218 void operator+= (const valarray<value_type>& v) const; 219 void operator-= (const valarray<value_type>& v) const; 220 void operator^= (const valarray<value_type>& v) const; 221 void operator&= (const valarray<value_type>& v) const; 222 void operator|= (const valarray<value_type>& v) const; 223 void operator<<=(const valarray<value_type>& v) const; 224 void operator>>=(const valarray<value_type>& v) const; 225 226 indirect_array(const indirect_array& ia); 227 ~indirect_array(); 228 const indirect_array& operator=(const indirect_array& ia) const; 229 void operator=(const value_type& x) const; 230 231 indirect_array() = delete; 232 }; 233 234 template<class T> void swap(valarray<T>& x, valarray<T>& y) noexcept; 235 236 template<class T> valarray<T> operator* (const valarray<T>& x, const valarray<T>& y); 237 template<class T> valarray<T> operator* (const valarray<T>& x, const T& y); 238 template<class T> valarray<T> operator* (const T& x, const valarray<T>& y); 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<bool> operator&&(const valarray<T>& x, const valarray<T>& y); 277 template<class T> valarray<bool> operator&&(const valarray<T>& x, const T& y); 278 template<class T> valarray<bool> 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<T> abs (const valarray<T>& x); 309 template<class T> valarray<T> acos (const valarray<T>& x); 310 template<class T> valarray<T> asin (const valarray<T>& x); 311 template<class T> valarray<T> atan (const valarray<T>& x); 312 313 template<class T> valarray<T> atan2(const valarray<T>& x, const valarray<T>& y); 314 template<class T> valarray<T> atan2(const valarray<T>& x, const T& y); 315 template<class T> valarray<T> atan2(const T& x, const valarray<T>& y); 316 317 template<class T> valarray<T> cos (const valarray<T>& x); 318 template<class T> valarray<T> cosh (const valarray<T>& x); 319 template<class T> valarray<T> exp (const valarray<T>& x); 320 template<class T> valarray<T> log (const valarray<T>& x); 321 template<class T> valarray<T> log10(const valarray<T>& x); 322 323 template<class T> valarray<T> pow(const valarray<T>& x, const valarray<T>& y); 324 template<class T> valarray<T> pow(const valarray<T>& x, const T& y); 325 template<class T> valarray<T> pow(const T& x, const valarray<T>& y); 326 327 template<class T> valarray<T> sin (const valarray<T>& x); 328 template<class T> valarray<T> sinh (const valarray<T>& x); 329 template<class T> valarray<T> sqrt (const valarray<T>& x); 330 template<class T> valarray<T> tan (const valarray<T>& x); 331 template<class T> valarray<T> tanh (const valarray<T>& x); 332 333 template <class T> unspecified1 begin(valarray<T>& v); 334 template <class T> unspecified2 begin(const valarray<T>& v); 335 template <class T> unspecified1 end(valarray<T>& v); 336 template <class T> unspecified2 end(const valarray<T>& v); 337 338 } // std 339 340 */ 341 342 #include <__config> 343 #include <cstddef> 344 #include <cmath> 345 #include <initializer_list> 346 #include <algorithm> 347 #include <functional> 348 #include <new> 349 350 #include <__undef_min_max> 351 #include <__undef___deallocate> 352 353 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 354 #pragma GCC system_header 355 #endif 356 357 _LIBCPP_BEGIN_NAMESPACE_STD 358 359 template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY valarray; 360 361 class _LIBCPP_TYPE_VIS_ONLY slice 362 { 363 size_t __start_; 364 size_t __size_; 365 size_t __stride_; 366 public: 367 _LIBCPP_INLINE_VISIBILITY 368 slice() 369 : __start_(0), 370 __size_(0), 371 __stride_(0) 372 {} 373 374 _LIBCPP_INLINE_VISIBILITY 375 slice(size_t __start, size_t __size, size_t __stride) 376 : __start_(__start), 377 __size_(__size), 378 __stride_(__stride) 379 {} 380 381 _LIBCPP_INLINE_VISIBILITY size_t start() const {return __start_;} 382 _LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;} 383 _LIBCPP_INLINE_VISIBILITY size_t stride() const {return __stride_;} 384 }; 385 386 template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY slice_array; 387 class _LIBCPP_TYPE_VIS gslice; 388 template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY gslice_array; 389 template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY mask_array; 390 template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY indirect_array; 391 392 template <class _Tp> 393 _LIBCPP_INLINE_VISIBILITY 394 _Tp* 395 begin(valarray<_Tp>& __v); 396 397 template <class _Tp> 398 _LIBCPP_INLINE_VISIBILITY 399 const _Tp* 400 begin(const valarray<_Tp>& __v); 401 402 template <class _Tp> 403 _LIBCPP_INLINE_VISIBILITY 404 _Tp* 405 end(valarray<_Tp>& __v); 406 407 template <class _Tp> 408 _LIBCPP_INLINE_VISIBILITY 409 const _Tp* 410 end(const valarray<_Tp>& __v); 411 412 template <class _Op, class _A0> 413 struct _UnaryOp 414 { 415 typedef typename _Op::result_type result_type; 416 typedef typename _A0::value_type value_type; 417 418 _Op __op_; 419 _A0 __a0_; 420 421 _LIBCPP_INLINE_VISIBILITY 422 _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {} 423 424 _LIBCPP_INLINE_VISIBILITY 425 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);} 426 427 _LIBCPP_INLINE_VISIBILITY 428 size_t size() const {return __a0_.size();} 429 }; 430 431 template <class _Op, class _A0, class _A1> 432 struct _BinaryOp 433 { 434 typedef typename _Op::result_type result_type; 435 typedef typename _A0::value_type value_type; 436 437 _Op __op_; 438 _A0 __a0_; 439 _A1 __a1_; 440 441 _LIBCPP_INLINE_VISIBILITY 442 _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1) 443 : __op_(__op), __a0_(__a0), __a1_(__a1) {} 444 445 _LIBCPP_INLINE_VISIBILITY 446 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);} 447 448 _LIBCPP_INLINE_VISIBILITY 449 size_t size() const {return __a0_.size();} 450 }; 451 452 template <class _Tp> 453 class __scalar_expr 454 { 455 public: 456 typedef _Tp value_type; 457 typedef const _Tp& result_type; 458 private: 459 const value_type& __t_; 460 size_t __s_; 461 public: 462 _LIBCPP_INLINE_VISIBILITY 463 explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {} 464 465 _LIBCPP_INLINE_VISIBILITY 466 result_type operator[](size_t) const {return __t_;} 467 468 _LIBCPP_INLINE_VISIBILITY 469 size_t size() const {return __s_;} 470 }; 471 472 template <class _Tp> 473 struct __unary_plus : unary_function<_Tp, _Tp> 474 { 475 _LIBCPP_INLINE_VISIBILITY 476 _Tp operator()(const _Tp& __x) const 477 {return +__x;} 478 }; 479 480 template <class _Tp> 481 struct __bit_not : unary_function<_Tp, _Tp> 482 { 483 _LIBCPP_INLINE_VISIBILITY 484 _Tp operator()(const _Tp& __x) const 485 {return ~__x;} 486 }; 487 488 template <class _Tp> 489 struct __bit_shift_left : binary_function<_Tp, _Tp, _Tp> 490 { 491 _LIBCPP_INLINE_VISIBILITY 492 _Tp operator()(const _Tp& __x, const _Tp& __y) const 493 {return __x << __y;} 494 }; 495 496 template <class _Tp> 497 struct __bit_shift_right : binary_function<_Tp, _Tp, _Tp> 498 { 499 _LIBCPP_INLINE_VISIBILITY 500 _Tp operator()(const _Tp& __x, const _Tp& __y) const 501 {return __x >> __y;} 502 }; 503 504 template <class _Tp, class _Fp> 505 struct __apply_expr : unary_function<_Tp, _Tp> 506 { 507 private: 508 _Fp __f_; 509 public: 510 _LIBCPP_INLINE_VISIBILITY 511 explicit __apply_expr(_Fp __f) : __f_(__f) {} 512 513 _LIBCPP_INLINE_VISIBILITY 514 _Tp operator()(const _Tp& __x) const 515 {return __f_(__x);} 516 }; 517 518 template <class _Tp> 519 struct __abs_expr : unary_function<_Tp, _Tp> 520 { 521 _LIBCPP_INLINE_VISIBILITY 522 _Tp operator()(const _Tp& __x) const 523 {return abs(__x);} 524 }; 525 526 template <class _Tp> 527 struct __acos_expr : unary_function<_Tp, _Tp> 528 { 529 _LIBCPP_INLINE_VISIBILITY 530 _Tp operator()(const _Tp& __x) const 531 {return acos(__x);} 532 }; 533 534 template <class _Tp> 535 struct __asin_expr : unary_function<_Tp, _Tp> 536 { 537 _LIBCPP_INLINE_VISIBILITY 538 _Tp operator()(const _Tp& __x) const 539 {return asin(__x);} 540 }; 541 542 template <class _Tp> 543 struct __atan_expr : unary_function<_Tp, _Tp> 544 { 545 _LIBCPP_INLINE_VISIBILITY 546 _Tp operator()(const _Tp& __x) const 547 {return atan(__x);} 548 }; 549 550 template <class _Tp> 551 struct __atan2_expr : binary_function<_Tp, _Tp, _Tp> 552 { 553 _LIBCPP_INLINE_VISIBILITY 554 _Tp operator()(const _Tp& __x, const _Tp& __y) const 555 {return atan2(__x, __y);} 556 }; 557 558 template <class _Tp> 559 struct __cos_expr : unary_function<_Tp, _Tp> 560 { 561 _LIBCPP_INLINE_VISIBILITY 562 _Tp operator()(const _Tp& __x) const 563 {return cos(__x);} 564 }; 565 566 template <class _Tp> 567 struct __cosh_expr : unary_function<_Tp, _Tp> 568 { 569 _LIBCPP_INLINE_VISIBILITY 570 _Tp operator()(const _Tp& __x) const 571 {return cosh(__x);} 572 }; 573 574 template <class _Tp> 575 struct __exp_expr : unary_function<_Tp, _Tp> 576 { 577 _LIBCPP_INLINE_VISIBILITY 578 _Tp operator()(const _Tp& __x) const 579 {return exp(__x);} 580 }; 581 582 template <class _Tp> 583 struct __log_expr : unary_function<_Tp, _Tp> 584 { 585 _LIBCPP_INLINE_VISIBILITY 586 _Tp operator()(const _Tp& __x) const 587 {return log(__x);} 588 }; 589 590 template <class _Tp> 591 struct __log10_expr : unary_function<_Tp, _Tp> 592 { 593 _LIBCPP_INLINE_VISIBILITY 594 _Tp operator()(const _Tp& __x) const 595 {return log10(__x);} 596 }; 597 598 template <class _Tp> 599 struct __pow_expr : binary_function<_Tp, _Tp, _Tp> 600 { 601 _LIBCPP_INLINE_VISIBILITY 602 _Tp operator()(const _Tp& __x, const _Tp& __y) const 603 {return pow(__x, __y);} 604 }; 605 606 template <class _Tp> 607 struct __sin_expr : unary_function<_Tp, _Tp> 608 { 609 _LIBCPP_INLINE_VISIBILITY 610 _Tp operator()(const _Tp& __x) const 611 {return sin(__x);} 612 }; 613 614 template <class _Tp> 615 struct __sinh_expr : unary_function<_Tp, _Tp> 616 { 617 _LIBCPP_INLINE_VISIBILITY 618 _Tp operator()(const _Tp& __x) const 619 {return sinh(__x);} 620 }; 621 622 template <class _Tp> 623 struct __sqrt_expr : unary_function<_Tp, _Tp> 624 { 625 _LIBCPP_INLINE_VISIBILITY 626 _Tp operator()(const _Tp& __x) const 627 {return sqrt(__x);} 628 }; 629 630 template <class _Tp> 631 struct __tan_expr : unary_function<_Tp, _Tp> 632 { 633 _LIBCPP_INLINE_VISIBILITY 634 _Tp operator()(const _Tp& __x) const 635 {return tan(__x);} 636 }; 637 638 template <class _Tp> 639 struct __tanh_expr : unary_function<_Tp, _Tp> 640 { 641 _LIBCPP_INLINE_VISIBILITY 642 _Tp operator()(const _Tp& __x) const 643 {return tanh(__x);} 644 }; 645 646 template <class _ValExpr> 647 class __slice_expr 648 { 649 typedef typename remove_reference<_ValExpr>::type _RmExpr; 650 public: 651 typedef typename _RmExpr::value_type value_type; 652 typedef value_type result_type; 653 654 private: 655 _ValExpr __expr_; 656 size_t __start_; 657 size_t __size_; 658 size_t __stride_; 659 660 _LIBCPP_INLINE_VISIBILITY 661 __slice_expr(const slice& __sl, const _RmExpr& __e) 662 : __expr_(__e), 663 __start_(__sl.start()), 664 __size_(__sl.size()), 665 __stride_(__sl.stride()) 666 {} 667 public: 668 669 _LIBCPP_INLINE_VISIBILITY 670 result_type operator[](size_t __i) const 671 {return __expr_[__start_ + __i * __stride_];} 672 673 _LIBCPP_INLINE_VISIBILITY 674 size_t size() const {return __size_;} 675 676 template <class> friend class _LIBCPP_TYPE_VIS_ONLY valarray; 677 }; 678 679 template <class _ValExpr> 680 class __mask_expr; 681 682 template <class _ValExpr> 683 class __indirect_expr; 684 685 template <class _ValExpr> 686 class __shift_expr 687 { 688 typedef typename remove_reference<_ValExpr>::type _RmExpr; 689 public: 690 typedef typename _RmExpr::value_type value_type; 691 typedef value_type result_type; 692 693 private: 694 _ValExpr __expr_; 695 size_t __size_; 696 ptrdiff_t __ul_; 697 ptrdiff_t __sn_; 698 ptrdiff_t __n_; 699 static const ptrdiff_t _Np = static_cast<ptrdiff_t>( 700 sizeof(ptrdiff_t) * __CHAR_BIT__ - 1); 701 702 _LIBCPP_INLINE_VISIBILITY 703 __shift_expr(int __n, const _RmExpr& __e) 704 : __expr_(__e), 705 __size_(__e.size()), 706 __n_(__n) 707 { 708 ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _Np); 709 __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _Np); 710 __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n); 711 } 712 public: 713 714 _LIBCPP_INLINE_VISIBILITY 715 result_type operator[](size_t __j) const 716 { 717 ptrdiff_t __i = static_cast<ptrdiff_t>(__j); 718 ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np; 719 return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m); 720 } 721 722 _LIBCPP_INLINE_VISIBILITY 723 size_t size() const {return __size_;} 724 725 template <class> friend class __val_expr; 726 }; 727 728 template <class _ValExpr> 729 class __cshift_expr 730 { 731 typedef typename remove_reference<_ValExpr>::type _RmExpr; 732 public: 733 typedef typename _RmExpr::value_type value_type; 734 typedef value_type result_type; 735 736 private: 737 _ValExpr __expr_; 738 size_t __size_; 739 size_t __m_; 740 size_t __o1_; 741 size_t __o2_; 742 743 _LIBCPP_INLINE_VISIBILITY 744 __cshift_expr(int __n, const _RmExpr& __e) 745 : __expr_(__e), 746 __size_(__e.size()) 747 { 748 __n %= static_cast<int>(__size_); 749 if (__n >= 0) 750 { 751 __m_ = __size_ - __n; 752 __o1_ = __n; 753 __o2_ = __n - __size_; 754 } 755 else 756 { 757 __m_ = -__n; 758 __o1_ = __n + __size_; 759 __o2_ = __n; 760 } 761 } 762 public: 763 764 _LIBCPP_INLINE_VISIBILITY 765 result_type operator[](size_t __i) const 766 { 767 if (__i < __m_) 768 return __expr_[__i + __o1_]; 769 return __expr_[__i + __o2_]; 770 } 771 772 _LIBCPP_INLINE_VISIBILITY 773 size_t size() const {return __size_;} 774 775 template <class> friend class __val_expr; 776 }; 777 778 template<class _ValExpr> 779 class __val_expr; 780 781 template<class _ValExpr> 782 struct __is_val_expr : false_type {}; 783 784 template<class _ValExpr> 785 struct __is_val_expr<__val_expr<_ValExpr> > : true_type {}; 786 787 template<class _Tp> 788 struct __is_val_expr<valarray<_Tp> > : true_type {}; 789 790 template<class _Tp> 791 class _LIBCPP_TYPE_VIS_ONLY valarray 792 { 793 public: 794 typedef _Tp value_type; 795 typedef _Tp result_type; 796 797 private: 798 value_type* __begin_; 799 value_type* __end_; 800 801 public: 802 // construct/destroy: 803 _LIBCPP_INLINE_VISIBILITY 804 valarray() : __begin_(0), __end_(0) {} 805 explicit valarray(size_t __n); 806 valarray(const value_type& __x, size_t __n); 807 valarray(const value_type* __p, size_t __n); 808 valarray(const valarray& __v); 809 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 810 valarray(valarray&& __v) _NOEXCEPT; 811 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 812 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 813 valarray(initializer_list<value_type> __il); 814 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 815 valarray(const slice_array<value_type>& __sa); 816 valarray(const gslice_array<value_type>& __ga); 817 valarray(const mask_array<value_type>& __ma); 818 valarray(const indirect_array<value_type>& __ia); 819 ~valarray(); 820 821 // assignment: 822 valarray& operator=(const valarray& __v); 823 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 824 valarray& operator=(valarray&& __v) _NOEXCEPT; 825 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 826 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 827 valarray& operator=(initializer_list<value_type>); 828 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 829 valarray& operator=(const value_type& __x); 830 valarray& operator=(const slice_array<value_type>& __sa); 831 valarray& operator=(const gslice_array<value_type>& __ga); 832 valarray& operator=(const mask_array<value_type>& __ma); 833 valarray& operator=(const indirect_array<value_type>& __ia); 834 template <class _ValExpr> 835 valarray& operator=(const __val_expr<_ValExpr>& __v); 836 837 // element access: 838 _LIBCPP_INLINE_VISIBILITY 839 const value_type& operator[](size_t __i) const {return __begin_[__i];} 840 841 _LIBCPP_INLINE_VISIBILITY 842 value_type& operator[](size_t __i) {return __begin_[__i];} 843 844 // subset operations: 845 __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const; 846 slice_array<value_type> operator[](slice __s); 847 __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const; 848 gslice_array<value_type> operator[](const gslice& __gs); 849 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 850 __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const; 851 gslice_array<value_type> operator[](gslice&& __gs); 852 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 853 __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const; 854 mask_array<value_type> operator[](const valarray<bool>& __vb); 855 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 856 __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const; 857 mask_array<value_type> operator[](valarray<bool>&& __vb); 858 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 859 __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const; 860 indirect_array<value_type> operator[](const valarray<size_t>& __vs); 861 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 862 __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const; 863 indirect_array<value_type> operator[](valarray<size_t>&& __vs); 864 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 865 866 // unary operators: 867 valarray operator+() const; 868 valarray operator-() const; 869 valarray operator~() const; 870 valarray<bool> operator!() const; 871 872 // computed assignment: 873 valarray& operator*= (const value_type& __x); 874 valarray& operator/= (const value_type& __x); 875 valarray& operator%= (const value_type& __x); 876 valarray& operator+= (const value_type& __x); 877 valarray& operator-= (const value_type& __x); 878 valarray& operator^= (const value_type& __x); 879 valarray& operator&= (const value_type& __x); 880 valarray& operator|= (const value_type& __x); 881 valarray& operator<<=(const value_type& __x); 882 valarray& operator>>=(const value_type& __x); 883 884 template <class _Expr> 885 typename enable_if 886 < 887 __is_val_expr<_Expr>::value, 888 valarray& 889 >::type 890 operator*= (const _Expr& __v); 891 892 template <class _Expr> 893 typename enable_if 894 < 895 __is_val_expr<_Expr>::value, 896 valarray& 897 >::type 898 operator/= (const _Expr& __v); 899 900 template <class _Expr> 901 typename enable_if 902 < 903 __is_val_expr<_Expr>::value, 904 valarray& 905 >::type 906 operator%= (const _Expr& __v); 907 908 template <class _Expr> 909 typename enable_if 910 < 911 __is_val_expr<_Expr>::value, 912 valarray& 913 >::type 914 operator+= (const _Expr& __v); 915 916 template <class _Expr> 917 typename enable_if 918 < 919 __is_val_expr<_Expr>::value, 920 valarray& 921 >::type 922 operator-= (const _Expr& __v); 923 924 template <class _Expr> 925 typename enable_if 926 < 927 __is_val_expr<_Expr>::value, 928 valarray& 929 >::type 930 operator^= (const _Expr& __v); 931 932 template <class _Expr> 933 typename enable_if 934 < 935 __is_val_expr<_Expr>::value, 936 valarray& 937 >::type 938 operator|= (const _Expr& __v); 939 940 template <class _Expr> 941 typename enable_if 942 < 943 __is_val_expr<_Expr>::value, 944 valarray& 945 >::type 946 operator&= (const _Expr& __v); 947 948 template <class _Expr> 949 typename enable_if 950 < 951 __is_val_expr<_Expr>::value, 952 valarray& 953 >::type 954 operator<<= (const _Expr& __v); 955 956 template <class _Expr> 957 typename enable_if 958 < 959 __is_val_expr<_Expr>::value, 960 valarray& 961 >::type 962 operator>>= (const _Expr& __v); 963 964 // member functions: 965 void swap(valarray& __v) _NOEXCEPT; 966 967 _LIBCPP_INLINE_VISIBILITY 968 size_t size() const {return static_cast<size_t>(__end_ - __begin_);} 969 970 value_type sum() const; 971 value_type min() const; 972 value_type max() const; 973 974 valarray shift (int __i) const; 975 valarray cshift(int __i) const; 976 valarray apply(value_type __f(value_type)) const; 977 valarray apply(value_type __f(const value_type&)) const; 978 void resize(size_t __n, value_type __x = value_type()); 979 980 private: 981 template <class> friend class _LIBCPP_TYPE_VIS_ONLY valarray; 982 template <class> friend class _LIBCPP_TYPE_VIS_ONLY slice_array; 983 template <class> friend class _LIBCPP_TYPE_VIS_ONLY gslice_array; 984 template <class> friend class _LIBCPP_TYPE_VIS_ONLY mask_array; 985 template <class> friend class __mask_expr; 986 template <class> friend class _LIBCPP_TYPE_VIS_ONLY indirect_array; 987 template <class> friend class __indirect_expr; 988 template <class> friend class __val_expr; 989 990 template <class _Up> 991 friend 992 _Up* 993 begin(valarray<_Up>& __v); 994 995 template <class _Up> 996 friend 997 const _Up* 998 begin(const valarray<_Up>& __v); 999 1000 template <class _Up> 1001 friend 1002 _Up* 1003 end(valarray<_Up>& __v); 1004 1005 template <class _Up> 1006 friend 1007 const _Up* 1008 end(const valarray<_Up>& __v); 1009 }; 1010 1011 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::valarray(size_t)) 1012 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::~valarray()) 1013 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void valarray<size_t>::resize(size_t, size_t)) 1014 1015 template <class _Op, class _Tp> 1016 struct _UnaryOp<_Op, valarray<_Tp> > 1017 { 1018 typedef typename _Op::result_type result_type; 1019 typedef _Tp value_type; 1020 1021 _Op __op_; 1022 const valarray<_Tp>& __a0_; 1023 1024 _LIBCPP_INLINE_VISIBILITY 1025 _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {} 1026 1027 _LIBCPP_INLINE_VISIBILITY 1028 result_type operator[](size_t __i) const {return __op_(__a0_[__i]);} 1029 1030 _LIBCPP_INLINE_VISIBILITY 1031 size_t size() const {return __a0_.size();} 1032 }; 1033 1034 template <class _Op, class _Tp, class _A1> 1035 struct _BinaryOp<_Op, valarray<_Tp>, _A1> 1036 { 1037 typedef typename _Op::result_type result_type; 1038 typedef _Tp value_type; 1039 1040 _Op __op_; 1041 const valarray<_Tp>& __a0_; 1042 _A1 __a1_; 1043 1044 _LIBCPP_INLINE_VISIBILITY 1045 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1) 1046 : __op_(__op), __a0_(__a0), __a1_(__a1) {} 1047 1048 _LIBCPP_INLINE_VISIBILITY 1049 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);} 1050 1051 _LIBCPP_INLINE_VISIBILITY 1052 size_t size() const {return __a0_.size();} 1053 }; 1054 1055 template <class _Op, class _A0, class _Tp> 1056 struct _BinaryOp<_Op, _A0, valarray<_Tp> > 1057 { 1058 typedef typename _Op::result_type result_type; 1059 typedef _Tp value_type; 1060 1061 _Op __op_; 1062 _A0 __a0_; 1063 const valarray<_Tp>& __a1_; 1064 1065 _LIBCPP_INLINE_VISIBILITY 1066 _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1) 1067 : __op_(__op), __a0_(__a0), __a1_(__a1) {} 1068 1069 _LIBCPP_INLINE_VISIBILITY 1070 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);} 1071 1072 _LIBCPP_INLINE_VISIBILITY 1073 size_t size() const {return __a0_.size();} 1074 }; 1075 1076 template <class _Op, class _Tp> 1077 struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> > 1078 { 1079 typedef typename _Op::result_type result_type; 1080 typedef _Tp value_type; 1081 1082 _Op __op_; 1083 const valarray<_Tp>& __a0_; 1084 const valarray<_Tp>& __a1_; 1085 1086 _LIBCPP_INLINE_VISIBILITY 1087 _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1) 1088 : __op_(__op), __a0_(__a0), __a1_(__a1) {} 1089 1090 _LIBCPP_INLINE_VISIBILITY 1091 value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);} 1092 1093 _LIBCPP_INLINE_VISIBILITY 1094 size_t size() const {return __a0_.size();} 1095 }; 1096 1097 // slice_array 1098 1099 template <class _Tp> 1100 class _LIBCPP_TYPE_VIS_ONLY slice_array 1101 { 1102 public: 1103 typedef _Tp value_type; 1104 1105 private: 1106 value_type* __vp_; 1107 size_t __size_; 1108 size_t __stride_; 1109 1110 public: 1111 template <class _Expr> 1112 typename enable_if 1113 < 1114 __is_val_expr<_Expr>::value, 1115 void 1116 >::type 1117 operator=(const _Expr& __v) const; 1118 1119 template <class _Expr> 1120 typename enable_if 1121 < 1122 __is_val_expr<_Expr>::value, 1123 void 1124 >::type 1125 operator*=(const _Expr& __v) const; 1126 1127 template <class _Expr> 1128 typename enable_if 1129 < 1130 __is_val_expr<_Expr>::value, 1131 void 1132 >::type 1133 operator/=(const _Expr& __v) const; 1134 1135 template <class _Expr> 1136 typename enable_if 1137 < 1138 __is_val_expr<_Expr>::value, 1139 void 1140 >::type 1141 operator%=(const _Expr& __v) const; 1142 1143 template <class _Expr> 1144 typename enable_if 1145 < 1146 __is_val_expr<_Expr>::value, 1147 void 1148 >::type 1149 operator+=(const _Expr& __v) const; 1150 1151 template <class _Expr> 1152 typename enable_if 1153 < 1154 __is_val_expr<_Expr>::value, 1155 void 1156 >::type 1157 operator-=(const _Expr& __v) const; 1158 1159 template <class _Expr> 1160 typename enable_if 1161 < 1162 __is_val_expr<_Expr>::value, 1163 void 1164 >::type 1165 operator^=(const _Expr& __v) const; 1166 1167 template <class _Expr> 1168 typename enable_if 1169 < 1170 __is_val_expr<_Expr>::value, 1171 void 1172 >::type 1173 operator&=(const _Expr& __v) const; 1174 1175 template <class _Expr> 1176 typename enable_if 1177 < 1178 __is_val_expr<_Expr>::value, 1179 void 1180 >::type 1181 operator|=(const _Expr& __v) const; 1182 1183 template <class _Expr> 1184 typename enable_if 1185 < 1186 __is_val_expr<_Expr>::value, 1187 void 1188 >::type 1189 operator<<=(const _Expr& __v) const; 1190 1191 template <class _Expr> 1192 typename enable_if 1193 < 1194 __is_val_expr<_Expr>::value, 1195 void 1196 >::type 1197 operator>>=(const _Expr& __v) const; 1198 1199 const slice_array& operator=(const slice_array& __sa) const; 1200 1201 void operator=(const value_type& __x) const; 1202 1203 private: 1204 _LIBCPP_INLINE_VISIBILITY 1205 slice_array(const slice& __sl, const valarray<value_type>& __v) 1206 : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())), 1207 __size_(__sl.size()), 1208 __stride_(__sl.stride()) 1209 {} 1210 1211 template <class> friend class valarray; 1212 template <class> friend class sliceExpr; 1213 }; 1214 1215 template <class _Tp> 1216 inline _LIBCPP_INLINE_VISIBILITY 1217 const slice_array<_Tp>& 1218 slice_array<_Tp>::operator=(const slice_array& __sa) const 1219 { 1220 value_type* __t = __vp_; 1221 const value_type* __s = __sa.__vp_; 1222 for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_) 1223 *__t = *__s; 1224 return *this; 1225 } 1226 1227 template <class _Tp> 1228 template <class _Expr> 1229 inline _LIBCPP_INLINE_VISIBILITY 1230 typename enable_if 1231 < 1232 __is_val_expr<_Expr>::value, 1233 void 1234 >::type 1235 slice_array<_Tp>::operator=(const _Expr& __v) const 1236 { 1237 value_type* __t = __vp_; 1238 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1239 *__t = __v[__i]; 1240 } 1241 1242 template <class _Tp> 1243 template <class _Expr> 1244 inline _LIBCPP_INLINE_VISIBILITY 1245 typename enable_if 1246 < 1247 __is_val_expr<_Expr>::value, 1248 void 1249 >::type 1250 slice_array<_Tp>::operator*=(const _Expr& __v) const 1251 { 1252 value_type* __t = __vp_; 1253 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1254 *__t *= __v[__i]; 1255 } 1256 1257 template <class _Tp> 1258 template <class _Expr> 1259 inline _LIBCPP_INLINE_VISIBILITY 1260 typename enable_if 1261 < 1262 __is_val_expr<_Expr>::value, 1263 void 1264 >::type 1265 slice_array<_Tp>::operator/=(const _Expr& __v) const 1266 { 1267 value_type* __t = __vp_; 1268 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1269 *__t /= __v[__i]; 1270 } 1271 1272 template <class _Tp> 1273 template <class _Expr> 1274 inline _LIBCPP_INLINE_VISIBILITY 1275 typename enable_if 1276 < 1277 __is_val_expr<_Expr>::value, 1278 void 1279 >::type 1280 slice_array<_Tp>::operator%=(const _Expr& __v) const 1281 { 1282 value_type* __t = __vp_; 1283 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1284 *__t %= __v[__i]; 1285 } 1286 1287 template <class _Tp> 1288 template <class _Expr> 1289 inline _LIBCPP_INLINE_VISIBILITY 1290 typename enable_if 1291 < 1292 __is_val_expr<_Expr>::value, 1293 void 1294 >::type 1295 slice_array<_Tp>::operator+=(const _Expr& __v) const 1296 { 1297 value_type* __t = __vp_; 1298 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1299 *__t += __v[__i]; 1300 } 1301 1302 template <class _Tp> 1303 template <class _Expr> 1304 inline _LIBCPP_INLINE_VISIBILITY 1305 typename enable_if 1306 < 1307 __is_val_expr<_Expr>::value, 1308 void 1309 >::type 1310 slice_array<_Tp>::operator-=(const _Expr& __v) const 1311 { 1312 value_type* __t = __vp_; 1313 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1314 *__t -= __v[__i]; 1315 } 1316 1317 template <class _Tp> 1318 template <class _Expr> 1319 inline _LIBCPP_INLINE_VISIBILITY 1320 typename enable_if 1321 < 1322 __is_val_expr<_Expr>::value, 1323 void 1324 >::type 1325 slice_array<_Tp>::operator^=(const _Expr& __v) const 1326 { 1327 value_type* __t = __vp_; 1328 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1329 *__t ^= __v[__i]; 1330 } 1331 1332 template <class _Tp> 1333 template <class _Expr> 1334 inline _LIBCPP_INLINE_VISIBILITY 1335 typename enable_if 1336 < 1337 __is_val_expr<_Expr>::value, 1338 void 1339 >::type 1340 slice_array<_Tp>::operator&=(const _Expr& __v) const 1341 { 1342 value_type* __t = __vp_; 1343 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1344 *__t &= __v[__i]; 1345 } 1346 1347 template <class _Tp> 1348 template <class _Expr> 1349 inline _LIBCPP_INLINE_VISIBILITY 1350 typename enable_if 1351 < 1352 __is_val_expr<_Expr>::value, 1353 void 1354 >::type 1355 slice_array<_Tp>::operator|=(const _Expr& __v) const 1356 { 1357 value_type* __t = __vp_; 1358 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1359 *__t |= __v[__i]; 1360 } 1361 1362 template <class _Tp> 1363 template <class _Expr> 1364 inline _LIBCPP_INLINE_VISIBILITY 1365 typename enable_if 1366 < 1367 __is_val_expr<_Expr>::value, 1368 void 1369 >::type 1370 slice_array<_Tp>::operator<<=(const _Expr& __v) const 1371 { 1372 value_type* __t = __vp_; 1373 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1374 *__t <<= __v[__i]; 1375 } 1376 1377 template <class _Tp> 1378 template <class _Expr> 1379 inline _LIBCPP_INLINE_VISIBILITY 1380 typename enable_if 1381 < 1382 __is_val_expr<_Expr>::value, 1383 void 1384 >::type 1385 slice_array<_Tp>::operator>>=(const _Expr& __v) const 1386 { 1387 value_type* __t = __vp_; 1388 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1389 *__t >>= __v[__i]; 1390 } 1391 1392 template <class _Tp> 1393 inline _LIBCPP_INLINE_VISIBILITY 1394 void 1395 slice_array<_Tp>::operator=(const value_type& __x) const 1396 { 1397 value_type* __t = __vp_; 1398 for (size_t __n = __size_; __n; --__n, __t += __stride_) 1399 *__t = __x; 1400 } 1401 1402 // gslice 1403 1404 class _LIBCPP_TYPE_VIS gslice 1405 { 1406 valarray<size_t> __size_; 1407 valarray<size_t> __stride_; 1408 valarray<size_t> __1d_; 1409 1410 public: 1411 _LIBCPP_INLINE_VISIBILITY 1412 gslice() {} 1413 1414 _LIBCPP_INLINE_VISIBILITY 1415 gslice(size_t __start, const valarray<size_t>& __size, 1416 const valarray<size_t>& __stride) 1417 : __size_(__size), 1418 __stride_(__stride) 1419 {__init(__start);} 1420 1421 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1422 1423 _LIBCPP_INLINE_VISIBILITY 1424 gslice(size_t __start, const valarray<size_t>& __size, 1425 valarray<size_t>&& __stride) 1426 : __size_(__size), 1427 __stride_(move(__stride)) 1428 {__init(__start);} 1429 1430 _LIBCPP_INLINE_VISIBILITY 1431 gslice(size_t __start, valarray<size_t>&& __size, 1432 const valarray<size_t>& __stride) 1433 : __size_(move(__size)), 1434 __stride_(__stride) 1435 {__init(__start);} 1436 1437 _LIBCPP_INLINE_VISIBILITY 1438 gslice(size_t __start, valarray<size_t>&& __size, 1439 valarray<size_t>&& __stride) 1440 : __size_(move(__size)), 1441 __stride_(move(__stride)) 1442 {__init(__start);} 1443 1444 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 1445 1446 // gslice(const gslice&) = default; 1447 // gslice(gslice&&) = default; 1448 // gslice& operator=(const gslice&) = default; 1449 // gslice& operator=(gslice&&) = default; 1450 1451 _LIBCPP_INLINE_VISIBILITY 1452 size_t start() const {return __1d_.size() ? __1d_[0] : 0;} 1453 1454 _LIBCPP_INLINE_VISIBILITY 1455 valarray<size_t> size() const {return __size_;} 1456 1457 _LIBCPP_INLINE_VISIBILITY 1458 valarray<size_t> stride() const {return __stride_;} 1459 1460 private: 1461 void __init(size_t __start); 1462 1463 template <class> friend class gslice_array; 1464 template <class> friend class valarray; 1465 template <class> friend class __val_expr; 1466 }; 1467 1468 // gslice_array 1469 1470 template <class _Tp> 1471 class _LIBCPP_TYPE_VIS_ONLY gslice_array 1472 { 1473 public: 1474 typedef _Tp value_type; 1475 1476 private: 1477 value_type* __vp_; 1478 valarray<size_t> __1d_; 1479 1480 public: 1481 template <class _Expr> 1482 typename enable_if 1483 < 1484 __is_val_expr<_Expr>::value, 1485 void 1486 >::type 1487 operator=(const _Expr& __v) const; 1488 1489 template <class _Expr> 1490 typename enable_if 1491 < 1492 __is_val_expr<_Expr>::value, 1493 void 1494 >::type 1495 operator*=(const _Expr& __v) const; 1496 1497 template <class _Expr> 1498 typename enable_if 1499 < 1500 __is_val_expr<_Expr>::value, 1501 void 1502 >::type 1503 operator/=(const _Expr& __v) const; 1504 1505 template <class _Expr> 1506 typename enable_if 1507 < 1508 __is_val_expr<_Expr>::value, 1509 void 1510 >::type 1511 operator%=(const _Expr& __v) const; 1512 1513 template <class _Expr> 1514 typename enable_if 1515 < 1516 __is_val_expr<_Expr>::value, 1517 void 1518 >::type 1519 operator+=(const _Expr& __v) const; 1520 1521 template <class _Expr> 1522 typename enable_if 1523 < 1524 __is_val_expr<_Expr>::value, 1525 void 1526 >::type 1527 operator-=(const _Expr& __v) const; 1528 1529 template <class _Expr> 1530 typename enable_if 1531 < 1532 __is_val_expr<_Expr>::value, 1533 void 1534 >::type 1535 operator^=(const _Expr& __v) const; 1536 1537 template <class _Expr> 1538 typename enable_if 1539 < 1540 __is_val_expr<_Expr>::value, 1541 void 1542 >::type 1543 operator&=(const _Expr& __v) const; 1544 1545 template <class _Expr> 1546 typename enable_if 1547 < 1548 __is_val_expr<_Expr>::value, 1549 void 1550 >::type 1551 operator|=(const _Expr& __v) const; 1552 1553 template <class _Expr> 1554 typename enable_if 1555 < 1556 __is_val_expr<_Expr>::value, 1557 void 1558 >::type 1559 operator<<=(const _Expr& __v) const; 1560 1561 template <class _Expr> 1562 typename enable_if 1563 < 1564 __is_val_expr<_Expr>::value, 1565 void 1566 >::type 1567 operator>>=(const _Expr& __v) const; 1568 1569 const gslice_array& operator=(const gslice_array& __ga) const; 1570 1571 void operator=(const value_type& __x) const; 1572 1573 // gslice_array(const gslice_array&) = default; 1574 // gslice_array(gslice_array&&) = default; 1575 // gslice_array& operator=(const gslice_array&) = default; 1576 // gslice_array& operator=(gslice_array&&) = default; 1577 1578 private: 1579 _LIBCPP_INLINE_VISIBILITY 1580 gslice_array(const gslice& __gs, const valarray<value_type>& __v) 1581 : __vp_(const_cast<value_type*>(__v.__begin_)), 1582 __1d_(__gs.__1d_) 1583 {} 1584 1585 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1586 1587 _LIBCPP_INLINE_VISIBILITY 1588 gslice_array(gslice&& __gs, const valarray<value_type>& __v) 1589 : __vp_(const_cast<value_type*>(__v.__begin_)), 1590 __1d_(move(__gs.__1d_)) 1591 {} 1592 1593 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 1594 1595 template <class> friend class valarray; 1596 }; 1597 1598 template <class _Tp> 1599 template <class _Expr> 1600 inline _LIBCPP_INLINE_VISIBILITY 1601 typename enable_if 1602 < 1603 __is_val_expr<_Expr>::value, 1604 void 1605 >::type 1606 gslice_array<_Tp>::operator=(const _Expr& __v) const 1607 { 1608 typedef const size_t* _Ip; 1609 size_t __j = 0; 1610 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1611 __vp_[*__i] = __v[__j]; 1612 } 1613 1614 template <class _Tp> 1615 template <class _Expr> 1616 inline _LIBCPP_INLINE_VISIBILITY 1617 typename enable_if 1618 < 1619 __is_val_expr<_Expr>::value, 1620 void 1621 >::type 1622 gslice_array<_Tp>::operator*=(const _Expr& __v) const 1623 { 1624 typedef const size_t* _Ip; 1625 size_t __j = 0; 1626 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1627 __vp_[*__i] *= __v[__j]; 1628 } 1629 1630 template <class _Tp> 1631 template <class _Expr> 1632 inline _LIBCPP_INLINE_VISIBILITY 1633 typename enable_if 1634 < 1635 __is_val_expr<_Expr>::value, 1636 void 1637 >::type 1638 gslice_array<_Tp>::operator/=(const _Expr& __v) const 1639 { 1640 typedef const size_t* _Ip; 1641 size_t __j = 0; 1642 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1643 __vp_[*__i] /= __v[__j]; 1644 } 1645 1646 template <class _Tp> 1647 template <class _Expr> 1648 inline _LIBCPP_INLINE_VISIBILITY 1649 typename enable_if 1650 < 1651 __is_val_expr<_Expr>::value, 1652 void 1653 >::type 1654 gslice_array<_Tp>::operator%=(const _Expr& __v) const 1655 { 1656 typedef const size_t* _Ip; 1657 size_t __j = 0; 1658 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1659 __vp_[*__i] %= __v[__j]; 1660 } 1661 1662 template <class _Tp> 1663 template <class _Expr> 1664 inline _LIBCPP_INLINE_VISIBILITY 1665 typename enable_if 1666 < 1667 __is_val_expr<_Expr>::value, 1668 void 1669 >::type 1670 gslice_array<_Tp>::operator+=(const _Expr& __v) const 1671 { 1672 typedef const size_t* _Ip; 1673 size_t __j = 0; 1674 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1675 __vp_[*__i] += __v[__j]; 1676 } 1677 1678 template <class _Tp> 1679 template <class _Expr> 1680 inline _LIBCPP_INLINE_VISIBILITY 1681 typename enable_if 1682 < 1683 __is_val_expr<_Expr>::value, 1684 void 1685 >::type 1686 gslice_array<_Tp>::operator-=(const _Expr& __v) const 1687 { 1688 typedef const size_t* _Ip; 1689 size_t __j = 0; 1690 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1691 __vp_[*__i] -= __v[__j]; 1692 } 1693 1694 template <class _Tp> 1695 template <class _Expr> 1696 inline _LIBCPP_INLINE_VISIBILITY 1697 typename enable_if 1698 < 1699 __is_val_expr<_Expr>::value, 1700 void 1701 >::type 1702 gslice_array<_Tp>::operator^=(const _Expr& __v) const 1703 { 1704 typedef const size_t* _Ip; 1705 size_t __j = 0; 1706 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1707 __vp_[*__i] ^= __v[__j]; 1708 } 1709 1710 template <class _Tp> 1711 template <class _Expr> 1712 inline _LIBCPP_INLINE_VISIBILITY 1713 typename enable_if 1714 < 1715 __is_val_expr<_Expr>::value, 1716 void 1717 >::type 1718 gslice_array<_Tp>::operator&=(const _Expr& __v) const 1719 { 1720 typedef const size_t* _Ip; 1721 size_t __j = 0; 1722 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1723 __vp_[*__i] &= __v[__j]; 1724 } 1725 1726 template <class _Tp> 1727 template <class _Expr> 1728 inline _LIBCPP_INLINE_VISIBILITY 1729 typename enable_if 1730 < 1731 __is_val_expr<_Expr>::value, 1732 void 1733 >::type 1734 gslice_array<_Tp>::operator|=(const _Expr& __v) const 1735 { 1736 typedef const size_t* _Ip; 1737 size_t __j = 0; 1738 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1739 __vp_[*__i] |= __v[__j]; 1740 } 1741 1742 template <class _Tp> 1743 template <class _Expr> 1744 inline _LIBCPP_INLINE_VISIBILITY 1745 typename enable_if 1746 < 1747 __is_val_expr<_Expr>::value, 1748 void 1749 >::type 1750 gslice_array<_Tp>::operator<<=(const _Expr& __v) const 1751 { 1752 typedef const size_t* _Ip; 1753 size_t __j = 0; 1754 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1755 __vp_[*__i] <<= __v[__j]; 1756 } 1757 1758 template <class _Tp> 1759 template <class _Expr> 1760 inline _LIBCPP_INLINE_VISIBILITY 1761 typename enable_if 1762 < 1763 __is_val_expr<_Expr>::value, 1764 void 1765 >::type 1766 gslice_array<_Tp>::operator>>=(const _Expr& __v) const 1767 { 1768 typedef const size_t* _Ip; 1769 size_t __j = 0; 1770 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1771 __vp_[*__i] >>= __v[__j]; 1772 } 1773 1774 template <class _Tp> 1775 inline _LIBCPP_INLINE_VISIBILITY 1776 const gslice_array<_Tp>& 1777 gslice_array<_Tp>::operator=(const gslice_array& __ga) const 1778 { 1779 typedef const size_t* _Ip; 1780 const value_type* __s = __ga.__vp_; 1781 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_; 1782 __i != __e; ++__i, ++__j) 1783 __vp_[*__i] = __s[*__j]; 1784 return *this; 1785 } 1786 1787 template <class _Tp> 1788 inline _LIBCPP_INLINE_VISIBILITY 1789 void 1790 gslice_array<_Tp>::operator=(const value_type& __x) const 1791 { 1792 typedef const size_t* _Ip; 1793 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i) 1794 __vp_[*__i] = __x; 1795 } 1796 1797 // mask_array 1798 1799 template <class _Tp> 1800 class _LIBCPP_TYPE_VIS_ONLY mask_array 1801 { 1802 public: 1803 typedef _Tp value_type; 1804 1805 private: 1806 value_type* __vp_; 1807 valarray<size_t> __1d_; 1808 1809 public: 1810 template <class _Expr> 1811 typename enable_if 1812 < 1813 __is_val_expr<_Expr>::value, 1814 void 1815 >::type 1816 operator=(const _Expr& __v) const; 1817 1818 template <class _Expr> 1819 typename enable_if 1820 < 1821 __is_val_expr<_Expr>::value, 1822 void 1823 >::type 1824 operator*=(const _Expr& __v) const; 1825 1826 template <class _Expr> 1827 typename enable_if 1828 < 1829 __is_val_expr<_Expr>::value, 1830 void 1831 >::type 1832 operator/=(const _Expr& __v) const; 1833 1834 template <class _Expr> 1835 typename enable_if 1836 < 1837 __is_val_expr<_Expr>::value, 1838 void 1839 >::type 1840 operator%=(const _Expr& __v) const; 1841 1842 template <class _Expr> 1843 typename enable_if 1844 < 1845 __is_val_expr<_Expr>::value, 1846 void 1847 >::type 1848 operator+=(const _Expr& __v) const; 1849 1850 template <class _Expr> 1851 typename enable_if 1852 < 1853 __is_val_expr<_Expr>::value, 1854 void 1855 >::type 1856 operator-=(const _Expr& __v) const; 1857 1858 template <class _Expr> 1859 typename enable_if 1860 < 1861 __is_val_expr<_Expr>::value, 1862 void 1863 >::type 1864 operator^=(const _Expr& __v) const; 1865 1866 template <class _Expr> 1867 typename enable_if 1868 < 1869 __is_val_expr<_Expr>::value, 1870 void 1871 >::type 1872 operator&=(const _Expr& __v) const; 1873 1874 template <class _Expr> 1875 typename enable_if 1876 < 1877 __is_val_expr<_Expr>::value, 1878 void 1879 >::type 1880 operator|=(const _Expr& __v) const; 1881 1882 template <class _Expr> 1883 typename enable_if 1884 < 1885 __is_val_expr<_Expr>::value, 1886 void 1887 >::type 1888 operator<<=(const _Expr& __v) const; 1889 1890 template <class _Expr> 1891 typename enable_if 1892 < 1893 __is_val_expr<_Expr>::value, 1894 void 1895 >::type 1896 operator>>=(const _Expr& __v) const; 1897 1898 const mask_array& operator=(const mask_array& __ma) const; 1899 1900 void operator=(const value_type& __x) const; 1901 1902 // mask_array(const mask_array&) = default; 1903 // mask_array(mask_array&&) = default; 1904 // mask_array& operator=(const mask_array&) = default; 1905 // mask_array& operator=(mask_array&&) = default; 1906 1907 private: 1908 _LIBCPP_INLINE_VISIBILITY 1909 mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v) 1910 : __vp_(const_cast<value_type*>(__v.__begin_)), 1911 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true))) 1912 { 1913 size_t __j = 0; 1914 for (size_t __i = 0; __i < __vb.size(); ++__i) 1915 if (__vb[__i]) 1916 __1d_[__j++] = __i; 1917 } 1918 1919 template <class> friend class valarray; 1920 }; 1921 1922 template <class _Tp> 1923 template <class _Expr> 1924 inline _LIBCPP_INLINE_VISIBILITY 1925 typename enable_if 1926 < 1927 __is_val_expr<_Expr>::value, 1928 void 1929 >::type 1930 mask_array<_Tp>::operator=(const _Expr& __v) const 1931 { 1932 size_t __n = __1d_.size(); 1933 for (size_t __i = 0; __i < __n; ++__i) 1934 __vp_[__1d_[__i]] = __v[__i]; 1935 } 1936 1937 template <class _Tp> 1938 template <class _Expr> 1939 inline _LIBCPP_INLINE_VISIBILITY 1940 typename enable_if 1941 < 1942 __is_val_expr<_Expr>::value, 1943 void 1944 >::type 1945 mask_array<_Tp>::operator*=(const _Expr& __v) const 1946 { 1947 size_t __n = __1d_.size(); 1948 for (size_t __i = 0; __i < __n; ++__i) 1949 __vp_[__1d_[__i]] *= __v[__i]; 1950 } 1951 1952 template <class _Tp> 1953 template <class _Expr> 1954 inline _LIBCPP_INLINE_VISIBILITY 1955 typename enable_if 1956 < 1957 __is_val_expr<_Expr>::value, 1958 void 1959 >::type 1960 mask_array<_Tp>::operator/=(const _Expr& __v) const 1961 { 1962 size_t __n = __1d_.size(); 1963 for (size_t __i = 0; __i < __n; ++__i) 1964 __vp_[__1d_[__i]] /= __v[__i]; 1965 } 1966 1967 template <class _Tp> 1968 template <class _Expr> 1969 inline _LIBCPP_INLINE_VISIBILITY 1970 typename enable_if 1971 < 1972 __is_val_expr<_Expr>::value, 1973 void 1974 >::type 1975 mask_array<_Tp>::operator%=(const _Expr& __v) const 1976 { 1977 size_t __n = __1d_.size(); 1978 for (size_t __i = 0; __i < __n; ++__i) 1979 __vp_[__1d_[__i]] %= __v[__i]; 1980 } 1981 1982 template <class _Tp> 1983 template <class _Expr> 1984 inline _LIBCPP_INLINE_VISIBILITY 1985 typename enable_if 1986 < 1987 __is_val_expr<_Expr>::value, 1988 void 1989 >::type 1990 mask_array<_Tp>::operator+=(const _Expr& __v) const 1991 { 1992 size_t __n = __1d_.size(); 1993 for (size_t __i = 0; __i < __n; ++__i) 1994 __vp_[__1d_[__i]] += __v[__i]; 1995 } 1996 1997 template <class _Tp> 1998 template <class _Expr> 1999 inline _LIBCPP_INLINE_VISIBILITY 2000 typename enable_if 2001 < 2002 __is_val_expr<_Expr>::value, 2003 void 2004 >::type 2005 mask_array<_Tp>::operator-=(const _Expr& __v) const 2006 { 2007 size_t __n = __1d_.size(); 2008 for (size_t __i = 0; __i < __n; ++__i) 2009 __vp_[__1d_[__i]] -= __v[__i]; 2010 } 2011 2012 template <class _Tp> 2013 template <class _Expr> 2014 inline _LIBCPP_INLINE_VISIBILITY 2015 typename enable_if 2016 < 2017 __is_val_expr<_Expr>::value, 2018 void 2019 >::type 2020 mask_array<_Tp>::operator^=(const _Expr& __v) const 2021 { 2022 size_t __n = __1d_.size(); 2023 for (size_t __i = 0; __i < __n; ++__i) 2024 __vp_[__1d_[__i]] ^= __v[__i]; 2025 } 2026 2027 template <class _Tp> 2028 template <class _Expr> 2029 inline _LIBCPP_INLINE_VISIBILITY 2030 typename enable_if 2031 < 2032 __is_val_expr<_Expr>::value, 2033 void 2034 >::type 2035 mask_array<_Tp>::operator&=(const _Expr& __v) const 2036 { 2037 size_t __n = __1d_.size(); 2038 for (size_t __i = 0; __i < __n; ++__i) 2039 __vp_[__1d_[__i]] &= __v[__i]; 2040 } 2041 2042 template <class _Tp> 2043 template <class _Expr> 2044 inline _LIBCPP_INLINE_VISIBILITY 2045 typename enable_if 2046 < 2047 __is_val_expr<_Expr>::value, 2048 void 2049 >::type 2050 mask_array<_Tp>::operator|=(const _Expr& __v) const 2051 { 2052 size_t __n = __1d_.size(); 2053 for (size_t __i = 0; __i < __n; ++__i) 2054 __vp_[__1d_[__i]] |= __v[__i]; 2055 } 2056 2057 template <class _Tp> 2058 template <class _Expr> 2059 inline _LIBCPP_INLINE_VISIBILITY 2060 typename enable_if 2061 < 2062 __is_val_expr<_Expr>::value, 2063 void 2064 >::type 2065 mask_array<_Tp>::operator<<=(const _Expr& __v) const 2066 { 2067 size_t __n = __1d_.size(); 2068 for (size_t __i = 0; __i < __n; ++__i) 2069 __vp_[__1d_[__i]] <<= __v[__i]; 2070 } 2071 2072 template <class _Tp> 2073 template <class _Expr> 2074 inline _LIBCPP_INLINE_VISIBILITY 2075 typename enable_if 2076 < 2077 __is_val_expr<_Expr>::value, 2078 void 2079 >::type 2080 mask_array<_Tp>::operator>>=(const _Expr& __v) const 2081 { 2082 size_t __n = __1d_.size(); 2083 for (size_t __i = 0; __i < __n; ++__i) 2084 __vp_[__1d_[__i]] >>= __v[__i]; 2085 } 2086 2087 template <class _Tp> 2088 inline _LIBCPP_INLINE_VISIBILITY 2089 const mask_array<_Tp>& 2090 mask_array<_Tp>::operator=(const mask_array& __ma) const 2091 { 2092 size_t __n = __1d_.size(); 2093 for (size_t __i = 0; __i < __n; ++__i) 2094 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]]; 2095 return *this; 2096 } 2097 2098 template <class _Tp> 2099 inline _LIBCPP_INLINE_VISIBILITY 2100 void 2101 mask_array<_Tp>::operator=(const value_type& __x) const 2102 { 2103 size_t __n = __1d_.size(); 2104 for (size_t __i = 0; __i < __n; ++__i) 2105 __vp_[__1d_[__i]] = __x; 2106 } 2107 2108 template <class _ValExpr> 2109 class __mask_expr 2110 { 2111 typedef typename remove_reference<_ValExpr>::type _RmExpr; 2112 public: 2113 typedef typename _RmExpr::value_type value_type; 2114 typedef value_type result_type; 2115 2116 private: 2117 _ValExpr __expr_; 2118 valarray<size_t> __1d_; 2119 2120 _LIBCPP_INLINE_VISIBILITY 2121 __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e) 2122 : __expr_(__e), 2123 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true))) 2124 { 2125 size_t __j = 0; 2126 for (size_t __i = 0; __i < __vb.size(); ++__i) 2127 if (__vb[__i]) 2128 __1d_[__j++] = __i; 2129 } 2130 2131 public: 2132 _LIBCPP_INLINE_VISIBILITY 2133 result_type operator[](size_t __i) const 2134 {return __expr_[__1d_[__i]];} 2135 2136 _LIBCPP_INLINE_VISIBILITY 2137 size_t size() const {return __1d_.size();} 2138 2139 template <class> friend class valarray; 2140 }; 2141 2142 // indirect_array 2143 2144 template <class _Tp> 2145 class _LIBCPP_TYPE_VIS_ONLY indirect_array 2146 { 2147 public: 2148 typedef _Tp value_type; 2149 2150 private: 2151 value_type* __vp_; 2152 valarray<size_t> __1d_; 2153 2154 public: 2155 template <class _Expr> 2156 typename enable_if 2157 < 2158 __is_val_expr<_Expr>::value, 2159 void 2160 >::type 2161 operator=(const _Expr& __v) const; 2162 2163 template <class _Expr> 2164 typename enable_if 2165 < 2166 __is_val_expr<_Expr>::value, 2167 void 2168 >::type 2169 operator*=(const _Expr& __v) const; 2170 2171 template <class _Expr> 2172 typename enable_if 2173 < 2174 __is_val_expr<_Expr>::value, 2175 void 2176 >::type 2177 operator/=(const _Expr& __v) const; 2178 2179 template <class _Expr> 2180 typename enable_if 2181 < 2182 __is_val_expr<_Expr>::value, 2183 void 2184 >::type 2185 operator%=(const _Expr& __v) const; 2186 2187 template <class _Expr> 2188 typename enable_if 2189 < 2190 __is_val_expr<_Expr>::value, 2191 void 2192 >::type 2193 operator+=(const _Expr& __v) const; 2194 2195 template <class _Expr> 2196 typename enable_if 2197 < 2198 __is_val_expr<_Expr>::value, 2199 void 2200 >::type 2201 operator-=(const _Expr& __v) const; 2202 2203 template <class _Expr> 2204 typename enable_if 2205 < 2206 __is_val_expr<_Expr>::value, 2207 void 2208 >::type 2209 operator^=(const _Expr& __v) const; 2210 2211 template <class _Expr> 2212 typename enable_if 2213 < 2214 __is_val_expr<_Expr>::value, 2215 void 2216 >::type 2217 operator&=(const _Expr& __v) const; 2218 2219 template <class _Expr> 2220 typename enable_if 2221 < 2222 __is_val_expr<_Expr>::value, 2223 void 2224 >::type 2225 operator|=(const _Expr& __v) const; 2226 2227 template <class _Expr> 2228 typename enable_if 2229 < 2230 __is_val_expr<_Expr>::value, 2231 void 2232 >::type 2233 operator<<=(const _Expr& __v) const; 2234 2235 template <class _Expr> 2236 typename enable_if 2237 < 2238 __is_val_expr<_Expr>::value, 2239 void 2240 >::type 2241 operator>>=(const _Expr& __v) const; 2242 2243 const indirect_array& operator=(const indirect_array& __ia) const; 2244 2245 void operator=(const value_type& __x) const; 2246 2247 // indirect_array(const indirect_array&) = default; 2248 // indirect_array(indirect_array&&) = default; 2249 // indirect_array& operator=(const indirect_array&) = default; 2250 // indirect_array& operator=(indirect_array&&) = default; 2251 2252 private: 2253 _LIBCPP_INLINE_VISIBILITY 2254 indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v) 2255 : __vp_(const_cast<value_type*>(__v.__begin_)), 2256 __1d_(__ia) 2257 {} 2258 2259 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2260 2261 _LIBCPP_INLINE_VISIBILITY 2262 indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v) 2263 : __vp_(const_cast<value_type*>(__v.__begin_)), 2264 __1d_(move(__ia)) 2265 {} 2266 2267 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2268 2269 template <class> friend class valarray; 2270 }; 2271 2272 template <class _Tp> 2273 template <class _Expr> 2274 inline _LIBCPP_INLINE_VISIBILITY 2275 typename enable_if 2276 < 2277 __is_val_expr<_Expr>::value, 2278 void 2279 >::type 2280 indirect_array<_Tp>::operator=(const _Expr& __v) const 2281 { 2282 size_t __n = __1d_.size(); 2283 for (size_t __i = 0; __i < __n; ++__i) 2284 __vp_[__1d_[__i]] = __v[__i]; 2285 } 2286 2287 template <class _Tp> 2288 template <class _Expr> 2289 inline _LIBCPP_INLINE_VISIBILITY 2290 typename enable_if 2291 < 2292 __is_val_expr<_Expr>::value, 2293 void 2294 >::type 2295 indirect_array<_Tp>::operator*=(const _Expr& __v) const 2296 { 2297 size_t __n = __1d_.size(); 2298 for (size_t __i = 0; __i < __n; ++__i) 2299 __vp_[__1d_[__i]] *= __v[__i]; 2300 } 2301 2302 template <class _Tp> 2303 template <class _Expr> 2304 inline _LIBCPP_INLINE_VISIBILITY 2305 typename enable_if 2306 < 2307 __is_val_expr<_Expr>::value, 2308 void 2309 >::type 2310 indirect_array<_Tp>::operator/=(const _Expr& __v) const 2311 { 2312 size_t __n = __1d_.size(); 2313 for (size_t __i = 0; __i < __n; ++__i) 2314 __vp_[__1d_[__i]] /= __v[__i]; 2315 } 2316 2317 template <class _Tp> 2318 template <class _Expr> 2319 inline _LIBCPP_INLINE_VISIBILITY 2320 typename enable_if 2321 < 2322 __is_val_expr<_Expr>::value, 2323 void 2324 >::type 2325 indirect_array<_Tp>::operator%=(const _Expr& __v) const 2326 { 2327 size_t __n = __1d_.size(); 2328 for (size_t __i = 0; __i < __n; ++__i) 2329 __vp_[__1d_[__i]] %= __v[__i]; 2330 } 2331 2332 template <class _Tp> 2333 template <class _Expr> 2334 inline _LIBCPP_INLINE_VISIBILITY 2335 typename enable_if 2336 < 2337 __is_val_expr<_Expr>::value, 2338 void 2339 >::type 2340 indirect_array<_Tp>::operator+=(const _Expr& __v) const 2341 { 2342 size_t __n = __1d_.size(); 2343 for (size_t __i = 0; __i < __n; ++__i) 2344 __vp_[__1d_[__i]] += __v[__i]; 2345 } 2346 2347 template <class _Tp> 2348 template <class _Expr> 2349 inline _LIBCPP_INLINE_VISIBILITY 2350 typename enable_if 2351 < 2352 __is_val_expr<_Expr>::value, 2353 void 2354 >::type 2355 indirect_array<_Tp>::operator-=(const _Expr& __v) const 2356 { 2357 size_t __n = __1d_.size(); 2358 for (size_t __i = 0; __i < __n; ++__i) 2359 __vp_[__1d_[__i]] -= __v[__i]; 2360 } 2361 2362 template <class _Tp> 2363 template <class _Expr> 2364 inline _LIBCPP_INLINE_VISIBILITY 2365 typename enable_if 2366 < 2367 __is_val_expr<_Expr>::value, 2368 void 2369 >::type 2370 indirect_array<_Tp>::operator^=(const _Expr& __v) const 2371 { 2372 size_t __n = __1d_.size(); 2373 for (size_t __i = 0; __i < __n; ++__i) 2374 __vp_[__1d_[__i]] ^= __v[__i]; 2375 } 2376 2377 template <class _Tp> 2378 template <class _Expr> 2379 inline _LIBCPP_INLINE_VISIBILITY 2380 typename enable_if 2381 < 2382 __is_val_expr<_Expr>::value, 2383 void 2384 >::type 2385 indirect_array<_Tp>::operator&=(const _Expr& __v) const 2386 { 2387 size_t __n = __1d_.size(); 2388 for (size_t __i = 0; __i < __n; ++__i) 2389 __vp_[__1d_[__i]] &= __v[__i]; 2390 } 2391 2392 template <class _Tp> 2393 template <class _Expr> 2394 inline _LIBCPP_INLINE_VISIBILITY 2395 typename enable_if 2396 < 2397 __is_val_expr<_Expr>::value, 2398 void 2399 >::type 2400 indirect_array<_Tp>::operator|=(const _Expr& __v) const 2401 { 2402 size_t __n = __1d_.size(); 2403 for (size_t __i = 0; __i < __n; ++__i) 2404 __vp_[__1d_[__i]] |= __v[__i]; 2405 } 2406 2407 template <class _Tp> 2408 template <class _Expr> 2409 inline _LIBCPP_INLINE_VISIBILITY 2410 typename enable_if 2411 < 2412 __is_val_expr<_Expr>::value, 2413 void 2414 >::type 2415 indirect_array<_Tp>::operator<<=(const _Expr& __v) const 2416 { 2417 size_t __n = __1d_.size(); 2418 for (size_t __i = 0; __i < __n; ++__i) 2419 __vp_[__1d_[__i]] <<= __v[__i]; 2420 } 2421 2422 template <class _Tp> 2423 template <class _Expr> 2424 inline _LIBCPP_INLINE_VISIBILITY 2425 typename enable_if 2426 < 2427 __is_val_expr<_Expr>::value, 2428 void 2429 >::type 2430 indirect_array<_Tp>::operator>>=(const _Expr& __v) const 2431 { 2432 size_t __n = __1d_.size(); 2433 for (size_t __i = 0; __i < __n; ++__i) 2434 __vp_[__1d_[__i]] >>= __v[__i]; 2435 } 2436 2437 template <class _Tp> 2438 inline _LIBCPP_INLINE_VISIBILITY 2439 const indirect_array<_Tp>& 2440 indirect_array<_Tp>::operator=(const indirect_array& __ia) const 2441 { 2442 typedef const size_t* _Ip; 2443 const value_type* __s = __ia.__vp_; 2444 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_; 2445 __i != __e; ++__i, ++__j) 2446 __vp_[*__i] = __s[*__j]; 2447 return *this; 2448 } 2449 2450 template <class _Tp> 2451 inline _LIBCPP_INLINE_VISIBILITY 2452 void 2453 indirect_array<_Tp>::operator=(const value_type& __x) const 2454 { 2455 typedef const size_t* _Ip; 2456 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i) 2457 __vp_[*__i] = __x; 2458 } 2459 2460 template <class _ValExpr> 2461 class __indirect_expr 2462 { 2463 typedef typename remove_reference<_ValExpr>::type _RmExpr; 2464 public: 2465 typedef typename _RmExpr::value_type value_type; 2466 typedef value_type result_type; 2467 2468 private: 2469 _ValExpr __expr_; 2470 valarray<size_t> __1d_; 2471 2472 _LIBCPP_INLINE_VISIBILITY 2473 __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e) 2474 : __expr_(__e), 2475 __1d_(__ia) 2476 {} 2477 2478 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2479 2480 _LIBCPP_INLINE_VISIBILITY 2481 __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e) 2482 : __expr_(__e), 2483 __1d_(move(__ia)) 2484 {} 2485 2486 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2487 2488 public: 2489 _LIBCPP_INLINE_VISIBILITY 2490 result_type operator[](size_t __i) const 2491 {return __expr_[__1d_[__i]];} 2492 2493 _LIBCPP_INLINE_VISIBILITY 2494 size_t size() const {return __1d_.size();} 2495 2496 template <class> friend class _LIBCPP_TYPE_VIS_ONLY valarray; 2497 }; 2498 2499 template<class _ValExpr> 2500 class __val_expr 2501 { 2502 typedef typename remove_reference<_ValExpr>::type _RmExpr; 2503 2504 _ValExpr __expr_; 2505 public: 2506 typedef typename _RmExpr::value_type value_type; 2507 typedef typename _RmExpr::result_type result_type; 2508 2509 _LIBCPP_INLINE_VISIBILITY 2510 explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {} 2511 2512 _LIBCPP_INLINE_VISIBILITY 2513 result_type operator[](size_t __i) const 2514 {return __expr_[__i];} 2515 2516 _LIBCPP_INLINE_VISIBILITY 2517 __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const 2518 {return __val_expr<__slice_expr<_ValExpr> >(__expr_, __s);} 2519 2520 _LIBCPP_INLINE_VISIBILITY 2521 __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const 2522 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __gs.__1d_);} 2523 2524 _LIBCPP_INLINE_VISIBILITY 2525 __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const 2526 {return __val_expr<__mask_expr<_ValExpr> >(__expr_, __vb);} 2527 2528 _LIBCPP_INLINE_VISIBILITY 2529 __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const 2530 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __vs);} 2531 2532 _LIBCPP_INLINE_VISIBILITY 2533 __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> > 2534 operator+() const 2535 { 2536 typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr; 2537 return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_)); 2538 } 2539 2540 _LIBCPP_INLINE_VISIBILITY 2541 __val_expr<_UnaryOp<negate<value_type>, _ValExpr> > 2542 operator-() const 2543 { 2544 typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr; 2545 return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_)); 2546 } 2547 2548 _LIBCPP_INLINE_VISIBILITY 2549 __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> > 2550 operator~() const 2551 { 2552 typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr; 2553 return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_)); 2554 } 2555 2556 _LIBCPP_INLINE_VISIBILITY 2557 __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> > 2558 operator!() const 2559 { 2560 typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr; 2561 return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_)); 2562 } 2563 2564 operator valarray<result_type>() const; 2565 2566 _LIBCPP_INLINE_VISIBILITY 2567 size_t size() const {return __expr_.size();} 2568 2569 _LIBCPP_INLINE_VISIBILITY 2570 result_type sum() const 2571 { 2572 size_t __n = __expr_.size(); 2573 result_type __r = __n ? __expr_[0] : result_type(); 2574 for (size_t __i = 1; __i < __n; ++__i) 2575 __r += __expr_[__i]; 2576 return __r; 2577 } 2578 2579 _LIBCPP_INLINE_VISIBILITY 2580 result_type min() const 2581 { 2582 size_t __n = size(); 2583 result_type __r = __n ? (*this)[0] : result_type(); 2584 for (size_t __i = 1; __i < __n; ++__i) 2585 { 2586 result_type __x = __expr_[__i]; 2587 if (__x < __r) 2588 __r = __x; 2589 } 2590 return __r; 2591 } 2592 2593 _LIBCPP_INLINE_VISIBILITY 2594 result_type max() const 2595 { 2596 size_t __n = size(); 2597 result_type __r = __n ? (*this)[0] : result_type(); 2598 for (size_t __i = 1; __i < __n; ++__i) 2599 { 2600 result_type __x = __expr_[__i]; 2601 if (__r < __x) 2602 __r = __x; 2603 } 2604 return __r; 2605 } 2606 2607 _LIBCPP_INLINE_VISIBILITY 2608 __val_expr<__shift_expr<_ValExpr> > shift (int __i) const 2609 {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));} 2610 2611 _LIBCPP_INLINE_VISIBILITY 2612 __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const 2613 {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));} 2614 2615 _LIBCPP_INLINE_VISIBILITY 2616 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> > 2617 apply(value_type __f(value_type)) const 2618 { 2619 typedef __apply_expr<value_type, value_type(*)(value_type)> _Op; 2620 typedef _UnaryOp<_Op, _ValExpr> _NewExpr; 2621 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_)); 2622 } 2623 2624 _LIBCPP_INLINE_VISIBILITY 2625 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> > 2626 apply(value_type __f(const value_type&)) const 2627 { 2628 typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op; 2629 typedef _UnaryOp<_Op, _ValExpr> _NewExpr; 2630 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_)); 2631 } 2632 }; 2633 2634 template<class _ValExpr> 2635 __val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const 2636 { 2637 valarray<result_type> __r; 2638 size_t __n = __expr_.size(); 2639 if (__n) 2640 { 2641 __r.__begin_ = 2642 __r.__end_ = 2643 static_cast<result_type*>(_VSTD::__allocate(__n * sizeof(result_type))); 2644 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i) 2645 ::new (__r.__end_) result_type(__expr_[__i]); 2646 } 2647 return __r; 2648 } 2649 2650 // valarray 2651 2652 template <class _Tp> 2653 inline _LIBCPP_INLINE_VISIBILITY 2654 valarray<_Tp>::valarray(size_t __n) 2655 : __begin_(0), 2656 __end_(0) 2657 { 2658 resize(__n); 2659 } 2660 2661 template <class _Tp> 2662 inline _LIBCPP_INLINE_VISIBILITY 2663 valarray<_Tp>::valarray(const value_type& __x, size_t __n) 2664 : __begin_(0), 2665 __end_(0) 2666 { 2667 resize(__n, __x); 2668 } 2669 2670 template <class _Tp> 2671 valarray<_Tp>::valarray(const value_type* __p, size_t __n) 2672 : __begin_(0), 2673 __end_(0) 2674 { 2675 if (__n) 2676 { 2677 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 2678 #ifndef _LIBCPP_NO_EXCEPTIONS 2679 try 2680 { 2681 #endif // _LIBCPP_NO_EXCEPTIONS 2682 for (; __n; ++__end_, ++__p, --__n) 2683 ::new (__end_) value_type(*__p); 2684 #ifndef _LIBCPP_NO_EXCEPTIONS 2685 } 2686 catch (...) 2687 { 2688 resize(0); 2689 throw; 2690 } 2691 #endif // _LIBCPP_NO_EXCEPTIONS 2692 } 2693 } 2694 2695 template <class _Tp> 2696 valarray<_Tp>::valarray(const valarray& __v) 2697 : __begin_(0), 2698 __end_(0) 2699 { 2700 if (__v.size()) 2701 { 2702 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__v.size() * sizeof(value_type))); 2703 #ifndef _LIBCPP_NO_EXCEPTIONS 2704 try 2705 { 2706 #endif // _LIBCPP_NO_EXCEPTIONS 2707 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p) 2708 ::new (__end_) value_type(*__p); 2709 #ifndef _LIBCPP_NO_EXCEPTIONS 2710 } 2711 catch (...) 2712 { 2713 resize(0); 2714 throw; 2715 } 2716 #endif // _LIBCPP_NO_EXCEPTIONS 2717 } 2718 } 2719 2720 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2721 2722 template <class _Tp> 2723 inline _LIBCPP_INLINE_VISIBILITY 2724 valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT 2725 : __begin_(__v.__begin_), 2726 __end_(__v.__end_) 2727 { 2728 __v.__begin_ = __v.__end_ = nullptr; 2729 } 2730 2731 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2732 2733 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 2734 2735 template <class _Tp> 2736 valarray<_Tp>::valarray(initializer_list<value_type> __il) 2737 : __begin_(0), 2738 __end_(0) 2739 { 2740 size_t __n = __il.size(); 2741 if (__n) 2742 { 2743 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 2744 #ifndef _LIBCPP_NO_EXCEPTIONS 2745 try 2746 { 2747 #endif // _LIBCPP_NO_EXCEPTIONS 2748 for (const value_type* __p = __il.begin(); __n; ++__end_, ++__p, --__n) 2749 ::new (__end_) value_type(*__p); 2750 #ifndef _LIBCPP_NO_EXCEPTIONS 2751 } 2752 catch (...) 2753 { 2754 resize(0); 2755 throw; 2756 } 2757 #endif // _LIBCPP_NO_EXCEPTIONS 2758 } 2759 } 2760 2761 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 2762 2763 template <class _Tp> 2764 valarray<_Tp>::valarray(const slice_array<value_type>& __sa) 2765 : __begin_(0), 2766 __end_(0) 2767 { 2768 size_t __n = __sa.__size_; 2769 if (__n) 2770 { 2771 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 2772 #ifndef _LIBCPP_NO_EXCEPTIONS 2773 try 2774 { 2775 #endif // _LIBCPP_NO_EXCEPTIONS 2776 for (const value_type* __p = __sa.__vp_; __n; ++__end_, __p += __sa.__stride_, --__n) 2777 ::new (__end_) value_type(*__p); 2778 #ifndef _LIBCPP_NO_EXCEPTIONS 2779 } 2780 catch (...) 2781 { 2782 resize(0); 2783 throw; 2784 } 2785 #endif // _LIBCPP_NO_EXCEPTIONS 2786 } 2787 } 2788 2789 template <class _Tp> 2790 valarray<_Tp>::valarray(const gslice_array<value_type>& __ga) 2791 : __begin_(0), 2792 __end_(0) 2793 { 2794 size_t __n = __ga.__1d_.size(); 2795 if (__n) 2796 { 2797 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 2798 #ifndef _LIBCPP_NO_EXCEPTIONS 2799 try 2800 { 2801 #endif // _LIBCPP_NO_EXCEPTIONS 2802 typedef const size_t* _Ip; 2803 const value_type* __s = __ga.__vp_; 2804 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; 2805 __i != __e; ++__i, ++__end_) 2806 ::new (__end_) value_type(__s[*__i]); 2807 #ifndef _LIBCPP_NO_EXCEPTIONS 2808 } 2809 catch (...) 2810 { 2811 resize(0); 2812 throw; 2813 } 2814 #endif // _LIBCPP_NO_EXCEPTIONS 2815 } 2816 } 2817 2818 template <class _Tp> 2819 valarray<_Tp>::valarray(const mask_array<value_type>& __ma) 2820 : __begin_(0), 2821 __end_(0) 2822 { 2823 size_t __n = __ma.__1d_.size(); 2824 if (__n) 2825 { 2826 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 2827 #ifndef _LIBCPP_NO_EXCEPTIONS 2828 try 2829 { 2830 #endif // _LIBCPP_NO_EXCEPTIONS 2831 typedef const size_t* _Ip; 2832 const value_type* __s = __ma.__vp_; 2833 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; 2834 __i != __e; ++__i, ++__end_) 2835 ::new (__end_) value_type(__s[*__i]); 2836 #ifndef _LIBCPP_NO_EXCEPTIONS 2837 } 2838 catch (...) 2839 { 2840 resize(0); 2841 throw; 2842 } 2843 #endif // _LIBCPP_NO_EXCEPTIONS 2844 } 2845 } 2846 2847 template <class _Tp> 2848 valarray<_Tp>::valarray(const indirect_array<value_type>& __ia) 2849 : __begin_(0), 2850 __end_(0) 2851 { 2852 size_t __n = __ia.__1d_.size(); 2853 if (__n) 2854 { 2855 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 2856 #ifndef _LIBCPP_NO_EXCEPTIONS 2857 try 2858 { 2859 #endif // _LIBCPP_NO_EXCEPTIONS 2860 typedef const size_t* _Ip; 2861 const value_type* __s = __ia.__vp_; 2862 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; 2863 __i != __e; ++__i, ++__end_) 2864 ::new (__end_) value_type(__s[*__i]); 2865 #ifndef _LIBCPP_NO_EXCEPTIONS 2866 } 2867 catch (...) 2868 { 2869 resize(0); 2870 throw; 2871 } 2872 #endif // _LIBCPP_NO_EXCEPTIONS 2873 } 2874 } 2875 2876 template <class _Tp> 2877 inline _LIBCPP_INLINE_VISIBILITY 2878 valarray<_Tp>::~valarray() 2879 { 2880 resize(0); 2881 } 2882 2883 template <class _Tp> 2884 valarray<_Tp>& 2885 valarray<_Tp>::operator=(const valarray& __v) 2886 { 2887 if (this != &__v) 2888 { 2889 if (size() != __v.size()) 2890 resize(__v.size()); 2891 _VSTD::copy(__v.__begin_, __v.__end_, __begin_); 2892 } 2893 return *this; 2894 } 2895 2896 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2897 2898 template <class _Tp> 2899 inline _LIBCPP_INLINE_VISIBILITY 2900 valarray<_Tp>& 2901 valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT 2902 { 2903 resize(0); 2904 __begin_ = __v.__begin_; 2905 __end_ = __v.__end_; 2906 __v.__begin_ = nullptr; 2907 __v.__end_ = nullptr; 2908 return *this; 2909 } 2910 2911 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2912 2913 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 2914 2915 template <class _Tp> 2916 inline _LIBCPP_INLINE_VISIBILITY 2917 valarray<_Tp>& 2918 valarray<_Tp>::operator=(initializer_list<value_type> __il) 2919 { 2920 if (size() != __il.size()) 2921 resize(__il.size()); 2922 _VSTD::copy(__il.begin(), __il.end(), __begin_); 2923 return *this; 2924 } 2925 2926 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 2927 2928 template <class _Tp> 2929 inline _LIBCPP_INLINE_VISIBILITY 2930 valarray<_Tp>& 2931 valarray<_Tp>::operator=(const value_type& __x) 2932 { 2933 _VSTD::fill(__begin_, __end_, __x); 2934 return *this; 2935 } 2936 2937 template <class _Tp> 2938 inline _LIBCPP_INLINE_VISIBILITY 2939 valarray<_Tp>& 2940 valarray<_Tp>::operator=(const slice_array<value_type>& __sa) 2941 { 2942 value_type* __t = __begin_; 2943 const value_type* __s = __sa.__vp_; 2944 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t) 2945 *__t = *__s; 2946 return *this; 2947 } 2948 2949 template <class _Tp> 2950 inline _LIBCPP_INLINE_VISIBILITY 2951 valarray<_Tp>& 2952 valarray<_Tp>::operator=(const gslice_array<value_type>& __ga) 2953 { 2954 typedef const size_t* _Ip; 2955 value_type* __t = __begin_; 2956 const value_type* __s = __ga.__vp_; 2957 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; 2958 __i != __e; ++__i, ++__t) 2959 *__t = __s[*__i]; 2960 return *this; 2961 } 2962 2963 template <class _Tp> 2964 inline _LIBCPP_INLINE_VISIBILITY 2965 valarray<_Tp>& 2966 valarray<_Tp>::operator=(const mask_array<value_type>& __ma) 2967 { 2968 typedef const size_t* _Ip; 2969 value_type* __t = __begin_; 2970 const value_type* __s = __ma.__vp_; 2971 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; 2972 __i != __e; ++__i, ++__t) 2973 *__t = __s[*__i]; 2974 return *this; 2975 } 2976 2977 template <class _Tp> 2978 inline _LIBCPP_INLINE_VISIBILITY 2979 valarray<_Tp>& 2980 valarray<_Tp>::operator=(const indirect_array<value_type>& __ia) 2981 { 2982 typedef const size_t* _Ip; 2983 value_type* __t = __begin_; 2984 const value_type* __s = __ia.__vp_; 2985 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; 2986 __i != __e; ++__i, ++__t) 2987 *__t = __s[*__i]; 2988 return *this; 2989 } 2990 2991 template <class _Tp> 2992 template <class _ValExpr> 2993 inline _LIBCPP_INLINE_VISIBILITY 2994 valarray<_Tp>& 2995 valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v) 2996 { 2997 size_t __n = __v.size(); 2998 if (size() != __n) 2999 resize(__n); 3000 value_type* __t = __begin_; 3001 for (size_t __i = 0; __i != __n; ++__t, ++__i) 3002 *__t = result_type(__v[__i]); 3003 return *this; 3004 } 3005 3006 template <class _Tp> 3007 inline _LIBCPP_INLINE_VISIBILITY 3008 __val_expr<__slice_expr<const valarray<_Tp>&> > 3009 valarray<_Tp>::operator[](slice __s) const 3010 { 3011 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this)); 3012 } 3013 3014 template <class _Tp> 3015 inline _LIBCPP_INLINE_VISIBILITY 3016 slice_array<_Tp> 3017 valarray<_Tp>::operator[](slice __s) 3018 { 3019 return slice_array<value_type>(__s, *this); 3020 } 3021 3022 template <class _Tp> 3023 inline _LIBCPP_INLINE_VISIBILITY 3024 __val_expr<__indirect_expr<const valarray<_Tp>&> > 3025 valarray<_Tp>::operator[](const gslice& __gs) const 3026 { 3027 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this)); 3028 } 3029 3030 template <class _Tp> 3031 inline _LIBCPP_INLINE_VISIBILITY 3032 gslice_array<_Tp> 3033 valarray<_Tp>::operator[](const gslice& __gs) 3034 { 3035 return gslice_array<value_type>(__gs, *this); 3036 } 3037 3038 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3039 3040 template <class _Tp> 3041 inline _LIBCPP_INLINE_VISIBILITY 3042 __val_expr<__indirect_expr<const valarray<_Tp>&> > 3043 valarray<_Tp>::operator[](gslice&& __gs) const 3044 { 3045 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this)); 3046 } 3047 3048 template <class _Tp> 3049 inline _LIBCPP_INLINE_VISIBILITY 3050 gslice_array<_Tp> 3051 valarray<_Tp>::operator[](gslice&& __gs) 3052 { 3053 return gslice_array<value_type>(move(__gs), *this); 3054 } 3055 3056 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3057 3058 template <class _Tp> 3059 inline _LIBCPP_INLINE_VISIBILITY 3060 __val_expr<__mask_expr<const valarray<_Tp>&> > 3061 valarray<_Tp>::operator[](const valarray<bool>& __vb) const 3062 { 3063 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this)); 3064 } 3065 3066 template <class _Tp> 3067 inline _LIBCPP_INLINE_VISIBILITY 3068 mask_array<_Tp> 3069 valarray<_Tp>::operator[](const valarray<bool>& __vb) 3070 { 3071 return mask_array<value_type>(__vb, *this); 3072 } 3073 3074 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3075 3076 template <class _Tp> 3077 inline _LIBCPP_INLINE_VISIBILITY 3078 __val_expr<__mask_expr<const valarray<_Tp>&> > 3079 valarray<_Tp>::operator[](valarray<bool>&& __vb) const 3080 { 3081 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this)); 3082 } 3083 3084 template <class _Tp> 3085 inline _LIBCPP_INLINE_VISIBILITY 3086 mask_array<_Tp> 3087 valarray<_Tp>::operator[](valarray<bool>&& __vb) 3088 { 3089 return mask_array<value_type>(move(__vb), *this); 3090 } 3091 3092 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3093 3094 template <class _Tp> 3095 inline _LIBCPP_INLINE_VISIBILITY 3096 __val_expr<__indirect_expr<const valarray<_Tp>&> > 3097 valarray<_Tp>::operator[](const valarray<size_t>& __vs) const 3098 { 3099 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this)); 3100 } 3101 3102 template <class _Tp> 3103 inline _LIBCPP_INLINE_VISIBILITY 3104 indirect_array<_Tp> 3105 valarray<_Tp>::operator[](const valarray<size_t>& __vs) 3106 { 3107 return indirect_array<value_type>(__vs, *this); 3108 } 3109 3110 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3111 3112 template <class _Tp> 3113 inline _LIBCPP_INLINE_VISIBILITY 3114 __val_expr<__indirect_expr<const valarray<_Tp>&> > 3115 valarray<_Tp>::operator[](valarray<size_t>&& __vs) const 3116 { 3117 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this)); 3118 } 3119 3120 template <class _Tp> 3121 inline _LIBCPP_INLINE_VISIBILITY 3122 indirect_array<_Tp> 3123 valarray<_Tp>::operator[](valarray<size_t>&& __vs) 3124 { 3125 return indirect_array<value_type>(move(__vs), *this); 3126 } 3127 3128 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3129 3130 template <class _Tp> 3131 valarray<_Tp> 3132 valarray<_Tp>::operator+() const 3133 { 3134 valarray<value_type> __r; 3135 size_t __n = size(); 3136 if (__n) 3137 { 3138 __r.__begin_ = 3139 __r.__end_ = 3140 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 3141 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) 3142 ::new (__r.__end_) value_type(+*__p); 3143 } 3144 return __r; 3145 } 3146 3147 template <class _Tp> 3148 valarray<_Tp> 3149 valarray<_Tp>::operator-() const 3150 { 3151 valarray<value_type> __r; 3152 size_t __n = size(); 3153 if (__n) 3154 { 3155 __r.__begin_ = 3156 __r.__end_ = 3157 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 3158 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) 3159 ::new (__r.__end_) value_type(-*__p); 3160 } 3161 return __r; 3162 } 3163 3164 template <class _Tp> 3165 valarray<_Tp> 3166 valarray<_Tp>::operator~() const 3167 { 3168 valarray<value_type> __r; 3169 size_t __n = size(); 3170 if (__n) 3171 { 3172 __r.__begin_ = 3173 __r.__end_ = 3174 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 3175 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) 3176 ::new (__r.__end_) value_type(~*__p); 3177 } 3178 return __r; 3179 } 3180 3181 template <class _Tp> 3182 valarray<bool> 3183 valarray<_Tp>::operator!() const 3184 { 3185 valarray<bool> __r; 3186 size_t __n = size(); 3187 if (__n) 3188 { 3189 __r.__begin_ = 3190 __r.__end_ = 3191 static_cast<bool*>(_VSTD::__allocate(__n * sizeof(bool))); 3192 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) 3193 ::new (__r.__end_) bool(!*__p); 3194 } 3195 return __r; 3196 } 3197 3198 template <class _Tp> 3199 inline _LIBCPP_INLINE_VISIBILITY 3200 valarray<_Tp>& 3201 valarray<_Tp>::operator*=(const value_type& __x) 3202 { 3203 for (value_type* __p = __begin_; __p != __end_; ++__p) 3204 *__p *= __x; 3205 return *this; 3206 } 3207 3208 template <class _Tp> 3209 inline _LIBCPP_INLINE_VISIBILITY 3210 valarray<_Tp>& 3211 valarray<_Tp>::operator/=(const value_type& __x) 3212 { 3213 for (value_type* __p = __begin_; __p != __end_; ++__p) 3214 *__p /= __x; 3215 return *this; 3216 } 3217 3218 template <class _Tp> 3219 inline _LIBCPP_INLINE_VISIBILITY 3220 valarray<_Tp>& 3221 valarray<_Tp>::operator%=(const value_type& __x) 3222 { 3223 for (value_type* __p = __begin_; __p != __end_; ++__p) 3224 *__p %= __x; 3225 return *this; 3226 } 3227 3228 template <class _Tp> 3229 inline _LIBCPP_INLINE_VISIBILITY 3230 valarray<_Tp>& 3231 valarray<_Tp>::operator+=(const value_type& __x) 3232 { 3233 for (value_type* __p = __begin_; __p != __end_; ++__p) 3234 *__p += __x; 3235 return *this; 3236 } 3237 3238 template <class _Tp> 3239 inline _LIBCPP_INLINE_VISIBILITY 3240 valarray<_Tp>& 3241 valarray<_Tp>::operator-=(const value_type& __x) 3242 { 3243 for (value_type* __p = __begin_; __p != __end_; ++__p) 3244 *__p -= __x; 3245 return *this; 3246 } 3247 3248 template <class _Tp> 3249 inline _LIBCPP_INLINE_VISIBILITY 3250 valarray<_Tp>& 3251 valarray<_Tp>::operator^=(const value_type& __x) 3252 { 3253 for (value_type* __p = __begin_; __p != __end_; ++__p) 3254 *__p ^= __x; 3255 return *this; 3256 } 3257 3258 template <class _Tp> 3259 inline _LIBCPP_INLINE_VISIBILITY 3260 valarray<_Tp>& 3261 valarray<_Tp>::operator&=(const value_type& __x) 3262 { 3263 for (value_type* __p = __begin_; __p != __end_; ++__p) 3264 *__p &= __x; 3265 return *this; 3266 } 3267 3268 template <class _Tp> 3269 inline _LIBCPP_INLINE_VISIBILITY 3270 valarray<_Tp>& 3271 valarray<_Tp>::operator|=(const value_type& __x) 3272 { 3273 for (value_type* __p = __begin_; __p != __end_; ++__p) 3274 *__p |= __x; 3275 return *this; 3276 } 3277 3278 template <class _Tp> 3279 inline _LIBCPP_INLINE_VISIBILITY 3280 valarray<_Tp>& 3281 valarray<_Tp>::operator<<=(const value_type& __x) 3282 { 3283 for (value_type* __p = __begin_; __p != __end_; ++__p) 3284 *__p <<= __x; 3285 return *this; 3286 } 3287 3288 template <class _Tp> 3289 inline _LIBCPP_INLINE_VISIBILITY 3290 valarray<_Tp>& 3291 valarray<_Tp>::operator>>=(const value_type& __x) 3292 { 3293 for (value_type* __p = __begin_; __p != __end_; ++__p) 3294 *__p >>= __x; 3295 return *this; 3296 } 3297 3298 template <class _Tp> 3299 template <class _Expr> 3300 inline _LIBCPP_INLINE_VISIBILITY 3301 typename enable_if 3302 < 3303 __is_val_expr<_Expr>::value, 3304 valarray<_Tp>& 3305 >::type 3306 valarray<_Tp>::operator*=(const _Expr& __v) 3307 { 3308 size_t __i = 0; 3309 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3310 *__t *= __v[__i]; 3311 return *this; 3312 } 3313 3314 template <class _Tp> 3315 template <class _Expr> 3316 inline _LIBCPP_INLINE_VISIBILITY 3317 typename enable_if 3318 < 3319 __is_val_expr<_Expr>::value, 3320 valarray<_Tp>& 3321 >::type 3322 valarray<_Tp>::operator/=(const _Expr& __v) 3323 { 3324 size_t __i = 0; 3325 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3326 *__t /= __v[__i]; 3327 return *this; 3328 } 3329 3330 template <class _Tp> 3331 template <class _Expr> 3332 inline _LIBCPP_INLINE_VISIBILITY 3333 typename enable_if 3334 < 3335 __is_val_expr<_Expr>::value, 3336 valarray<_Tp>& 3337 >::type 3338 valarray<_Tp>::operator%=(const _Expr& __v) 3339 { 3340 size_t __i = 0; 3341 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3342 *__t %= __v[__i]; 3343 return *this; 3344 } 3345 3346 template <class _Tp> 3347 template <class _Expr> 3348 inline _LIBCPP_INLINE_VISIBILITY 3349 typename enable_if 3350 < 3351 __is_val_expr<_Expr>::value, 3352 valarray<_Tp>& 3353 >::type 3354 valarray<_Tp>::operator+=(const _Expr& __v) 3355 { 3356 size_t __i = 0; 3357 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3358 *__t += __v[__i]; 3359 return *this; 3360 } 3361 3362 template <class _Tp> 3363 template <class _Expr> 3364 inline _LIBCPP_INLINE_VISIBILITY 3365 typename enable_if 3366 < 3367 __is_val_expr<_Expr>::value, 3368 valarray<_Tp>& 3369 >::type 3370 valarray<_Tp>::operator-=(const _Expr& __v) 3371 { 3372 size_t __i = 0; 3373 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3374 *__t -= __v[__i]; 3375 return *this; 3376 } 3377 3378 template <class _Tp> 3379 template <class _Expr> 3380 inline _LIBCPP_INLINE_VISIBILITY 3381 typename enable_if 3382 < 3383 __is_val_expr<_Expr>::value, 3384 valarray<_Tp>& 3385 >::type 3386 valarray<_Tp>::operator^=(const _Expr& __v) 3387 { 3388 size_t __i = 0; 3389 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3390 *__t ^= __v[__i]; 3391 return *this; 3392 } 3393 3394 template <class _Tp> 3395 template <class _Expr> 3396 inline _LIBCPP_INLINE_VISIBILITY 3397 typename enable_if 3398 < 3399 __is_val_expr<_Expr>::value, 3400 valarray<_Tp>& 3401 >::type 3402 valarray<_Tp>::operator|=(const _Expr& __v) 3403 { 3404 size_t __i = 0; 3405 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3406 *__t |= __v[__i]; 3407 return *this; 3408 } 3409 3410 template <class _Tp> 3411 template <class _Expr> 3412 inline _LIBCPP_INLINE_VISIBILITY 3413 typename enable_if 3414 < 3415 __is_val_expr<_Expr>::value, 3416 valarray<_Tp>& 3417 >::type 3418 valarray<_Tp>::operator&=(const _Expr& __v) 3419 { 3420 size_t __i = 0; 3421 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3422 *__t &= __v[__i]; 3423 return *this; 3424 } 3425 3426 template <class _Tp> 3427 template <class _Expr> 3428 inline _LIBCPP_INLINE_VISIBILITY 3429 typename enable_if 3430 < 3431 __is_val_expr<_Expr>::value, 3432 valarray<_Tp>& 3433 >::type 3434 valarray<_Tp>::operator<<=(const _Expr& __v) 3435 { 3436 size_t __i = 0; 3437 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3438 *__t <<= __v[__i]; 3439 return *this; 3440 } 3441 3442 template <class _Tp> 3443 template <class _Expr> 3444 inline _LIBCPP_INLINE_VISIBILITY 3445 typename enable_if 3446 < 3447 __is_val_expr<_Expr>::value, 3448 valarray<_Tp>& 3449 >::type 3450 valarray<_Tp>::operator>>=(const _Expr& __v) 3451 { 3452 size_t __i = 0; 3453 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3454 *__t >>= __v[__i]; 3455 return *this; 3456 } 3457 3458 template <class _Tp> 3459 inline _LIBCPP_INLINE_VISIBILITY 3460 void 3461 valarray<_Tp>::swap(valarray& __v) _NOEXCEPT 3462 { 3463 _VSTD::swap(__begin_, __v.__begin_); 3464 _VSTD::swap(__end_, __v.__end_); 3465 } 3466 3467 template <class _Tp> 3468 inline _LIBCPP_INLINE_VISIBILITY 3469 _Tp 3470 valarray<_Tp>::sum() const 3471 { 3472 if (__begin_ == __end_) 3473 return value_type(); 3474 const value_type* __p = __begin_; 3475 _Tp __r = *__p; 3476 for (++__p; __p != __end_; ++__p) 3477 __r += *__p; 3478 return __r; 3479 } 3480 3481 template <class _Tp> 3482 inline _LIBCPP_INLINE_VISIBILITY 3483 _Tp 3484 valarray<_Tp>::min() const 3485 { 3486 if (__begin_ == __end_) 3487 return value_type(); 3488 return *_VSTD::min_element(__begin_, __end_); 3489 } 3490 3491 template <class _Tp> 3492 inline _LIBCPP_INLINE_VISIBILITY 3493 _Tp 3494 valarray<_Tp>::max() const 3495 { 3496 if (__begin_ == __end_) 3497 return value_type(); 3498 return *_VSTD::max_element(__begin_, __end_); 3499 } 3500 3501 template <class _Tp> 3502 valarray<_Tp> 3503 valarray<_Tp>::shift(int __i) const 3504 { 3505 valarray<value_type> __r; 3506 size_t __n = size(); 3507 if (__n) 3508 { 3509 __r.__begin_ = 3510 __r.__end_ = 3511 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 3512 const value_type* __sb; 3513 value_type* __tb; 3514 value_type* __te; 3515 if (__i >= 0) 3516 { 3517 __i = _VSTD::min(__i, static_cast<int>(__n)); 3518 __sb = __begin_ + __i; 3519 __tb = __r.__begin_; 3520 __te = __r.__begin_ + (__n - __i); 3521 } 3522 else 3523 { 3524 __i = _VSTD::min(-__i, static_cast<int>(__n)); 3525 __sb = __begin_; 3526 __tb = __r.__begin_ + __i; 3527 __te = __r.__begin_ + __n; 3528 } 3529 for (; __r.__end_ != __tb; ++__r.__end_) 3530 ::new (__r.__end_) value_type(); 3531 for (; __r.__end_ != __te; ++__r.__end_, ++__sb) 3532 ::new (__r.__end_) value_type(*__sb); 3533 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_) 3534 ::new (__r.__end_) value_type(); 3535 } 3536 return __r; 3537 } 3538 3539 template <class _Tp> 3540 valarray<_Tp> 3541 valarray<_Tp>::cshift(int __i) const 3542 { 3543 valarray<value_type> __r; 3544 size_t __n = size(); 3545 if (__n) 3546 { 3547 __r.__begin_ = 3548 __r.__end_ = 3549 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 3550 __i %= static_cast<int>(__n); 3551 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i; 3552 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s) 3553 ::new (__r.__end_) value_type(*__s); 3554 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s) 3555 ::new (__r.__end_) value_type(*__s); 3556 } 3557 return __r; 3558 } 3559 3560 template <class _Tp> 3561 valarray<_Tp> 3562 valarray<_Tp>::apply(value_type __f(value_type)) const 3563 { 3564 valarray<value_type> __r; 3565 size_t __n = size(); 3566 if (__n) 3567 { 3568 __r.__begin_ = 3569 __r.__end_ = 3570 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 3571 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) 3572 ::new (__r.__end_) value_type(__f(*__p)); 3573 } 3574 return __r; 3575 } 3576 3577 template <class _Tp> 3578 valarray<_Tp> 3579 valarray<_Tp>::apply(value_type __f(const value_type&)) const 3580 { 3581 valarray<value_type> __r; 3582 size_t __n = size(); 3583 if (__n) 3584 { 3585 __r.__begin_ = 3586 __r.__end_ = 3587 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 3588 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) 3589 ::new (__r.__end_) value_type(__f(*__p)); 3590 } 3591 return __r; 3592 } 3593 3594 template <class _Tp> 3595 void 3596 valarray<_Tp>::resize(size_t __n, value_type __x) 3597 { 3598 if (__begin_ != nullptr) 3599 { 3600 while (__end_ != __begin_) 3601 (--__end_)->~value_type(); 3602 _VSTD::__deallocate(__begin_); 3603 __begin_ = __end_ = nullptr; 3604 } 3605 if (__n) 3606 { 3607 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 3608 #ifndef _LIBCPP_NO_EXCEPTIONS 3609 try 3610 { 3611 #endif // _LIBCPP_NO_EXCEPTIONS 3612 for (; __n; --__n, ++__end_) 3613 ::new (__end_) value_type(__x); 3614 #ifndef _LIBCPP_NO_EXCEPTIONS 3615 } 3616 catch (...) 3617 { 3618 resize(0); 3619 throw; 3620 } 3621 #endif // _LIBCPP_NO_EXCEPTIONS 3622 } 3623 } 3624 3625 template<class _Tp> 3626 inline _LIBCPP_INLINE_VISIBILITY 3627 void 3628 swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT 3629 { 3630 __x.swap(__y); 3631 } 3632 3633 template<class _Expr1, class _Expr2> 3634 inline _LIBCPP_INLINE_VISIBILITY 3635 typename enable_if 3636 < 3637 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3638 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> > 3639 >::type 3640 operator*(const _Expr1& __x, const _Expr2& __y) 3641 { 3642 typedef typename _Expr1::value_type value_type; 3643 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op; 3644 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y)); 3645 } 3646 3647 template<class _Expr> 3648 inline _LIBCPP_INLINE_VISIBILITY 3649 typename enable_if 3650 < 3651 __is_val_expr<_Expr>::value, 3652 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>, 3653 _Expr, __scalar_expr<typename _Expr::value_type> > > 3654 >::type 3655 operator*(const _Expr& __x, const typename _Expr::value_type& __y) 3656 { 3657 typedef typename _Expr::value_type value_type; 3658 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3659 return __val_expr<_Op>(_Op(multiplies<value_type>(), 3660 __x, __scalar_expr<value_type>(__y, __x.size()))); 3661 } 3662 3663 template<class _Expr> 3664 inline _LIBCPP_INLINE_VISIBILITY 3665 typename enable_if 3666 < 3667 __is_val_expr<_Expr>::value, 3668 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>, 3669 __scalar_expr<typename _Expr::value_type>, _Expr> > 3670 >::type 3671 operator*(const typename _Expr::value_type& __x, const _Expr& __y) 3672 { 3673 typedef typename _Expr::value_type value_type; 3674 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3675 return __val_expr<_Op>(_Op(multiplies<value_type>(), 3676 __scalar_expr<value_type>(__x, __y.size()), __y)); 3677 } 3678 3679 template<class _Expr1, class _Expr2> 3680 inline _LIBCPP_INLINE_VISIBILITY 3681 typename enable_if 3682 < 3683 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3684 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> > 3685 >::type 3686 operator/(const _Expr1& __x, const _Expr2& __y) 3687 { 3688 typedef typename _Expr1::value_type value_type; 3689 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op; 3690 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y)); 3691 } 3692 3693 template<class _Expr> 3694 inline _LIBCPP_INLINE_VISIBILITY 3695 typename enable_if 3696 < 3697 __is_val_expr<_Expr>::value, 3698 __val_expr<_BinaryOp<divides<typename _Expr::value_type>, 3699 _Expr, __scalar_expr<typename _Expr::value_type> > > 3700 >::type 3701 operator/(const _Expr& __x, const typename _Expr::value_type& __y) 3702 { 3703 typedef typename _Expr::value_type value_type; 3704 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3705 return __val_expr<_Op>(_Op(divides<value_type>(), 3706 __x, __scalar_expr<value_type>(__y, __x.size()))); 3707 } 3708 3709 template<class _Expr> 3710 inline _LIBCPP_INLINE_VISIBILITY 3711 typename enable_if 3712 < 3713 __is_val_expr<_Expr>::value, 3714 __val_expr<_BinaryOp<divides<typename _Expr::value_type>, 3715 __scalar_expr<typename _Expr::value_type>, _Expr> > 3716 >::type 3717 operator/(const typename _Expr::value_type& __x, const _Expr& __y) 3718 { 3719 typedef typename _Expr::value_type value_type; 3720 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3721 return __val_expr<_Op>(_Op(divides<value_type>(), 3722 __scalar_expr<value_type>(__x, __y.size()), __y)); 3723 } 3724 3725 template<class _Expr1, class _Expr2> 3726 inline _LIBCPP_INLINE_VISIBILITY 3727 typename enable_if 3728 < 3729 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3730 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> > 3731 >::type 3732 operator%(const _Expr1& __x, const _Expr2& __y) 3733 { 3734 typedef typename _Expr1::value_type value_type; 3735 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op; 3736 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y)); 3737 } 3738 3739 template<class _Expr> 3740 inline _LIBCPP_INLINE_VISIBILITY 3741 typename enable_if 3742 < 3743 __is_val_expr<_Expr>::value, 3744 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>, 3745 _Expr, __scalar_expr<typename _Expr::value_type> > > 3746 >::type 3747 operator%(const _Expr& __x, const typename _Expr::value_type& __y) 3748 { 3749 typedef typename _Expr::value_type value_type; 3750 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3751 return __val_expr<_Op>(_Op(modulus<value_type>(), 3752 __x, __scalar_expr<value_type>(__y, __x.size()))); 3753 } 3754 3755 template<class _Expr> 3756 inline _LIBCPP_INLINE_VISIBILITY 3757 typename enable_if 3758 < 3759 __is_val_expr<_Expr>::value, 3760 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>, 3761 __scalar_expr<typename _Expr::value_type>, _Expr> > 3762 >::type 3763 operator%(const typename _Expr::value_type& __x, const _Expr& __y) 3764 { 3765 typedef typename _Expr::value_type value_type; 3766 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3767 return __val_expr<_Op>(_Op(modulus<value_type>(), 3768 __scalar_expr<value_type>(__x, __y.size()), __y)); 3769 } 3770 3771 template<class _Expr1, class _Expr2> 3772 inline _LIBCPP_INLINE_VISIBILITY 3773 typename enable_if 3774 < 3775 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3776 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> > 3777 >::type 3778 operator+(const _Expr1& __x, const _Expr2& __y) 3779 { 3780 typedef typename _Expr1::value_type value_type; 3781 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op; 3782 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y)); 3783 } 3784 3785 template<class _Expr> 3786 inline _LIBCPP_INLINE_VISIBILITY 3787 typename enable_if 3788 < 3789 __is_val_expr<_Expr>::value, 3790 __val_expr<_BinaryOp<plus<typename _Expr::value_type>, 3791 _Expr, __scalar_expr<typename _Expr::value_type> > > 3792 >::type 3793 operator+(const _Expr& __x, const typename _Expr::value_type& __y) 3794 { 3795 typedef typename _Expr::value_type value_type; 3796 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3797 return __val_expr<_Op>(_Op(plus<value_type>(), 3798 __x, __scalar_expr<value_type>(__y, __x.size()))); 3799 } 3800 3801 template<class _Expr> 3802 inline _LIBCPP_INLINE_VISIBILITY 3803 typename enable_if 3804 < 3805 __is_val_expr<_Expr>::value, 3806 __val_expr<_BinaryOp<plus<typename _Expr::value_type>, 3807 __scalar_expr<typename _Expr::value_type>, _Expr> > 3808 >::type 3809 operator+(const typename _Expr::value_type& __x, const _Expr& __y) 3810 { 3811 typedef typename _Expr::value_type value_type; 3812 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3813 return __val_expr<_Op>(_Op(plus<value_type>(), 3814 __scalar_expr<value_type>(__x, __y.size()), __y)); 3815 } 3816 3817 template<class _Expr1, class _Expr2> 3818 inline _LIBCPP_INLINE_VISIBILITY 3819 typename enable_if 3820 < 3821 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3822 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> > 3823 >::type 3824 operator-(const _Expr1& __x, const _Expr2& __y) 3825 { 3826 typedef typename _Expr1::value_type value_type; 3827 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op; 3828 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y)); 3829 } 3830 3831 template<class _Expr> 3832 inline _LIBCPP_INLINE_VISIBILITY 3833 typename enable_if 3834 < 3835 __is_val_expr<_Expr>::value, 3836 __val_expr<_BinaryOp<minus<typename _Expr::value_type>, 3837 _Expr, __scalar_expr<typename _Expr::value_type> > > 3838 >::type 3839 operator-(const _Expr& __x, const typename _Expr::value_type& __y) 3840 { 3841 typedef typename _Expr::value_type value_type; 3842 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3843 return __val_expr<_Op>(_Op(minus<value_type>(), 3844 __x, __scalar_expr<value_type>(__y, __x.size()))); 3845 } 3846 3847 template<class _Expr> 3848 inline _LIBCPP_INLINE_VISIBILITY 3849 typename enable_if 3850 < 3851 __is_val_expr<_Expr>::value, 3852 __val_expr<_BinaryOp<minus<typename _Expr::value_type>, 3853 __scalar_expr<typename _Expr::value_type>, _Expr> > 3854 >::type 3855 operator-(const typename _Expr::value_type& __x, const _Expr& __y) 3856 { 3857 typedef typename _Expr::value_type value_type; 3858 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3859 return __val_expr<_Op>(_Op(minus<value_type>(), 3860 __scalar_expr<value_type>(__x, __y.size()), __y)); 3861 } 3862 3863 template<class _Expr1, class _Expr2> 3864 inline _LIBCPP_INLINE_VISIBILITY 3865 typename enable_if 3866 < 3867 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3868 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> > 3869 >::type 3870 operator^(const _Expr1& __x, const _Expr2& __y) 3871 { 3872 typedef typename _Expr1::value_type value_type; 3873 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op; 3874 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y)); 3875 } 3876 3877 template<class _Expr> 3878 inline _LIBCPP_INLINE_VISIBILITY 3879 typename enable_if 3880 < 3881 __is_val_expr<_Expr>::value, 3882 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>, 3883 _Expr, __scalar_expr<typename _Expr::value_type> > > 3884 >::type 3885 operator^(const _Expr& __x, const typename _Expr::value_type& __y) 3886 { 3887 typedef typename _Expr::value_type value_type; 3888 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3889 return __val_expr<_Op>(_Op(bit_xor<value_type>(), 3890 __x, __scalar_expr<value_type>(__y, __x.size()))); 3891 } 3892 3893 template<class _Expr> 3894 inline _LIBCPP_INLINE_VISIBILITY 3895 typename enable_if 3896 < 3897 __is_val_expr<_Expr>::value, 3898 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>, 3899 __scalar_expr<typename _Expr::value_type>, _Expr> > 3900 >::type 3901 operator^(const typename _Expr::value_type& __x, const _Expr& __y) 3902 { 3903 typedef typename _Expr::value_type value_type; 3904 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3905 return __val_expr<_Op>(_Op(bit_xor<value_type>(), 3906 __scalar_expr<value_type>(__x, __y.size()), __y)); 3907 } 3908 3909 template<class _Expr1, class _Expr2> 3910 inline _LIBCPP_INLINE_VISIBILITY 3911 typename enable_if 3912 < 3913 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3914 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> > 3915 >::type 3916 operator&(const _Expr1& __x, const _Expr2& __y) 3917 { 3918 typedef typename _Expr1::value_type value_type; 3919 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op; 3920 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y)); 3921 } 3922 3923 template<class _Expr> 3924 inline _LIBCPP_INLINE_VISIBILITY 3925 typename enable_if 3926 < 3927 __is_val_expr<_Expr>::value, 3928 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>, 3929 _Expr, __scalar_expr<typename _Expr::value_type> > > 3930 >::type 3931 operator&(const _Expr& __x, const typename _Expr::value_type& __y) 3932 { 3933 typedef typename _Expr::value_type value_type; 3934 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3935 return __val_expr<_Op>(_Op(bit_and<value_type>(), 3936 __x, __scalar_expr<value_type>(__y, __x.size()))); 3937 } 3938 3939 template<class _Expr> 3940 inline _LIBCPP_INLINE_VISIBILITY 3941 typename enable_if 3942 < 3943 __is_val_expr<_Expr>::value, 3944 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>, 3945 __scalar_expr<typename _Expr::value_type>, _Expr> > 3946 >::type 3947 operator&(const typename _Expr::value_type& __x, const _Expr& __y) 3948 { 3949 typedef typename _Expr::value_type value_type; 3950 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3951 return __val_expr<_Op>(_Op(bit_and<value_type>(), 3952 __scalar_expr<value_type>(__x, __y.size()), __y)); 3953 } 3954 3955 template<class _Expr1, class _Expr2> 3956 inline _LIBCPP_INLINE_VISIBILITY 3957 typename enable_if 3958 < 3959 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3960 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> > 3961 >::type 3962 operator|(const _Expr1& __x, const _Expr2& __y) 3963 { 3964 typedef typename _Expr1::value_type value_type; 3965 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op; 3966 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y)); 3967 } 3968 3969 template<class _Expr> 3970 inline _LIBCPP_INLINE_VISIBILITY 3971 typename enable_if 3972 < 3973 __is_val_expr<_Expr>::value, 3974 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>, 3975 _Expr, __scalar_expr<typename _Expr::value_type> > > 3976 >::type 3977 operator|(const _Expr& __x, const typename _Expr::value_type& __y) 3978 { 3979 typedef typename _Expr::value_type value_type; 3980 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3981 return __val_expr<_Op>(_Op(bit_or<value_type>(), 3982 __x, __scalar_expr<value_type>(__y, __x.size()))); 3983 } 3984 3985 template<class _Expr> 3986 inline _LIBCPP_INLINE_VISIBILITY 3987 typename enable_if 3988 < 3989 __is_val_expr<_Expr>::value, 3990 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>, 3991 __scalar_expr<typename _Expr::value_type>, _Expr> > 3992 >::type 3993 operator|(const typename _Expr::value_type& __x, const _Expr& __y) 3994 { 3995 typedef typename _Expr::value_type value_type; 3996 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3997 return __val_expr<_Op>(_Op(bit_or<value_type>(), 3998 __scalar_expr<value_type>(__x, __y.size()), __y)); 3999 } 4000 4001 template<class _Expr1, class _Expr2> 4002 inline _LIBCPP_INLINE_VISIBILITY 4003 typename enable_if 4004 < 4005 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4006 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> > 4007 >::type 4008 operator<<(const _Expr1& __x, const _Expr2& __y) 4009 { 4010 typedef typename _Expr1::value_type value_type; 4011 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op; 4012 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y)); 4013 } 4014 4015 template<class _Expr> 4016 inline _LIBCPP_INLINE_VISIBILITY 4017 typename enable_if 4018 < 4019 __is_val_expr<_Expr>::value, 4020 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>, 4021 _Expr, __scalar_expr<typename _Expr::value_type> > > 4022 >::type 4023 operator<<(const _Expr& __x, const typename _Expr::value_type& __y) 4024 { 4025 typedef typename _Expr::value_type value_type; 4026 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4027 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), 4028 __x, __scalar_expr<value_type>(__y, __x.size()))); 4029 } 4030 4031 template<class _Expr> 4032 inline _LIBCPP_INLINE_VISIBILITY 4033 typename enable_if 4034 < 4035 __is_val_expr<_Expr>::value, 4036 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>, 4037 __scalar_expr<typename _Expr::value_type>, _Expr> > 4038 >::type 4039 operator<<(const typename _Expr::value_type& __x, const _Expr& __y) 4040 { 4041 typedef typename _Expr::value_type value_type; 4042 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4043 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), 4044 __scalar_expr<value_type>(__x, __y.size()), __y)); 4045 } 4046 4047 template<class _Expr1, class _Expr2> 4048 inline _LIBCPP_INLINE_VISIBILITY 4049 typename enable_if 4050 < 4051 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4052 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> > 4053 >::type 4054 operator>>(const _Expr1& __x, const _Expr2& __y) 4055 { 4056 typedef typename _Expr1::value_type value_type; 4057 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op; 4058 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y)); 4059 } 4060 4061 template<class _Expr> 4062 inline _LIBCPP_INLINE_VISIBILITY 4063 typename enable_if 4064 < 4065 __is_val_expr<_Expr>::value, 4066 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>, 4067 _Expr, __scalar_expr<typename _Expr::value_type> > > 4068 >::type 4069 operator>>(const _Expr& __x, const typename _Expr::value_type& __y) 4070 { 4071 typedef typename _Expr::value_type value_type; 4072 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4073 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), 4074 __x, __scalar_expr<value_type>(__y, __x.size()))); 4075 } 4076 4077 template<class _Expr> 4078 inline _LIBCPP_INLINE_VISIBILITY 4079 typename enable_if 4080 < 4081 __is_val_expr<_Expr>::value, 4082 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>, 4083 __scalar_expr<typename _Expr::value_type>, _Expr> > 4084 >::type 4085 operator>>(const typename _Expr::value_type& __x, const _Expr& __y) 4086 { 4087 typedef typename _Expr::value_type value_type; 4088 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4089 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), 4090 __scalar_expr<value_type>(__x, __y.size()), __y)); 4091 } 4092 4093 template<class _Expr1, class _Expr2> 4094 inline _LIBCPP_INLINE_VISIBILITY 4095 typename enable_if 4096 < 4097 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4098 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> > 4099 >::type 4100 operator&&(const _Expr1& __x, const _Expr2& __y) 4101 { 4102 typedef typename _Expr1::value_type value_type; 4103 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op; 4104 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y)); 4105 } 4106 4107 template<class _Expr> 4108 inline _LIBCPP_INLINE_VISIBILITY 4109 typename enable_if 4110 < 4111 __is_val_expr<_Expr>::value, 4112 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>, 4113 _Expr, __scalar_expr<typename _Expr::value_type> > > 4114 >::type 4115 operator&&(const _Expr& __x, const typename _Expr::value_type& __y) 4116 { 4117 typedef typename _Expr::value_type value_type; 4118 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4119 return __val_expr<_Op>(_Op(logical_and<value_type>(), 4120 __x, __scalar_expr<value_type>(__y, __x.size()))); 4121 } 4122 4123 template<class _Expr> 4124 inline _LIBCPP_INLINE_VISIBILITY 4125 typename enable_if 4126 < 4127 __is_val_expr<_Expr>::value, 4128 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>, 4129 __scalar_expr<typename _Expr::value_type>, _Expr> > 4130 >::type 4131 operator&&(const typename _Expr::value_type& __x, const _Expr& __y) 4132 { 4133 typedef typename _Expr::value_type value_type; 4134 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4135 return __val_expr<_Op>(_Op(logical_and<value_type>(), 4136 __scalar_expr<value_type>(__x, __y.size()), __y)); 4137 } 4138 4139 template<class _Expr1, class _Expr2> 4140 inline _LIBCPP_INLINE_VISIBILITY 4141 typename enable_if 4142 < 4143 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4144 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> > 4145 >::type 4146 operator||(const _Expr1& __x, const _Expr2& __y) 4147 { 4148 typedef typename _Expr1::value_type value_type; 4149 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op; 4150 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y)); 4151 } 4152 4153 template<class _Expr> 4154 inline _LIBCPP_INLINE_VISIBILITY 4155 typename enable_if 4156 < 4157 __is_val_expr<_Expr>::value, 4158 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>, 4159 _Expr, __scalar_expr<typename _Expr::value_type> > > 4160 >::type 4161 operator||(const _Expr& __x, const typename _Expr::value_type& __y) 4162 { 4163 typedef typename _Expr::value_type value_type; 4164 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4165 return __val_expr<_Op>(_Op(logical_or<value_type>(), 4166 __x, __scalar_expr<value_type>(__y, __x.size()))); 4167 } 4168 4169 template<class _Expr> 4170 inline _LIBCPP_INLINE_VISIBILITY 4171 typename enable_if 4172 < 4173 __is_val_expr<_Expr>::value, 4174 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>, 4175 __scalar_expr<typename _Expr::value_type>, _Expr> > 4176 >::type 4177 operator||(const typename _Expr::value_type& __x, const _Expr& __y) 4178 { 4179 typedef typename _Expr::value_type value_type; 4180 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4181 return __val_expr<_Op>(_Op(logical_or<value_type>(), 4182 __scalar_expr<value_type>(__x, __y.size()), __y)); 4183 } 4184 4185 template<class _Expr1, class _Expr2> 4186 inline _LIBCPP_INLINE_VISIBILITY 4187 typename enable_if 4188 < 4189 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4190 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> > 4191 >::type 4192 operator==(const _Expr1& __x, const _Expr2& __y) 4193 { 4194 typedef typename _Expr1::value_type value_type; 4195 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op; 4196 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y)); 4197 } 4198 4199 template<class _Expr> 4200 inline _LIBCPP_INLINE_VISIBILITY 4201 typename enable_if 4202 < 4203 __is_val_expr<_Expr>::value, 4204 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>, 4205 _Expr, __scalar_expr<typename _Expr::value_type> > > 4206 >::type 4207 operator==(const _Expr& __x, const typename _Expr::value_type& __y) 4208 { 4209 typedef typename _Expr::value_type value_type; 4210 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4211 return __val_expr<_Op>(_Op(equal_to<value_type>(), 4212 __x, __scalar_expr<value_type>(__y, __x.size()))); 4213 } 4214 4215 template<class _Expr> 4216 inline _LIBCPP_INLINE_VISIBILITY 4217 typename enable_if 4218 < 4219 __is_val_expr<_Expr>::value, 4220 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>, 4221 __scalar_expr<typename _Expr::value_type>, _Expr> > 4222 >::type 4223 operator==(const typename _Expr::value_type& __x, const _Expr& __y) 4224 { 4225 typedef typename _Expr::value_type value_type; 4226 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4227 return __val_expr<_Op>(_Op(equal_to<value_type>(), 4228 __scalar_expr<value_type>(__x, __y.size()), __y)); 4229 } 4230 4231 template<class _Expr1, class _Expr2> 4232 inline _LIBCPP_INLINE_VISIBILITY 4233 typename enable_if 4234 < 4235 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4236 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> > 4237 >::type 4238 operator!=(const _Expr1& __x, const _Expr2& __y) 4239 { 4240 typedef typename _Expr1::value_type value_type; 4241 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op; 4242 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y)); 4243 } 4244 4245 template<class _Expr> 4246 inline _LIBCPP_INLINE_VISIBILITY 4247 typename enable_if 4248 < 4249 __is_val_expr<_Expr>::value, 4250 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>, 4251 _Expr, __scalar_expr<typename _Expr::value_type> > > 4252 >::type 4253 operator!=(const _Expr& __x, const typename _Expr::value_type& __y) 4254 { 4255 typedef typename _Expr::value_type value_type; 4256 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4257 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), 4258 __x, __scalar_expr<value_type>(__y, __x.size()))); 4259 } 4260 4261 template<class _Expr> 4262 inline _LIBCPP_INLINE_VISIBILITY 4263 typename enable_if 4264 < 4265 __is_val_expr<_Expr>::value, 4266 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>, 4267 __scalar_expr<typename _Expr::value_type>, _Expr> > 4268 >::type 4269 operator!=(const typename _Expr::value_type& __x, const _Expr& __y) 4270 { 4271 typedef typename _Expr::value_type value_type; 4272 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4273 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), 4274 __scalar_expr<value_type>(__x, __y.size()), __y)); 4275 } 4276 4277 template<class _Expr1, class _Expr2> 4278 inline _LIBCPP_INLINE_VISIBILITY 4279 typename enable_if 4280 < 4281 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4282 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> > 4283 >::type 4284 operator<(const _Expr1& __x, const _Expr2& __y) 4285 { 4286 typedef typename _Expr1::value_type value_type; 4287 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op; 4288 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y)); 4289 } 4290 4291 template<class _Expr> 4292 inline _LIBCPP_INLINE_VISIBILITY 4293 typename enable_if 4294 < 4295 __is_val_expr<_Expr>::value, 4296 __val_expr<_BinaryOp<less<typename _Expr::value_type>, 4297 _Expr, __scalar_expr<typename _Expr::value_type> > > 4298 >::type 4299 operator<(const _Expr& __x, const typename _Expr::value_type& __y) 4300 { 4301 typedef typename _Expr::value_type value_type; 4302 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4303 return __val_expr<_Op>(_Op(less<value_type>(), 4304 __x, __scalar_expr<value_type>(__y, __x.size()))); 4305 } 4306 4307 template<class _Expr> 4308 inline _LIBCPP_INLINE_VISIBILITY 4309 typename enable_if 4310 < 4311 __is_val_expr<_Expr>::value, 4312 __val_expr<_BinaryOp<less<typename _Expr::value_type>, 4313 __scalar_expr<typename _Expr::value_type>, _Expr> > 4314 >::type 4315 operator<(const typename _Expr::value_type& __x, const _Expr& __y) 4316 { 4317 typedef typename _Expr::value_type value_type; 4318 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4319 return __val_expr<_Op>(_Op(less<value_type>(), 4320 __scalar_expr<value_type>(__x, __y.size()), __y)); 4321 } 4322 4323 template<class _Expr1, class _Expr2> 4324 inline _LIBCPP_INLINE_VISIBILITY 4325 typename enable_if 4326 < 4327 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4328 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> > 4329 >::type 4330 operator>(const _Expr1& __x, const _Expr2& __y) 4331 { 4332 typedef typename _Expr1::value_type value_type; 4333 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op; 4334 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y)); 4335 } 4336 4337 template<class _Expr> 4338 inline _LIBCPP_INLINE_VISIBILITY 4339 typename enable_if 4340 < 4341 __is_val_expr<_Expr>::value, 4342 __val_expr<_BinaryOp<greater<typename _Expr::value_type>, 4343 _Expr, __scalar_expr<typename _Expr::value_type> > > 4344 >::type 4345 operator>(const _Expr& __x, const typename _Expr::value_type& __y) 4346 { 4347 typedef typename _Expr::value_type value_type; 4348 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4349 return __val_expr<_Op>(_Op(greater<value_type>(), 4350 __x, __scalar_expr<value_type>(__y, __x.size()))); 4351 } 4352 4353 template<class _Expr> 4354 inline _LIBCPP_INLINE_VISIBILITY 4355 typename enable_if 4356 < 4357 __is_val_expr<_Expr>::value, 4358 __val_expr<_BinaryOp<greater<typename _Expr::value_type>, 4359 __scalar_expr<typename _Expr::value_type>, _Expr> > 4360 >::type 4361 operator>(const typename _Expr::value_type& __x, const _Expr& __y) 4362 { 4363 typedef typename _Expr::value_type value_type; 4364 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4365 return __val_expr<_Op>(_Op(greater<value_type>(), 4366 __scalar_expr<value_type>(__x, __y.size()), __y)); 4367 } 4368 4369 template<class _Expr1, class _Expr2> 4370 inline _LIBCPP_INLINE_VISIBILITY 4371 typename enable_if 4372 < 4373 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4374 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> > 4375 >::type 4376 operator<=(const _Expr1& __x, const _Expr2& __y) 4377 { 4378 typedef typename _Expr1::value_type value_type; 4379 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op; 4380 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y)); 4381 } 4382 4383 template<class _Expr> 4384 inline _LIBCPP_INLINE_VISIBILITY 4385 typename enable_if 4386 < 4387 __is_val_expr<_Expr>::value, 4388 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>, 4389 _Expr, __scalar_expr<typename _Expr::value_type> > > 4390 >::type 4391 operator<=(const _Expr& __x, const typename _Expr::value_type& __y) 4392 { 4393 typedef typename _Expr::value_type value_type; 4394 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4395 return __val_expr<_Op>(_Op(less_equal<value_type>(), 4396 __x, __scalar_expr<value_type>(__y, __x.size()))); 4397 } 4398 4399 template<class _Expr> 4400 inline _LIBCPP_INLINE_VISIBILITY 4401 typename enable_if 4402 < 4403 __is_val_expr<_Expr>::value, 4404 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>, 4405 __scalar_expr<typename _Expr::value_type>, _Expr> > 4406 >::type 4407 operator<=(const typename _Expr::value_type& __x, const _Expr& __y) 4408 { 4409 typedef typename _Expr::value_type value_type; 4410 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4411 return __val_expr<_Op>(_Op(less_equal<value_type>(), 4412 __scalar_expr<value_type>(__x, __y.size()), __y)); 4413 } 4414 4415 template<class _Expr1, class _Expr2> 4416 inline _LIBCPP_INLINE_VISIBILITY 4417 typename enable_if 4418 < 4419 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4420 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> > 4421 >::type 4422 operator>=(const _Expr1& __x, const _Expr2& __y) 4423 { 4424 typedef typename _Expr1::value_type value_type; 4425 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op; 4426 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y)); 4427 } 4428 4429 template<class _Expr> 4430 inline _LIBCPP_INLINE_VISIBILITY 4431 typename enable_if 4432 < 4433 __is_val_expr<_Expr>::value, 4434 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>, 4435 _Expr, __scalar_expr<typename _Expr::value_type> > > 4436 >::type 4437 operator>=(const _Expr& __x, const typename _Expr::value_type& __y) 4438 { 4439 typedef typename _Expr::value_type value_type; 4440 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4441 return __val_expr<_Op>(_Op(greater_equal<value_type>(), 4442 __x, __scalar_expr<value_type>(__y, __x.size()))); 4443 } 4444 4445 template<class _Expr> 4446 inline _LIBCPP_INLINE_VISIBILITY 4447 typename enable_if 4448 < 4449 __is_val_expr<_Expr>::value, 4450 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>, 4451 __scalar_expr<typename _Expr::value_type>, _Expr> > 4452 >::type 4453 operator>=(const typename _Expr::value_type& __x, const _Expr& __y) 4454 { 4455 typedef typename _Expr::value_type value_type; 4456 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4457 return __val_expr<_Op>(_Op(greater_equal<value_type>(), 4458 __scalar_expr<value_type>(__x, __y.size()), __y)); 4459 } 4460 4461 template<class _Expr> 4462 inline _LIBCPP_INLINE_VISIBILITY 4463 typename enable_if 4464 < 4465 __is_val_expr<_Expr>::value, 4466 __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> > 4467 >::type 4468 abs(const _Expr& __x) 4469 { 4470 typedef typename _Expr::value_type value_type; 4471 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op; 4472 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x)); 4473 } 4474 4475 template<class _Expr> 4476 inline _LIBCPP_INLINE_VISIBILITY 4477 typename enable_if 4478 < 4479 __is_val_expr<_Expr>::value, 4480 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> > 4481 >::type 4482 acos(const _Expr& __x) 4483 { 4484 typedef typename _Expr::value_type value_type; 4485 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op; 4486 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x)); 4487 } 4488 4489 template<class _Expr> 4490 inline _LIBCPP_INLINE_VISIBILITY 4491 typename enable_if 4492 < 4493 __is_val_expr<_Expr>::value, 4494 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> > 4495 >::type 4496 asin(const _Expr& __x) 4497 { 4498 typedef typename _Expr::value_type value_type; 4499 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op; 4500 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x)); 4501 } 4502 4503 template<class _Expr> 4504 inline _LIBCPP_INLINE_VISIBILITY 4505 typename enable_if 4506 < 4507 __is_val_expr<_Expr>::value, 4508 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> > 4509 >::type 4510 atan(const _Expr& __x) 4511 { 4512 typedef typename _Expr::value_type value_type; 4513 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op; 4514 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x)); 4515 } 4516 4517 template<class _Expr1, class _Expr2> 4518 inline _LIBCPP_INLINE_VISIBILITY 4519 typename enable_if 4520 < 4521 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4522 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> > 4523 >::type 4524 atan2(const _Expr1& __x, const _Expr2& __y) 4525 { 4526 typedef typename _Expr1::value_type value_type; 4527 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op; 4528 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y)); 4529 } 4530 4531 template<class _Expr> 4532 inline _LIBCPP_INLINE_VISIBILITY 4533 typename enable_if 4534 < 4535 __is_val_expr<_Expr>::value, 4536 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>, 4537 _Expr, __scalar_expr<typename _Expr::value_type> > > 4538 >::type 4539 atan2(const _Expr& __x, const typename _Expr::value_type& __y) 4540 { 4541 typedef typename _Expr::value_type value_type; 4542 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4543 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), 4544 __x, __scalar_expr<value_type>(__y, __x.size()))); 4545 } 4546 4547 template<class _Expr> 4548 inline _LIBCPP_INLINE_VISIBILITY 4549 typename enable_if 4550 < 4551 __is_val_expr<_Expr>::value, 4552 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>, 4553 __scalar_expr<typename _Expr::value_type>, _Expr> > 4554 >::type 4555 atan2(const typename _Expr::value_type& __x, const _Expr& __y) 4556 { 4557 typedef typename _Expr::value_type value_type; 4558 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4559 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), 4560 __scalar_expr<value_type>(__x, __y.size()), __y)); 4561 } 4562 4563 template<class _Expr> 4564 inline _LIBCPP_INLINE_VISIBILITY 4565 typename enable_if 4566 < 4567 __is_val_expr<_Expr>::value, 4568 __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> > 4569 >::type 4570 cos(const _Expr& __x) 4571 { 4572 typedef typename _Expr::value_type value_type; 4573 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op; 4574 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x)); 4575 } 4576 4577 template<class _Expr> 4578 inline _LIBCPP_INLINE_VISIBILITY 4579 typename enable_if 4580 < 4581 __is_val_expr<_Expr>::value, 4582 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> > 4583 >::type 4584 cosh(const _Expr& __x) 4585 { 4586 typedef typename _Expr::value_type value_type; 4587 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op; 4588 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x)); 4589 } 4590 4591 template<class _Expr> 4592 inline _LIBCPP_INLINE_VISIBILITY 4593 typename enable_if 4594 < 4595 __is_val_expr<_Expr>::value, 4596 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> > 4597 >::type 4598 exp(const _Expr& __x) 4599 { 4600 typedef typename _Expr::value_type value_type; 4601 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op; 4602 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x)); 4603 } 4604 4605 template<class _Expr> 4606 inline _LIBCPP_INLINE_VISIBILITY 4607 typename enable_if 4608 < 4609 __is_val_expr<_Expr>::value, 4610 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> > 4611 >::type 4612 log(const _Expr& __x) 4613 { 4614 typedef typename _Expr::value_type value_type; 4615 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op; 4616 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x)); 4617 } 4618 4619 template<class _Expr> 4620 inline _LIBCPP_INLINE_VISIBILITY 4621 typename enable_if 4622 < 4623 __is_val_expr<_Expr>::value, 4624 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> > 4625 >::type 4626 log10(const _Expr& __x) 4627 { 4628 typedef typename _Expr::value_type value_type; 4629 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op; 4630 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x)); 4631 } 4632 4633 template<class _Expr1, class _Expr2> 4634 inline _LIBCPP_INLINE_VISIBILITY 4635 typename enable_if 4636 < 4637 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4638 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> > 4639 >::type 4640 pow(const _Expr1& __x, const _Expr2& __y) 4641 { 4642 typedef typename _Expr1::value_type value_type; 4643 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op; 4644 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y)); 4645 } 4646 4647 template<class _Expr> 4648 inline _LIBCPP_INLINE_VISIBILITY 4649 typename enable_if 4650 < 4651 __is_val_expr<_Expr>::value, 4652 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>, 4653 _Expr, __scalar_expr<typename _Expr::value_type> > > 4654 >::type 4655 pow(const _Expr& __x, const typename _Expr::value_type& __y) 4656 { 4657 typedef typename _Expr::value_type value_type; 4658 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4659 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), 4660 __x, __scalar_expr<value_type>(__y, __x.size()))); 4661 } 4662 4663 template<class _Expr> 4664 inline _LIBCPP_INLINE_VISIBILITY 4665 typename enable_if 4666 < 4667 __is_val_expr<_Expr>::value, 4668 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>, 4669 __scalar_expr<typename _Expr::value_type>, _Expr> > 4670 >::type 4671 pow(const typename _Expr::value_type& __x, const _Expr& __y) 4672 { 4673 typedef typename _Expr::value_type value_type; 4674 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4675 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), 4676 __scalar_expr<value_type>(__x, __y.size()), __y)); 4677 } 4678 4679 template<class _Expr> 4680 inline _LIBCPP_INLINE_VISIBILITY 4681 typename enable_if 4682 < 4683 __is_val_expr<_Expr>::value, 4684 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> > 4685 >::type 4686 sin(const _Expr& __x) 4687 { 4688 typedef typename _Expr::value_type value_type; 4689 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op; 4690 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x)); 4691 } 4692 4693 template<class _Expr> 4694 inline _LIBCPP_INLINE_VISIBILITY 4695 typename enable_if 4696 < 4697 __is_val_expr<_Expr>::value, 4698 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> > 4699 >::type 4700 sinh(const _Expr& __x) 4701 { 4702 typedef typename _Expr::value_type value_type; 4703 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op; 4704 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x)); 4705 } 4706 4707 template<class _Expr> 4708 inline _LIBCPP_INLINE_VISIBILITY 4709 typename enable_if 4710 < 4711 __is_val_expr<_Expr>::value, 4712 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> > 4713 >::type 4714 sqrt(const _Expr& __x) 4715 { 4716 typedef typename _Expr::value_type value_type; 4717 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op; 4718 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x)); 4719 } 4720 4721 template<class _Expr> 4722 inline _LIBCPP_INLINE_VISIBILITY 4723 typename enable_if 4724 < 4725 __is_val_expr<_Expr>::value, 4726 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> > 4727 >::type 4728 tan(const _Expr& __x) 4729 { 4730 typedef typename _Expr::value_type value_type; 4731 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op; 4732 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x)); 4733 } 4734 4735 template<class _Expr> 4736 inline _LIBCPP_INLINE_VISIBILITY 4737 typename enable_if 4738 < 4739 __is_val_expr<_Expr>::value, 4740 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> > 4741 >::type 4742 tanh(const _Expr& __x) 4743 { 4744 typedef typename _Expr::value_type value_type; 4745 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op; 4746 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x)); 4747 } 4748 4749 template <class _Tp> 4750 inline _LIBCPP_INLINE_VISIBILITY 4751 _Tp* 4752 begin(valarray<_Tp>& __v) 4753 { 4754 return __v.__begin_; 4755 } 4756 4757 template <class _Tp> 4758 inline _LIBCPP_INLINE_VISIBILITY 4759 const _Tp* 4760 begin(const valarray<_Tp>& __v) 4761 { 4762 return __v.__begin_; 4763 } 4764 4765 template <class _Tp> 4766 inline _LIBCPP_INLINE_VISIBILITY 4767 _Tp* 4768 end(valarray<_Tp>& __v) 4769 { 4770 return __v.__end_; 4771 } 4772 4773 template <class _Tp> 4774 inline _LIBCPP_INLINE_VISIBILITY 4775 const _Tp* 4776 end(const valarray<_Tp>& __v) 4777 { 4778 return __v.__end_; 4779 } 4780 4781 _LIBCPP_END_NAMESPACE_STD 4782 4783 #endif // _LIBCPP_VALARRAY 4784