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