~ubuntu-branches/ubuntu/trusty/libc++/trusty

« back to all changes in this revision

Viewing changes to libcxx/include/valarray

  • Committer: Package Import Robot
  • Author(s): Andrej Belym
  • Date: 2012-06-02 19:25:47 UTC
  • Revision ID: package-import@ubuntu.com-20120602192547-b6ta950a8ckc9um2
Tags: upstream-1.0~svn160132
ImportĀ upstreamĀ versionĀ 1.0~svn160132

Show diffs side-by-side

added added

removed removed

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