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