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