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