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