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