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