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