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 void operator=(const valarray<T>& val_arr) const; 140 141 slice_array() = delete; 142}; 143 144class gslice 145{ 146public: 147 gslice(); 148 gslice(size_t start, const valarray<size_t>& size, 149 const valarray<size_t>& stride); 150 151 size_t start() const; 152 valarray<size_t> size() const; 153 valarray<size_t> stride() const; 154}; 155 156template <class T> 157class gslice_array 158{ 159public: 160 typedef T value_type; 161 162 void operator= (const valarray<value_type>& v) const; 163 void operator*= (const valarray<value_type>& v) const; 164 void operator/= (const valarray<value_type>& v) const; 165 void operator%= (const valarray<value_type>& v) const; 166 void operator+= (const valarray<value_type>& v) const; 167 void operator-= (const valarray<value_type>& v) const; 168 void operator^= (const valarray<value_type>& v) const; 169 void operator&= (const valarray<value_type>& v) const; 170 void operator|= (const valarray<value_type>& v) const; 171 void operator<<=(const valarray<value_type>& v) const; 172 void operator>>=(const valarray<value_type>& v) const; 173 174 gslice_array(const gslice_array& ga); 175 ~gslice_array(); 176 const gslice_array& operator=(const gslice_array& ga) const; 177 void operator=(const value_type& x) const; 178 179 gslice_array() = delete; 180}; 181 182template <class T> 183class mask_array 184{ 185public: 186 typedef T value_type; 187 188 void operator= (const valarray<value_type>& v) const; 189 void operator*= (const valarray<value_type>& v) const; 190 void operator/= (const valarray<value_type>& v) const; 191 void operator%= (const valarray<value_type>& v) const; 192 void operator+= (const valarray<value_type>& v) const; 193 void operator-= (const valarray<value_type>& v) const; 194 void operator^= (const valarray<value_type>& v) const; 195 void operator&= (const valarray<value_type>& v) const; 196 void operator|= (const valarray<value_type>& v) const; 197 void operator<<=(const valarray<value_type>& v) const; 198 void operator>>=(const valarray<value_type>& v) const; 199 200 mask_array(const mask_array& ma); 201 ~mask_array(); 202 const mask_array& operator=(const mask_array& ma) const; 203 void operator=(const value_type& x) const; 204 205 mask_array() = delete; 206}; 207 208template <class T> 209class indirect_array 210{ 211public: 212 typedef T value_type; 213 214 void operator= (const valarray<value_type>& v) const; 215 void operator*= (const valarray<value_type>& v) const; 216 void operator/= (const valarray<value_type>& v) const; 217 void operator%= (const valarray<value_type>& v) const; 218 void operator+= (const valarray<value_type>& v) const; 219 void operator-= (const valarray<value_type>& v) const; 220 void operator^= (const valarray<value_type>& v) const; 221 void operator&= (const valarray<value_type>& v) const; 222 void operator|= (const valarray<value_type>& v) const; 223 void operator<<=(const valarray<value_type>& v) const; 224 void operator>>=(const valarray<value_type>& v) const; 225 226 indirect_array(const indirect_array& ia); 227 ~indirect_array(); 228 const indirect_array& operator=(const indirect_array& ia) const; 229 void operator=(const value_type& x) const; 230 231 indirect_array() = delete; 232}; 233 234template<class T> void swap(valarray<T>& x, valarray<T>& y) noexcept; 235 236template<class T> valarray<T> operator* (const valarray<T>& x, const valarray<T>& y); 237template<class T> valarray<T> operator* (const valarray<T>& x, const T& y); 238template<class T> valarray<T> operator* (const T& x, const valarray<T>& y); 239 240template<class T> valarray<T> operator/ (const valarray<T>& x, const valarray<T>& y); 241template<class T> valarray<T> operator/ (const valarray<T>& x, const T& y); 242template<class T> valarray<T> operator/ (const T& x, const valarray<T>& y); 243 244template<class T> valarray<T> operator% (const valarray<T>& x, const valarray<T>& y); 245template<class T> valarray<T> operator% (const valarray<T>& x, const T& y); 246template<class T> valarray<T> operator% (const T& x, const valarray<T>& y); 247 248template<class T> valarray<T> operator+ (const valarray<T>& x, const valarray<T>& y); 249template<class T> valarray<T> operator+ (const valarray<T>& x, const T& y); 250template<class T> valarray<T> operator+ (const T& x, const valarray<T>& y); 251 252template<class T> valarray<T> operator- (const valarray<T>& x, const valarray<T>& y); 253template<class T> valarray<T> operator- (const valarray<T>& x, const T& y); 254template<class T> valarray<T> operator- (const T& x, const valarray<T>& y); 255 256template<class T> valarray<T> operator^ (const valarray<T>& x, const valarray<T>& y); 257template<class T> valarray<T> operator^ (const valarray<T>& x, const T& y); 258template<class T> valarray<T> operator^ (const T& x, const valarray<T>& y); 259 260template<class T> valarray<T> operator& (const valarray<T>& x, const valarray<T>& y); 261template<class T> valarray<T> operator& (const valarray<T>& x, const T& y); 262template<class T> valarray<T> operator& (const T& x, const valarray<T>& y); 263 264template<class T> valarray<T> operator| (const valarray<T>& x, const valarray<T>& y); 265template<class T> valarray<T> operator| (const valarray<T>& x, const T& y); 266template<class T> valarray<T> operator| (const T& x, const valarray<T>& y); 267 268template<class T> valarray<T> operator<<(const valarray<T>& x, const valarray<T>& y); 269template<class T> valarray<T> operator<<(const valarray<T>& x, const T& y); 270template<class T> valarray<T> operator<<(const T& x, const valarray<T>& y); 271 272template<class T> valarray<T> operator>>(const valarray<T>& x, const valarray<T>& y); 273template<class T> valarray<T> operator>>(const valarray<T>& x, const T& y); 274template<class T> valarray<T> operator>>(const T& x, const valarray<T>& y); 275 276template<class T> valarray<bool> operator&&(const valarray<T>& x, const valarray<T>& y); 277template<class T> valarray<bool> operator&&(const valarray<T>& x, const T& y); 278template<class T> valarray<bool> operator&&(const T& x, const valarray<T>& y); 279 280template<class T> valarray<bool> operator||(const valarray<T>& x, const valarray<T>& y); 281template<class T> valarray<bool> operator||(const valarray<T>& x, const T& y); 282template<class T> valarray<bool> operator||(const T& x, const valarray<T>& y); 283 284template<class T> valarray<bool> operator==(const valarray<T>& x, const valarray<T>& y); 285template<class T> valarray<bool> operator==(const valarray<T>& x, const T& y); 286template<class T> valarray<bool> operator==(const T& x, const valarray<T>& y); 287 288template<class T> valarray<bool> operator!=(const valarray<T>& x, const valarray<T>& y); 289template<class T> valarray<bool> operator!=(const valarray<T>& x, const T& y); 290template<class T> valarray<bool> operator!=(const T& x, const valarray<T>& y); 291 292template<class T> valarray<bool> operator< (const valarray<T>& x, const valarray<T>& y); 293template<class T> valarray<bool> operator< (const valarray<T>& x, const T& y); 294template<class T> valarray<bool> operator< (const T& x, const valarray<T>& y); 295 296template<class T> valarray<bool> operator> (const valarray<T>& x, const valarray<T>& y); 297template<class T> valarray<bool> operator> (const valarray<T>& x, const T& y); 298template<class T> valarray<bool> operator> (const T& x, const valarray<T>& y); 299 300template<class T> valarray<bool> operator<=(const valarray<T>& x, const valarray<T>& y); 301template<class T> valarray<bool> operator<=(const valarray<T>& x, const T& y); 302template<class T> valarray<bool> operator<=(const T& x, const valarray<T>& y); 303 304template<class T> valarray<bool> operator>=(const valarray<T>& x, const valarray<T>& y); 305template<class T> valarray<bool> operator>=(const valarray<T>& x, const T& y); 306template<class T> valarray<bool> operator>=(const T& x, const valarray<T>& y); 307 308template<class T> valarray<T> abs (const valarray<T>& x); 309template<class T> valarray<T> acos (const valarray<T>& x); 310template<class T> valarray<T> asin (const valarray<T>& x); 311template<class T> valarray<T> atan (const valarray<T>& x); 312 313template<class T> valarray<T> atan2(const valarray<T>& x, const valarray<T>& y); 314template<class T> valarray<T> atan2(const valarray<T>& x, const T& y); 315template<class T> valarray<T> atan2(const T& x, const valarray<T>& y); 316 317template<class T> valarray<T> cos (const valarray<T>& x); 318template<class T> valarray<T> cosh (const valarray<T>& x); 319template<class T> valarray<T> exp (const valarray<T>& x); 320template<class T> valarray<T> log (const valarray<T>& x); 321template<class T> valarray<T> log10(const valarray<T>& x); 322 323template<class T> valarray<T> pow(const valarray<T>& x, const valarray<T>& y); 324template<class T> valarray<T> pow(const valarray<T>& x, const T& y); 325template<class T> valarray<T> pow(const T& x, const valarray<T>& y); 326 327template<class T> valarray<T> sin (const valarray<T>& x); 328template<class T> valarray<T> sinh (const valarray<T>& x); 329template<class T> valarray<T> sqrt (const valarray<T>& x); 330template<class T> valarray<T> tan (const valarray<T>& x); 331template<class T> valarray<T> tanh (const valarray<T>& x); 332 333template <class T> unspecified1 begin(valarray<T>& v); 334template <class T> unspecified2 begin(const valarray<T>& v); 335template <class T> unspecified1 end(valarray<T>& v); 336template <class T> unspecified2 end(const valarray<T>& v); 337 338} // std 339 340*/ 341 342#include <__config> 343#include <algorithm> 344#include <cmath> 345#include <cstddef> 346#include <functional> 347#include <initializer_list> 348#include <new> 349 350#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 351#pragma GCC system_header 352#endif 353 354_LIBCPP_PUSH_MACROS 355#include <__undef_macros> 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_(nullptr), __end_(nullptr) {} 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 slice_array(slice_array const&) = default; 1260 1261 _LIBCPP_INLINE_VISIBILITY 1262 const slice_array& operator=(const slice_array& __sa) const; 1263 1264 _LIBCPP_INLINE_VISIBILITY 1265 void operator=(const value_type& __x) const; 1266 1267 _LIBCPP_INLINE_VISIBILITY 1268 void operator=(const valarray<value_type>& __va) const; 1269 1270private: 1271 _LIBCPP_INLINE_VISIBILITY 1272 slice_array(const slice& __sl, const valarray<value_type>& __v) 1273 : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())), 1274 __size_(__sl.size()), 1275 __stride_(__sl.stride()) 1276 {} 1277 1278 template <class> friend class valarray; 1279 template <class> friend class sliceExpr; 1280}; 1281 1282template <class _Tp> 1283inline 1284const slice_array<_Tp>& 1285slice_array<_Tp>::operator=(const slice_array& __sa) const 1286{ 1287 value_type* __t = __vp_; 1288 const value_type* __s = __sa.__vp_; 1289 for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_) 1290 *__t = *__s; 1291 return *this; 1292} 1293 1294template <class _Tp> 1295template <class _Expr> 1296inline 1297typename enable_if 1298< 1299 __is_val_expr<_Expr>::value, 1300 void 1301>::type 1302slice_array<_Tp>::operator=(const _Expr& __v) const 1303{ 1304 value_type* __t = __vp_; 1305 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1306 *__t = __v[__i]; 1307} 1308 1309template <class _Tp> 1310inline void 1311slice_array<_Tp>::operator=(const valarray<value_type>& __va) const 1312{ 1313 value_type* __t = __vp_; 1314 for (size_t __i = 0; __i < __va.size(); ++__i, __t += __stride_) 1315 *__t = __va[__i]; 1316} 1317 1318template <class _Tp> 1319template <class _Expr> 1320inline 1321typename enable_if 1322< 1323 __is_val_expr<_Expr>::value, 1324 void 1325>::type 1326slice_array<_Tp>::operator*=(const _Expr& __v) const 1327{ 1328 value_type* __t = __vp_; 1329 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1330 *__t *= __v[__i]; 1331} 1332 1333template <class _Tp> 1334template <class _Expr> 1335inline 1336typename enable_if 1337< 1338 __is_val_expr<_Expr>::value, 1339 void 1340>::type 1341slice_array<_Tp>::operator/=(const _Expr& __v) const 1342{ 1343 value_type* __t = __vp_; 1344 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1345 *__t /= __v[__i]; 1346} 1347 1348template <class _Tp> 1349template <class _Expr> 1350inline 1351typename enable_if 1352< 1353 __is_val_expr<_Expr>::value, 1354 void 1355>::type 1356slice_array<_Tp>::operator%=(const _Expr& __v) const 1357{ 1358 value_type* __t = __vp_; 1359 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1360 *__t %= __v[__i]; 1361} 1362 1363template <class _Tp> 1364template <class _Expr> 1365inline 1366typename enable_if 1367< 1368 __is_val_expr<_Expr>::value, 1369 void 1370>::type 1371slice_array<_Tp>::operator+=(const _Expr& __v) const 1372{ 1373 value_type* __t = __vp_; 1374 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1375 *__t += __v[__i]; 1376} 1377 1378template <class _Tp> 1379template <class _Expr> 1380inline 1381typename enable_if 1382< 1383 __is_val_expr<_Expr>::value, 1384 void 1385>::type 1386slice_array<_Tp>::operator-=(const _Expr& __v) const 1387{ 1388 value_type* __t = __vp_; 1389 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1390 *__t -= __v[__i]; 1391} 1392 1393template <class _Tp> 1394template <class _Expr> 1395inline 1396typename enable_if 1397< 1398 __is_val_expr<_Expr>::value, 1399 void 1400>::type 1401slice_array<_Tp>::operator^=(const _Expr& __v) const 1402{ 1403 value_type* __t = __vp_; 1404 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1405 *__t ^= __v[__i]; 1406} 1407 1408template <class _Tp> 1409template <class _Expr> 1410inline 1411typename enable_if 1412< 1413 __is_val_expr<_Expr>::value, 1414 void 1415>::type 1416slice_array<_Tp>::operator&=(const _Expr& __v) const 1417{ 1418 value_type* __t = __vp_; 1419 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1420 *__t &= __v[__i]; 1421} 1422 1423template <class _Tp> 1424template <class _Expr> 1425inline 1426typename enable_if 1427< 1428 __is_val_expr<_Expr>::value, 1429 void 1430>::type 1431slice_array<_Tp>::operator|=(const _Expr& __v) const 1432{ 1433 value_type* __t = __vp_; 1434 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1435 *__t |= __v[__i]; 1436} 1437 1438template <class _Tp> 1439template <class _Expr> 1440inline 1441typename enable_if 1442< 1443 __is_val_expr<_Expr>::value, 1444 void 1445>::type 1446slice_array<_Tp>::operator<<=(const _Expr& __v) const 1447{ 1448 value_type* __t = __vp_; 1449 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1450 *__t <<= __v[__i]; 1451} 1452 1453template <class _Tp> 1454template <class _Expr> 1455inline 1456typename enable_if 1457< 1458 __is_val_expr<_Expr>::value, 1459 void 1460>::type 1461slice_array<_Tp>::operator>>=(const _Expr& __v) const 1462{ 1463 value_type* __t = __vp_; 1464 for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_) 1465 *__t >>= __v[__i]; 1466} 1467 1468template <class _Tp> 1469inline 1470void 1471slice_array<_Tp>::operator=(const value_type& __x) const 1472{ 1473 value_type* __t = __vp_; 1474 for (size_t __n = __size_; __n; --__n, __t += __stride_) 1475 *__t = __x; 1476} 1477 1478// gslice 1479 1480class _LIBCPP_TYPE_VIS gslice 1481{ 1482 valarray<size_t> __size_; 1483 valarray<size_t> __stride_; 1484 valarray<size_t> __1d_; 1485 1486public: 1487 _LIBCPP_INLINE_VISIBILITY 1488 gslice() {} 1489 1490 _LIBCPP_INLINE_VISIBILITY 1491 gslice(size_t __start, const valarray<size_t>& __size, 1492 const valarray<size_t>& __stride) 1493 : __size_(__size), 1494 __stride_(__stride) 1495 {__init(__start);} 1496 1497#ifndef _LIBCPP_CXX03_LANG 1498 1499 _LIBCPP_INLINE_VISIBILITY 1500 gslice(size_t __start, const valarray<size_t>& __size, 1501 valarray<size_t>&& __stride) 1502 : __size_(__size), 1503 __stride_(move(__stride)) 1504 {__init(__start);} 1505 1506 _LIBCPP_INLINE_VISIBILITY 1507 gslice(size_t __start, valarray<size_t>&& __size, 1508 const valarray<size_t>& __stride) 1509 : __size_(move(__size)), 1510 __stride_(__stride) 1511 {__init(__start);} 1512 1513 _LIBCPP_INLINE_VISIBILITY 1514 gslice(size_t __start, valarray<size_t>&& __size, 1515 valarray<size_t>&& __stride) 1516 : __size_(move(__size)), 1517 __stride_(move(__stride)) 1518 {__init(__start);} 1519 1520#endif // _LIBCPP_CXX03_LANG 1521 1522 _LIBCPP_INLINE_VISIBILITY 1523 size_t start() const {return __1d_.size() ? __1d_[0] : 0;} 1524 1525 _LIBCPP_INLINE_VISIBILITY 1526 valarray<size_t> size() const {return __size_;} 1527 1528 _LIBCPP_INLINE_VISIBILITY 1529 valarray<size_t> stride() const {return __stride_;} 1530 1531private: 1532 void __init(size_t __start); 1533 1534 template <class> friend class gslice_array; 1535 template <class> friend class valarray; 1536 template <class> friend class __val_expr; 1537}; 1538 1539// gslice_array 1540 1541template <class _Tp> 1542class _LIBCPP_TEMPLATE_VIS gslice_array 1543{ 1544public: 1545 typedef _Tp value_type; 1546 1547private: 1548 value_type* __vp_; 1549 valarray<size_t> __1d_; 1550 1551public: 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 template <class _Expr> 1643 typename enable_if 1644 < 1645 __is_val_expr<_Expr>::value, 1646 void 1647 >::type 1648 _LIBCPP_INLINE_VISIBILITY 1649 operator>>=(const _Expr& __v) const; 1650 1651 _LIBCPP_INLINE_VISIBILITY 1652 const gslice_array& operator=(const gslice_array& __ga) const; 1653 1654 _LIBCPP_INLINE_VISIBILITY 1655 void operator=(const value_type& __x) const; 1656 1657 gslice_array(const gslice_array&) = default; 1658 1659private: 1660 gslice_array(const gslice& __gs, const valarray<value_type>& __v) 1661 : __vp_(const_cast<value_type*>(__v.__begin_)), 1662 __1d_(__gs.__1d_) 1663 {} 1664 1665#ifndef _LIBCPP_CXX03_LANG 1666 gslice_array(gslice&& __gs, const valarray<value_type>& __v) 1667 : __vp_(const_cast<value_type*>(__v.__begin_)), 1668 __1d_(move(__gs.__1d_)) 1669 {} 1670#endif // _LIBCPP_CXX03_LANG 1671 1672 template <class> friend class valarray; 1673}; 1674 1675template <class _Tp> 1676template <class _Expr> 1677inline 1678typename enable_if 1679< 1680 __is_val_expr<_Expr>::value, 1681 void 1682>::type 1683gslice_array<_Tp>::operator=(const _Expr& __v) const 1684{ 1685 typedef const size_t* _Ip; 1686 size_t __j = 0; 1687 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1688 __vp_[*__i] = __v[__j]; 1689} 1690 1691template <class _Tp> 1692template <class _Expr> 1693inline 1694typename enable_if 1695< 1696 __is_val_expr<_Expr>::value, 1697 void 1698>::type 1699gslice_array<_Tp>::operator*=(const _Expr& __v) const 1700{ 1701 typedef const size_t* _Ip; 1702 size_t __j = 0; 1703 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1704 __vp_[*__i] *= __v[__j]; 1705} 1706 1707template <class _Tp> 1708template <class _Expr> 1709inline 1710typename enable_if 1711< 1712 __is_val_expr<_Expr>::value, 1713 void 1714>::type 1715gslice_array<_Tp>::operator/=(const _Expr& __v) const 1716{ 1717 typedef const size_t* _Ip; 1718 size_t __j = 0; 1719 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1720 __vp_[*__i] /= __v[__j]; 1721} 1722 1723template <class _Tp> 1724template <class _Expr> 1725inline 1726typename enable_if 1727< 1728 __is_val_expr<_Expr>::value, 1729 void 1730>::type 1731gslice_array<_Tp>::operator%=(const _Expr& __v) const 1732{ 1733 typedef const size_t* _Ip; 1734 size_t __j = 0; 1735 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1736 __vp_[*__i] %= __v[__j]; 1737} 1738 1739template <class _Tp> 1740template <class _Expr> 1741inline 1742typename enable_if 1743< 1744 __is_val_expr<_Expr>::value, 1745 void 1746>::type 1747gslice_array<_Tp>::operator+=(const _Expr& __v) const 1748{ 1749 typedef const size_t* _Ip; 1750 size_t __j = 0; 1751 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1752 __vp_[*__i] += __v[__j]; 1753} 1754 1755template <class _Tp> 1756template <class _Expr> 1757inline 1758typename enable_if 1759< 1760 __is_val_expr<_Expr>::value, 1761 void 1762>::type 1763gslice_array<_Tp>::operator-=(const _Expr& __v) const 1764{ 1765 typedef const size_t* _Ip; 1766 size_t __j = 0; 1767 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1768 __vp_[*__i] -= __v[__j]; 1769} 1770 1771template <class _Tp> 1772template <class _Expr> 1773inline 1774typename enable_if 1775< 1776 __is_val_expr<_Expr>::value, 1777 void 1778>::type 1779gslice_array<_Tp>::operator^=(const _Expr& __v) const 1780{ 1781 typedef const size_t* _Ip; 1782 size_t __j = 0; 1783 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1784 __vp_[*__i] ^= __v[__j]; 1785} 1786 1787template <class _Tp> 1788template <class _Expr> 1789inline 1790typename enable_if 1791< 1792 __is_val_expr<_Expr>::value, 1793 void 1794>::type 1795gslice_array<_Tp>::operator&=(const _Expr& __v) const 1796{ 1797 typedef const size_t* _Ip; 1798 size_t __j = 0; 1799 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1800 __vp_[*__i] &= __v[__j]; 1801} 1802 1803template <class _Tp> 1804template <class _Expr> 1805inline 1806typename enable_if 1807< 1808 __is_val_expr<_Expr>::value, 1809 void 1810>::type 1811gslice_array<_Tp>::operator|=(const _Expr& __v) const 1812{ 1813 typedef const size_t* _Ip; 1814 size_t __j = 0; 1815 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1816 __vp_[*__i] |= __v[__j]; 1817} 1818 1819template <class _Tp> 1820template <class _Expr> 1821inline 1822typename enable_if 1823< 1824 __is_val_expr<_Expr>::value, 1825 void 1826>::type 1827gslice_array<_Tp>::operator<<=(const _Expr& __v) const 1828{ 1829 typedef const size_t* _Ip; 1830 size_t __j = 0; 1831 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1832 __vp_[*__i] <<= __v[__j]; 1833} 1834 1835template <class _Tp> 1836template <class _Expr> 1837inline 1838typename enable_if 1839< 1840 __is_val_expr<_Expr>::value, 1841 void 1842>::type 1843gslice_array<_Tp>::operator>>=(const _Expr& __v) const 1844{ 1845 typedef const size_t* _Ip; 1846 size_t __j = 0; 1847 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j) 1848 __vp_[*__i] >>= __v[__j]; 1849} 1850 1851template <class _Tp> 1852inline 1853const gslice_array<_Tp>& 1854gslice_array<_Tp>::operator=(const gslice_array& __ga) const 1855{ 1856 typedef const size_t* _Ip; 1857 const value_type* __s = __ga.__vp_; 1858 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_; 1859 __i != __e; ++__i, ++__j) 1860 __vp_[*__i] = __s[*__j]; 1861 return *this; 1862} 1863 1864template <class _Tp> 1865inline 1866void 1867gslice_array<_Tp>::operator=(const value_type& __x) const 1868{ 1869 typedef const size_t* _Ip; 1870 for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i) 1871 __vp_[*__i] = __x; 1872} 1873 1874// mask_array 1875 1876template <class _Tp> 1877class _LIBCPP_TEMPLATE_VIS mask_array 1878{ 1879public: 1880 typedef _Tp value_type; 1881 1882private: 1883 value_type* __vp_; 1884 valarray<size_t> __1d_; 1885 1886public: 1887 template <class _Expr> 1888 typename enable_if 1889 < 1890 __is_val_expr<_Expr>::value, 1891 void 1892 >::type 1893 _LIBCPP_INLINE_VISIBILITY 1894 operator=(const _Expr& __v) const; 1895 1896 template <class _Expr> 1897 typename enable_if 1898 < 1899 __is_val_expr<_Expr>::value, 1900 void 1901 >::type 1902 _LIBCPP_INLINE_VISIBILITY 1903 operator*=(const _Expr& __v) const; 1904 1905 template <class _Expr> 1906 typename enable_if 1907 < 1908 __is_val_expr<_Expr>::value, 1909 void 1910 >::type 1911 _LIBCPP_INLINE_VISIBILITY 1912 operator/=(const _Expr& __v) const; 1913 1914 template <class _Expr> 1915 typename enable_if 1916 < 1917 __is_val_expr<_Expr>::value, 1918 void 1919 >::type 1920 _LIBCPP_INLINE_VISIBILITY 1921 operator%=(const _Expr& __v) const; 1922 1923 template <class _Expr> 1924 typename enable_if 1925 < 1926 __is_val_expr<_Expr>::value, 1927 void 1928 >::type 1929 _LIBCPP_INLINE_VISIBILITY 1930 operator+=(const _Expr& __v) const; 1931 1932 template <class _Expr> 1933 typename enable_if 1934 < 1935 __is_val_expr<_Expr>::value, 1936 void 1937 >::type 1938 _LIBCPP_INLINE_VISIBILITY 1939 operator-=(const _Expr& __v) const; 1940 1941 template <class _Expr> 1942 typename enable_if 1943 < 1944 __is_val_expr<_Expr>::value, 1945 void 1946 >::type 1947 _LIBCPP_INLINE_VISIBILITY 1948 operator^=(const _Expr& __v) const; 1949 1950 template <class _Expr> 1951 typename enable_if 1952 < 1953 __is_val_expr<_Expr>::value, 1954 void 1955 >::type 1956 _LIBCPP_INLINE_VISIBILITY 1957 operator&=(const _Expr& __v) const; 1958 1959 template <class _Expr> 1960 typename enable_if 1961 < 1962 __is_val_expr<_Expr>::value, 1963 void 1964 >::type 1965 _LIBCPP_INLINE_VISIBILITY 1966 operator|=(const _Expr& __v) const; 1967 1968 template <class _Expr> 1969 typename enable_if 1970 < 1971 __is_val_expr<_Expr>::value, 1972 void 1973 >::type 1974 _LIBCPP_INLINE_VISIBILITY 1975 operator<<=(const _Expr& __v) const; 1976 1977 template <class _Expr> 1978 typename enable_if 1979 < 1980 __is_val_expr<_Expr>::value, 1981 void 1982 >::type 1983 _LIBCPP_INLINE_VISIBILITY 1984 operator>>=(const _Expr& __v) const; 1985 1986 mask_array(const mask_array&) = default; 1987 1988 _LIBCPP_INLINE_VISIBILITY 1989 const mask_array& operator=(const mask_array& __ma) const; 1990 1991 _LIBCPP_INLINE_VISIBILITY 1992 void operator=(const value_type& __x) const; 1993 1994private: 1995 _LIBCPP_INLINE_VISIBILITY 1996 mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v) 1997 : __vp_(const_cast<value_type*>(__v.__begin_)), 1998 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true))) 1999 { 2000 size_t __j = 0; 2001 for (size_t __i = 0; __i < __vb.size(); ++__i) 2002 if (__vb[__i]) 2003 __1d_[__j++] = __i; 2004 } 2005 2006 template <class> friend class valarray; 2007}; 2008 2009template <class _Tp> 2010template <class _Expr> 2011inline 2012typename enable_if 2013< 2014 __is_val_expr<_Expr>::value, 2015 void 2016>::type 2017mask_array<_Tp>::operator=(const _Expr& __v) const 2018{ 2019 size_t __n = __1d_.size(); 2020 for (size_t __i = 0; __i < __n; ++__i) 2021 __vp_[__1d_[__i]] = __v[__i]; 2022} 2023 2024template <class _Tp> 2025template <class _Expr> 2026inline 2027typename enable_if 2028< 2029 __is_val_expr<_Expr>::value, 2030 void 2031>::type 2032mask_array<_Tp>::operator*=(const _Expr& __v) const 2033{ 2034 size_t __n = __1d_.size(); 2035 for (size_t __i = 0; __i < __n; ++__i) 2036 __vp_[__1d_[__i]] *= __v[__i]; 2037} 2038 2039template <class _Tp> 2040template <class _Expr> 2041inline 2042typename enable_if 2043< 2044 __is_val_expr<_Expr>::value, 2045 void 2046>::type 2047mask_array<_Tp>::operator/=(const _Expr& __v) const 2048{ 2049 size_t __n = __1d_.size(); 2050 for (size_t __i = 0; __i < __n; ++__i) 2051 __vp_[__1d_[__i]] /= __v[__i]; 2052} 2053 2054template <class _Tp> 2055template <class _Expr> 2056inline 2057typename enable_if 2058< 2059 __is_val_expr<_Expr>::value, 2060 void 2061>::type 2062mask_array<_Tp>::operator%=(const _Expr& __v) const 2063{ 2064 size_t __n = __1d_.size(); 2065 for (size_t __i = 0; __i < __n; ++__i) 2066 __vp_[__1d_[__i]] %= __v[__i]; 2067} 2068 2069template <class _Tp> 2070template <class _Expr> 2071inline 2072typename enable_if 2073< 2074 __is_val_expr<_Expr>::value, 2075 void 2076>::type 2077mask_array<_Tp>::operator+=(const _Expr& __v) const 2078{ 2079 size_t __n = __1d_.size(); 2080 for (size_t __i = 0; __i < __n; ++__i) 2081 __vp_[__1d_[__i]] += __v[__i]; 2082} 2083 2084template <class _Tp> 2085template <class _Expr> 2086inline 2087typename enable_if 2088< 2089 __is_val_expr<_Expr>::value, 2090 void 2091>::type 2092mask_array<_Tp>::operator-=(const _Expr& __v) const 2093{ 2094 size_t __n = __1d_.size(); 2095 for (size_t __i = 0; __i < __n; ++__i) 2096 __vp_[__1d_[__i]] -= __v[__i]; 2097} 2098 2099template <class _Tp> 2100template <class _Expr> 2101inline 2102typename enable_if 2103< 2104 __is_val_expr<_Expr>::value, 2105 void 2106>::type 2107mask_array<_Tp>::operator^=(const _Expr& __v) const 2108{ 2109 size_t __n = __1d_.size(); 2110 for (size_t __i = 0; __i < __n; ++__i) 2111 __vp_[__1d_[__i]] ^= __v[__i]; 2112} 2113 2114template <class _Tp> 2115template <class _Expr> 2116inline 2117typename enable_if 2118< 2119 __is_val_expr<_Expr>::value, 2120 void 2121>::type 2122mask_array<_Tp>::operator&=(const _Expr& __v) const 2123{ 2124 size_t __n = __1d_.size(); 2125 for (size_t __i = 0; __i < __n; ++__i) 2126 __vp_[__1d_[__i]] &= __v[__i]; 2127} 2128 2129template <class _Tp> 2130template <class _Expr> 2131inline 2132typename enable_if 2133< 2134 __is_val_expr<_Expr>::value, 2135 void 2136>::type 2137mask_array<_Tp>::operator|=(const _Expr& __v) const 2138{ 2139 size_t __n = __1d_.size(); 2140 for (size_t __i = 0; __i < __n; ++__i) 2141 __vp_[__1d_[__i]] |= __v[__i]; 2142} 2143 2144template <class _Tp> 2145template <class _Expr> 2146inline 2147typename enable_if 2148< 2149 __is_val_expr<_Expr>::value, 2150 void 2151>::type 2152mask_array<_Tp>::operator<<=(const _Expr& __v) const 2153{ 2154 size_t __n = __1d_.size(); 2155 for (size_t __i = 0; __i < __n; ++__i) 2156 __vp_[__1d_[__i]] <<= __v[__i]; 2157} 2158 2159template <class _Tp> 2160template <class _Expr> 2161inline 2162typename enable_if 2163< 2164 __is_val_expr<_Expr>::value, 2165 void 2166>::type 2167mask_array<_Tp>::operator>>=(const _Expr& __v) const 2168{ 2169 size_t __n = __1d_.size(); 2170 for (size_t __i = 0; __i < __n; ++__i) 2171 __vp_[__1d_[__i]] >>= __v[__i]; 2172} 2173 2174template <class _Tp> 2175inline 2176const mask_array<_Tp>& 2177mask_array<_Tp>::operator=(const mask_array& __ma) const 2178{ 2179 size_t __n = __1d_.size(); 2180 for (size_t __i = 0; __i < __n; ++__i) 2181 __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]]; 2182 return *this; 2183} 2184 2185template <class _Tp> 2186inline 2187void 2188mask_array<_Tp>::operator=(const value_type& __x) const 2189{ 2190 size_t __n = __1d_.size(); 2191 for (size_t __i = 0; __i < __n; ++__i) 2192 __vp_[__1d_[__i]] = __x; 2193} 2194 2195template <class _ValExpr> 2196class __mask_expr 2197{ 2198 typedef typename remove_reference<_ValExpr>::type _RmExpr; 2199public: 2200 typedef typename _RmExpr::value_type value_type; 2201 typedef value_type result_type; 2202 2203private: 2204 _ValExpr __expr_; 2205 valarray<size_t> __1d_; 2206 2207 _LIBCPP_INLINE_VISIBILITY 2208 __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e) 2209 : __expr_(__e), 2210 __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true))) 2211 { 2212 size_t __j = 0; 2213 for (size_t __i = 0; __i < __vb.size(); ++__i) 2214 if (__vb[__i]) 2215 __1d_[__j++] = __i; 2216 } 2217 2218public: 2219 _LIBCPP_INLINE_VISIBILITY 2220 result_type operator[](size_t __i) const 2221 {return __expr_[__1d_[__i]];} 2222 2223 _LIBCPP_INLINE_VISIBILITY 2224 size_t size() const {return __1d_.size();} 2225 2226 template <class> friend class __val_expr; 2227 template <class> friend class valarray; 2228}; 2229 2230// indirect_array 2231 2232template <class _Tp> 2233class _LIBCPP_TEMPLATE_VIS indirect_array 2234{ 2235public: 2236 typedef _Tp value_type; 2237 2238private: 2239 value_type* __vp_; 2240 valarray<size_t> __1d_; 2241 2242public: 2243 template <class _Expr> 2244 typename enable_if 2245 < 2246 __is_val_expr<_Expr>::value, 2247 void 2248 >::type 2249 _LIBCPP_INLINE_VISIBILITY 2250 operator=(const _Expr& __v) const; 2251 2252 template <class _Expr> 2253 typename enable_if 2254 < 2255 __is_val_expr<_Expr>::value, 2256 void 2257 >::type 2258 _LIBCPP_INLINE_VISIBILITY 2259 operator*=(const _Expr& __v) const; 2260 2261 template <class _Expr> 2262 typename enable_if 2263 < 2264 __is_val_expr<_Expr>::value, 2265 void 2266 >::type 2267 _LIBCPP_INLINE_VISIBILITY 2268 operator/=(const _Expr& __v) const; 2269 2270 template <class _Expr> 2271 typename enable_if 2272 < 2273 __is_val_expr<_Expr>::value, 2274 void 2275 >::type 2276 _LIBCPP_INLINE_VISIBILITY 2277 operator%=(const _Expr& __v) const; 2278 2279 template <class _Expr> 2280 typename enable_if 2281 < 2282 __is_val_expr<_Expr>::value, 2283 void 2284 >::type 2285 _LIBCPP_INLINE_VISIBILITY 2286 operator+=(const _Expr& __v) const; 2287 2288 template <class _Expr> 2289 typename enable_if 2290 < 2291 __is_val_expr<_Expr>::value, 2292 void 2293 >::type 2294 _LIBCPP_INLINE_VISIBILITY 2295 operator-=(const _Expr& __v) const; 2296 2297 template <class _Expr> 2298 typename enable_if 2299 < 2300 __is_val_expr<_Expr>::value, 2301 void 2302 >::type 2303 _LIBCPP_INLINE_VISIBILITY 2304 operator^=(const _Expr& __v) const; 2305 2306 template <class _Expr> 2307 typename enable_if 2308 < 2309 __is_val_expr<_Expr>::value, 2310 void 2311 >::type 2312 _LIBCPP_INLINE_VISIBILITY 2313 operator&=(const _Expr& __v) const; 2314 2315 template <class _Expr> 2316 typename enable_if 2317 < 2318 __is_val_expr<_Expr>::value, 2319 void 2320 >::type 2321 _LIBCPP_INLINE_VISIBILITY 2322 operator|=(const _Expr& __v) const; 2323 2324 template <class _Expr> 2325 typename enable_if 2326 < 2327 __is_val_expr<_Expr>::value, 2328 void 2329 >::type 2330 _LIBCPP_INLINE_VISIBILITY 2331 operator<<=(const _Expr& __v) const; 2332 2333 template <class _Expr> 2334 typename enable_if 2335 < 2336 __is_val_expr<_Expr>::value, 2337 void 2338 >::type 2339 _LIBCPP_INLINE_VISIBILITY 2340 operator>>=(const _Expr& __v) const; 2341 2342 indirect_array(const indirect_array&) = default; 2343 2344 _LIBCPP_INLINE_VISIBILITY 2345 const indirect_array& operator=(const indirect_array& __ia) const; 2346 2347 _LIBCPP_INLINE_VISIBILITY 2348 void operator=(const value_type& __x) const; 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_ = allocator<result_type>().allocate(__n); 2754 for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i) 2755 ::new ((void*)__r.__end_) result_type(__expr_[__i]); 2756 } 2757 return __r; 2758} 2759 2760// valarray 2761 2762template <class _Tp> 2763inline 2764valarray<_Tp>::valarray(size_t __n) 2765 : __begin_(nullptr), 2766 __end_(nullptr) 2767{ 2768 if (__n) 2769 { 2770 __begin_ = __end_ = allocator<value_type>().allocate(__n); 2771#ifndef _LIBCPP_NO_EXCEPTIONS 2772 try 2773 { 2774#endif // _LIBCPP_NO_EXCEPTIONS 2775 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_) 2776 ::new ((void*)__end_) value_type(); 2777#ifndef _LIBCPP_NO_EXCEPTIONS 2778 } 2779 catch (...) 2780 { 2781 __clear(__n); 2782 throw; 2783 } 2784#endif // _LIBCPP_NO_EXCEPTIONS 2785 } 2786} 2787 2788template <class _Tp> 2789inline 2790valarray<_Tp>::valarray(const value_type& __x, size_t __n) 2791 : __begin_(nullptr), 2792 __end_(nullptr) 2793{ 2794 resize(__n, __x); 2795} 2796 2797template <class _Tp> 2798valarray<_Tp>::valarray(const value_type* __p, size_t __n) 2799 : __begin_(nullptr), 2800 __end_(nullptr) 2801{ 2802 if (__n) 2803 { 2804 __begin_ = __end_ = allocator<value_type>().allocate(__n); 2805#ifndef _LIBCPP_NO_EXCEPTIONS 2806 try 2807 { 2808#endif // _LIBCPP_NO_EXCEPTIONS 2809 for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left) 2810 ::new ((void*)__end_) value_type(*__p); 2811#ifndef _LIBCPP_NO_EXCEPTIONS 2812 } 2813 catch (...) 2814 { 2815 __clear(__n); 2816 throw; 2817 } 2818#endif // _LIBCPP_NO_EXCEPTIONS 2819 } 2820} 2821 2822template <class _Tp> 2823valarray<_Tp>::valarray(const valarray& __v) 2824 : __begin_(nullptr), 2825 __end_(nullptr) 2826{ 2827 if (__v.size()) 2828 { 2829 __begin_ = __end_ = allocator<value_type>().allocate(__v.size()); 2830#ifndef _LIBCPP_NO_EXCEPTIONS 2831 try 2832 { 2833#endif // _LIBCPP_NO_EXCEPTIONS 2834 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p) 2835 ::new ((void*)__end_) value_type(*__p); 2836#ifndef _LIBCPP_NO_EXCEPTIONS 2837 } 2838 catch (...) 2839 { 2840 __clear(__v.size()); 2841 throw; 2842 } 2843#endif // _LIBCPP_NO_EXCEPTIONS 2844 } 2845} 2846 2847#ifndef _LIBCPP_CXX03_LANG 2848 2849template <class _Tp> 2850inline 2851valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT 2852 : __begin_(__v.__begin_), 2853 __end_(__v.__end_) 2854{ 2855 __v.__begin_ = __v.__end_ = nullptr; 2856} 2857 2858template <class _Tp> 2859valarray<_Tp>::valarray(initializer_list<value_type> __il) 2860 : __begin_(nullptr), 2861 __end_(nullptr) 2862{ 2863 const size_t __n = __il.size(); 2864 if (__n) 2865 { 2866 __begin_ = __end_ = allocator<value_type>().allocate(__n); 2867#ifndef _LIBCPP_NO_EXCEPTIONS 2868 try 2869 { 2870#endif // _LIBCPP_NO_EXCEPTIONS 2871 size_t __n_left = __n; 2872 for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left) 2873 ::new ((void*)__end_) value_type(*__p); 2874#ifndef _LIBCPP_NO_EXCEPTIONS 2875 } 2876 catch (...) 2877 { 2878 __clear(__n); 2879 throw; 2880 } 2881#endif // _LIBCPP_NO_EXCEPTIONS 2882 } 2883} 2884 2885#endif // _LIBCPP_CXX03_LANG 2886 2887template <class _Tp> 2888valarray<_Tp>::valarray(const slice_array<value_type>& __sa) 2889 : __begin_(nullptr), 2890 __end_(nullptr) 2891{ 2892 const size_t __n = __sa.__size_; 2893 if (__n) 2894 { 2895 __begin_ = __end_ = allocator<value_type>().allocate(__n); 2896#ifndef _LIBCPP_NO_EXCEPTIONS 2897 try 2898 { 2899#endif // _LIBCPP_NO_EXCEPTIONS 2900 size_t __n_left = __n; 2901 for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left) 2902 ::new ((void*)__end_) value_type(*__p); 2903#ifndef _LIBCPP_NO_EXCEPTIONS 2904 } 2905 catch (...) 2906 { 2907 __clear(__n); 2908 throw; 2909 } 2910#endif // _LIBCPP_NO_EXCEPTIONS 2911 } 2912} 2913 2914template <class _Tp> 2915valarray<_Tp>::valarray(const gslice_array<value_type>& __ga) 2916 : __begin_(nullptr), 2917 __end_(nullptr) 2918{ 2919 const size_t __n = __ga.__1d_.size(); 2920 if (__n) 2921 { 2922 __begin_ = __end_ = allocator<value_type>().allocate(__n); 2923#ifndef _LIBCPP_NO_EXCEPTIONS 2924 try 2925 { 2926#endif // _LIBCPP_NO_EXCEPTIONS 2927 typedef const size_t* _Ip; 2928 const value_type* __s = __ga.__vp_; 2929 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; 2930 __i != __e; ++__i, ++__end_) 2931 ::new ((void*)__end_) value_type(__s[*__i]); 2932#ifndef _LIBCPP_NO_EXCEPTIONS 2933 } 2934 catch (...) 2935 { 2936 __clear(__n); 2937 throw; 2938 } 2939#endif // _LIBCPP_NO_EXCEPTIONS 2940 } 2941} 2942 2943template <class _Tp> 2944valarray<_Tp>::valarray(const mask_array<value_type>& __ma) 2945 : __begin_(nullptr), 2946 __end_(nullptr) 2947{ 2948 const size_t __n = __ma.__1d_.size(); 2949 if (__n) 2950 { 2951 __begin_ = __end_ = allocator<value_type>().allocate(__n); 2952#ifndef _LIBCPP_NO_EXCEPTIONS 2953 try 2954 { 2955#endif // _LIBCPP_NO_EXCEPTIONS 2956 typedef const size_t* _Ip; 2957 const value_type* __s = __ma.__vp_; 2958 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; 2959 __i != __e; ++__i, ++__end_) 2960 ::new ((void*)__end_) value_type(__s[*__i]); 2961#ifndef _LIBCPP_NO_EXCEPTIONS 2962 } 2963 catch (...) 2964 { 2965 __clear(__n); 2966 throw; 2967 } 2968#endif // _LIBCPP_NO_EXCEPTIONS 2969 } 2970} 2971 2972template <class _Tp> 2973valarray<_Tp>::valarray(const indirect_array<value_type>& __ia) 2974 : __begin_(nullptr), 2975 __end_(nullptr) 2976{ 2977 const size_t __n = __ia.__1d_.size(); 2978 if (__n) 2979 { 2980 __begin_ = __end_ = allocator<value_type>().allocate(__n); 2981#ifndef _LIBCPP_NO_EXCEPTIONS 2982 try 2983 { 2984#endif // _LIBCPP_NO_EXCEPTIONS 2985 typedef const size_t* _Ip; 2986 const value_type* __s = __ia.__vp_; 2987 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; 2988 __i != __e; ++__i, ++__end_) 2989 ::new ((void*)__end_) value_type(__s[*__i]); 2990#ifndef _LIBCPP_NO_EXCEPTIONS 2991 } 2992 catch (...) 2993 { 2994 __clear(__n); 2995 throw; 2996 } 2997#endif // _LIBCPP_NO_EXCEPTIONS 2998 } 2999} 3000 3001template <class _Tp> 3002inline 3003valarray<_Tp>::~valarray() 3004{ 3005 __clear(size()); 3006} 3007 3008template <class _Tp> 3009valarray<_Tp>& 3010valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l) 3011{ 3012 size_t __n = __l - __f; 3013 if (size() != __n) 3014 { 3015 __clear(size()); 3016 __begin_ = allocator<value_type>().allocate(__n); 3017 __end_ = __begin_ + __n; 3018 _VSTD::uninitialized_copy(__f, __l, __begin_); 3019 } else { 3020 _VSTD::copy(__f, __l, __begin_); 3021 } 3022 return *this; 3023} 3024 3025template <class _Tp> 3026valarray<_Tp>& 3027valarray<_Tp>::operator=(const valarray& __v) 3028{ 3029 if (this != &__v) 3030 return __assign_range(__v.__begin_, __v.__end_); 3031 return *this; 3032} 3033 3034#ifndef _LIBCPP_CXX03_LANG 3035 3036template <class _Tp> 3037inline 3038valarray<_Tp>& 3039valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT 3040{ 3041 __clear(size()); 3042 __begin_ = __v.__begin_; 3043 __end_ = __v.__end_; 3044 __v.__begin_ = nullptr; 3045 __v.__end_ = nullptr; 3046 return *this; 3047} 3048 3049template <class _Tp> 3050inline 3051valarray<_Tp>& 3052valarray<_Tp>::operator=(initializer_list<value_type> __il) 3053{ 3054 return __assign_range(__il.begin(), __il.end()); 3055} 3056 3057#endif // _LIBCPP_CXX03_LANG 3058 3059template <class _Tp> 3060inline 3061valarray<_Tp>& 3062valarray<_Tp>::operator=(const value_type& __x) 3063{ 3064 _VSTD::fill(__begin_, __end_, __x); 3065 return *this; 3066} 3067 3068template <class _Tp> 3069inline 3070valarray<_Tp>& 3071valarray<_Tp>::operator=(const slice_array<value_type>& __sa) 3072{ 3073 value_type* __t = __begin_; 3074 const value_type* __s = __sa.__vp_; 3075 for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t) 3076 *__t = *__s; 3077 return *this; 3078} 3079 3080template <class _Tp> 3081inline 3082valarray<_Tp>& 3083valarray<_Tp>::operator=(const gslice_array<value_type>& __ga) 3084{ 3085 typedef const size_t* _Ip; 3086 value_type* __t = __begin_; 3087 const value_type* __s = __ga.__vp_; 3088 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; 3089 __i != __e; ++__i, ++__t) 3090 *__t = __s[*__i]; 3091 return *this; 3092} 3093 3094template <class _Tp> 3095inline 3096valarray<_Tp>& 3097valarray<_Tp>::operator=(const mask_array<value_type>& __ma) 3098{ 3099 typedef const size_t* _Ip; 3100 value_type* __t = __begin_; 3101 const value_type* __s = __ma.__vp_; 3102 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; 3103 __i != __e; ++__i, ++__t) 3104 *__t = __s[*__i]; 3105 return *this; 3106} 3107 3108template <class _Tp> 3109inline 3110valarray<_Tp>& 3111valarray<_Tp>::operator=(const indirect_array<value_type>& __ia) 3112{ 3113 typedef const size_t* _Ip; 3114 value_type* __t = __begin_; 3115 const value_type* __s = __ia.__vp_; 3116 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; 3117 __i != __e; ++__i, ++__t) 3118 *__t = __s[*__i]; 3119 return *this; 3120} 3121 3122template <class _Tp> 3123template <class _ValExpr> 3124inline 3125valarray<_Tp>& 3126valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v) 3127{ 3128 size_t __n = __v.size(); 3129 if (size() != __n) 3130 resize(__n); 3131 value_type* __t = __begin_; 3132 for (size_t __i = 0; __i != __n; ++__t, ++__i) 3133 *__t = result_type(__v[__i]); 3134 return *this; 3135} 3136 3137template <class _Tp> 3138inline 3139__val_expr<__slice_expr<const valarray<_Tp>&> > 3140valarray<_Tp>::operator[](slice __s) const 3141{ 3142 return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this)); 3143} 3144 3145template <class _Tp> 3146inline 3147slice_array<_Tp> 3148valarray<_Tp>::operator[](slice __s) 3149{ 3150 return slice_array<value_type>(__s, *this); 3151} 3152 3153template <class _Tp> 3154inline 3155__val_expr<__indirect_expr<const valarray<_Tp>&> > 3156valarray<_Tp>::operator[](const gslice& __gs) const 3157{ 3158 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this)); 3159} 3160 3161template <class _Tp> 3162inline 3163gslice_array<_Tp> 3164valarray<_Tp>::operator[](const gslice& __gs) 3165{ 3166 return gslice_array<value_type>(__gs, *this); 3167} 3168 3169#ifndef _LIBCPP_CXX03_LANG 3170 3171template <class _Tp> 3172inline 3173__val_expr<__indirect_expr<const valarray<_Tp>&> > 3174valarray<_Tp>::operator[](gslice&& __gs) const 3175{ 3176 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this)); 3177} 3178 3179template <class _Tp> 3180inline 3181gslice_array<_Tp> 3182valarray<_Tp>::operator[](gslice&& __gs) 3183{ 3184 return gslice_array<value_type>(move(__gs), *this); 3185} 3186 3187#endif // _LIBCPP_CXX03_LANG 3188 3189template <class _Tp> 3190inline 3191__val_expr<__mask_expr<const valarray<_Tp>&> > 3192valarray<_Tp>::operator[](const valarray<bool>& __vb) const 3193{ 3194 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this)); 3195} 3196 3197template <class _Tp> 3198inline 3199mask_array<_Tp> 3200valarray<_Tp>::operator[](const valarray<bool>& __vb) 3201{ 3202 return mask_array<value_type>(__vb, *this); 3203} 3204 3205#ifndef _LIBCPP_CXX03_LANG 3206 3207template <class _Tp> 3208inline 3209__val_expr<__mask_expr<const valarray<_Tp>&> > 3210valarray<_Tp>::operator[](valarray<bool>&& __vb) const 3211{ 3212 return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this)); 3213} 3214 3215template <class _Tp> 3216inline 3217mask_array<_Tp> 3218valarray<_Tp>::operator[](valarray<bool>&& __vb) 3219{ 3220 return mask_array<value_type>(move(__vb), *this); 3221} 3222 3223#endif // _LIBCPP_CXX03_LANG 3224 3225template <class _Tp> 3226inline 3227__val_expr<__indirect_expr<const valarray<_Tp>&> > 3228valarray<_Tp>::operator[](const valarray<size_t>& __vs) const 3229{ 3230 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this)); 3231} 3232 3233template <class _Tp> 3234inline 3235indirect_array<_Tp> 3236valarray<_Tp>::operator[](const valarray<size_t>& __vs) 3237{ 3238 return indirect_array<value_type>(__vs, *this); 3239} 3240 3241#ifndef _LIBCPP_CXX03_LANG 3242 3243template <class _Tp> 3244inline 3245__val_expr<__indirect_expr<const valarray<_Tp>&> > 3246valarray<_Tp>::operator[](valarray<size_t>&& __vs) const 3247{ 3248 return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this)); 3249} 3250 3251template <class _Tp> 3252inline 3253indirect_array<_Tp> 3254valarray<_Tp>::operator[](valarray<size_t>&& __vs) 3255{ 3256 return indirect_array<value_type>(move(__vs), *this); 3257} 3258 3259#endif // _LIBCPP_CXX03_LANG 3260 3261template <class _Tp> 3262valarray<_Tp> 3263valarray<_Tp>::operator+() const 3264{ 3265 valarray<value_type> __r; 3266 size_t __n = size(); 3267 if (__n) 3268 { 3269 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n); 3270 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) 3271 ::new ((void*)__r.__end_) value_type(+*__p); 3272 } 3273 return __r; 3274} 3275 3276template <class _Tp> 3277valarray<_Tp> 3278valarray<_Tp>::operator-() const 3279{ 3280 valarray<value_type> __r; 3281 size_t __n = size(); 3282 if (__n) 3283 { 3284 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n); 3285 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) 3286 ::new ((void*)__r.__end_) value_type(-*__p); 3287 } 3288 return __r; 3289} 3290 3291template <class _Tp> 3292valarray<_Tp> 3293valarray<_Tp>::operator~() const 3294{ 3295 valarray<value_type> __r; 3296 size_t __n = size(); 3297 if (__n) 3298 { 3299 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n); 3300 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) 3301 ::new ((void*)__r.__end_) value_type(~*__p); 3302 } 3303 return __r; 3304} 3305 3306template <class _Tp> 3307valarray<bool> 3308valarray<_Tp>::operator!() const 3309{ 3310 valarray<bool> __r; 3311 size_t __n = size(); 3312 if (__n) 3313 { 3314 __r.__begin_ = __r.__end_ = allocator<bool>().allocate(__n); 3315 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) 3316 ::new ((void*)__r.__end_) bool(!*__p); 3317 } 3318 return __r; 3319} 3320 3321template <class _Tp> 3322inline 3323valarray<_Tp>& 3324valarray<_Tp>::operator*=(const value_type& __x) 3325{ 3326 for (value_type* __p = __begin_; __p != __end_; ++__p) 3327 *__p *= __x; 3328 return *this; 3329} 3330 3331template <class _Tp> 3332inline 3333valarray<_Tp>& 3334valarray<_Tp>::operator/=(const value_type& __x) 3335{ 3336 for (value_type* __p = __begin_; __p != __end_; ++__p) 3337 *__p /= __x; 3338 return *this; 3339} 3340 3341template <class _Tp> 3342inline 3343valarray<_Tp>& 3344valarray<_Tp>::operator%=(const value_type& __x) 3345{ 3346 for (value_type* __p = __begin_; __p != __end_; ++__p) 3347 *__p %= __x; 3348 return *this; 3349} 3350 3351template <class _Tp> 3352inline 3353valarray<_Tp>& 3354valarray<_Tp>::operator+=(const value_type& __x) 3355{ 3356 for (value_type* __p = __begin_; __p != __end_; ++__p) 3357 *__p += __x; 3358 return *this; 3359} 3360 3361template <class _Tp> 3362inline 3363valarray<_Tp>& 3364valarray<_Tp>::operator-=(const value_type& __x) 3365{ 3366 for (value_type* __p = __begin_; __p != __end_; ++__p) 3367 *__p -= __x; 3368 return *this; 3369} 3370 3371template <class _Tp> 3372inline 3373valarray<_Tp>& 3374valarray<_Tp>::operator^=(const value_type& __x) 3375{ 3376 for (value_type* __p = __begin_; __p != __end_; ++__p) 3377 *__p ^= __x; 3378 return *this; 3379} 3380 3381template <class _Tp> 3382inline 3383valarray<_Tp>& 3384valarray<_Tp>::operator&=(const value_type& __x) 3385{ 3386 for (value_type* __p = __begin_; __p != __end_; ++__p) 3387 *__p &= __x; 3388 return *this; 3389} 3390 3391template <class _Tp> 3392inline 3393valarray<_Tp>& 3394valarray<_Tp>::operator|=(const value_type& __x) 3395{ 3396 for (value_type* __p = __begin_; __p != __end_; ++__p) 3397 *__p |= __x; 3398 return *this; 3399} 3400 3401template <class _Tp> 3402inline 3403valarray<_Tp>& 3404valarray<_Tp>::operator<<=(const value_type& __x) 3405{ 3406 for (value_type* __p = __begin_; __p != __end_; ++__p) 3407 *__p <<= __x; 3408 return *this; 3409} 3410 3411template <class _Tp> 3412inline 3413valarray<_Tp>& 3414valarray<_Tp>::operator>>=(const value_type& __x) 3415{ 3416 for (value_type* __p = __begin_; __p != __end_; ++__p) 3417 *__p >>= __x; 3418 return *this; 3419} 3420 3421template <class _Tp> 3422template <class _Expr> 3423inline 3424typename enable_if 3425< 3426 __is_val_expr<_Expr>::value, 3427 valarray<_Tp>& 3428>::type 3429valarray<_Tp>::operator*=(const _Expr& __v) 3430{ 3431 size_t __i = 0; 3432 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3433 *__t *= __v[__i]; 3434 return *this; 3435} 3436 3437template <class _Tp> 3438template <class _Expr> 3439inline 3440typename enable_if 3441< 3442 __is_val_expr<_Expr>::value, 3443 valarray<_Tp>& 3444>::type 3445valarray<_Tp>::operator/=(const _Expr& __v) 3446{ 3447 size_t __i = 0; 3448 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3449 *__t /= __v[__i]; 3450 return *this; 3451} 3452 3453template <class _Tp> 3454template <class _Expr> 3455inline 3456typename enable_if 3457< 3458 __is_val_expr<_Expr>::value, 3459 valarray<_Tp>& 3460>::type 3461valarray<_Tp>::operator%=(const _Expr& __v) 3462{ 3463 size_t __i = 0; 3464 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3465 *__t %= __v[__i]; 3466 return *this; 3467} 3468 3469template <class _Tp> 3470template <class _Expr> 3471inline 3472typename enable_if 3473< 3474 __is_val_expr<_Expr>::value, 3475 valarray<_Tp>& 3476>::type 3477valarray<_Tp>::operator+=(const _Expr& __v) 3478{ 3479 size_t __i = 0; 3480 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3481 *__t += __v[__i]; 3482 return *this; 3483} 3484 3485template <class _Tp> 3486template <class _Expr> 3487inline 3488typename enable_if 3489< 3490 __is_val_expr<_Expr>::value, 3491 valarray<_Tp>& 3492>::type 3493valarray<_Tp>::operator-=(const _Expr& __v) 3494{ 3495 size_t __i = 0; 3496 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3497 *__t -= __v[__i]; 3498 return *this; 3499} 3500 3501template <class _Tp> 3502template <class _Expr> 3503inline 3504typename enable_if 3505< 3506 __is_val_expr<_Expr>::value, 3507 valarray<_Tp>& 3508>::type 3509valarray<_Tp>::operator^=(const _Expr& __v) 3510{ 3511 size_t __i = 0; 3512 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3513 *__t ^= __v[__i]; 3514 return *this; 3515} 3516 3517template <class _Tp> 3518template <class _Expr> 3519inline 3520typename enable_if 3521< 3522 __is_val_expr<_Expr>::value, 3523 valarray<_Tp>& 3524>::type 3525valarray<_Tp>::operator|=(const _Expr& __v) 3526{ 3527 size_t __i = 0; 3528 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3529 *__t |= __v[__i]; 3530 return *this; 3531} 3532 3533template <class _Tp> 3534template <class _Expr> 3535inline 3536typename enable_if 3537< 3538 __is_val_expr<_Expr>::value, 3539 valarray<_Tp>& 3540>::type 3541valarray<_Tp>::operator&=(const _Expr& __v) 3542{ 3543 size_t __i = 0; 3544 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3545 *__t &= __v[__i]; 3546 return *this; 3547} 3548 3549template <class _Tp> 3550template <class _Expr> 3551inline 3552typename enable_if 3553< 3554 __is_val_expr<_Expr>::value, 3555 valarray<_Tp>& 3556>::type 3557valarray<_Tp>::operator<<=(const _Expr& __v) 3558{ 3559 size_t __i = 0; 3560 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3561 *__t <<= __v[__i]; 3562 return *this; 3563} 3564 3565template <class _Tp> 3566template <class _Expr> 3567inline 3568typename enable_if 3569< 3570 __is_val_expr<_Expr>::value, 3571 valarray<_Tp>& 3572>::type 3573valarray<_Tp>::operator>>=(const _Expr& __v) 3574{ 3575 size_t __i = 0; 3576 for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i) 3577 *__t >>= __v[__i]; 3578 return *this; 3579} 3580 3581template <class _Tp> 3582inline 3583void 3584valarray<_Tp>::swap(valarray& __v) _NOEXCEPT 3585{ 3586 _VSTD::swap(__begin_, __v.__begin_); 3587 _VSTD::swap(__end_, __v.__end_); 3588} 3589 3590template <class _Tp> 3591inline 3592_Tp 3593valarray<_Tp>::sum() const 3594{ 3595 if (__begin_ == __end_) 3596 return value_type(); 3597 const value_type* __p = __begin_; 3598 _Tp __r = *__p; 3599 for (++__p; __p != __end_; ++__p) 3600 __r += *__p; 3601 return __r; 3602} 3603 3604template <class _Tp> 3605inline 3606_Tp 3607valarray<_Tp>::min() const 3608{ 3609 if (__begin_ == __end_) 3610 return value_type(); 3611 return *_VSTD::min_element(__begin_, __end_); 3612} 3613 3614template <class _Tp> 3615inline 3616_Tp 3617valarray<_Tp>::max() const 3618{ 3619 if (__begin_ == __end_) 3620 return value_type(); 3621 return *_VSTD::max_element(__begin_, __end_); 3622} 3623 3624template <class _Tp> 3625valarray<_Tp> 3626valarray<_Tp>::shift(int __i) const 3627{ 3628 valarray<value_type> __r; 3629 size_t __n = size(); 3630 if (__n) 3631 { 3632 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n); 3633 const value_type* __sb; 3634 value_type* __tb; 3635 value_type* __te; 3636 if (__i >= 0) 3637 { 3638 __i = _VSTD::min(__i, static_cast<int>(__n)); 3639 __sb = __begin_ + __i; 3640 __tb = __r.__begin_; 3641 __te = __r.__begin_ + (__n - __i); 3642 } 3643 else 3644 { 3645 __i = _VSTD::min(-__i, static_cast<int>(__n)); 3646 __sb = __begin_; 3647 __tb = __r.__begin_ + __i; 3648 __te = __r.__begin_ + __n; 3649 } 3650 for (; __r.__end_ != __tb; ++__r.__end_) 3651 ::new ((void*)__r.__end_) value_type(); 3652 for (; __r.__end_ != __te; ++__r.__end_, ++__sb) 3653 ::new ((void*)__r.__end_) value_type(*__sb); 3654 for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_) 3655 ::new ((void*)__r.__end_) value_type(); 3656 } 3657 return __r; 3658} 3659 3660template <class _Tp> 3661valarray<_Tp> 3662valarray<_Tp>::cshift(int __i) const 3663{ 3664 valarray<value_type> __r; 3665 size_t __n = size(); 3666 if (__n) 3667 { 3668 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n); 3669 __i %= static_cast<int>(__n); 3670 const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i; 3671 for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s) 3672 ::new ((void*)__r.__end_) value_type(*__s); 3673 for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s) 3674 ::new ((void*)__r.__end_) value_type(*__s); 3675 } 3676 return __r; 3677} 3678 3679template <class _Tp> 3680valarray<_Tp> 3681valarray<_Tp>::apply(value_type __f(value_type)) const 3682{ 3683 valarray<value_type> __r; 3684 size_t __n = size(); 3685 if (__n) 3686 { 3687 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n); 3688 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) 3689 ::new ((void*)__r.__end_) value_type(__f(*__p)); 3690 } 3691 return __r; 3692} 3693 3694template <class _Tp> 3695valarray<_Tp> 3696valarray<_Tp>::apply(value_type __f(const value_type&)) const 3697{ 3698 valarray<value_type> __r; 3699 size_t __n = size(); 3700 if (__n) 3701 { 3702 __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n); 3703 for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n) 3704 ::new ((void*)__r.__end_) value_type(__f(*__p)); 3705 } 3706 return __r; 3707} 3708 3709template <class _Tp> 3710inline 3711void valarray<_Tp>::__clear(size_t __capacity) 3712{ 3713 if (__begin_ != nullptr) 3714 { 3715 while (__end_ != __begin_) 3716 (--__end_)->~value_type(); 3717 allocator<value_type>().deallocate(__begin_, __capacity); 3718 __begin_ = __end_ = nullptr; 3719 } 3720} 3721 3722template <class _Tp> 3723void 3724valarray<_Tp>::resize(size_t __n, value_type __x) 3725{ 3726 __clear(size()); 3727 if (__n) 3728 { 3729 __begin_ = __end_ = allocator<value_type>().allocate(__n); 3730#ifndef _LIBCPP_NO_EXCEPTIONS 3731 try 3732 { 3733#endif // _LIBCPP_NO_EXCEPTIONS 3734 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_) 3735 ::new ((void*)__end_) value_type(__x); 3736#ifndef _LIBCPP_NO_EXCEPTIONS 3737 } 3738 catch (...) 3739 { 3740 __clear(__n); 3741 throw; 3742 } 3743#endif // _LIBCPP_NO_EXCEPTIONS 3744 } 3745} 3746 3747template<class _Tp> 3748inline _LIBCPP_INLINE_VISIBILITY 3749void 3750swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT 3751{ 3752 __x.swap(__y); 3753} 3754 3755template<class _Expr1, class _Expr2> 3756inline _LIBCPP_INLINE_VISIBILITY 3757typename enable_if 3758< 3759 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3760 __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> > 3761>::type 3762operator*(const _Expr1& __x, const _Expr2& __y) 3763{ 3764 typedef typename _Expr1::value_type value_type; 3765 typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op; 3766 return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y)); 3767} 3768 3769template<class _Expr> 3770inline _LIBCPP_INLINE_VISIBILITY 3771typename enable_if 3772< 3773 __is_val_expr<_Expr>::value, 3774 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>, 3775 _Expr, __scalar_expr<typename _Expr::value_type> > > 3776>::type 3777operator*(const _Expr& __x, const typename _Expr::value_type& __y) 3778{ 3779 typedef typename _Expr::value_type value_type; 3780 typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3781 return __val_expr<_Op>(_Op(multiplies<value_type>(), 3782 __x, __scalar_expr<value_type>(__y, __x.size()))); 3783} 3784 3785template<class _Expr> 3786inline _LIBCPP_INLINE_VISIBILITY 3787typename enable_if 3788< 3789 __is_val_expr<_Expr>::value, 3790 __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>, 3791 __scalar_expr<typename _Expr::value_type>, _Expr> > 3792>::type 3793operator*(const typename _Expr::value_type& __x, const _Expr& __y) 3794{ 3795 typedef typename _Expr::value_type value_type; 3796 typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3797 return __val_expr<_Op>(_Op(multiplies<value_type>(), 3798 __scalar_expr<value_type>(__x, __y.size()), __y)); 3799} 3800 3801template<class _Expr1, class _Expr2> 3802inline _LIBCPP_INLINE_VISIBILITY 3803typename enable_if 3804< 3805 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3806 __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> > 3807>::type 3808operator/(const _Expr1& __x, const _Expr2& __y) 3809{ 3810 typedef typename _Expr1::value_type value_type; 3811 typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op; 3812 return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y)); 3813} 3814 3815template<class _Expr> 3816inline _LIBCPP_INLINE_VISIBILITY 3817typename enable_if 3818< 3819 __is_val_expr<_Expr>::value, 3820 __val_expr<_BinaryOp<divides<typename _Expr::value_type>, 3821 _Expr, __scalar_expr<typename _Expr::value_type> > > 3822>::type 3823operator/(const _Expr& __x, const typename _Expr::value_type& __y) 3824{ 3825 typedef typename _Expr::value_type value_type; 3826 typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3827 return __val_expr<_Op>(_Op(divides<value_type>(), 3828 __x, __scalar_expr<value_type>(__y, __x.size()))); 3829} 3830 3831template<class _Expr> 3832inline _LIBCPP_INLINE_VISIBILITY 3833typename enable_if 3834< 3835 __is_val_expr<_Expr>::value, 3836 __val_expr<_BinaryOp<divides<typename _Expr::value_type>, 3837 __scalar_expr<typename _Expr::value_type>, _Expr> > 3838>::type 3839operator/(const typename _Expr::value_type& __x, const _Expr& __y) 3840{ 3841 typedef typename _Expr::value_type value_type; 3842 typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3843 return __val_expr<_Op>(_Op(divides<value_type>(), 3844 __scalar_expr<value_type>(__x, __y.size()), __y)); 3845} 3846 3847template<class _Expr1, class _Expr2> 3848inline _LIBCPP_INLINE_VISIBILITY 3849typename enable_if 3850< 3851 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3852 __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> > 3853>::type 3854operator%(const _Expr1& __x, const _Expr2& __y) 3855{ 3856 typedef typename _Expr1::value_type value_type; 3857 typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op; 3858 return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y)); 3859} 3860 3861template<class _Expr> 3862inline _LIBCPP_INLINE_VISIBILITY 3863typename enable_if 3864< 3865 __is_val_expr<_Expr>::value, 3866 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>, 3867 _Expr, __scalar_expr<typename _Expr::value_type> > > 3868>::type 3869operator%(const _Expr& __x, const typename _Expr::value_type& __y) 3870{ 3871 typedef typename _Expr::value_type value_type; 3872 typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3873 return __val_expr<_Op>(_Op(modulus<value_type>(), 3874 __x, __scalar_expr<value_type>(__y, __x.size()))); 3875} 3876 3877template<class _Expr> 3878inline _LIBCPP_INLINE_VISIBILITY 3879typename enable_if 3880< 3881 __is_val_expr<_Expr>::value, 3882 __val_expr<_BinaryOp<modulus<typename _Expr::value_type>, 3883 __scalar_expr<typename _Expr::value_type>, _Expr> > 3884>::type 3885operator%(const typename _Expr::value_type& __x, const _Expr& __y) 3886{ 3887 typedef typename _Expr::value_type value_type; 3888 typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3889 return __val_expr<_Op>(_Op(modulus<value_type>(), 3890 __scalar_expr<value_type>(__x, __y.size()), __y)); 3891} 3892 3893template<class _Expr1, class _Expr2> 3894inline _LIBCPP_INLINE_VISIBILITY 3895typename enable_if 3896< 3897 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3898 __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> > 3899>::type 3900operator+(const _Expr1& __x, const _Expr2& __y) 3901{ 3902 typedef typename _Expr1::value_type value_type; 3903 typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op; 3904 return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y)); 3905} 3906 3907template<class _Expr> 3908inline _LIBCPP_INLINE_VISIBILITY 3909typename enable_if 3910< 3911 __is_val_expr<_Expr>::value, 3912 __val_expr<_BinaryOp<plus<typename _Expr::value_type>, 3913 _Expr, __scalar_expr<typename _Expr::value_type> > > 3914>::type 3915operator+(const _Expr& __x, const typename _Expr::value_type& __y) 3916{ 3917 typedef typename _Expr::value_type value_type; 3918 typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3919 return __val_expr<_Op>(_Op(plus<value_type>(), 3920 __x, __scalar_expr<value_type>(__y, __x.size()))); 3921} 3922 3923template<class _Expr> 3924inline _LIBCPP_INLINE_VISIBILITY 3925typename enable_if 3926< 3927 __is_val_expr<_Expr>::value, 3928 __val_expr<_BinaryOp<plus<typename _Expr::value_type>, 3929 __scalar_expr<typename _Expr::value_type>, _Expr> > 3930>::type 3931operator+(const typename _Expr::value_type& __x, const _Expr& __y) 3932{ 3933 typedef typename _Expr::value_type value_type; 3934 typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3935 return __val_expr<_Op>(_Op(plus<value_type>(), 3936 __scalar_expr<value_type>(__x, __y.size()), __y)); 3937} 3938 3939template<class _Expr1, class _Expr2> 3940inline _LIBCPP_INLINE_VISIBILITY 3941typename enable_if 3942< 3943 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3944 __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> > 3945>::type 3946operator-(const _Expr1& __x, const _Expr2& __y) 3947{ 3948 typedef typename _Expr1::value_type value_type; 3949 typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op; 3950 return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y)); 3951} 3952 3953template<class _Expr> 3954inline _LIBCPP_INLINE_VISIBILITY 3955typename enable_if 3956< 3957 __is_val_expr<_Expr>::value, 3958 __val_expr<_BinaryOp<minus<typename _Expr::value_type>, 3959 _Expr, __scalar_expr<typename _Expr::value_type> > > 3960>::type 3961operator-(const _Expr& __x, const typename _Expr::value_type& __y) 3962{ 3963 typedef typename _Expr::value_type value_type; 3964 typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op; 3965 return __val_expr<_Op>(_Op(minus<value_type>(), 3966 __x, __scalar_expr<value_type>(__y, __x.size()))); 3967} 3968 3969template<class _Expr> 3970inline _LIBCPP_INLINE_VISIBILITY 3971typename enable_if 3972< 3973 __is_val_expr<_Expr>::value, 3974 __val_expr<_BinaryOp<minus<typename _Expr::value_type>, 3975 __scalar_expr<typename _Expr::value_type>, _Expr> > 3976>::type 3977operator-(const typename _Expr::value_type& __x, const _Expr& __y) 3978{ 3979 typedef typename _Expr::value_type value_type; 3980 typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op; 3981 return __val_expr<_Op>(_Op(minus<value_type>(), 3982 __scalar_expr<value_type>(__x, __y.size()), __y)); 3983} 3984 3985template<class _Expr1, class _Expr2> 3986inline _LIBCPP_INLINE_VISIBILITY 3987typename enable_if 3988< 3989 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 3990 __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> > 3991>::type 3992operator^(const _Expr1& __x, const _Expr2& __y) 3993{ 3994 typedef typename _Expr1::value_type value_type; 3995 typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op; 3996 return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y)); 3997} 3998 3999template<class _Expr> 4000inline _LIBCPP_INLINE_VISIBILITY 4001typename enable_if 4002< 4003 __is_val_expr<_Expr>::value, 4004 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>, 4005 _Expr, __scalar_expr<typename _Expr::value_type> > > 4006>::type 4007operator^(const _Expr& __x, const typename _Expr::value_type& __y) 4008{ 4009 typedef typename _Expr::value_type value_type; 4010 typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4011 return __val_expr<_Op>(_Op(bit_xor<value_type>(), 4012 __x, __scalar_expr<value_type>(__y, __x.size()))); 4013} 4014 4015template<class _Expr> 4016inline _LIBCPP_INLINE_VISIBILITY 4017typename enable_if 4018< 4019 __is_val_expr<_Expr>::value, 4020 __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>, 4021 __scalar_expr<typename _Expr::value_type>, _Expr> > 4022>::type 4023operator^(const typename _Expr::value_type& __x, const _Expr& __y) 4024{ 4025 typedef typename _Expr::value_type value_type; 4026 typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4027 return __val_expr<_Op>(_Op(bit_xor<value_type>(), 4028 __scalar_expr<value_type>(__x, __y.size()), __y)); 4029} 4030 4031template<class _Expr1, class _Expr2> 4032inline _LIBCPP_INLINE_VISIBILITY 4033typename enable_if 4034< 4035 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4036 __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> > 4037>::type 4038operator&(const _Expr1& __x, const _Expr2& __y) 4039{ 4040 typedef typename _Expr1::value_type value_type; 4041 typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op; 4042 return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y)); 4043} 4044 4045template<class _Expr> 4046inline _LIBCPP_INLINE_VISIBILITY 4047typename enable_if 4048< 4049 __is_val_expr<_Expr>::value, 4050 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>, 4051 _Expr, __scalar_expr<typename _Expr::value_type> > > 4052>::type 4053operator&(const _Expr& __x, const typename _Expr::value_type& __y) 4054{ 4055 typedef typename _Expr::value_type value_type; 4056 typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4057 return __val_expr<_Op>(_Op(bit_and<value_type>(), 4058 __x, __scalar_expr<value_type>(__y, __x.size()))); 4059} 4060 4061template<class _Expr> 4062inline _LIBCPP_INLINE_VISIBILITY 4063typename enable_if 4064< 4065 __is_val_expr<_Expr>::value, 4066 __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>, 4067 __scalar_expr<typename _Expr::value_type>, _Expr> > 4068>::type 4069operator&(const typename _Expr::value_type& __x, const _Expr& __y) 4070{ 4071 typedef typename _Expr::value_type value_type; 4072 typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4073 return __val_expr<_Op>(_Op(bit_and<value_type>(), 4074 __scalar_expr<value_type>(__x, __y.size()), __y)); 4075} 4076 4077template<class _Expr1, class _Expr2> 4078inline _LIBCPP_INLINE_VISIBILITY 4079typename enable_if 4080< 4081 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4082 __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> > 4083>::type 4084operator|(const _Expr1& __x, const _Expr2& __y) 4085{ 4086 typedef typename _Expr1::value_type value_type; 4087 typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op; 4088 return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y)); 4089} 4090 4091template<class _Expr> 4092inline _LIBCPP_INLINE_VISIBILITY 4093typename enable_if 4094< 4095 __is_val_expr<_Expr>::value, 4096 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>, 4097 _Expr, __scalar_expr<typename _Expr::value_type> > > 4098>::type 4099operator|(const _Expr& __x, const typename _Expr::value_type& __y) 4100{ 4101 typedef typename _Expr::value_type value_type; 4102 typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4103 return __val_expr<_Op>(_Op(bit_or<value_type>(), 4104 __x, __scalar_expr<value_type>(__y, __x.size()))); 4105} 4106 4107template<class _Expr> 4108inline _LIBCPP_INLINE_VISIBILITY 4109typename enable_if 4110< 4111 __is_val_expr<_Expr>::value, 4112 __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>, 4113 __scalar_expr<typename _Expr::value_type>, _Expr> > 4114>::type 4115operator|(const typename _Expr::value_type& __x, const _Expr& __y) 4116{ 4117 typedef typename _Expr::value_type value_type; 4118 typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4119 return __val_expr<_Op>(_Op(bit_or<value_type>(), 4120 __scalar_expr<value_type>(__x, __y.size()), __y)); 4121} 4122 4123template<class _Expr1, class _Expr2> 4124inline _LIBCPP_INLINE_VISIBILITY 4125typename enable_if 4126< 4127 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4128 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> > 4129>::type 4130operator<<(const _Expr1& __x, const _Expr2& __y) 4131{ 4132 typedef typename _Expr1::value_type value_type; 4133 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op; 4134 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y)); 4135} 4136 4137template<class _Expr> 4138inline _LIBCPP_INLINE_VISIBILITY 4139typename enable_if 4140< 4141 __is_val_expr<_Expr>::value, 4142 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>, 4143 _Expr, __scalar_expr<typename _Expr::value_type> > > 4144>::type 4145operator<<(const _Expr& __x, const typename _Expr::value_type& __y) 4146{ 4147 typedef typename _Expr::value_type value_type; 4148 typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4149 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), 4150 __x, __scalar_expr<value_type>(__y, __x.size()))); 4151} 4152 4153template<class _Expr> 4154inline _LIBCPP_INLINE_VISIBILITY 4155typename enable_if 4156< 4157 __is_val_expr<_Expr>::value, 4158 __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>, 4159 __scalar_expr<typename _Expr::value_type>, _Expr> > 4160>::type 4161operator<<(const typename _Expr::value_type& __x, const _Expr& __y) 4162{ 4163 typedef typename _Expr::value_type value_type; 4164 typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4165 return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), 4166 __scalar_expr<value_type>(__x, __y.size()), __y)); 4167} 4168 4169template<class _Expr1, class _Expr2> 4170inline _LIBCPP_INLINE_VISIBILITY 4171typename enable_if 4172< 4173 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4174 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> > 4175>::type 4176operator>>(const _Expr1& __x, const _Expr2& __y) 4177{ 4178 typedef typename _Expr1::value_type value_type; 4179 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op; 4180 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y)); 4181} 4182 4183template<class _Expr> 4184inline _LIBCPP_INLINE_VISIBILITY 4185typename enable_if 4186< 4187 __is_val_expr<_Expr>::value, 4188 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>, 4189 _Expr, __scalar_expr<typename _Expr::value_type> > > 4190>::type 4191operator>>(const _Expr& __x, const typename _Expr::value_type& __y) 4192{ 4193 typedef typename _Expr::value_type value_type; 4194 typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4195 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), 4196 __x, __scalar_expr<value_type>(__y, __x.size()))); 4197} 4198 4199template<class _Expr> 4200inline _LIBCPP_INLINE_VISIBILITY 4201typename enable_if 4202< 4203 __is_val_expr<_Expr>::value, 4204 __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>, 4205 __scalar_expr<typename _Expr::value_type>, _Expr> > 4206>::type 4207operator>>(const typename _Expr::value_type& __x, const _Expr& __y) 4208{ 4209 typedef typename _Expr::value_type value_type; 4210 typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4211 return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), 4212 __scalar_expr<value_type>(__x, __y.size()), __y)); 4213} 4214 4215template<class _Expr1, class _Expr2> 4216inline _LIBCPP_INLINE_VISIBILITY 4217typename enable_if 4218< 4219 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4220 __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> > 4221>::type 4222operator&&(const _Expr1& __x, const _Expr2& __y) 4223{ 4224 typedef typename _Expr1::value_type value_type; 4225 typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op; 4226 return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y)); 4227} 4228 4229template<class _Expr> 4230inline _LIBCPP_INLINE_VISIBILITY 4231typename enable_if 4232< 4233 __is_val_expr<_Expr>::value, 4234 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>, 4235 _Expr, __scalar_expr<typename _Expr::value_type> > > 4236>::type 4237operator&&(const _Expr& __x, const typename _Expr::value_type& __y) 4238{ 4239 typedef typename _Expr::value_type value_type; 4240 typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4241 return __val_expr<_Op>(_Op(logical_and<value_type>(), 4242 __x, __scalar_expr<value_type>(__y, __x.size()))); 4243} 4244 4245template<class _Expr> 4246inline _LIBCPP_INLINE_VISIBILITY 4247typename enable_if 4248< 4249 __is_val_expr<_Expr>::value, 4250 __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>, 4251 __scalar_expr<typename _Expr::value_type>, _Expr> > 4252>::type 4253operator&&(const typename _Expr::value_type& __x, const _Expr& __y) 4254{ 4255 typedef typename _Expr::value_type value_type; 4256 typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4257 return __val_expr<_Op>(_Op(logical_and<value_type>(), 4258 __scalar_expr<value_type>(__x, __y.size()), __y)); 4259} 4260 4261template<class _Expr1, class _Expr2> 4262inline _LIBCPP_INLINE_VISIBILITY 4263typename enable_if 4264< 4265 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4266 __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> > 4267>::type 4268operator||(const _Expr1& __x, const _Expr2& __y) 4269{ 4270 typedef typename _Expr1::value_type value_type; 4271 typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op; 4272 return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y)); 4273} 4274 4275template<class _Expr> 4276inline _LIBCPP_INLINE_VISIBILITY 4277typename enable_if 4278< 4279 __is_val_expr<_Expr>::value, 4280 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>, 4281 _Expr, __scalar_expr<typename _Expr::value_type> > > 4282>::type 4283operator||(const _Expr& __x, const typename _Expr::value_type& __y) 4284{ 4285 typedef typename _Expr::value_type value_type; 4286 typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4287 return __val_expr<_Op>(_Op(logical_or<value_type>(), 4288 __x, __scalar_expr<value_type>(__y, __x.size()))); 4289} 4290 4291template<class _Expr> 4292inline _LIBCPP_INLINE_VISIBILITY 4293typename enable_if 4294< 4295 __is_val_expr<_Expr>::value, 4296 __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>, 4297 __scalar_expr<typename _Expr::value_type>, _Expr> > 4298>::type 4299operator||(const typename _Expr::value_type& __x, const _Expr& __y) 4300{ 4301 typedef typename _Expr::value_type value_type; 4302 typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4303 return __val_expr<_Op>(_Op(logical_or<value_type>(), 4304 __scalar_expr<value_type>(__x, __y.size()), __y)); 4305} 4306 4307template<class _Expr1, class _Expr2> 4308inline _LIBCPP_INLINE_VISIBILITY 4309typename enable_if 4310< 4311 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4312 __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> > 4313>::type 4314operator==(const _Expr1& __x, const _Expr2& __y) 4315{ 4316 typedef typename _Expr1::value_type value_type; 4317 typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op; 4318 return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y)); 4319} 4320 4321template<class _Expr> 4322inline _LIBCPP_INLINE_VISIBILITY 4323typename enable_if 4324< 4325 __is_val_expr<_Expr>::value, 4326 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>, 4327 _Expr, __scalar_expr<typename _Expr::value_type> > > 4328>::type 4329operator==(const _Expr& __x, const typename _Expr::value_type& __y) 4330{ 4331 typedef typename _Expr::value_type value_type; 4332 typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4333 return __val_expr<_Op>(_Op(equal_to<value_type>(), 4334 __x, __scalar_expr<value_type>(__y, __x.size()))); 4335} 4336 4337template<class _Expr> 4338inline _LIBCPP_INLINE_VISIBILITY 4339typename enable_if 4340< 4341 __is_val_expr<_Expr>::value, 4342 __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>, 4343 __scalar_expr<typename _Expr::value_type>, _Expr> > 4344>::type 4345operator==(const typename _Expr::value_type& __x, const _Expr& __y) 4346{ 4347 typedef typename _Expr::value_type value_type; 4348 typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4349 return __val_expr<_Op>(_Op(equal_to<value_type>(), 4350 __scalar_expr<value_type>(__x, __y.size()), __y)); 4351} 4352 4353template<class _Expr1, class _Expr2> 4354inline _LIBCPP_INLINE_VISIBILITY 4355typename enable_if 4356< 4357 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4358 __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> > 4359>::type 4360operator!=(const _Expr1& __x, const _Expr2& __y) 4361{ 4362 typedef typename _Expr1::value_type value_type; 4363 typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op; 4364 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y)); 4365} 4366 4367template<class _Expr> 4368inline _LIBCPP_INLINE_VISIBILITY 4369typename enable_if 4370< 4371 __is_val_expr<_Expr>::value, 4372 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>, 4373 _Expr, __scalar_expr<typename _Expr::value_type> > > 4374>::type 4375operator!=(const _Expr& __x, const typename _Expr::value_type& __y) 4376{ 4377 typedef typename _Expr::value_type value_type; 4378 typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4379 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), 4380 __x, __scalar_expr<value_type>(__y, __x.size()))); 4381} 4382 4383template<class _Expr> 4384inline _LIBCPP_INLINE_VISIBILITY 4385typename enable_if 4386< 4387 __is_val_expr<_Expr>::value, 4388 __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>, 4389 __scalar_expr<typename _Expr::value_type>, _Expr> > 4390>::type 4391operator!=(const typename _Expr::value_type& __x, const _Expr& __y) 4392{ 4393 typedef typename _Expr::value_type value_type; 4394 typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4395 return __val_expr<_Op>(_Op(not_equal_to<value_type>(), 4396 __scalar_expr<value_type>(__x, __y.size()), __y)); 4397} 4398 4399template<class _Expr1, class _Expr2> 4400inline _LIBCPP_INLINE_VISIBILITY 4401typename enable_if 4402< 4403 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4404 __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> > 4405>::type 4406operator<(const _Expr1& __x, const _Expr2& __y) 4407{ 4408 typedef typename _Expr1::value_type value_type; 4409 typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op; 4410 return __val_expr<_Op>(_Op(less<value_type>(), __x, __y)); 4411} 4412 4413template<class _Expr> 4414inline _LIBCPP_INLINE_VISIBILITY 4415typename enable_if 4416< 4417 __is_val_expr<_Expr>::value, 4418 __val_expr<_BinaryOp<less<typename _Expr::value_type>, 4419 _Expr, __scalar_expr<typename _Expr::value_type> > > 4420>::type 4421operator<(const _Expr& __x, const typename _Expr::value_type& __y) 4422{ 4423 typedef typename _Expr::value_type value_type; 4424 typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4425 return __val_expr<_Op>(_Op(less<value_type>(), 4426 __x, __scalar_expr<value_type>(__y, __x.size()))); 4427} 4428 4429template<class _Expr> 4430inline _LIBCPP_INLINE_VISIBILITY 4431typename enable_if 4432< 4433 __is_val_expr<_Expr>::value, 4434 __val_expr<_BinaryOp<less<typename _Expr::value_type>, 4435 __scalar_expr<typename _Expr::value_type>, _Expr> > 4436>::type 4437operator<(const typename _Expr::value_type& __x, const _Expr& __y) 4438{ 4439 typedef typename _Expr::value_type value_type; 4440 typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4441 return __val_expr<_Op>(_Op(less<value_type>(), 4442 __scalar_expr<value_type>(__x, __y.size()), __y)); 4443} 4444 4445template<class _Expr1, class _Expr2> 4446inline _LIBCPP_INLINE_VISIBILITY 4447typename enable_if 4448< 4449 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4450 __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> > 4451>::type 4452operator>(const _Expr1& __x, const _Expr2& __y) 4453{ 4454 typedef typename _Expr1::value_type value_type; 4455 typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op; 4456 return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y)); 4457} 4458 4459template<class _Expr> 4460inline _LIBCPP_INLINE_VISIBILITY 4461typename enable_if 4462< 4463 __is_val_expr<_Expr>::value, 4464 __val_expr<_BinaryOp<greater<typename _Expr::value_type>, 4465 _Expr, __scalar_expr<typename _Expr::value_type> > > 4466>::type 4467operator>(const _Expr& __x, const typename _Expr::value_type& __y) 4468{ 4469 typedef typename _Expr::value_type value_type; 4470 typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4471 return __val_expr<_Op>(_Op(greater<value_type>(), 4472 __x, __scalar_expr<value_type>(__y, __x.size()))); 4473} 4474 4475template<class _Expr> 4476inline _LIBCPP_INLINE_VISIBILITY 4477typename enable_if 4478< 4479 __is_val_expr<_Expr>::value, 4480 __val_expr<_BinaryOp<greater<typename _Expr::value_type>, 4481 __scalar_expr<typename _Expr::value_type>, _Expr> > 4482>::type 4483operator>(const typename _Expr::value_type& __x, const _Expr& __y) 4484{ 4485 typedef typename _Expr::value_type value_type; 4486 typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4487 return __val_expr<_Op>(_Op(greater<value_type>(), 4488 __scalar_expr<value_type>(__x, __y.size()), __y)); 4489} 4490 4491template<class _Expr1, class _Expr2> 4492inline _LIBCPP_INLINE_VISIBILITY 4493typename enable_if 4494< 4495 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4496 __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> > 4497>::type 4498operator<=(const _Expr1& __x, const _Expr2& __y) 4499{ 4500 typedef typename _Expr1::value_type value_type; 4501 typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op; 4502 return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y)); 4503} 4504 4505template<class _Expr> 4506inline _LIBCPP_INLINE_VISIBILITY 4507typename enable_if 4508< 4509 __is_val_expr<_Expr>::value, 4510 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>, 4511 _Expr, __scalar_expr<typename _Expr::value_type> > > 4512>::type 4513operator<=(const _Expr& __x, const typename _Expr::value_type& __y) 4514{ 4515 typedef typename _Expr::value_type value_type; 4516 typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4517 return __val_expr<_Op>(_Op(less_equal<value_type>(), 4518 __x, __scalar_expr<value_type>(__y, __x.size()))); 4519} 4520 4521template<class _Expr> 4522inline _LIBCPP_INLINE_VISIBILITY 4523typename enable_if 4524< 4525 __is_val_expr<_Expr>::value, 4526 __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>, 4527 __scalar_expr<typename _Expr::value_type>, _Expr> > 4528>::type 4529operator<=(const typename _Expr::value_type& __x, const _Expr& __y) 4530{ 4531 typedef typename _Expr::value_type value_type; 4532 typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4533 return __val_expr<_Op>(_Op(less_equal<value_type>(), 4534 __scalar_expr<value_type>(__x, __y.size()), __y)); 4535} 4536 4537template<class _Expr1, class _Expr2> 4538inline _LIBCPP_INLINE_VISIBILITY 4539typename enable_if 4540< 4541 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4542 __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> > 4543>::type 4544operator>=(const _Expr1& __x, const _Expr2& __y) 4545{ 4546 typedef typename _Expr1::value_type value_type; 4547 typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op; 4548 return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y)); 4549} 4550 4551template<class _Expr> 4552inline _LIBCPP_INLINE_VISIBILITY 4553typename enable_if 4554< 4555 __is_val_expr<_Expr>::value, 4556 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>, 4557 _Expr, __scalar_expr<typename _Expr::value_type> > > 4558>::type 4559operator>=(const _Expr& __x, const typename _Expr::value_type& __y) 4560{ 4561 typedef typename _Expr::value_type value_type; 4562 typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4563 return __val_expr<_Op>(_Op(greater_equal<value_type>(), 4564 __x, __scalar_expr<value_type>(__y, __x.size()))); 4565} 4566 4567template<class _Expr> 4568inline _LIBCPP_INLINE_VISIBILITY 4569typename enable_if 4570< 4571 __is_val_expr<_Expr>::value, 4572 __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>, 4573 __scalar_expr<typename _Expr::value_type>, _Expr> > 4574>::type 4575operator>=(const typename _Expr::value_type& __x, const _Expr& __y) 4576{ 4577 typedef typename _Expr::value_type value_type; 4578 typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4579 return __val_expr<_Op>(_Op(greater_equal<value_type>(), 4580 __scalar_expr<value_type>(__x, __y.size()), __y)); 4581} 4582 4583template<class _Expr> 4584inline _LIBCPP_INLINE_VISIBILITY 4585typename enable_if 4586< 4587 __is_val_expr<_Expr>::value, 4588 __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> > 4589>::type 4590abs(const _Expr& __x) 4591{ 4592 typedef typename _Expr::value_type value_type; 4593 typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op; 4594 return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x)); 4595} 4596 4597template<class _Expr> 4598inline _LIBCPP_INLINE_VISIBILITY 4599typename enable_if 4600< 4601 __is_val_expr<_Expr>::value, 4602 __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> > 4603>::type 4604acos(const _Expr& __x) 4605{ 4606 typedef typename _Expr::value_type value_type; 4607 typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op; 4608 return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x)); 4609} 4610 4611template<class _Expr> 4612inline _LIBCPP_INLINE_VISIBILITY 4613typename enable_if 4614< 4615 __is_val_expr<_Expr>::value, 4616 __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> > 4617>::type 4618asin(const _Expr& __x) 4619{ 4620 typedef typename _Expr::value_type value_type; 4621 typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op; 4622 return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x)); 4623} 4624 4625template<class _Expr> 4626inline _LIBCPP_INLINE_VISIBILITY 4627typename enable_if 4628< 4629 __is_val_expr<_Expr>::value, 4630 __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> > 4631>::type 4632atan(const _Expr& __x) 4633{ 4634 typedef typename _Expr::value_type value_type; 4635 typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op; 4636 return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x)); 4637} 4638 4639template<class _Expr1, class _Expr2> 4640inline _LIBCPP_INLINE_VISIBILITY 4641typename enable_if 4642< 4643 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4644 __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> > 4645>::type 4646atan2(const _Expr1& __x, const _Expr2& __y) 4647{ 4648 typedef typename _Expr1::value_type value_type; 4649 typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op; 4650 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y)); 4651} 4652 4653template<class _Expr> 4654inline _LIBCPP_INLINE_VISIBILITY 4655typename enable_if 4656< 4657 __is_val_expr<_Expr>::value, 4658 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>, 4659 _Expr, __scalar_expr<typename _Expr::value_type> > > 4660>::type 4661atan2(const _Expr& __x, const typename _Expr::value_type& __y) 4662{ 4663 typedef typename _Expr::value_type value_type; 4664 typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4665 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), 4666 __x, __scalar_expr<value_type>(__y, __x.size()))); 4667} 4668 4669template<class _Expr> 4670inline _LIBCPP_INLINE_VISIBILITY 4671typename enable_if 4672< 4673 __is_val_expr<_Expr>::value, 4674 __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>, 4675 __scalar_expr<typename _Expr::value_type>, _Expr> > 4676>::type 4677atan2(const typename _Expr::value_type& __x, const _Expr& __y) 4678{ 4679 typedef typename _Expr::value_type value_type; 4680 typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4681 return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), 4682 __scalar_expr<value_type>(__x, __y.size()), __y)); 4683} 4684 4685template<class _Expr> 4686inline _LIBCPP_INLINE_VISIBILITY 4687typename enable_if 4688< 4689 __is_val_expr<_Expr>::value, 4690 __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> > 4691>::type 4692cos(const _Expr& __x) 4693{ 4694 typedef typename _Expr::value_type value_type; 4695 typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op; 4696 return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x)); 4697} 4698 4699template<class _Expr> 4700inline _LIBCPP_INLINE_VISIBILITY 4701typename enable_if 4702< 4703 __is_val_expr<_Expr>::value, 4704 __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> > 4705>::type 4706cosh(const _Expr& __x) 4707{ 4708 typedef typename _Expr::value_type value_type; 4709 typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op; 4710 return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x)); 4711} 4712 4713template<class _Expr> 4714inline _LIBCPP_INLINE_VISIBILITY 4715typename enable_if 4716< 4717 __is_val_expr<_Expr>::value, 4718 __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> > 4719>::type 4720exp(const _Expr& __x) 4721{ 4722 typedef typename _Expr::value_type value_type; 4723 typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op; 4724 return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x)); 4725} 4726 4727template<class _Expr> 4728inline _LIBCPP_INLINE_VISIBILITY 4729typename enable_if 4730< 4731 __is_val_expr<_Expr>::value, 4732 __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> > 4733>::type 4734log(const _Expr& __x) 4735{ 4736 typedef typename _Expr::value_type value_type; 4737 typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op; 4738 return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x)); 4739} 4740 4741template<class _Expr> 4742inline _LIBCPP_INLINE_VISIBILITY 4743typename enable_if 4744< 4745 __is_val_expr<_Expr>::value, 4746 __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> > 4747>::type 4748log10(const _Expr& __x) 4749{ 4750 typedef typename _Expr::value_type value_type; 4751 typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op; 4752 return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x)); 4753} 4754 4755template<class _Expr1, class _Expr2> 4756inline _LIBCPP_INLINE_VISIBILITY 4757typename enable_if 4758< 4759 __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, 4760 __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> > 4761>::type 4762pow(const _Expr1& __x, const _Expr2& __y) 4763{ 4764 typedef typename _Expr1::value_type value_type; 4765 typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op; 4766 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y)); 4767} 4768 4769template<class _Expr> 4770inline _LIBCPP_INLINE_VISIBILITY 4771typename enable_if 4772< 4773 __is_val_expr<_Expr>::value, 4774 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>, 4775 _Expr, __scalar_expr<typename _Expr::value_type> > > 4776>::type 4777pow(const _Expr& __x, const typename _Expr::value_type& __y) 4778{ 4779 typedef typename _Expr::value_type value_type; 4780 typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op; 4781 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), 4782 __x, __scalar_expr<value_type>(__y, __x.size()))); 4783} 4784 4785template<class _Expr> 4786inline _LIBCPP_INLINE_VISIBILITY 4787typename enable_if 4788< 4789 __is_val_expr<_Expr>::value, 4790 __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>, 4791 __scalar_expr<typename _Expr::value_type>, _Expr> > 4792>::type 4793pow(const typename _Expr::value_type& __x, const _Expr& __y) 4794{ 4795 typedef typename _Expr::value_type value_type; 4796 typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op; 4797 return __val_expr<_Op>(_Op(__pow_expr<value_type>(), 4798 __scalar_expr<value_type>(__x, __y.size()), __y)); 4799} 4800 4801template<class _Expr> 4802inline _LIBCPP_INLINE_VISIBILITY 4803typename enable_if 4804< 4805 __is_val_expr<_Expr>::value, 4806 __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> > 4807>::type 4808sin(const _Expr& __x) 4809{ 4810 typedef typename _Expr::value_type value_type; 4811 typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op; 4812 return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x)); 4813} 4814 4815template<class _Expr> 4816inline _LIBCPP_INLINE_VISIBILITY 4817typename enable_if 4818< 4819 __is_val_expr<_Expr>::value, 4820 __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> > 4821>::type 4822sinh(const _Expr& __x) 4823{ 4824 typedef typename _Expr::value_type value_type; 4825 typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op; 4826 return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x)); 4827} 4828 4829template<class _Expr> 4830inline _LIBCPP_INLINE_VISIBILITY 4831typename enable_if 4832< 4833 __is_val_expr<_Expr>::value, 4834 __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> > 4835>::type 4836sqrt(const _Expr& __x) 4837{ 4838 typedef typename _Expr::value_type value_type; 4839 typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op; 4840 return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x)); 4841} 4842 4843template<class _Expr> 4844inline _LIBCPP_INLINE_VISIBILITY 4845typename enable_if 4846< 4847 __is_val_expr<_Expr>::value, 4848 __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> > 4849>::type 4850tan(const _Expr& __x) 4851{ 4852 typedef typename _Expr::value_type value_type; 4853 typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op; 4854 return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x)); 4855} 4856 4857template<class _Expr> 4858inline _LIBCPP_INLINE_VISIBILITY 4859typename enable_if 4860< 4861 __is_val_expr<_Expr>::value, 4862 __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> > 4863>::type 4864tanh(const _Expr& __x) 4865{ 4866 typedef typename _Expr::value_type value_type; 4867 typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op; 4868 return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x)); 4869} 4870 4871template <class _Tp> 4872inline _LIBCPP_INLINE_VISIBILITY 4873_Tp* 4874begin(valarray<_Tp>& __v) 4875{ 4876 return __v.__begin_; 4877} 4878 4879template <class _Tp> 4880inline _LIBCPP_INLINE_VISIBILITY 4881const _Tp* 4882begin(const valarray<_Tp>& __v) 4883{ 4884 return __v.__begin_; 4885} 4886 4887template <class _Tp> 4888inline _LIBCPP_INLINE_VISIBILITY 4889_Tp* 4890end(valarray<_Tp>& __v) 4891{ 4892 return __v.__end_; 4893} 4894 4895template <class _Tp> 4896inline _LIBCPP_INLINE_VISIBILITY 4897const _Tp* 4898end(const valarray<_Tp>& __v) 4899{ 4900 return __v.__end_; 4901} 4902 4903_LIBCPP_END_NAMESPACE_STD 4904 4905_LIBCPP_POP_MACROS 4906 4907#endif // _LIBCPP_VALARRAY 4908