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