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