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} 1224 1225template <class _Tp> 1226template <class _Expr> 1227inline _LIBCPP_INLINE_VISIBILITY 1228typename enable_if 1229< 1230 __is_val_expr<_Expr>::value, 1231 void 1232>::type 1233slice_array<_Tp>::operator=(const _Expr& __v) const 1234{ 1235 value_type* __t = __vp_; 1236 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1237 *__t = __v[__i]; 1238} 1239 1240template <class _Tp> 1241template <class _Expr> 1242inline _LIBCPP_INLINE_VISIBILITY 1243typename enable_if 1244< 1245 __is_val_expr<_Expr>::value, 1246 void 1247>::type 1248slice_array<_Tp>::operator*=(const _Expr& __v) const 1249{ 1250 value_type* __t = __vp_; 1251 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1252 *__t *= __v[__i]; 1253} 1254 1255template <class _Tp> 1256template <class _Expr> 1257inline _LIBCPP_INLINE_VISIBILITY 1258typename enable_if 1259< 1260 __is_val_expr<_Expr>::value, 1261 void 1262>::type 1263slice_array<_Tp>::operator/=(const _Expr& __v) const 1264{ 1265 value_type* __t = __vp_; 1266 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1267 *__t /= __v[__i]; 1268} 1269 1270template <class _Tp> 1271template <class _Expr> 1272inline _LIBCPP_INLINE_VISIBILITY 1273typename enable_if 1274< 1275 __is_val_expr<_Expr>::value, 1276 void 1277>::type 1278slice_array<_Tp>::operator%=(const _Expr& __v) const 1279{ 1280 value_type* __t = __vp_; 1281 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1282 *__t %= __v[__i]; 1283} 1284 1285template <class _Tp> 1286template <class _Expr> 1287inline _LIBCPP_INLINE_VISIBILITY 1288typename enable_if 1289< 1290 __is_val_expr<_Expr>::value, 1291 void 1292>::type 1293slice_array<_Tp>::operator+=(const _Expr& __v) const 1294{ 1295 value_type* __t = __vp_; 1296 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1297 *__t += __v[__i]; 1298} 1299 1300template <class _Tp> 1301template <class _Expr> 1302inline _LIBCPP_INLINE_VISIBILITY 1303typename enable_if 1304< 1305 __is_val_expr<_Expr>::value, 1306 void 1307>::type 1308slice_array<_Tp>::operator-=(const _Expr& __v) const 1309{ 1310 value_type* __t = __vp_; 1311 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1312 *__t -= __v[__i]; 1313} 1314 1315template <class _Tp> 1316template <class _Expr> 1317inline _LIBCPP_INLINE_VISIBILITY 1318typename enable_if 1319< 1320 __is_val_expr<_Expr>::value, 1321 void 1322>::type 1323slice_array<_Tp>::operator^=(const _Expr& __v) const 1324{ 1325 value_type* __t = __vp_; 1326 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1327 *__t ^= __v[__i]; 1328} 1329 1330template <class _Tp> 1331template <class _Expr> 1332inline _LIBCPP_INLINE_VISIBILITY 1333typename enable_if 1334< 1335 __is_val_expr<_Expr>::value, 1336 void 1337>::type 1338slice_array<_Tp>::operator&=(const _Expr& __v) const 1339{ 1340 value_type* __t = __vp_; 1341 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1342 *__t &= __v[__i]; 1343} 1344 1345template <class _Tp> 1346template <class _Expr> 1347inline _LIBCPP_INLINE_VISIBILITY 1348typename enable_if 1349< 1350 __is_val_expr<_Expr>::value, 1351 void 1352>::type 1353slice_array<_Tp>::operator|=(const _Expr& __v) const 1354{ 1355 value_type* __t = __vp_; 1356 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1357 *__t |= __v[__i]; 1358} 1359 1360template <class _Tp> 1361template <class _Expr> 1362inline _LIBCPP_INLINE_VISIBILITY 1363typename enable_if 1364< 1365 __is_val_expr<_Expr>::value, 1366 void 1367>::type 1368slice_array<_Tp>::operator<<=(const _Expr& __v) const 1369{ 1370 value_type* __t = __vp_; 1371 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1372 *__t <<= __v[__i]; 1373} 1374 1375template <class _Tp> 1376template <class _Expr> 1377inline _LIBCPP_INLINE_VISIBILITY 1378typename enable_if 1379< 1380 __is_val_expr<_Expr>::value, 1381 void 1382>::type 1383slice_array<_Tp>::operator>>=(const _Expr& __v) const 1384{ 1385 value_type* __t = __vp_; 1386 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1387 *__t >>= __v[__i]; 1388} 1389 1390template <class _Tp> 1391inline _LIBCPP_INLINE_VISIBILITY 1392void 1393slice_array<_Tp>::operator=(const value_type& __x) const 1394{ 1395 value_type* __t = __vp_; 1396 for (size_t __n = __size_; __n; --__n, __t += __stride_) 1397 *__t = __x; 1398} 1399 1400// gslice 1401 1402class _LIBCPP_TYPE_VIS gslice 1403{ 1404 valarray<size_t> __size_; 1405 valarray<size_t> __stride_; 1406 valarray<size_t> __1d_; 1407 1408public: 1409 _LIBCPP_INLINE_VISIBILITY 1410 gslice() {} 1411 1412 _LIBCPP_INLINE_VISIBILITY 1413 gslice(size_t __start, const valarray<size_t>& __size, 1414 const valarray<size_t>& __stride) 1415 : __size_(__size), 1416 __stride_(__stride) 1417 {__init(__start);} 1418 1419#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1420 1421 _LIBCPP_INLINE_VISIBILITY 1422 gslice(size_t __start, const valarray<size_t>& __size, 1423 valarray<size_t>&& __stride) 1424 : __size_(__size), 1425 __stride_(move(__stride)) 1426 {__init(__start);} 1427 1428 _LIBCPP_INLINE_VISIBILITY 1429 gslice(size_t __start, valarray<size_t>&& __size, 1430 const valarray<size_t>& __stride) 1431 : __size_(move(__size)), 1432 __stride_(__stride) 1433 {__init(__start);} 1434 1435 _LIBCPP_INLINE_VISIBILITY 1436 gslice(size_t __start, valarray<size_t>&& __size, 1437 valarray<size_t>&& __stride) 1438 : __size_(move(__size)), 1439 __stride_(move(__stride)) 1440 {__init(__start);} 1441 1442#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 1443 1444// gslice(const gslice&) = default; 1445// gslice(gslice&&) = default; 1446// gslice& operator=(const gslice&) = default; 1447// gslice& operator=(gslice&&) = default; 1448 1449 _LIBCPP_INLINE_VISIBILITY 1450 size_t start() const {return __1d_.size() ? __1d_[0] : 0;} 1451 1452 _LIBCPP_INLINE_VISIBILITY 1453 valarray<size_t> size() const {return __size_;} 1454 1455 _LIBCPP_INLINE_VISIBILITY 1456 valarray<size_t> stride() const {return __stride_;} 1457 1458private: 1459 void __init(size_t __start); 1460 1461 template <class> friend class gslice_array; 1462 template <class> friend class valarray; 1463 template <class> friend class __val_expr; 1464}; 1465 1466// gslice_array 1467 1468template <class _Tp> 1469class _LIBCPP_TYPE_VIS_ONLY gslice_array 1470{ 1471public: 1472 typedef _Tp value_type; 1473 1474private: 1475 value_type* __vp_; 1476 valarray<size_t> __1d_; 1477 1478public: 1479 template <class _Expr> 1480 typename enable_if 1481 < 1482 __is_val_expr<_Expr>::value, 1483 void 1484 >::type 1485 operator=(const _Expr& __v) const; 1486 1487 template <class _Expr> 1488 typename enable_if 1489 < 1490 __is_val_expr<_Expr>::value, 1491 void 1492 >::type 1493 operator*=(const _Expr& __v) const; 1494 1495 template <class _Expr> 1496 typename enable_if 1497 < 1498 __is_val_expr<_Expr>::value, 1499 void 1500 >::type 1501 operator/=(const _Expr& __v) const; 1502 1503 template <class _Expr> 1504 typename enable_if 1505 < 1506 __is_val_expr<_Expr>::value, 1507 void 1508 >::type 1509 operator%=(const _Expr& __v) const; 1510 1511 template <class _Expr> 1512 typename enable_if 1513 < 1514 __is_val_expr<_Expr>::value, 1515 void 1516 >::type 1517 operator+=(const _Expr& __v) const; 1518 1519 template <class _Expr> 1520 typename enable_if 1521 < 1522 __is_val_expr<_Expr>::value, 1523 void 1524 >::type 1525 operator-=(const _Expr& __v) const; 1526 1527 template <class _Expr> 1528 typename enable_if 1529 < 1530 __is_val_expr<_Expr>::value, 1531 void 1532 >::type 1533 operator^=(const _Expr& __v) const; 1534 1535 template <class _Expr> 1536 typename enable_if 1537 < 1538 __is_val_expr<_Expr>::value, 1539 void 1540 >::type 1541 operator&=(const _Expr& __v) const; 1542 1543 template <class _Expr> 1544 typename enable_if 1545 < 1546 __is_val_expr<_Expr>::value, 1547 void 1548 >::type 1549 operator|=(const _Expr& __v) const; 1550 1551 template <class _Expr> 1552 typename enable_if 1553 < 1554 __is_val_expr<_Expr>::value, 1555 void 1556 >::type 1557 operator<<=(const _Expr& __v) const; 1558 1559 template <class _Expr> 1560 typename enable_if 1561 < 1562 __is_val_expr<_Expr>::value, 1563 void 1564 >::type 1565 operator>>=(const _Expr& __v) const; 1566 1567 const gslice_array& operator=(const gslice_array& __ga) const; 1568 1569 void operator=(const value_type& __x) const; 1570 1571// gslice_array(const gslice_array&) = default; 1572// gslice_array(gslice_array&&) = default; 1573// gslice_array& operator=(const gslice_array&) = default; 1574// gslice_array& operator=(gslice_array&&) = default; 1575 1576private: 1577 _LIBCPP_INLINE_VISIBILITY 1578 gslice_array(const gslice& __gs, const valarray<value_type>& __v) 1579 : __vp_(const_cast<value_type*>(__v.__begin_)), 1580 __1d_(__gs.__1d_) 1581 {} 1582 1583#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1584 1585 _LIBCPP_INLINE_VISIBILITY 1586 gslice_array(gslice&& __gs, const valarray<value_type>& __v) 1587 : __vp_(const_cast<value_type*>(__v.__begin_)), 1588 __1d_(move(__gs.__1d_)) 1589 {} 1590 1591#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 1592 1593 template <class> friend class valarray; 1594}; 1595 1596template <class _Tp> 1597template <class _Expr> 1598inline _LIBCPP_INLINE_VISIBILITY 1599typename enable_if 1600< 1601 __is_val_expr<_Expr>::value, 1602 void 1603>::type 1604gslice_array<_Tp>::operator=(const _Expr& __v) const 1605{ 1606 typedef const size_t* _Ip; 1607 size_t __j = 0; 1608 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1609 __vp_[*__i] = __v[__j]; 1610} 1611 1612template <class _Tp> 1613template <class _Expr> 1614inline _LIBCPP_INLINE_VISIBILITY 1615typename enable_if 1616< 1617 __is_val_expr<_Expr>::value, 1618 void 1619>::type 1620gslice_array<_Tp>::operator*=(const _Expr& __v) const 1621{ 1622 typedef const size_t* _Ip; 1623 size_t __j = 0; 1624 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1625 __vp_[*__i] *= __v[__j]; 1626} 1627 1628template <class _Tp> 1629template <class _Expr> 1630inline _LIBCPP_INLINE_VISIBILITY 1631typename enable_if 1632< 1633 __is_val_expr<_Expr>::value, 1634 void 1635>::type 1636gslice_array<_Tp>::operator/=(const _Expr& __v) const 1637{ 1638 typedef const size_t* _Ip; 1639 size_t __j = 0; 1640 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1641 __vp_[*__i] /= __v[__j]; 1642} 1643 1644template <class _Tp> 1645template <class _Expr> 1646inline _LIBCPP_INLINE_VISIBILITY 1647typename enable_if 1648< 1649 __is_val_expr<_Expr>::value, 1650 void 1651>::type 1652gslice_array<_Tp>::operator%=(const _Expr& __v) const 1653{ 1654 typedef const size_t* _Ip; 1655 size_t __j = 0; 1656 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1657 __vp_[*__i] %= __v[__j]; 1658} 1659 1660template <class _Tp> 1661template <class _Expr> 1662inline _LIBCPP_INLINE_VISIBILITY 1663typename enable_if 1664< 1665 __is_val_expr<_Expr>::value, 1666 void 1667>::type 1668gslice_array<_Tp>::operator+=(const _Expr& __v) const 1669{ 1670 typedef const size_t* _Ip; 1671 size_t __j = 0; 1672 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1673 __vp_[*__i] += __v[__j]; 1674} 1675 1676template <class _Tp> 1677template <class _Expr> 1678inline _LIBCPP_INLINE_VISIBILITY 1679typename enable_if 1680< 1681 __is_val_expr<_Expr>::value, 1682 void 1683>::type 1684gslice_array<_Tp>::operator-=(const _Expr& __v) const 1685{ 1686 typedef const size_t* _Ip; 1687 size_t __j = 0; 1688 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1689 __vp_[*__i] -= __v[__j]; 1690} 1691 1692template <class _Tp> 1693template <class _Expr> 1694inline _LIBCPP_INLINE_VISIBILITY 1695typename enable_if 1696< 1697 __is_val_expr<_Expr>::value, 1698 void 1699>::type 1700gslice_array<_Tp>::operator^=(const _Expr& __v) const 1701{ 1702 typedef const size_t* _Ip; 1703 size_t __j = 0; 1704 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1705 __vp_[*__i] ^= __v[__j]; 1706} 1707 1708template <class _Tp> 1709template <class _Expr> 1710inline _LIBCPP_INLINE_VISIBILITY 1711typename enable_if 1712< 1713 __is_val_expr<_Expr>::value, 1714 void 1715>::type 1716gslice_array<_Tp>::operator&=(const _Expr& __v) const 1717{ 1718 typedef const size_t* _Ip; 1719 size_t __j = 0; 1720 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1721 __vp_[*__i] &= __v[__j]; 1722} 1723 1724template <class _Tp> 1725template <class _Expr> 1726inline _LIBCPP_INLINE_VISIBILITY 1727typename enable_if 1728< 1729 __is_val_expr<_Expr>::value, 1730 void 1731>::type 1732gslice_array<_Tp>::operator|=(const _Expr& __v) const 1733{ 1734 typedef const size_t* _Ip; 1735 size_t __j = 0; 1736 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1737 __vp_[*__i] |= __v[__j]; 1738} 1739 1740template <class _Tp> 1741template <class _Expr> 1742inline _LIBCPP_INLINE_VISIBILITY 1743typename enable_if 1744< 1745 __is_val_expr<_Expr>::value, 1746 void 1747>::type 1748gslice_array<_Tp>::operator<<=(const _Expr& __v) const 1749{ 1750 typedef const size_t* _Ip; 1751 size_t __j = 0; 1752 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1753 __vp_[*__i] <<= __v[__j]; 1754} 1755 1756template <class _Tp> 1757template <class _Expr> 1758inline _LIBCPP_INLINE_VISIBILITY 1759typename enable_if 1760< 1761 __is_val_expr<_Expr>::value, 1762 void 1763>::type 1764gslice_array<_Tp>::operator>>=(const _Expr& __v) const 1765{ 1766 typedef const size_t* _Ip; 1767 size_t __j = 0; 1768 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1769 __vp_[*__i] >>= __v[__j]; 1770} 1771 1772template <class _Tp> 1773inline _LIBCPP_INLINE_VISIBILITY 1774const gslice_array<_Tp>& 1775gslice_array<_Tp>::operator=(const gslice_array& __ga) const 1776{ 1777 typedef const size_t* _Ip; 1778 const value_type* __s = __ga.__vp_; 1779 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_; 1780 __i != __e; ++__i, ++__j) 1781 __vp_[*__i] = __s[*__j]; 1782 return *this; 1783} 1784 1785template <class _Tp> 1786inline _LIBCPP_INLINE_VISIBILITY 1787void 1788gslice_array<_Tp>::operator=(const value_type& __x) const 1789{ 1790 typedef const size_t* _Ip; 1791 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i) 1792 __vp_[*__i] = __x; 1793} 1794 1795// mask_array 1796 1797template <class _Tp> 1798class _LIBCPP_TYPE_VIS_ONLY mask_array 1799{ 1800public: 1801 typedef _Tp value_type; 1802 1803private: 1804 value_type* __vp_; 1805 valarray<size_t> __1d_; 1806 1807public: 1808 template <class _Expr> 1809 typename enable_if 1810 < 1811 __is_val_expr<_Expr>::value, 1812 void 1813 >::type 1814 operator=(const _Expr& __v) const; 1815 1816 template <class _Expr> 1817 typename enable_if 1818 < 1819 __is_val_expr<_Expr>::value, 1820 void 1821 >::type 1822 operator*=(const _Expr& __v) const; 1823 1824 template <class _Expr> 1825 typename enable_if 1826 < 1827 __is_val_expr<_Expr>::value, 1828 void 1829 >::type 1830 operator/=(const _Expr& __v) const; 1831 1832 template <class _Expr> 1833 typename enable_if 1834 < 1835 __is_val_expr<_Expr>::value, 1836 void 1837 >::type 1838 operator%=(const _Expr& __v) const; 1839 1840 template <class _Expr> 1841 typename enable_if 1842 < 1843 __is_val_expr<_Expr>::value, 1844 void 1845 >::type 1846 operator+=(const _Expr& __v) const; 1847 1848 template <class _Expr> 1849 typename enable_if 1850 < 1851 __is_val_expr<_Expr>::value, 1852 void 1853 >::type 1854 operator-=(const _Expr& __v) const; 1855 1856 template <class _Expr> 1857 typename enable_if 1858 < 1859 __is_val_expr<_Expr>::value, 1860 void 1861 >::type 1862 operator^=(const _Expr& __v) const; 1863 1864 template <class _Expr> 1865 typename enable_if 1866 < 1867 __is_val_expr<_Expr>::value, 1868 void 1869 >::type 1870 operator&=(const _Expr& __v) const; 1871 1872 template <class _Expr> 1873 typename enable_if 1874 < 1875 __is_val_expr<_Expr>::value, 1876 void 1877 >::type 1878 operator|=(const _Expr& __v) const; 1879 1880 template <class _Expr> 1881 typename enable_if 1882 < 1883 __is_val_expr<_Expr>::value, 1884 void 1885 >::type 1886 operator<<=(const _Expr& __v) const; 1887 1888 template <class _Expr> 1889 typename enable_if 1890 < 1891 __is_val_expr<_Expr>::value, 1892 void 1893 >::type 1894 operator>>=(const _Expr& __v) const; 1895 1896 const mask_array& operator=(const mask_array& __ma) const; 1897 1898 void operator=(const value_type& __x) const; 1899 1900// mask_array(const mask_array&) = default; 1901// mask_array(mask_array&&) = default; 1902// mask_array& operator=(const mask_array&) = default; 1903// mask_array& operator=(mask_array&&) = default; 1904 1905private: 1906 _LIBCPP_INLINE_VISIBILITY 1907 mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v) 1908 : __vp_(const_cast<value_type*>(__v.__begin_)), 1909 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true))) 1910 { 1911 size_t __j = 0; 1912 for (size_t __i = 0; __i < __vb.size(); ++__i) 1913 if (__vb[__i]) 1914 __1d_[__j++] = __i; 1915 } 1916 1917 template <class> friend class valarray; 1918}; 1919 1920template <class _Tp> 1921template <class _Expr> 1922inline _LIBCPP_INLINE_VISIBILITY 1923typename enable_if 1924< 1925 __is_val_expr<_Expr>::value, 1926 void 1927>::type 1928mask_array<_Tp>::operator=(const _Expr& __v) const 1929{ 1930 size_t __n = __1d_.size(); 1931 for (size_t __i = 0; __i < __n; ++__i) 1932 __vp_[__1d_[__i]] = __v[__i]; 1933} 1934 1935template <class _Tp> 1936template <class _Expr> 1937inline _LIBCPP_INLINE_VISIBILITY 1938typename enable_if 1939< 1940 __is_val_expr<_Expr>::value, 1941 void 1942>::type 1943mask_array<_Tp>::operator*=(const _Expr& __v) const 1944{ 1945 size_t __n = __1d_.size(); 1946 for (size_t __i = 0; __i < __n; ++__i) 1947 __vp_[__1d_[__i]] *= __v[__i]; 1948} 1949 1950template <class _Tp> 1951template <class _Expr> 1952inline _LIBCPP_INLINE_VISIBILITY 1953typename enable_if 1954< 1955 __is_val_expr<_Expr>::value, 1956 void 1957>::type 1958mask_array<_Tp>::operator/=(const _Expr& __v) const 1959{ 1960 size_t __n = __1d_.size(); 1961 for (size_t __i = 0; __i < __n; ++__i) 1962 __vp_[__1d_[__i]] /= __v[__i]; 1963} 1964 1965template <class _Tp> 1966template <class _Expr> 1967inline _LIBCPP_INLINE_VISIBILITY 1968typename enable_if 1969< 1970 __is_val_expr<_Expr>::value, 1971 void 1972>::type 1973mask_array<_Tp>::operator%=(const _Expr& __v) const 1974{ 1975 size_t __n = __1d_.size(); 1976 for (size_t __i = 0; __i < __n; ++__i) 1977 __vp_[__1d_[__i]] %= __v[__i]; 1978} 1979 1980template <class _Tp> 1981template <class _Expr> 1982inline _LIBCPP_INLINE_VISIBILITY 1983typename enable_if 1984< 1985 __is_val_expr<_Expr>::value, 1986 void 1987>::type 1988mask_array<_Tp>::operator+=(const _Expr& __v) const 1989{ 1990 size_t __n = __1d_.size(); 1991 for (size_t __i = 0; __i < __n; ++__i) 1992 __vp_[__1d_[__i]] += __v[__i]; 1993} 1994 1995template <class _Tp> 1996template <class _Expr> 1997inline _LIBCPP_INLINE_VISIBILITY 1998typename enable_if 1999< 2000 __is_val_expr<_Expr>::value, 2001 void 2002>::type 2003mask_array<_Tp>::operator-=(const _Expr& __v) const 2004{ 2005 size_t __n = __1d_.size(); 2006 for (size_t __i = 0; __i < __n; ++__i) 2007 __vp_[__1d_[__i]] -= __v[__i]; 2008} 2009 2010template <class _Tp> 2011template <class _Expr> 2012inline _LIBCPP_INLINE_VISIBILITY 2013typename enable_if 2014< 2015 __is_val_expr<_Expr>::value, 2016 void 2017>::type 2018mask_array<_Tp>::operator^=(const _Expr& __v) const 2019{ 2020 size_t __n = __1d_.size(); 2021 for (size_t __i = 0; __i < __n; ++__i) 2022 __vp_[__1d_[__i]] ^= __v[__i]; 2023} 2024 2025template <class _Tp> 2026template <class _Expr> 2027inline _LIBCPP_INLINE_VISIBILITY 2028typename enable_if 2029< 2030 __is_val_expr<_Expr>::value, 2031 void 2032>::type 2033mask_array<_Tp>::operator&=(const _Expr& __v) const 2034{ 2035 size_t __n = __1d_.size(); 2036 for (size_t __i = 0; __i < __n; ++__i) 2037 __vp_[__1d_[__i]] &= __v[__i]; 2038} 2039 2040template <class _Tp> 2041template <class _Expr> 2042inline _LIBCPP_INLINE_VISIBILITY 2043typename enable_if 2044< 2045 __is_val_expr<_Expr>::value, 2046 void 2047>::type 2048mask_array<_Tp>::operator|=(const _Expr& __v) const 2049{ 2050 size_t __n = __1d_.size(); 2051 for (size_t __i = 0; __i < __n; ++__i) 2052 __vp_[__1d_[__i]] |= __v[__i]; 2053} 2054 2055template <class _Tp> 2056template <class _Expr> 2057inline _LIBCPP_INLINE_VISIBILITY 2058typename enable_if 2059< 2060 __is_val_expr<_Expr>::value, 2061 void 2062>::type 2063mask_array<_Tp>::operator<<=(const _Expr& __v) const 2064{ 2065 size_t __n = __1d_.size(); 2066 for (size_t __i = 0; __i < __n; ++__i) 2067 __vp_[__1d_[__i]] <<= __v[__i]; 2068} 2069 2070template <class _Tp> 2071template <class _Expr> 2072inline _LIBCPP_INLINE_VISIBILITY 2073typename enable_if 2074< 2075 __is_val_expr<_Expr>::value, 2076 void 2077>::type 2078mask_array<_Tp>::operator>>=(const _Expr& __v) const 2079{ 2080 size_t __n = __1d_.size(); 2081 for (size_t __i = 0; __i < __n; ++__i) 2082 __vp_[__1d_[__i]] >>= __v[__i]; 2083} 2084 2085template <class _Tp> 2086inline _LIBCPP_INLINE_VISIBILITY 2087const mask_array<_Tp>& 2088mask_array<_Tp>::operator=(const mask_array& __ma) const 2089{ 2090 size_t __n = __1d_.size(); 2091 for (size_t __i = 0; __i < __n; ++__i) 2092 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]]; 2093} 2094 2095template <class _Tp> 2096inline _LIBCPP_INLINE_VISIBILITY 2097void 2098mask_array<_Tp>::operator=(const value_type& __x) const 2099{ 2100 size_t __n = __1d_.size(); 2101 for (size_t __i = 0; __i < __n; ++__i) 2102 __vp_[__1d_[__i]] = __x; 2103} 2104 2105template <class _ValExpr> 2106class __mask_expr 2107{ 2108 typedef typename remove_reference<_ValExpr>::type _RmExpr; 2109public: 2110 typedef typename _RmExpr::value_type value_type; 2111 typedef value_type result_type; 2112 2113private: 2114 _ValExpr __expr_; 2115 valarray<size_t> __1d_; 2116 2117 _LIBCPP_INLINE_VISIBILITY 2118 __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e) 2119 : __expr_(__e), 2120 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true))) 2121 { 2122 size_t __j = 0; 2123 for (size_t __i = 0; __i < __vb.size(); ++__i) 2124 if (__vb[__i]) 2125 __1d_[__j++] = __i; 2126 } 2127 2128public: 2129 _LIBCPP_INLINE_VISIBILITY 2130 result_type operator[](size_t __i) const 2131 {return __expr_[__1d_[__i]];} 2132 2133 _LIBCPP_INLINE_VISIBILITY 2134 size_t size() const {return __1d_.size();} 2135 2136 template <class> friend class valarray; 2137}; 2138 2139// indirect_array 2140 2141template <class _Tp> 2142class _LIBCPP_TYPE_VIS_ONLY indirect_array 2143{ 2144public: 2145 typedef _Tp value_type; 2146 2147private: 2148 value_type* __vp_; 2149 valarray<size_t> __1d_; 2150 2151public: 2152 template <class _Expr> 2153 typename enable_if 2154 < 2155 __is_val_expr<_Expr>::value, 2156 void 2157 >::type 2158 operator=(const _Expr& __v) const; 2159 2160 template <class _Expr> 2161 typename enable_if 2162 < 2163 __is_val_expr<_Expr>::value, 2164 void 2165 >::type 2166 operator*=(const _Expr& __v) const; 2167 2168 template <class _Expr> 2169 typename enable_if 2170 < 2171 __is_val_expr<_Expr>::value, 2172 void 2173 >::type 2174 operator/=(const _Expr& __v) const; 2175 2176 template <class _Expr> 2177 typename enable_if 2178 < 2179 __is_val_expr<_Expr>::value, 2180 void 2181 >::type 2182 operator%=(const _Expr& __v) const; 2183 2184 template <class _Expr> 2185 typename enable_if 2186 < 2187 __is_val_expr<_Expr>::value, 2188 void 2189 >::type 2190 operator+=(const _Expr& __v) const; 2191 2192 template <class _Expr> 2193 typename enable_if 2194 < 2195 __is_val_expr<_Expr>::value, 2196 void 2197 >::type 2198 operator-=(const _Expr& __v) const; 2199 2200 template <class _Expr> 2201 typename enable_if 2202 < 2203 __is_val_expr<_Expr>::value, 2204 void 2205 >::type 2206 operator^=(const _Expr& __v) const; 2207 2208 template <class _Expr> 2209 typename enable_if 2210 < 2211 __is_val_expr<_Expr>::value, 2212 void 2213 >::type 2214 operator&=(const _Expr& __v) const; 2215 2216 template <class _Expr> 2217 typename enable_if 2218 < 2219 __is_val_expr<_Expr>::value, 2220 void 2221 >::type 2222 operator|=(const _Expr& __v) const; 2223 2224 template <class _Expr> 2225 typename enable_if 2226 < 2227 __is_val_expr<_Expr>::value, 2228 void 2229 >::type 2230 operator<<=(const _Expr& __v) const; 2231 2232 template <class _Expr> 2233 typename enable_if 2234 < 2235 __is_val_expr<_Expr>::value, 2236 void 2237 >::type 2238 operator>>=(const _Expr& __v) const; 2239 2240 const indirect_array& operator=(const indirect_array& __ia) const; 2241 2242 void operator=(const value_type& __x) const; 2243 2244// indirect_array(const indirect_array&) = default; 2245// indirect_array(indirect_array&&) = default; 2246// indirect_array& operator=(const indirect_array&) = default; 2247// indirect_array& operator=(indirect_array&&) = default; 2248 2249private: 2250 _LIBCPP_INLINE_VISIBILITY 2251 indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v) 2252 : __vp_(const_cast<value_type*>(__v.__begin_)), 2253 __1d_(__ia) 2254 {} 2255 2256#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2257 2258 _LIBCPP_INLINE_VISIBILITY 2259 indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v) 2260 : __vp_(const_cast<value_type*>(__v.__begin_)), 2261 __1d_(move(__ia)) 2262 {} 2263 2264#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2265 2266 template <class> friend class valarray; 2267}; 2268 2269template <class _Tp> 2270template <class _Expr> 2271inline _LIBCPP_INLINE_VISIBILITY 2272typename enable_if 2273< 2274 __is_val_expr<_Expr>::value, 2275 void 2276>::type 2277indirect_array<_Tp>::operator=(const _Expr& __v) const 2278{ 2279 size_t __n = __1d_.size(); 2280 for (size_t __i = 0; __i < __n; ++__i) 2281 __vp_[__1d_[__i]] = __v[__i]; 2282} 2283 2284template <class _Tp> 2285template <class _Expr> 2286inline _LIBCPP_INLINE_VISIBILITY 2287typename enable_if 2288< 2289 __is_val_expr<_Expr>::value, 2290 void 2291>::type 2292indirect_array<_Tp>::operator*=(const _Expr& __v) const 2293{ 2294 size_t __n = __1d_.size(); 2295 for (size_t __i = 0; __i < __n; ++__i) 2296 __vp_[__1d_[__i]] *= __v[__i]; 2297} 2298 2299template <class _Tp> 2300template <class _Expr> 2301inline _LIBCPP_INLINE_VISIBILITY 2302typename enable_if 2303< 2304 __is_val_expr<_Expr>::value, 2305 void 2306>::type 2307indirect_array<_Tp>::operator/=(const _Expr& __v) const 2308{ 2309 size_t __n = __1d_.size(); 2310 for (size_t __i = 0; __i < __n; ++__i) 2311 __vp_[__1d_[__i]] /= __v[__i]; 2312} 2313 2314template <class _Tp> 2315template <class _Expr> 2316inline _LIBCPP_INLINE_VISIBILITY 2317typename enable_if 2318< 2319 __is_val_expr<_Expr>::value, 2320 void 2321>::type 2322indirect_array<_Tp>::operator%=(const _Expr& __v) const 2323{ 2324 size_t __n = __1d_.size(); 2325 for (size_t __i = 0; __i < __n; ++__i) 2326 __vp_[__1d_[__i]] %= __v[__i]; 2327} 2328 2329template <class _Tp> 2330template <class _Expr> 2331inline _LIBCPP_INLINE_VISIBILITY 2332typename enable_if 2333< 2334 __is_val_expr<_Expr>::value, 2335 void 2336>::type 2337indirect_array<_Tp>::operator+=(const _Expr& __v) const 2338{ 2339 size_t __n = __1d_.size(); 2340 for (size_t __i = 0; __i < __n; ++__i) 2341 __vp_[__1d_[__i]] += __v[__i]; 2342} 2343 2344template <class _Tp> 2345template <class _Expr> 2346inline _LIBCPP_INLINE_VISIBILITY 2347typename enable_if 2348< 2349 __is_val_expr<_Expr>::value, 2350 void 2351>::type 2352indirect_array<_Tp>::operator-=(const _Expr& __v) const 2353{ 2354 size_t __n = __1d_.size(); 2355 for (size_t __i = 0; __i < __n; ++__i) 2356 __vp_[__1d_[__i]] -= __v[__i]; 2357} 2358 2359template <class _Tp> 2360template <class _Expr> 2361inline _LIBCPP_INLINE_VISIBILITY 2362typename enable_if 2363< 2364 __is_val_expr<_Expr>::value, 2365 void 2366>::type 2367indirect_array<_Tp>::operator^=(const _Expr& __v) const 2368{ 2369 size_t __n = __1d_.size(); 2370 for (size_t __i = 0; __i < __n; ++__i) 2371 __vp_[__1d_[__i]] ^= __v[__i]; 2372} 2373 2374template <class _Tp> 2375template <class _Expr> 2376inline _LIBCPP_INLINE_VISIBILITY 2377typename enable_if 2378< 2379 __is_val_expr<_Expr>::value, 2380 void 2381>::type 2382indirect_array<_Tp>::operator&=(const _Expr& __v) const 2383{ 2384 size_t __n = __1d_.size(); 2385 for (size_t __i = 0; __i < __n; ++__i) 2386 __vp_[__1d_[__i]] &= __v[__i]; 2387} 2388 2389template <class _Tp> 2390template <class _Expr> 2391inline _LIBCPP_INLINE_VISIBILITY 2392typename enable_if 2393< 2394 __is_val_expr<_Expr>::value, 2395 void 2396>::type 2397indirect_array<_Tp>::operator|=(const _Expr& __v) const 2398{ 2399 size_t __n = __1d_.size(); 2400 for (size_t __i = 0; __i < __n; ++__i) 2401 __vp_[__1d_[__i]] |= __v[__i]; 2402} 2403 2404template <class _Tp> 2405template <class _Expr> 2406inline _LIBCPP_INLINE_VISIBILITY 2407typename enable_if 2408< 2409 __is_val_expr<_Expr>::value, 2410 void 2411>::type 2412indirect_array<_Tp>::operator<<=(const _Expr& __v) const 2413{ 2414 size_t __n = __1d_.size(); 2415 for (size_t __i = 0; __i < __n; ++__i) 2416 __vp_[__1d_[__i]] <<= __v[__i]; 2417} 2418 2419template <class _Tp> 2420template <class _Expr> 2421inline _LIBCPP_INLINE_VISIBILITY 2422typename enable_if 2423< 2424 __is_val_expr<_Expr>::value, 2425 void 2426>::type 2427indirect_array<_Tp>::operator>>=(const _Expr& __v) const 2428{ 2429 size_t __n = __1d_.size(); 2430 for (size_t __i = 0; __i < __n; ++__i) 2431 __vp_[__1d_[__i]] >>= __v[__i]; 2432} 2433 2434template <class _Tp> 2435inline _LIBCPP_INLINE_VISIBILITY 2436const indirect_array<_Tp>& 2437indirect_array<_Tp>::operator=(const indirect_array& __ia) const 2438{ 2439 typedef const size_t* _Ip; 2440 const value_type* __s = __ia.__vp_; 2441 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_; 2442 __i != __e; ++__i, ++__j) 2443 __vp_[*__i] = __s[*__j]; 2444 return *this; 2445} 2446 2447template <class _Tp> 2448inline _LIBCPP_INLINE_VISIBILITY 2449void 2450indirect_array<_Tp>::operator=(const value_type& __x) const 2451{ 2452 typedef const size_t* _Ip; 2453 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i) 2454 __vp_[*__i] = __x; 2455} 2456 2457template <class _ValExpr> 2458class __indirect_expr 2459{ 2460 typedef typename remove_reference<_ValExpr>::type _RmExpr; 2461public: 2462 typedef typename _RmExpr::value_type value_type; 2463 typedef value_type result_type; 2464 2465private: 2466 _ValExpr __expr_; 2467 valarray<size_t> __1d_; 2468 2469 _LIBCPP_INLINE_VISIBILITY 2470 __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e) 2471 : __expr_(__e), 2472 __1d_(__ia) 2473 {} 2474 2475#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2476 2477 _LIBCPP_INLINE_VISIBILITY 2478 __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e) 2479 : __expr_(__e), 2480 __1d_(move(__ia)) 2481 {} 2482 2483#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2484 2485public: 2486 _LIBCPP_INLINE_VISIBILITY 2487 result_type operator[](size_t __i) const 2488 {return __expr_[__1d_[__i]];} 2489 2490 _LIBCPP_INLINE_VISIBILITY 2491 size_t size() const {return __1d_.size();} 2492 2493 template <class> friend class _LIBCPP_TYPE_VIS_ONLY valarray; 2494}; 2495 2496template<class _ValExpr> 2497class __val_expr 2498{ 2499 typedef typename remove_reference<_ValExpr>::type _RmExpr; 2500 2501 _ValExpr __expr_; 2502public: 2503 typedef typename _RmExpr::value_type value_type; 2504 typedef typename _RmExpr::result_type result_type; 2505 2506 _LIBCPP_INLINE_VISIBILITY 2507 explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {} 2508 2509 _LIBCPP_INLINE_VISIBILITY 2510 result_type operator[](size_t __i) const 2511 {return __expr_[__i];} 2512 2513 _LIBCPP_INLINE_VISIBILITY 2514 __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const 2515 {return __val_expr<__slice_expr<_ValExpr> >(__expr_, __s);} 2516 2517 _LIBCPP_INLINE_VISIBILITY 2518 __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const 2519 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __gs.__1d_);} 2520 2521 _LIBCPP_INLINE_VISIBILITY 2522 __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const 2523 {return __val_expr<__mask_expr<_ValExpr> >(__expr_, __vb);} 2524 2525 _LIBCPP_INLINE_VISIBILITY 2526 __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const 2527 {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __vs);} 2528 2529 _LIBCPP_INLINE_VISIBILITY 2530 __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> > 2531 operator+() const 2532 { 2533 typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr; 2534 return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_)); 2535 } 2536 2537 _LIBCPP_INLINE_VISIBILITY 2538 __val_expr<_UnaryOp<negate<value_type>, _ValExpr> > 2539 operator-() const 2540 { 2541 typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr; 2542 return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_)); 2543 } 2544 2545 _LIBCPP_INLINE_VISIBILITY 2546 __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> > 2547 operator~() const 2548 { 2549 typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr; 2550 return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_)); 2551 } 2552 2553 _LIBCPP_INLINE_VISIBILITY 2554 __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> > 2555 operator!() const 2556 { 2557 typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr; 2558 return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_)); 2559 } 2560 2561 operator valarray<result_type>() const; 2562 2563 _LIBCPP_INLINE_VISIBILITY 2564 size_t size() const {return __expr_.size();} 2565 2566 _LIBCPP_INLINE_VISIBILITY 2567 result_type sum() const 2568 { 2569 size_t __n = __expr_.size(); 2570 result_type __r = __n ? __expr_[0] : result_type(); 2571 for (size_t __i = 1; __i < __n; ++__i) 2572 __r += __expr_[__i]; 2573 return __r; 2574 } 2575 2576 _LIBCPP_INLINE_VISIBILITY 2577 result_type min() const 2578 { 2579 size_t __n = size(); 2580 result_type __r = __n ? (*this)[0] : result_type(); 2581 for (size_t __i = 1; __i < __n; ++__i) 2582 { 2583 result_type __x = __expr_[__i]; 2584 if (__x < __r) 2585 __r = __x; 2586 } 2587 return __r; 2588 } 2589 2590 _LIBCPP_INLINE_VISIBILITY 2591 result_type max() const 2592 { 2593 size_t __n = size(); 2594 result_type __r = __n ? (*this)[0] : result_type(); 2595 for (size_t __i = 1; __i < __n; ++__i) 2596 { 2597 result_type __x = __expr_[__i]; 2598 if (__r < __x) 2599 __r = __x; 2600 } 2601 return __r; 2602 } 2603 2604 _LIBCPP_INLINE_VISIBILITY 2605 __val_expr<__shift_expr<_ValExpr> > shift (int __i) const 2606 {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));} 2607 2608 _LIBCPP_INLINE_VISIBILITY 2609 __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const 2610 {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));} 2611 2612 _LIBCPP_INLINE_VISIBILITY 2613 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> > 2614 apply(value_type __f(value_type)) const 2615 { 2616 typedef __apply_expr<value_type, value_type(*)(value_type)> _Op; 2617 typedef _UnaryOp<_Op, _ValExpr> _NewExpr; 2618 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_)); 2619 } 2620 2621 _LIBCPP_INLINE_VISIBILITY 2622 __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> > 2623 apply(value_type __f(const value_type&)) const 2624 { 2625 typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op; 2626 typedef _UnaryOp<_Op, _ValExpr> _NewExpr; 2627 return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_)); 2628 } 2629}; 2630 2631template<class _ValExpr> 2632__val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const 2633{ 2634 valarray<result_type> __r; 2635 size_t __n = __expr_.size(); 2636 if (__n) 2637 { 2638 __r.__begin_ = 2639 __r.__end_ = 2640 static_cast<result_type*>(_VSTD::__allocate(__n * sizeof(result_type))); 2641 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i) 2642 ::new (__r.__end_) result_type(__expr_[__i]); 2643 } 2644 return __r; 2645} 2646 2647// valarray 2648 2649template <class _Tp> 2650inline _LIBCPP_INLINE_VISIBILITY 2651valarray<_Tp>::valarray(size_t __n) 2652 : __begin_(0), 2653 __end_(0) 2654{ 2655 resize(__n); 2656} 2657 2658template <class _Tp> 2659inline _LIBCPP_INLINE_VISIBILITY 2660valarray<_Tp>::valarray(const value_type& __x, size_t __n) 2661 : __begin_(0), 2662 __end_(0) 2663{ 2664 resize(__n, __x); 2665} 2666 2667template <class _Tp> 2668valarray<_Tp>::valarray(const value_type* __p, size_t __n) 2669 : __begin_(0), 2670 __end_(0) 2671{ 2672 if (__n) 2673 { 2674 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 2675#ifndef _LIBCPP_NO_EXCEPTIONS 2676 try 2677 { 2678#endif // _LIBCPP_NO_EXCEPTIONS 2679 for (; __n; ++__end_, ++__p, --__n) 2680 ::new (__end_) value_type(*__p); 2681#ifndef _LIBCPP_NO_EXCEPTIONS 2682 } 2683 catch (...) 2684 { 2685 resize(0); 2686 throw; 2687 } 2688#endif // _LIBCPP_NO_EXCEPTIONS 2689 } 2690} 2691 2692template <class _Tp> 2693valarray<_Tp>::valarray(const valarray& __v) 2694 : __begin_(0), 2695 __end_(0) 2696{ 2697 if (__v.size()) 2698 { 2699 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__v.size() * sizeof(value_type))); 2700#ifndef _LIBCPP_NO_EXCEPTIONS 2701 try 2702 { 2703#endif // _LIBCPP_NO_EXCEPTIONS 2704 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p) 2705 ::new (__end_) value_type(*__p); 2706#ifndef _LIBCPP_NO_EXCEPTIONS 2707 } 2708 catch (...) 2709 { 2710 resize(0); 2711 throw; 2712 } 2713#endif // _LIBCPP_NO_EXCEPTIONS 2714 } 2715} 2716 2717#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2718 2719template <class _Tp> 2720inline _LIBCPP_INLINE_VISIBILITY 2721valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT 2722 : __begin_(__v.__begin_), 2723 __end_(__v.__end_) 2724{ 2725 __v.__begin_ = __v.__end_ = nullptr; 2726} 2727 2728#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2729 2730#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 2731 2732template <class _Tp> 2733valarray<_Tp>::valarray(initializer_list<value_type> __il) 2734 : __begin_(0), 2735 __end_(0) 2736{ 2737 size_t __n = __il.size(); 2738 if (__n) 2739 { 2740 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 2741#ifndef _LIBCPP_NO_EXCEPTIONS 2742 try 2743 { 2744#endif // _LIBCPP_NO_EXCEPTIONS 2745 for (const value_type* __p = __il.begin(); __n; ++__end_, ++__p, --__n) 2746 ::new (__end_) value_type(*__p); 2747#ifndef _LIBCPP_NO_EXCEPTIONS 2748 } 2749 catch (...) 2750 { 2751 resize(0); 2752 throw; 2753 } 2754#endif // _LIBCPP_NO_EXCEPTIONS 2755 } 2756} 2757 2758#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 2759 2760template <class _Tp> 2761valarray<_Tp>::valarray(const slice_array<value_type>& __sa) 2762 : __begin_(0), 2763 __end_(0) 2764{ 2765 size_t __n = __sa.__size_; 2766 if (__n) 2767 { 2768 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 2769#ifndef _LIBCPP_NO_EXCEPTIONS 2770 try 2771 { 2772#endif // _LIBCPP_NO_EXCEPTIONS 2773 for (const value_type* __p = __sa.__vp_; __n; ++__end_, __p += __sa.__stride_, --__n) 2774 ::new (__end_) value_type(*__p); 2775#ifndef _LIBCPP_NO_EXCEPTIONS 2776 } 2777 catch (...) 2778 { 2779 resize(0); 2780 throw; 2781 } 2782#endif // _LIBCPP_NO_EXCEPTIONS 2783 } 2784} 2785 2786template <class _Tp> 2787valarray<_Tp>::valarray(const gslice_array<value_type>& __ga) 2788 : __begin_(0), 2789 __end_(0) 2790{ 2791 size_t __n = __ga.__1d_.size(); 2792 if (__n) 2793 { 2794 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 2795#ifndef _LIBCPP_NO_EXCEPTIONS 2796 try 2797 { 2798#endif // _LIBCPP_NO_EXCEPTIONS 2799 typedef const size_t* _Ip; 2800 const value_type* __s = __ga.__vp_; 2801 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; 2802 __i != __e; ++__i, ++__end_) 2803 ::new (__end_) value_type(__s[*__i]); 2804#ifndef _LIBCPP_NO_EXCEPTIONS 2805 } 2806 catch (...) 2807 { 2808 resize(0); 2809 throw; 2810 } 2811#endif // _LIBCPP_NO_EXCEPTIONS 2812 } 2813} 2814 2815template <class _Tp> 2816valarray<_Tp>::valarray(const mask_array<value_type>& __ma) 2817 : __begin_(0), 2818 __end_(0) 2819{ 2820 size_t __n = __ma.__1d_.size(); 2821 if (__n) 2822 { 2823 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 2824#ifndef _LIBCPP_NO_EXCEPTIONS 2825 try 2826 { 2827#endif // _LIBCPP_NO_EXCEPTIONS 2828 typedef const size_t* _Ip; 2829 const value_type* __s = __ma.__vp_; 2830 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; 2831 __i != __e; ++__i, ++__end_) 2832 ::new (__end_) value_type(__s[*__i]); 2833#ifndef _LIBCPP_NO_EXCEPTIONS 2834 } 2835 catch (...) 2836 { 2837 resize(0); 2838 throw; 2839 } 2840#endif // _LIBCPP_NO_EXCEPTIONS 2841 } 2842} 2843 2844template <class _Tp> 2845valarray<_Tp>::valarray(const indirect_array<value_type>& __ia) 2846 : __begin_(0), 2847 __end_(0) 2848{ 2849 size_t __n = __ia.__1d_.size(); 2850 if (__n) 2851 { 2852 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 2853#ifndef _LIBCPP_NO_EXCEPTIONS 2854 try 2855 { 2856#endif // _LIBCPP_NO_EXCEPTIONS 2857 typedef const size_t* _Ip; 2858 const value_type* __s = __ia.__vp_; 2859 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; 2860 __i != __e; ++__i, ++__end_) 2861 ::new (__end_) value_type(__s[*__i]); 2862#ifndef _LIBCPP_NO_EXCEPTIONS 2863 } 2864 catch (...) 2865 { 2866 resize(0); 2867 throw; 2868 } 2869#endif // _LIBCPP_NO_EXCEPTIONS 2870 } 2871} 2872 2873template <class _Tp> 2874inline _LIBCPP_INLINE_VISIBILITY 2875valarray<_Tp>::~valarray() 2876{ 2877 resize(0); 2878} 2879 2880template <class _Tp> 2881valarray<_Tp>& 2882valarray<_Tp>::operator=(const valarray& __v) 2883{ 2884 if (this != &__v) 2885 { 2886 if (size() != __v.size()) 2887 resize(__v.size()); 2888 _VSTD::copy(__v.__begin_, __v.__end_, __begin_); 2889 } 2890 return *this; 2891} 2892 2893#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2894 2895template <class _Tp> 2896inline _LIBCPP_INLINE_VISIBILITY 2897valarray<_Tp>& 2898valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT 2899{ 2900 resize(0); 2901 __begin_ = __v.__begin_; 2902 __end_ = __v.__end_; 2903 __v.__begin_ = nullptr; 2904 __v.__end_ = nullptr; 2905 return *this; 2906} 2907 2908#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2909 2910#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 2911 2912template <class _Tp> 2913inline _LIBCPP_INLINE_VISIBILITY 2914valarray<_Tp>& 2915valarray<_Tp>::operator=(initializer_list<value_type> __il) 2916{ 2917 if (size() != __il.size()) 2918 resize(__il.size()); 2919 _VSTD::copy(__il.begin(), __il.end(), __begin_); 2920 return *this; 2921} 2922 2923#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 2924 2925template <class _Tp> 2926inline _LIBCPP_INLINE_VISIBILITY 2927valarray<_Tp>& 2928valarray<_Tp>::operator=(const value_type& __x) 2929{ 2930 _VSTD::fill(__begin_, __end_, __x); 2931 return *this; 2932} 2933 2934template <class _Tp> 2935inline _LIBCPP_INLINE_VISIBILITY 2936valarray<_Tp>& 2937valarray<_Tp>::operator=(const slice_array<value_type>& __sa) 2938{ 2939 value_type* __t = __begin_; 2940 const value_type* __s = __sa.__vp_; 2941 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t) 2942 *__t = *__s; 2943 return *this; 2944} 2945 2946template <class _Tp> 2947inline _LIBCPP_INLINE_VISIBILITY 2948valarray<_Tp>& 2949valarray<_Tp>::operator=(const gslice_array<value_type>& __ga) 2950{ 2951 typedef const size_t* _Ip; 2952 value_type* __t = __begin_; 2953 const value_type* __s = __ga.__vp_; 2954 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; 2955 __i != __e; ++__i, ++__t) 2956 *__t = __s[*__i]; 2957 return *this; 2958} 2959 2960template <class _Tp> 2961inline _LIBCPP_INLINE_VISIBILITY 2962valarray<_Tp>& 2963valarray<_Tp>::operator=(const mask_array<value_type>& __ma) 2964{ 2965 typedef const size_t* _Ip; 2966 value_type* __t = __begin_; 2967 const value_type* __s = __ma.__vp_; 2968 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; 2969 __i != __e; ++__i, ++__t) 2970 *__t = __s[*__i]; 2971 return *this; 2972} 2973 2974template <class _Tp> 2975inline _LIBCPP_INLINE_VISIBILITY 2976valarray<_Tp>& 2977valarray<_Tp>::operator=(const indirect_array<value_type>& __ia) 2978{ 2979 typedef const size_t* _Ip; 2980 value_type* __t = __begin_; 2981 const value_type* __s = __ia.__vp_; 2982 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; 2983 __i != __e; ++__i, ++__t) 2984 *__t = __s[*__i]; 2985 return *this; 2986} 2987 2988template <class _Tp> 2989template <class _ValExpr> 2990inline _LIBCPP_INLINE_VISIBILITY 2991valarray<_Tp>& 2992valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v) 2993{ 2994 size_t __n = __v.size(); 2995 if (size() != __n) 2996 resize(__n); 2997 value_type* __t = __begin_; 2998 for (size_t __i = 0; __i != __n; ++__t, ++__i) 2999 *__t = result_type(__v[__i]); 3000 return *this; 3001} 3002 3003template <class _Tp> 3004inline _LIBCPP_INLINE_VISIBILITY 3005__val_expr<__slice_expr<const valarray<_Tp>&> > 3006valarray<_Tp>::operator[](slice __s) const 3007{ 3008 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this)); 3009} 3010 3011template <class _Tp> 3012inline _LIBCPP_INLINE_VISIBILITY 3013slice_array<_Tp> 3014valarray<_Tp>::operator[](slice __s) 3015{ 3016 return slice_array<value_type>(__s, *this); 3017} 3018 3019template <class _Tp> 3020inline _LIBCPP_INLINE_VISIBILITY 3021__val_expr<__indirect_expr<const valarray<_Tp>&> > 3022valarray<_Tp>::operator[](const gslice& __gs) const 3023{ 3024 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this)); 3025} 3026 3027template <class _Tp> 3028inline _LIBCPP_INLINE_VISIBILITY 3029gslice_array<_Tp> 3030valarray<_Tp>::operator[](const gslice& __gs) 3031{ 3032 return gslice_array<value_type>(__gs, *this); 3033} 3034 3035#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3036 3037template <class _Tp> 3038inline _LIBCPP_INLINE_VISIBILITY 3039__val_expr<__indirect_expr<const valarray<_Tp>&> > 3040valarray<_Tp>::operator[](gslice&& __gs) const 3041{ 3042 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this)); 3043} 3044 3045template <class _Tp> 3046inline _LIBCPP_INLINE_VISIBILITY 3047gslice_array<_Tp> 3048valarray<_Tp>::operator[](gslice&& __gs) 3049{ 3050 return gslice_array<value_type>(move(__gs), *this); 3051} 3052 3053#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3054 3055template <class _Tp> 3056inline _LIBCPP_INLINE_VISIBILITY 3057__val_expr<__mask_expr<const valarray<_Tp>&> > 3058valarray<_Tp>::operator[](const valarray<bool>& __vb) const 3059{ 3060 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this)); 3061} 3062 3063template <class _Tp> 3064inline _LIBCPP_INLINE_VISIBILITY 3065mask_array<_Tp> 3066valarray<_Tp>::operator[](const valarray<bool>& __vb) 3067{ 3068 return mask_array<value_type>(__vb, *this); 3069} 3070 3071#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3072 3073template <class _Tp> 3074inline _LIBCPP_INLINE_VISIBILITY 3075__val_expr<__mask_expr<const valarray<_Tp>&> > 3076valarray<_Tp>::operator[](valarray<bool>&& __vb) const 3077{ 3078 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this)); 3079} 3080 3081template <class _Tp> 3082inline _LIBCPP_INLINE_VISIBILITY 3083mask_array<_Tp> 3084valarray<_Tp>::operator[](valarray<bool>&& __vb) 3085{ 3086 return mask_array<value_type>(move(__vb), *this); 3087} 3088 3089#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3090 3091template <class _Tp> 3092inline _LIBCPP_INLINE_VISIBILITY 3093__val_expr<__indirect_expr<const valarray<_Tp>&> > 3094valarray<_Tp>::operator[](const valarray<size_t>& __vs) const 3095{ 3096 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this)); 3097} 3098 3099template <class _Tp> 3100inline _LIBCPP_INLINE_VISIBILITY 3101indirect_array<_Tp> 3102valarray<_Tp>::operator[](const valarray<size_t>& __vs) 3103{ 3104 return indirect_array<value_type>(__vs, *this); 3105} 3106 3107#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3108 3109template <class _Tp> 3110inline _LIBCPP_INLINE_VISIBILITY 3111__val_expr<__indirect_expr<const valarray<_Tp>&> > 3112valarray<_Tp>::operator[](valarray<size_t>&& __vs) const 3113{ 3114 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this)); 3115} 3116 3117template <class _Tp> 3118inline _LIBCPP_INLINE_VISIBILITY 3119indirect_array<_Tp> 3120valarray<_Tp>::operator[](valarray<size_t>&& __vs) 3121{ 3122 return indirect_array<value_type>(move(__vs), *this); 3123} 3124 3125#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3126 3127template <class _Tp> 3128valarray<_Tp> 3129valarray<_Tp>::operator+() const 3130{ 3131 valarray<value_type> __r; 3132 size_t __n = size(); 3133 if (__n) 3134 { 3135 __r.__begin_ = 3136 __r.__end_ = 3137 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 3138 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) 3139 ::new (__r.__end_) value_type(+*__p); 3140 } 3141 return __r; 3142} 3143 3144template <class _Tp> 3145valarray<_Tp> 3146valarray<_Tp>::operator-() const 3147{ 3148 valarray<value_type> __r; 3149 size_t __n = size(); 3150 if (__n) 3151 { 3152 __r.__begin_ = 3153 __r.__end_ = 3154 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 3155 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) 3156 ::new (__r.__end_) value_type(-*__p); 3157 } 3158 return __r; 3159} 3160 3161template <class _Tp> 3162valarray<_Tp> 3163valarray<_Tp>::operator~() const 3164{ 3165 valarray<value_type> __r; 3166 size_t __n = size(); 3167 if (__n) 3168 { 3169 __r.__begin_ = 3170 __r.__end_ = 3171 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 3172 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) 3173 ::new (__r.__end_) value_type(~*__p); 3174 } 3175 return __r; 3176} 3177 3178template <class _Tp> 3179valarray<bool> 3180valarray<_Tp>::operator!() const 3181{ 3182 valarray<bool> __r; 3183 size_t __n = size(); 3184 if (__n) 3185 { 3186 __r.__begin_ = 3187 __r.__end_ = 3188 static_cast<bool*>(_VSTD::__allocate(__n * sizeof(bool))); 3189 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) 3190 ::new (__r.__end_) bool(!*__p); 3191 } 3192 return __r; 3193} 3194 3195template <class _Tp> 3196inline _LIBCPP_INLINE_VISIBILITY 3197valarray<_Tp>& 3198valarray<_Tp>::operator*=(const value_type& __x) 3199{ 3200 for (value_type* __p = __begin_; __p != __end_; ++__p) 3201 *__p *= __x; 3202 return *this; 3203} 3204 3205template <class _Tp> 3206inline _LIBCPP_INLINE_VISIBILITY 3207valarray<_Tp>& 3208valarray<_Tp>::operator/=(const value_type& __x) 3209{ 3210 for (value_type* __p = __begin_; __p != __end_; ++__p) 3211 *__p /= __x; 3212 return *this; 3213} 3214 3215template <class _Tp> 3216inline _LIBCPP_INLINE_VISIBILITY 3217valarray<_Tp>& 3218valarray<_Tp>::operator%=(const value_type& __x) 3219{ 3220 for (value_type* __p = __begin_; __p != __end_; ++__p) 3221 *__p %= __x; 3222 return *this; 3223} 3224 3225template <class _Tp> 3226inline _LIBCPP_INLINE_VISIBILITY 3227valarray<_Tp>& 3228valarray<_Tp>::operator+=(const value_type& __x) 3229{ 3230 for (value_type* __p = __begin_; __p != __end_; ++__p) 3231 *__p += __x; 3232 return *this; 3233} 3234 3235template <class _Tp> 3236inline _LIBCPP_INLINE_VISIBILITY 3237valarray<_Tp>& 3238valarray<_Tp>::operator-=(const value_type& __x) 3239{ 3240 for (value_type* __p = __begin_; __p != __end_; ++__p) 3241 *__p -= __x; 3242 return *this; 3243} 3244 3245template <class _Tp> 3246inline _LIBCPP_INLINE_VISIBILITY 3247valarray<_Tp>& 3248valarray<_Tp>::operator^=(const value_type& __x) 3249{ 3250 for (value_type* __p = __begin_; __p != __end_; ++__p) 3251 *__p ^= __x; 3252 return *this; 3253} 3254 3255template <class _Tp> 3256inline _LIBCPP_INLINE_VISIBILITY 3257valarray<_Tp>& 3258valarray<_Tp>::operator&=(const value_type& __x) 3259{ 3260 for (value_type* __p = __begin_; __p != __end_; ++__p) 3261 *__p &= __x; 3262 return *this; 3263} 3264 3265template <class _Tp> 3266inline _LIBCPP_INLINE_VISIBILITY 3267valarray<_Tp>& 3268valarray<_Tp>::operator|=(const value_type& __x) 3269{ 3270 for (value_type* __p = __begin_; __p != __end_; ++__p) 3271 *__p |= __x; 3272 return *this; 3273} 3274 3275template <class _Tp> 3276inline _LIBCPP_INLINE_VISIBILITY 3277valarray<_Tp>& 3278valarray<_Tp>::operator<<=(const value_type& __x) 3279{ 3280 for (value_type* __p = __begin_; __p != __end_; ++__p) 3281 *__p <<= __x; 3282 return *this; 3283} 3284 3285template <class _Tp> 3286inline _LIBCPP_INLINE_VISIBILITY 3287valarray<_Tp>& 3288valarray<_Tp>::operator>>=(const value_type& __x) 3289{ 3290 for (value_type* __p = __begin_; __p != __end_; ++__p) 3291 *__p >>= __x; 3292 return *this; 3293} 3294 3295template <class _Tp> 3296template <class _Expr> 3297inline _LIBCPP_INLINE_VISIBILITY 3298typename enable_if 3299< 3300 __is_val_expr<_Expr>::value, 3301 valarray<_Tp>& 3302>::type 3303valarray<_Tp>::operator*=(const _Expr& __v) 3304{ 3305 size_t __i = 0; 3306 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3307 *__t *= __v[__i]; 3308 return *this; 3309} 3310 3311template <class _Tp> 3312template <class _Expr> 3313inline _LIBCPP_INLINE_VISIBILITY 3314typename enable_if 3315< 3316 __is_val_expr<_Expr>::value, 3317 valarray<_Tp>& 3318>::type 3319valarray<_Tp>::operator/=(const _Expr& __v) 3320{ 3321 size_t __i = 0; 3322 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3323 *__t /= __v[__i]; 3324 return *this; 3325} 3326 3327template <class _Tp> 3328template <class _Expr> 3329inline _LIBCPP_INLINE_VISIBILITY 3330typename enable_if 3331< 3332 __is_val_expr<_Expr>::value, 3333 valarray<_Tp>& 3334>::type 3335valarray<_Tp>::operator%=(const _Expr& __v) 3336{ 3337 size_t __i = 0; 3338 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3339 *__t %= __v[__i]; 3340 return *this; 3341} 3342 3343template <class _Tp> 3344template <class _Expr> 3345inline _LIBCPP_INLINE_VISIBILITY 3346typename enable_if 3347< 3348 __is_val_expr<_Expr>::value, 3349 valarray<_Tp>& 3350>::type 3351valarray<_Tp>::operator+=(const _Expr& __v) 3352{ 3353 size_t __i = 0; 3354 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3355 *__t += __v[__i]; 3356 return *this; 3357} 3358 3359template <class _Tp> 3360template <class _Expr> 3361inline _LIBCPP_INLINE_VISIBILITY 3362typename enable_if 3363< 3364 __is_val_expr<_Expr>::value, 3365 valarray<_Tp>& 3366>::type 3367valarray<_Tp>::operator-=(const _Expr& __v) 3368{ 3369 size_t __i = 0; 3370 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3371 *__t -= __v[__i]; 3372 return *this; 3373} 3374 3375template <class _Tp> 3376template <class _Expr> 3377inline _LIBCPP_INLINE_VISIBILITY 3378typename enable_if 3379< 3380 __is_val_expr<_Expr>::value, 3381 valarray<_Tp>& 3382>::type 3383valarray<_Tp>::operator^=(const _Expr& __v) 3384{ 3385 size_t __i = 0; 3386 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3387 *__t ^= __v[__i]; 3388 return *this; 3389} 3390 3391template <class _Tp> 3392template <class _Expr> 3393inline _LIBCPP_INLINE_VISIBILITY 3394typename enable_if 3395< 3396 __is_val_expr<_Expr>::value, 3397 valarray<_Tp>& 3398>::type 3399valarray<_Tp>::operator|=(const _Expr& __v) 3400{ 3401 size_t __i = 0; 3402 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3403 *__t |= __v[__i]; 3404 return *this; 3405} 3406 3407template <class _Tp> 3408template <class _Expr> 3409inline _LIBCPP_INLINE_VISIBILITY 3410typename enable_if 3411< 3412 __is_val_expr<_Expr>::value, 3413 valarray<_Tp>& 3414>::type 3415valarray<_Tp>::operator&=(const _Expr& __v) 3416{ 3417 size_t __i = 0; 3418 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3419 *__t &= __v[__i]; 3420 return *this; 3421} 3422 3423template <class _Tp> 3424template <class _Expr> 3425inline _LIBCPP_INLINE_VISIBILITY 3426typename enable_if 3427< 3428 __is_val_expr<_Expr>::value, 3429 valarray<_Tp>& 3430>::type 3431valarray<_Tp>::operator<<=(const _Expr& __v) 3432{ 3433 size_t __i = 0; 3434 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3435 *__t <<= __v[__i]; 3436 return *this; 3437} 3438 3439template <class _Tp> 3440template <class _Expr> 3441inline _LIBCPP_INLINE_VISIBILITY 3442typename enable_if 3443< 3444 __is_val_expr<_Expr>::value, 3445 valarray<_Tp>& 3446>::type 3447valarray<_Tp>::operator>>=(const _Expr& __v) 3448{ 3449 size_t __i = 0; 3450 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3451 *__t >>= __v[__i]; 3452 return *this; 3453} 3454 3455template <class _Tp> 3456inline _LIBCPP_INLINE_VISIBILITY 3457void 3458valarray<_Tp>::swap(valarray& __v) _NOEXCEPT 3459{ 3460 _VSTD::swap(__begin_, __v.__begin_); 3461 _VSTD::swap(__end_, __v.__end_); 3462} 3463 3464template <class _Tp> 3465inline _LIBCPP_INLINE_VISIBILITY 3466_Tp 3467valarray<_Tp>::sum() const 3468{ 3469 if (__begin_ == __end_) 3470 return value_type(); 3471 const value_type* __p = __begin_; 3472 _Tp __r = *__p; 3473 for (++__p; __p != __end_; ++__p) 3474 __r += *__p; 3475 return __r; 3476} 3477 3478template <class _Tp> 3479inline _LIBCPP_INLINE_VISIBILITY 3480_Tp 3481valarray<_Tp>::min() const 3482{ 3483 if (__begin_ == __end_) 3484 return value_type(); 3485 return *_VSTD::min_element(__begin_, __end_); 3486} 3487 3488template <class _Tp> 3489inline _LIBCPP_INLINE_VISIBILITY 3490_Tp 3491valarray<_Tp>::max() const 3492{ 3493 if (__begin_ == __end_) 3494 return value_type(); 3495 return *_VSTD::max_element(__begin_, __end_); 3496} 3497 3498template <class _Tp> 3499valarray<_Tp> 3500valarray<_Tp>::shift(int __i) const 3501{ 3502 valarray<value_type> __r; 3503 size_t __n = size(); 3504 if (__n) 3505 { 3506 __r.__begin_ = 3507 __r.__end_ = 3508 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 3509 const value_type* __sb; 3510 value_type* __tb; 3511 value_type* __te; 3512 if (__i >= 0) 3513 { 3514 __i = _VSTD::min(__i, static_cast<int>(__n)); 3515 __sb = __begin_ + __i; 3516 __tb = __r.__begin_; 3517 __te = __r.__begin_ + (__n - __i); 3518 } 3519 else 3520 { 3521 __i = _VSTD::min(-__i, static_cast<int>(__n)); 3522 __sb = __begin_; 3523 __tb = __r.__begin_ + __i; 3524 __te = __r.__begin_ + __n; 3525 } 3526 for (; __r.__end_ != __tb; ++__r.__end_) 3527 ::new (__r.__end_) value_type(); 3528 for (; __r.__end_ != __te; ++__r.__end_, ++__sb) 3529 ::new (__r.__end_) value_type(*__sb); 3530 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_) 3531 ::new (__r.__end_) value_type(); 3532 } 3533 return __r; 3534} 3535 3536template <class _Tp> 3537valarray<_Tp> 3538valarray<_Tp>::cshift(int __i) const 3539{ 3540 valarray<value_type> __r; 3541 size_t __n = size(); 3542 if (__n) 3543 { 3544 __r.__begin_ = 3545 __r.__end_ = 3546 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 3547 __i %= static_cast<int>(__n); 3548 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i; 3549 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s) 3550 ::new (__r.__end_) value_type(*__s); 3551 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s) 3552 ::new (__r.__end_) value_type(*__s); 3553 } 3554 return __r; 3555} 3556 3557template <class _Tp> 3558valarray<_Tp> 3559valarray<_Tp>::apply(value_type __f(value_type)) const 3560{ 3561 valarray<value_type> __r; 3562 size_t __n = size(); 3563 if (__n) 3564 { 3565 __r.__begin_ = 3566 __r.__end_ = 3567 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 3568 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) 3569 ::new (__r.__end_) value_type(__f(*__p)); 3570 } 3571 return __r; 3572} 3573 3574template <class _Tp> 3575valarray<_Tp> 3576valarray<_Tp>::apply(value_type __f(const value_type&)) const 3577{ 3578 valarray<value_type> __r; 3579 size_t __n = size(); 3580 if (__n) 3581 { 3582 __r.__begin_ = 3583 __r.__end_ = 3584 static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 3585 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) 3586 ::new (__r.__end_) value_type(__f(*__p)); 3587 } 3588 return __r; 3589} 3590 3591template <class _Tp> 3592void 3593valarray<_Tp>::resize(size_t __n, value_type __x) 3594{ 3595 if (__begin_ != nullptr) 3596 { 3597 while (__end_ != __begin_) 3598 (--__end_)->~value_type(); 3599 _VSTD::__deallocate(__begin_); 3600 __begin_ = __end_ = nullptr; 3601 } 3602 if (__n) 3603 { 3604 __begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type))); 3605#ifndef _LIBCPP_NO_EXCEPTIONS 3606 try 3607 { 3608#endif // _LIBCPP_NO_EXCEPTIONS 3609 for (; __n; --__n, ++__end_) 3610 ::new (__end_) value_type(__x); 3611#ifndef _LIBCPP_NO_EXCEPTIONS 3612 } 3613 catch (...) 3614 { 3615 resize(0); 3616 throw; 3617 } 3618#endif // _LIBCPP_NO_EXCEPTIONS 3619 } 3620} 3621 3622template<class _Tp> 3623inline _LIBCPP_INLINE_VISIBILITY 3624void 3625swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT 3626{ 3627 __x.swap(__y); 3628} 3629 3630template<class _Expr1, class _Expr2> 3631inline _LIBCPP_INLINE_VISIBILITY 3632typename enable_if 3633< 3634 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3635 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> > 3636>::type 3637operator*(const _Expr1& __x, const _Expr2& __y) 3638{ 3639 typedef typename _Expr1::value_type value_type; 3640 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op; 3641 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y)); 3642} 3643 3644template<class _Expr> 3645inline _LIBCPP_INLINE_VISIBILITY 3646typename enable_if 3647< 3648 __is_val_expr<_Expr>::value, 3649 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>, 3650 _Expr, __scalar_expr<typename _Expr::value_type> > > 3651>::type 3652operator*(const _Expr& __x, const typename _Expr::value_type& __y) 3653{ 3654 typedef typename _Expr::value_type value_type; 3655 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3656 return __val_expr<_Op>(_Op(multiplies<value_type>(), 3657 __x, __scalar_expr<value_type>(__y, __x.size()))); 3658} 3659 3660template<class _Expr> 3661inline _LIBCPP_INLINE_VISIBILITY 3662typename enable_if 3663< 3664 __is_val_expr<_Expr>::value, 3665 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>, 3666 __scalar_expr<typename _Expr::value_type>, _Expr> > 3667>::type 3668operator*(const typename _Expr::value_type& __x, const _Expr& __y) 3669{ 3670 typedef typename _Expr::value_type value_type; 3671 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3672 return __val_expr<_Op>(_Op(multiplies<value_type>(), 3673 __scalar_expr<value_type>(__x, __y.size()), __y)); 3674} 3675 3676template<class _Expr1, class _Expr2> 3677inline _LIBCPP_INLINE_VISIBILITY 3678typename enable_if 3679< 3680 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3681 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> > 3682>::type 3683operator/(const _Expr1& __x, const _Expr2& __y) 3684{ 3685 typedef typename _Expr1::value_type value_type; 3686 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op; 3687 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y)); 3688} 3689 3690template<class _Expr> 3691inline _LIBCPP_INLINE_VISIBILITY 3692typename enable_if 3693< 3694 __is_val_expr<_Expr>::value, 3695 __val_expr<_BinaryOp<divides<typename _Expr::value_type>, 3696 _Expr, __scalar_expr<typename _Expr::value_type> > > 3697>::type 3698operator/(const _Expr& __x, const typename _Expr::value_type& __y) 3699{ 3700 typedef typename _Expr::value_type value_type; 3701 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3702 return __val_expr<_Op>(_Op(divides<value_type>(), 3703 __x, __scalar_expr<value_type>(__y, __x.size()))); 3704} 3705 3706template<class _Expr> 3707inline _LIBCPP_INLINE_VISIBILITY 3708typename enable_if 3709< 3710 __is_val_expr<_Expr>::value, 3711 __val_expr<_BinaryOp<divides<typename _Expr::value_type>, 3712 __scalar_expr<typename _Expr::value_type>, _Expr> > 3713>::type 3714operator/(const typename _Expr::value_type& __x, const _Expr& __y) 3715{ 3716 typedef typename _Expr::value_type value_type; 3717 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3718 return __val_expr<_Op>(_Op(divides<value_type>(), 3719 __scalar_expr<value_type>(__x, __y.size()), __y)); 3720} 3721 3722template<class _Expr1, class _Expr2> 3723inline _LIBCPP_INLINE_VISIBILITY 3724typename enable_if 3725< 3726 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3727 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> > 3728>::type 3729operator%(const _Expr1& __x, const _Expr2& __y) 3730{ 3731 typedef typename _Expr1::value_type value_type; 3732 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op; 3733 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y)); 3734} 3735 3736template<class _Expr> 3737inline _LIBCPP_INLINE_VISIBILITY 3738typename enable_if 3739< 3740 __is_val_expr<_Expr>::value, 3741 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>, 3742 _Expr, __scalar_expr<typename _Expr::value_type> > > 3743>::type 3744operator%(const _Expr& __x, const typename _Expr::value_type& __y) 3745{ 3746 typedef typename _Expr::value_type value_type; 3747 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3748 return __val_expr<_Op>(_Op(modulus<value_type>(), 3749 __x, __scalar_expr<value_type>(__y, __x.size()))); 3750} 3751 3752template<class _Expr> 3753inline _LIBCPP_INLINE_VISIBILITY 3754typename enable_if 3755< 3756 __is_val_expr<_Expr>::value, 3757 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>, 3758 __scalar_expr<typename _Expr::value_type>, _Expr> > 3759>::type 3760operator%(const typename _Expr::value_type& __x, const _Expr& __y) 3761{ 3762 typedef typename _Expr::value_type value_type; 3763 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3764 return __val_expr<_Op>(_Op(modulus<value_type>(), 3765 __scalar_expr<value_type>(__x, __y.size()), __y)); 3766} 3767 3768template<class _Expr1, class _Expr2> 3769inline _LIBCPP_INLINE_VISIBILITY 3770typename enable_if 3771< 3772 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3773 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> > 3774>::type 3775operator+(const _Expr1& __x, const _Expr2& __y) 3776{ 3777 typedef typename _Expr1::value_type value_type; 3778 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op; 3779 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y)); 3780} 3781 3782template<class _Expr> 3783inline _LIBCPP_INLINE_VISIBILITY 3784typename enable_if 3785< 3786 __is_val_expr<_Expr>::value, 3787 __val_expr<_BinaryOp<plus<typename _Expr::value_type>, 3788 _Expr, __scalar_expr<typename _Expr::value_type> > > 3789>::type 3790operator+(const _Expr& __x, const typename _Expr::value_type& __y) 3791{ 3792 typedef typename _Expr::value_type value_type; 3793 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3794 return __val_expr<_Op>(_Op(plus<value_type>(), 3795 __x, __scalar_expr<value_type>(__y, __x.size()))); 3796} 3797 3798template<class _Expr> 3799inline _LIBCPP_INLINE_VISIBILITY 3800typename enable_if 3801< 3802 __is_val_expr<_Expr>::value, 3803 __val_expr<_BinaryOp<plus<typename _Expr::value_type>, 3804 __scalar_expr<typename _Expr::value_type>, _Expr> > 3805>::type 3806operator+(const typename _Expr::value_type& __x, const _Expr& __y) 3807{ 3808 typedef typename _Expr::value_type value_type; 3809 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3810 return __val_expr<_Op>(_Op(plus<value_type>(), 3811 __scalar_expr<value_type>(__x, __y.size()), __y)); 3812} 3813 3814template<class _Expr1, class _Expr2> 3815inline _LIBCPP_INLINE_VISIBILITY 3816typename enable_if 3817< 3818 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3819 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> > 3820>::type 3821operator-(const _Expr1& __x, const _Expr2& __y) 3822{ 3823 typedef typename _Expr1::value_type value_type; 3824 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op; 3825 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y)); 3826} 3827 3828template<class _Expr> 3829inline _LIBCPP_INLINE_VISIBILITY 3830typename enable_if 3831< 3832 __is_val_expr<_Expr>::value, 3833 __val_expr<_BinaryOp<minus<typename _Expr::value_type>, 3834 _Expr, __scalar_expr<typename _Expr::value_type> > > 3835>::type 3836operator-(const _Expr& __x, const typename _Expr::value_type& __y) 3837{ 3838 typedef typename _Expr::value_type value_type; 3839 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3840 return __val_expr<_Op>(_Op(minus<value_type>(), 3841 __x, __scalar_expr<value_type>(__y, __x.size()))); 3842} 3843 3844template<class _Expr> 3845inline _LIBCPP_INLINE_VISIBILITY 3846typename enable_if 3847< 3848 __is_val_expr<_Expr>::value, 3849 __val_expr<_BinaryOp<minus<typename _Expr::value_type>, 3850 __scalar_expr<typename _Expr::value_type>, _Expr> > 3851>::type 3852operator-(const typename _Expr::value_type& __x, const _Expr& __y) 3853{ 3854 typedef typename _Expr::value_type value_type; 3855 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3856 return __val_expr<_Op>(_Op(minus<value_type>(), 3857 __scalar_expr<value_type>(__x, __y.size()), __y)); 3858} 3859 3860template<class _Expr1, class _Expr2> 3861inline _LIBCPP_INLINE_VISIBILITY 3862typename enable_if 3863< 3864 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3865 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> > 3866>::type 3867operator^(const _Expr1& __x, const _Expr2& __y) 3868{ 3869 typedef typename _Expr1::value_type value_type; 3870 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op; 3871 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y)); 3872} 3873 3874template<class _Expr> 3875inline _LIBCPP_INLINE_VISIBILITY 3876typename enable_if 3877< 3878 __is_val_expr<_Expr>::value, 3879 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>, 3880 _Expr, __scalar_expr<typename _Expr::value_type> > > 3881>::type 3882operator^(const _Expr& __x, const typename _Expr::value_type& __y) 3883{ 3884 typedef typename _Expr::value_type value_type; 3885 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3886 return __val_expr<_Op>(_Op(bit_xor<value_type>(), 3887 __x, __scalar_expr<value_type>(__y, __x.size()))); 3888} 3889 3890template<class _Expr> 3891inline _LIBCPP_INLINE_VISIBILITY 3892typename enable_if 3893< 3894 __is_val_expr<_Expr>::value, 3895 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>, 3896 __scalar_expr<typename _Expr::value_type>, _Expr> > 3897>::type 3898operator^(const typename _Expr::value_type& __x, const _Expr& __y) 3899{ 3900 typedef typename _Expr::value_type value_type; 3901 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3902 return __val_expr<_Op>(_Op(bit_xor<value_type>(), 3903 __scalar_expr<value_type>(__x, __y.size()), __y)); 3904} 3905 3906template<class _Expr1, class _Expr2> 3907inline _LIBCPP_INLINE_VISIBILITY 3908typename enable_if 3909< 3910 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3911 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> > 3912>::type 3913operator&(const _Expr1& __x, const _Expr2& __y) 3914{ 3915 typedef typename _Expr1::value_type value_type; 3916 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op; 3917 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y)); 3918} 3919 3920template<class _Expr> 3921inline _LIBCPP_INLINE_VISIBILITY 3922typename enable_if 3923< 3924 __is_val_expr<_Expr>::value, 3925 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>, 3926 _Expr, __scalar_expr<typename _Expr::value_type> > > 3927>::type 3928operator&(const _Expr& __x, const typename _Expr::value_type& __y) 3929{ 3930 typedef typename _Expr::value_type value_type; 3931 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3932 return __val_expr<_Op>(_Op(bit_and<value_type>(), 3933 __x, __scalar_expr<value_type>(__y, __x.size()))); 3934} 3935 3936template<class _Expr> 3937inline _LIBCPP_INLINE_VISIBILITY 3938typename enable_if 3939< 3940 __is_val_expr<_Expr>::value, 3941 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>, 3942 __scalar_expr<typename _Expr::value_type>, _Expr> > 3943>::type 3944operator&(const typename _Expr::value_type& __x, const _Expr& __y) 3945{ 3946 typedef typename _Expr::value_type value_type; 3947 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3948 return __val_expr<_Op>(_Op(bit_and<value_type>(), 3949 __scalar_expr<value_type>(__x, __y.size()), __y)); 3950} 3951 3952template<class _Expr1, class _Expr2> 3953inline _LIBCPP_INLINE_VISIBILITY 3954typename enable_if 3955< 3956 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3957 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> > 3958>::type 3959operator|(const _Expr1& __x, const _Expr2& __y) 3960{ 3961 typedef typename _Expr1::value_type value_type; 3962 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op; 3963 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y)); 3964} 3965 3966template<class _Expr> 3967inline _LIBCPP_INLINE_VISIBILITY 3968typename enable_if 3969< 3970 __is_val_expr<_Expr>::value, 3971 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>, 3972 _Expr, __scalar_expr<typename _Expr::value_type> > > 3973>::type 3974operator|(const _Expr& __x, const typename _Expr::value_type& __y) 3975{ 3976 typedef typename _Expr::value_type value_type; 3977 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3978 return __val_expr<_Op>(_Op(bit_or<value_type>(), 3979 __x, __scalar_expr<value_type>(__y, __x.size()))); 3980} 3981 3982template<class _Expr> 3983inline _LIBCPP_INLINE_VISIBILITY 3984typename enable_if 3985< 3986 __is_val_expr<_Expr>::value, 3987 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>, 3988 __scalar_expr<typename _Expr::value_type>, _Expr> > 3989>::type 3990operator|(const typename _Expr::value_type& __x, const _Expr& __y) 3991{ 3992 typedef typename _Expr::value_type value_type; 3993 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3994 return __val_expr<_Op>(_Op(bit_or<value_type>(), 3995 __scalar_expr<value_type>(__x, __y.size()), __y)); 3996} 3997 3998template<class _Expr1, class _Expr2> 3999inline _LIBCPP_INLINE_VISIBILITY 4000typename enable_if 4001< 4002 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4003 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> > 4004>::type 4005operator<<(const _Expr1& __x, const _Expr2& __y) 4006{ 4007 typedef typename _Expr1::value_type value_type; 4008 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op; 4009 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y)); 4010} 4011 4012template<class _Expr> 4013inline _LIBCPP_INLINE_VISIBILITY 4014typename enable_if 4015< 4016 __is_val_expr<_Expr>::value, 4017 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>, 4018 _Expr, __scalar_expr<typename _Expr::value_type> > > 4019>::type 4020operator<<(const _Expr& __x, const typename _Expr::value_type& __y) 4021{ 4022 typedef typename _Expr::value_type value_type; 4023 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4024 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), 4025 __x, __scalar_expr<value_type>(__y, __x.size()))); 4026} 4027 4028template<class _Expr> 4029inline _LIBCPP_INLINE_VISIBILITY 4030typename enable_if 4031< 4032 __is_val_expr<_Expr>::value, 4033 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>, 4034 __scalar_expr<typename _Expr::value_type>, _Expr> > 4035>::type 4036operator<<(const typename _Expr::value_type& __x, const _Expr& __y) 4037{ 4038 typedef typename _Expr::value_type value_type; 4039 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4040 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), 4041 __scalar_expr<value_type>(__x, __y.size()), __y)); 4042} 4043 4044template<class _Expr1, class _Expr2> 4045inline _LIBCPP_INLINE_VISIBILITY 4046typename enable_if 4047< 4048 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4049 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> > 4050>::type 4051operator>>(const _Expr1& __x, const _Expr2& __y) 4052{ 4053 typedef typename _Expr1::value_type value_type; 4054 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op; 4055 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y)); 4056} 4057 4058template<class _Expr> 4059inline _LIBCPP_INLINE_VISIBILITY 4060typename enable_if 4061< 4062 __is_val_expr<_Expr>::value, 4063 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>, 4064 _Expr, __scalar_expr<typename _Expr::value_type> > > 4065>::type 4066operator>>(const _Expr& __x, const typename _Expr::value_type& __y) 4067{ 4068 typedef typename _Expr::value_type value_type; 4069 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4070 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), 4071 __x, __scalar_expr<value_type>(__y, __x.size()))); 4072} 4073 4074template<class _Expr> 4075inline _LIBCPP_INLINE_VISIBILITY 4076typename enable_if 4077< 4078 __is_val_expr<_Expr>::value, 4079 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>, 4080 __scalar_expr<typename _Expr::value_type>, _Expr> > 4081>::type 4082operator>>(const typename _Expr::value_type& __x, const _Expr& __y) 4083{ 4084 typedef typename _Expr::value_type value_type; 4085 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4086 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), 4087 __scalar_expr<value_type>(__x, __y.size()), __y)); 4088} 4089 4090template<class _Expr1, class _Expr2> 4091inline _LIBCPP_INLINE_VISIBILITY 4092typename enable_if 4093< 4094 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4095 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> > 4096>::type 4097operator&&(const _Expr1& __x, const _Expr2& __y) 4098{ 4099 typedef typename _Expr1::value_type value_type; 4100 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op; 4101 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y)); 4102} 4103 4104template<class _Expr> 4105inline _LIBCPP_INLINE_VISIBILITY 4106typename enable_if 4107< 4108 __is_val_expr<_Expr>::value, 4109 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>, 4110 _Expr, __scalar_expr<typename _Expr::value_type> > > 4111>::type 4112operator&&(const _Expr& __x, const typename _Expr::value_type& __y) 4113{ 4114 typedef typename _Expr::value_type value_type; 4115 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4116 return __val_expr<_Op>(_Op(logical_and<value_type>(), 4117 __x, __scalar_expr<value_type>(__y, __x.size()))); 4118} 4119 4120template<class _Expr> 4121inline _LIBCPP_INLINE_VISIBILITY 4122typename enable_if 4123< 4124 __is_val_expr<_Expr>::value, 4125 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>, 4126 __scalar_expr<typename _Expr::value_type>, _Expr> > 4127>::type 4128operator&&(const typename _Expr::value_type& __x, const _Expr& __y) 4129{ 4130 typedef typename _Expr::value_type value_type; 4131 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4132 return __val_expr<_Op>(_Op(logical_and<value_type>(), 4133 __scalar_expr<value_type>(__x, __y.size()), __y)); 4134} 4135 4136template<class _Expr1, class _Expr2> 4137inline _LIBCPP_INLINE_VISIBILITY 4138typename enable_if 4139< 4140 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4141 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> > 4142>::type 4143operator||(const _Expr1& __x, const _Expr2& __y) 4144{ 4145 typedef typename _Expr1::value_type value_type; 4146 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op; 4147 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y)); 4148} 4149 4150template<class _Expr> 4151inline _LIBCPP_INLINE_VISIBILITY 4152typename enable_if 4153< 4154 __is_val_expr<_Expr>::value, 4155 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>, 4156 _Expr, __scalar_expr<typename _Expr::value_type> > > 4157>::type 4158operator||(const _Expr& __x, const typename _Expr::value_type& __y) 4159{ 4160 typedef typename _Expr::value_type value_type; 4161 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4162 return __val_expr<_Op>(_Op(logical_or<value_type>(), 4163 __x, __scalar_expr<value_type>(__y, __x.size()))); 4164} 4165 4166template<class _Expr> 4167inline _LIBCPP_INLINE_VISIBILITY 4168typename enable_if 4169< 4170 __is_val_expr<_Expr>::value, 4171 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>, 4172 __scalar_expr<typename _Expr::value_type>, _Expr> > 4173>::type 4174operator||(const typename _Expr::value_type& __x, const _Expr& __y) 4175{ 4176 typedef typename _Expr::value_type value_type; 4177 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4178 return __val_expr<_Op>(_Op(logical_or<value_type>(), 4179 __scalar_expr<value_type>(__x, __y.size()), __y)); 4180} 4181 4182template<class _Expr1, class _Expr2> 4183inline _LIBCPP_INLINE_VISIBILITY 4184typename enable_if 4185< 4186 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4187 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> > 4188>::type 4189operator==(const _Expr1& __x, const _Expr2& __y) 4190{ 4191 typedef typename _Expr1::value_type value_type; 4192 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op; 4193 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y)); 4194} 4195 4196template<class _Expr> 4197inline _LIBCPP_INLINE_VISIBILITY 4198typename enable_if 4199< 4200 __is_val_expr<_Expr>::value, 4201 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>, 4202 _Expr, __scalar_expr<typename _Expr::value_type> > > 4203>::type 4204operator==(const _Expr& __x, const typename _Expr::value_type& __y) 4205{ 4206 typedef typename _Expr::value_type value_type; 4207 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4208 return __val_expr<_Op>(_Op(equal_to<value_type>(), 4209 __x, __scalar_expr<value_type>(__y, __x.size()))); 4210} 4211 4212template<class _Expr> 4213inline _LIBCPP_INLINE_VISIBILITY 4214typename enable_if 4215< 4216 __is_val_expr<_Expr>::value, 4217 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>, 4218 __scalar_expr<typename _Expr::value_type>, _Expr> > 4219>::type 4220operator==(const typename _Expr::value_type& __x, const _Expr& __y) 4221{ 4222 typedef typename _Expr::value_type value_type; 4223 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4224 return __val_expr<_Op>(_Op(equal_to<value_type>(), 4225 __scalar_expr<value_type>(__x, __y.size()), __y)); 4226} 4227 4228template<class _Expr1, class _Expr2> 4229inline _LIBCPP_INLINE_VISIBILITY 4230typename enable_if 4231< 4232 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4233 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> > 4234>::type 4235operator!=(const _Expr1& __x, const _Expr2& __y) 4236{ 4237 typedef typename _Expr1::value_type value_type; 4238 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op; 4239 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y)); 4240} 4241 4242template<class _Expr> 4243inline _LIBCPP_INLINE_VISIBILITY 4244typename enable_if 4245< 4246 __is_val_expr<_Expr>::value, 4247 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>, 4248 _Expr, __scalar_expr<typename _Expr::value_type> > > 4249>::type 4250operator!=(const _Expr& __x, const typename _Expr::value_type& __y) 4251{ 4252 typedef typename _Expr::value_type value_type; 4253 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4254 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), 4255 __x, __scalar_expr<value_type>(__y, __x.size()))); 4256} 4257 4258template<class _Expr> 4259inline _LIBCPP_INLINE_VISIBILITY 4260typename enable_if 4261< 4262 __is_val_expr<_Expr>::value, 4263 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>, 4264 __scalar_expr<typename _Expr::value_type>, _Expr> > 4265>::type 4266operator!=(const typename _Expr::value_type& __x, const _Expr& __y) 4267{ 4268 typedef typename _Expr::value_type value_type; 4269 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4270 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), 4271 __scalar_expr<value_type>(__x, __y.size()), __y)); 4272} 4273 4274template<class _Expr1, class _Expr2> 4275inline _LIBCPP_INLINE_VISIBILITY 4276typename enable_if 4277< 4278 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4279 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> > 4280>::type 4281operator<(const _Expr1& __x, const _Expr2& __y) 4282{ 4283 typedef typename _Expr1::value_type value_type; 4284 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op; 4285 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y)); 4286} 4287 4288template<class _Expr> 4289inline _LIBCPP_INLINE_VISIBILITY 4290typename enable_if 4291< 4292 __is_val_expr<_Expr>::value, 4293 __val_expr<_BinaryOp<less<typename _Expr::value_type>, 4294 _Expr, __scalar_expr<typename _Expr::value_type> > > 4295>::type 4296operator<(const _Expr& __x, const typename _Expr::value_type& __y) 4297{ 4298 typedef typename _Expr::value_type value_type; 4299 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4300 return __val_expr<_Op>(_Op(less<value_type>(), 4301 __x, __scalar_expr<value_type>(__y, __x.size()))); 4302} 4303 4304template<class _Expr> 4305inline _LIBCPP_INLINE_VISIBILITY 4306typename enable_if 4307< 4308 __is_val_expr<_Expr>::value, 4309 __val_expr<_BinaryOp<less<typename _Expr::value_type>, 4310 __scalar_expr<typename _Expr::value_type>, _Expr> > 4311>::type 4312operator<(const typename _Expr::value_type& __x, const _Expr& __y) 4313{ 4314 typedef typename _Expr::value_type value_type; 4315 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4316 return __val_expr<_Op>(_Op(less<value_type>(), 4317 __scalar_expr<value_type>(__x, __y.size()), __y)); 4318} 4319 4320template<class _Expr1, class _Expr2> 4321inline _LIBCPP_INLINE_VISIBILITY 4322typename enable_if 4323< 4324 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4325 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> > 4326>::type 4327operator>(const _Expr1& __x, const _Expr2& __y) 4328{ 4329 typedef typename _Expr1::value_type value_type; 4330 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op; 4331 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y)); 4332} 4333 4334template<class _Expr> 4335inline _LIBCPP_INLINE_VISIBILITY 4336typename enable_if 4337< 4338 __is_val_expr<_Expr>::value, 4339 __val_expr<_BinaryOp<greater<typename _Expr::value_type>, 4340 _Expr, __scalar_expr<typename _Expr::value_type> > > 4341>::type 4342operator>(const _Expr& __x, const typename _Expr::value_type& __y) 4343{ 4344 typedef typename _Expr::value_type value_type; 4345 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4346 return __val_expr<_Op>(_Op(greater<value_type>(), 4347 __x, __scalar_expr<value_type>(__y, __x.size()))); 4348} 4349 4350template<class _Expr> 4351inline _LIBCPP_INLINE_VISIBILITY 4352typename enable_if 4353< 4354 __is_val_expr<_Expr>::value, 4355 __val_expr<_BinaryOp<greater<typename _Expr::value_type>, 4356 __scalar_expr<typename _Expr::value_type>, _Expr> > 4357>::type 4358operator>(const typename _Expr::value_type& __x, const _Expr& __y) 4359{ 4360 typedef typename _Expr::value_type value_type; 4361 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4362 return __val_expr<_Op>(_Op(greater<value_type>(), 4363 __scalar_expr<value_type>(__x, __y.size()), __y)); 4364} 4365 4366template<class _Expr1, class _Expr2> 4367inline _LIBCPP_INLINE_VISIBILITY 4368typename enable_if 4369< 4370 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4371 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> > 4372>::type 4373operator<=(const _Expr1& __x, const _Expr2& __y) 4374{ 4375 typedef typename _Expr1::value_type value_type; 4376 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op; 4377 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y)); 4378} 4379 4380template<class _Expr> 4381inline _LIBCPP_INLINE_VISIBILITY 4382typename enable_if 4383< 4384 __is_val_expr<_Expr>::value, 4385 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>, 4386 _Expr, __scalar_expr<typename _Expr::value_type> > > 4387>::type 4388operator<=(const _Expr& __x, const typename _Expr::value_type& __y) 4389{ 4390 typedef typename _Expr::value_type value_type; 4391 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4392 return __val_expr<_Op>(_Op(less_equal<value_type>(), 4393 __x, __scalar_expr<value_type>(__y, __x.size()))); 4394} 4395 4396template<class _Expr> 4397inline _LIBCPP_INLINE_VISIBILITY 4398typename enable_if 4399< 4400 __is_val_expr<_Expr>::value, 4401 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>, 4402 __scalar_expr<typename _Expr::value_type>, _Expr> > 4403>::type 4404operator<=(const typename _Expr::value_type& __x, const _Expr& __y) 4405{ 4406 typedef typename _Expr::value_type value_type; 4407 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4408 return __val_expr<_Op>(_Op(less_equal<value_type>(), 4409 __scalar_expr<value_type>(__x, __y.size()), __y)); 4410} 4411 4412template<class _Expr1, class _Expr2> 4413inline _LIBCPP_INLINE_VISIBILITY 4414typename enable_if 4415< 4416 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4417 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> > 4418>::type 4419operator>=(const _Expr1& __x, const _Expr2& __y) 4420{ 4421 typedef typename _Expr1::value_type value_type; 4422 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op; 4423 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y)); 4424} 4425 4426template<class _Expr> 4427inline _LIBCPP_INLINE_VISIBILITY 4428typename enable_if 4429< 4430 __is_val_expr<_Expr>::value, 4431 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>, 4432 _Expr, __scalar_expr<typename _Expr::value_type> > > 4433>::type 4434operator>=(const _Expr& __x, const typename _Expr::value_type& __y) 4435{ 4436 typedef typename _Expr::value_type value_type; 4437 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4438 return __val_expr<_Op>(_Op(greater_equal<value_type>(), 4439 __x, __scalar_expr<value_type>(__y, __x.size()))); 4440} 4441 4442template<class _Expr> 4443inline _LIBCPP_INLINE_VISIBILITY 4444typename enable_if 4445< 4446 __is_val_expr<_Expr>::value, 4447 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>, 4448 __scalar_expr<typename _Expr::value_type>, _Expr> > 4449>::type 4450operator>=(const typename _Expr::value_type& __x, const _Expr& __y) 4451{ 4452 typedef typename _Expr::value_type value_type; 4453 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4454 return __val_expr<_Op>(_Op(greater_equal<value_type>(), 4455 __scalar_expr<value_type>(__x, __y.size()), __y)); 4456} 4457 4458template<class _Expr> 4459inline _LIBCPP_INLINE_VISIBILITY 4460typename enable_if 4461< 4462 __is_val_expr<_Expr>::value, 4463 __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> > 4464>::type 4465abs(const _Expr& __x) 4466{ 4467 typedef typename _Expr::value_type value_type; 4468 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op; 4469 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x)); 4470} 4471 4472template<class _Expr> 4473inline _LIBCPP_INLINE_VISIBILITY 4474typename enable_if 4475< 4476 __is_val_expr<_Expr>::value, 4477 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> > 4478>::type 4479acos(const _Expr& __x) 4480{ 4481 typedef typename _Expr::value_type value_type; 4482 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op; 4483 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x)); 4484} 4485 4486template<class _Expr> 4487inline _LIBCPP_INLINE_VISIBILITY 4488typename enable_if 4489< 4490 __is_val_expr<_Expr>::value, 4491 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> > 4492>::type 4493asin(const _Expr& __x) 4494{ 4495 typedef typename _Expr::value_type value_type; 4496 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op; 4497 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x)); 4498} 4499 4500template<class _Expr> 4501inline _LIBCPP_INLINE_VISIBILITY 4502typename enable_if 4503< 4504 __is_val_expr<_Expr>::value, 4505 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> > 4506>::type 4507atan(const _Expr& __x) 4508{ 4509 typedef typename _Expr::value_type value_type; 4510 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op; 4511 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x)); 4512} 4513 4514template<class _Expr1, class _Expr2> 4515inline _LIBCPP_INLINE_VISIBILITY 4516typename enable_if 4517< 4518 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4519 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> > 4520>::type 4521atan2(const _Expr1& __x, const _Expr2& __y) 4522{ 4523 typedef typename _Expr1::value_type value_type; 4524 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op; 4525 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y)); 4526} 4527 4528template<class _Expr> 4529inline _LIBCPP_INLINE_VISIBILITY 4530typename enable_if 4531< 4532 __is_val_expr<_Expr>::value, 4533 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>, 4534 _Expr, __scalar_expr<typename _Expr::value_type> > > 4535>::type 4536atan2(const _Expr& __x, const typename _Expr::value_type& __y) 4537{ 4538 typedef typename _Expr::value_type value_type; 4539 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4540 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), 4541 __x, __scalar_expr<value_type>(__y, __x.size()))); 4542} 4543 4544template<class _Expr> 4545inline _LIBCPP_INLINE_VISIBILITY 4546typename enable_if 4547< 4548 __is_val_expr<_Expr>::value, 4549 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>, 4550 __scalar_expr<typename _Expr::value_type>, _Expr> > 4551>::type 4552atan2(const typename _Expr::value_type& __x, const _Expr& __y) 4553{ 4554 typedef typename _Expr::value_type value_type; 4555 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4556 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), 4557 __scalar_expr<value_type>(__x, __y.size()), __y)); 4558} 4559 4560template<class _Expr> 4561inline _LIBCPP_INLINE_VISIBILITY 4562typename enable_if 4563< 4564 __is_val_expr<_Expr>::value, 4565 __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> > 4566>::type 4567cos(const _Expr& __x) 4568{ 4569 typedef typename _Expr::value_type value_type; 4570 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op; 4571 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x)); 4572} 4573 4574template<class _Expr> 4575inline _LIBCPP_INLINE_VISIBILITY 4576typename enable_if 4577< 4578 __is_val_expr<_Expr>::value, 4579 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> > 4580>::type 4581cosh(const _Expr& __x) 4582{ 4583 typedef typename _Expr::value_type value_type; 4584 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op; 4585 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x)); 4586} 4587 4588template<class _Expr> 4589inline _LIBCPP_INLINE_VISIBILITY 4590typename enable_if 4591< 4592 __is_val_expr<_Expr>::value, 4593 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> > 4594>::type 4595exp(const _Expr& __x) 4596{ 4597 typedef typename _Expr::value_type value_type; 4598 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op; 4599 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x)); 4600} 4601 4602template<class _Expr> 4603inline _LIBCPP_INLINE_VISIBILITY 4604typename enable_if 4605< 4606 __is_val_expr<_Expr>::value, 4607 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> > 4608>::type 4609log(const _Expr& __x) 4610{ 4611 typedef typename _Expr::value_type value_type; 4612 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op; 4613 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x)); 4614} 4615 4616template<class _Expr> 4617inline _LIBCPP_INLINE_VISIBILITY 4618typename enable_if 4619< 4620 __is_val_expr<_Expr>::value, 4621 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> > 4622>::type 4623log10(const _Expr& __x) 4624{ 4625 typedef typename _Expr::value_type value_type; 4626 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op; 4627 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x)); 4628} 4629 4630template<class _Expr1, class _Expr2> 4631inline _LIBCPP_INLINE_VISIBILITY 4632typename enable_if 4633< 4634 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4635 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> > 4636>::type 4637pow(const _Expr1& __x, const _Expr2& __y) 4638{ 4639 typedef typename _Expr1::value_type value_type; 4640 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op; 4641 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y)); 4642} 4643 4644template<class _Expr> 4645inline _LIBCPP_INLINE_VISIBILITY 4646typename enable_if 4647< 4648 __is_val_expr<_Expr>::value, 4649 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>, 4650 _Expr, __scalar_expr<typename _Expr::value_type> > > 4651>::type 4652pow(const _Expr& __x, const typename _Expr::value_type& __y) 4653{ 4654 typedef typename _Expr::value_type value_type; 4655 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4656 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), 4657 __x, __scalar_expr<value_type>(__y, __x.size()))); 4658} 4659 4660template<class _Expr> 4661inline _LIBCPP_INLINE_VISIBILITY 4662typename enable_if 4663< 4664 __is_val_expr<_Expr>::value, 4665 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>, 4666 __scalar_expr<typename _Expr::value_type>, _Expr> > 4667>::type 4668pow(const typename _Expr::value_type& __x, const _Expr& __y) 4669{ 4670 typedef typename _Expr::value_type value_type; 4671 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4672 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), 4673 __scalar_expr<value_type>(__x, __y.size()), __y)); 4674} 4675 4676template<class _Expr> 4677inline _LIBCPP_INLINE_VISIBILITY 4678typename enable_if 4679< 4680 __is_val_expr<_Expr>::value, 4681 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> > 4682>::type 4683sin(const _Expr& __x) 4684{ 4685 typedef typename _Expr::value_type value_type; 4686 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op; 4687 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x)); 4688} 4689 4690template<class _Expr> 4691inline _LIBCPP_INLINE_VISIBILITY 4692typename enable_if 4693< 4694 __is_val_expr<_Expr>::value, 4695 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> > 4696>::type 4697sinh(const _Expr& __x) 4698{ 4699 typedef typename _Expr::value_type value_type; 4700 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op; 4701 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x)); 4702} 4703 4704template<class _Expr> 4705inline _LIBCPP_INLINE_VISIBILITY 4706typename enable_if 4707< 4708 __is_val_expr<_Expr>::value, 4709 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> > 4710>::type 4711sqrt(const _Expr& __x) 4712{ 4713 typedef typename _Expr::value_type value_type; 4714 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op; 4715 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x)); 4716} 4717 4718template<class _Expr> 4719inline _LIBCPP_INLINE_VISIBILITY 4720typename enable_if 4721< 4722 __is_val_expr<_Expr>::value, 4723 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> > 4724>::type 4725tan(const _Expr& __x) 4726{ 4727 typedef typename _Expr::value_type value_type; 4728 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op; 4729 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x)); 4730} 4731 4732template<class _Expr> 4733inline _LIBCPP_INLINE_VISIBILITY 4734typename enable_if 4735< 4736 __is_val_expr<_Expr>::value, 4737 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> > 4738>::type 4739tanh(const _Expr& __x) 4740{ 4741 typedef typename _Expr::value_type value_type; 4742 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op; 4743 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x)); 4744} 4745 4746template <class _Tp> 4747inline _LIBCPP_INLINE_VISIBILITY 4748_Tp* 4749begin(valarray<_Tp>& __v) 4750{ 4751 return __v.__begin_; 4752} 4753 4754template <class _Tp> 4755inline _LIBCPP_INLINE_VISIBILITY 4756const _Tp* 4757begin(const valarray<_Tp>& __v) 4758{ 4759 return __v.__begin_; 4760} 4761 4762template <class _Tp> 4763inline _LIBCPP_INLINE_VISIBILITY 4764_Tp* 4765end(valarray<_Tp>& __v) 4766{ 4767 return __v.__end_; 4768} 4769 4770template <class _Tp> 4771inline _LIBCPP_INLINE_VISIBILITY 4772const _Tp* 4773end(const valarray<_Tp>& __v) 4774{ 4775 return __v.__end_; 4776} 4777 4778_LIBCPP_END_NAMESPACE_STD 4779 4780#endif // _LIBCPP_VALARRAY 4781