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