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