File: valarray

package info (click to toggle)
cppreference-doc 20151129%2Bdfsg0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 220,072 kB
  • ctags: 451
  • sloc: xml: 474,959; python: 1,770; php: 263; makefile: 162; sh: 30; cpp: 9; ansic: 9
file content (381 lines) | stat: -rw-r--r-- 14,891 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/*  Copyright (C) 2015  Povilas Kanapickas <povilas@radix.lt>

    This file is part of cppreference-doc

    This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
    Unported License. To view a copy of this license, visit
    http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
    Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 1.3 or
    any later version published by the Free Software Foundation; with no
    Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
*/

#ifndef CPPREFERENCE_VALARRAY_H
#define CPPREFERENCE_VALARRAY_H

namespace std {

template<class T>
class valarray {
public:
    typedef T value_type;

    valarray();
    explicit valarray(std::size_t count);
    valarray(const T& val, std::size_t count);
    valarray(const T* vals, std::size_t count);
    valarray(const valarray& other);
#if CPPREFERENCE_STDVER>= 2011
    valarray(valarray&& other);
#endif
    valarray(const std::slice_array<T>&);
    valarray(const std::gslice_array<T>&);
    valarray(const std::mask_array<T>&);
    valarray(const std::indirect_array<T>&);
#if CPPREFERENCE_STDVER>= 2011
    valarray(std::initializer_list<T> il);
#endif

    ~valarray();

    valarray<T>& operator=(const valarray<T>& other);
#if CPPREFERENCE_STDVER>= 2011
    valarray<T>& operator=(valarray<T>&& other);
#endif
    valarray<T>& operator=(const T& val);
    valarray<T>& operator=(const std::slice_array& other);
    valarray<T>& operator=(const std::gslice_array& other);
    valarray<T>& operator=(const std::mask_array& other);
    valarray<T>& operator=(const std::indirect_array& other);
#if CPPREFERENCE_STDVER>= 2011
    valarray<T>& operator=(std::initializer_list<T> il);
#endif

    T                      operator[](std::size_t pos) const;
    const T&               operator[](std::size_t pos) const;
    T&                     operator[](std::size_t pos);
    std::valarray<T>       operator[](std::slice slicearr) const;
    std::slice_array<T>    operator[](std::slice slicearr);
    std::valarray<T>       operator[](const std::gslice& gslicearr) const;
    std::gslice_array<T>   operator[](const std::gslice& gslicearr);
    std::valarray<T>       operator[](const valarray<bool>& boolarr) const;
    std::mask_array<T>     operator[](const valarray<bool>& boolarr);
    std::valarray<T>       operator[](const valarray<std::size_t>& indarr) const;
    std::indirect_array<T> operator[](const valarray<std::size_t>& indarr);

    valarray<T> operator+() const;
    valarray<T> operator-() const;
    valarray<T> operator~() const;
    valarray<bool> operator!() const;

    valarray<T> operator+=(const valarray<T>& v);
    valarray<T> operator-=(const valarray<T>& v);
    valarray<T> operator*=(const valarray<T>& v);
    valarray<T> operator/=(const valarray<T>& v);
    valarray<T> operator%=(const valarray<T>& v);
    valarray<T> operator&=(const valarray<T>& v);
    valarray<T> operator|=(const valarray<T>& v);
    valarray<T> operator^=(const valarray<T>& v);
    valarray<T> operator<<=(const valarray<T>& v);
    valarray<T> operator>>=(const valarray<T>& v);
    valarray<T> operator+=(const T& val);

    valarray<T> operator-=(const T& val);
    valarray<T> operator*=(const T& val);
    valarray<T> operator/=(const T& val);
    valarray<T> operator%=(const T& val);
    valarray<T> operator&=(const T& val);
    valarray<T> operator|=(const T& val);
    valarray<T> operator^=(const T& val);
    valarray<T> operator<<=(const T& val);
    valarray<T> operator>>=(const T& val);

    void swap(valarray& other);

    std::size_t size() const;
    void resize(std::size_t count, T value = T());

    T sum() const;
    T min() const;
    T max() const;

    valarray shift(int count) const;
    valarray cshift(int count) const;
    valarray<T> apply(T func(T)) const;
    valarray<T> apply(T func(const T&)) const;
};

template<class T>
void swap(valarray<T>& lhs, valarray<T>& rhs);

struct __unspecified;

#if CPPREFERENCE_STDVER>= 2011
template<class T>
__unspecified begin(valarray<T>& v);

template<class T>
__unspecified begin(const valarray<T>& v);

template<class T>
__unspecified end(valarray<T>& v);

template<class T>
__unspecified end(const valarray<T>& v);
#endif

template <class T> std::valarray<T> operator+ (const std::valarray<T>& lhs, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator- (const std::valarray<T>& lhs, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator* (const std::valarray<T>& lhs, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator/ (const std::valarray<T>& lhs, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator% (const std::valarray<T>& lhs, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator& (const std::valarray<T>& lhs, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator| (const std::valarray<T>& lhs, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator^ (const std::valarray<T>& lhs, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator<<(const std::valarray<T>& lhs, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator>> (const std::valarray<T>& lhs, const std::valarray<T>& rhs);
template <class T> std::valarray<bool> operator&&(const std::valarray<T>& lhs, const std::valarray<T>& rhs);
template <class T> std::valarray<bool> operator||(const std::valarray<T>& lhs, const std::valarray<T>& rhs);

template <class T> std::valarray<T> operator+ (const T& val, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator- (const T& val, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator* (const T& val, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator/ (const T& val, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator% (const T& val, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator& (const T& val, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator| (const T& val, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator^ (const T& val, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator<<(const T& val, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator>> (const T& val, const std::valarray<T>& rhs);
template <class T> std::valarray<bool> operator&&(const T& val, const std::valarray<T>& rhs);
template <class T> std::valarray<bool> operator||(const T& val, const std::valarray<T>& rhs);

template <class T> std::valarray<T> operator+ (const std::valarray<T>& lhs, const T& rhs);
template <class T> std::valarray<T> operator- (const std::valarray<T>& lhs, const T& val);
template <class T> std::valarray<T> operator* (const std::valarray<T>& lhs, const T& val);
template <class T> std::valarray<T> operator/ (const std::valarray<T>& lhs, const T& val);
template <class T> std::valarray<T> operator% (const std::valarray<T>& lhs, const T& val);
template <class T> std::valarray<T> operator& (const std::valarray<T>& lhs, const T& val);
template <class T> std::valarray<T> operator| (const std::valarray<T>& lhs, const T& val);
template <class T> std::valarray<T> operator^ (const std::valarray<T>& lhs, const T& val);
template <class T> std::valarray<T> operator<<(const std::valarray<T>& lhs, const T& val);
template <class T> std::valarray<T> operator>> (const std::valarray<T>& lhs, const T& val);
template <class T> std::valarray<bool> operator&&(const std::valarray<T>& lhs, const T& val);
template <class T> std::valarray<bool> operator||(const std::valarray<T>& lhs, const T& val);

template<class T>
valarray<bool> operator==(const valarray<T>& lhs, const valarray<T>& rhs);
template<class T>
valarray<bool> operator!=(const valarray<T>& lhs, const valarray<T>& rhs);
template<class T>
valarray<bool> operator<(const valarray<T>& lhs, const valarray<T>& rhs);
template<class T>
valarray<bool> operator<=(const valarray<T>& lhs, const valarray<T>& rhs);
template<class T>
valarray<bool> operator>(const valarray<T>& lhs, const valarray<T>& rhs);
template<class T>
valarray<bool> operator>=(const valarray<T>& lhs, const valarray<T>& rhs);

template<class T>
valarray<bool> operator==(const T& lhsv, const valarray<T>& rhs);
template<class T>
valarray<bool> operator!=(const T& lhsv, const valarray<T>& rhs);
template<class T>
valarray<bool> operator<(const T& lhsv, const valarray<T>& rhs);
template<class T>
valarray<bool> operator<=(const T& lhsv, const valarray<T>& rhs);
template<class T>
valarray<bool> operator>(const T& lhsv, const valarray<T>& rhs);
template<class T>
valarray<bool> operator>=(const T& lhsv, const valarray<T>& rhs);

template<class T>
valarray<bool> operator==(const valarray<T>& lhs, const T& rhsv);
template<class T>
valarray<bool> operator!=(const valarray<T>& lhs, const T& rhsv);
template<class T>
valarray<bool> operator<(const valarray<T>& lhs, const T& rhsv);
template<class T>
valarray<bool> operator<=(const valarray<T>& lhs, const T& rhsv);
template<class T>
valarray<bool> operator>(const valarray<T>& lhs, const T& rhsv);
template<class T>
valarray<bool> operator>=(const valarray<T>& lhs, const T& rhsv);

template<class T>
valarray<T> abs(const valarray<T>& va);
template<class T>
valarray<T> exp(const valarray<T>& va);
template<class T>
valarray<T> log(const valarray<T>& va);
template<class T>
valarray<T> log10(const valarray<T>& va);
template<class T>
valarray<T> pow(const valarray<T>& base, const valarray<T>& exp);
template<class T>
valarray<T> pow(const valarray<T>& base, const T& vexp);
template<class T>
valarray<T> pow(const T& vbase, const valarray<T>& exp);
template<class T>
valarray<T> sqrt(const valarray<T>& va);
template<class T>
valarray<T> sin(const valarray<T>& va);
template<class T>
valarray<T> cos(const valarray<T>& va);
template<class T>
valarray<T> tan(const valarray<T>& va);
template<class T>
valarray<T> asin(const valarray<T>& va);
template<class T>
valarray<T> acos(const valarray<T>& va);
template<class T>
valarray<T> atan(const valarray<T>& va);
template<class T>
valarray<T> atan2(const valarray<T>& y, const valarray<T>& x);
template<class T>
valarray<T> atan2(const valarray<T>& y, const T& vx);
template<class T>
valarray<T> atan2(const T& vy, const valarray<T>& x);
template<class T>
valarray<T> sinh(const valarray<T>& va);
template<class T>
valarray<T> tanh(const valarray<T>& va);


class slice {
public:
    slice();
    slice(std::size_t start, std::size_t size, std::size_t stride);
    slice(const slice& other);

    size_t start() const;
    size_t size() const;
    size_t stride() const;
};

template<class T>
class slice_array {
public:
    typedef T value_type;

    slice_array() = delete;
    slice_array(const slice_array& other);
    ~slice_array();

    void operator+=(const std::valarray<T>& other);
    void operator-=(const std::valarray<T>& other);
    void operator*=(const std::valarray<T>& other);
    void operator/=(const std::valarray<T>& other);
    void operator%=(const std::valarray<T>& other);
    void operator&=(const std::valarray<T>& other);
    void operator|=(const std::valarray<T>& other);
    void operator^=(const std::valarray<T>& other);
    void operator<<=(const std::valarray<T>& other);
    void operator>>=(const std::valarray<T>& other);

    void operator=(const T& value) const;
    void operator=(const std::valarray<T>& val_arr) const;
#if CPPREFERENCE_STDVER>= 2011
    const slice_array& operator=(const slice_array& sl_arr) const;
#endif
};

class gslice {
public:
    gslice();
    gslice(std::size_t start, const std::valarray<std::size_t>& sizes,
           const std::valarray<std::size_t>& strides);
    gslice(const gslice& other);

    size_t           start()  const;
    valarray<size_t> size()   const;
    valarray<size_t> stride() const;
};

template<class T>
class gslice_array {
public:
    typedef T value_type;

    gslice_array(const gslice_array& other);
    gslice_array() = delete;
    ~gslice_array();

    void operator=(const T& value) const;
    void operator=(const std::valarray<T>& val_arr) const;
#if CPPREFERENCE_STDVER>= 2011
    const gslice_array& operator=(const gslice_array& sl_arr) const;
#endif

    void operator+=(const std::valarray<T>& other);
    void operator-=(const std::valarray<T>& other);
    void operator*=(const std::valarray<T>& other);
    void operator/=(const std::valarray<T>& other);
    void operator%=(const std::valarray<T>& other);
    void operator&=(const std::valarray<T>& other);
    void operator|=(const std::valarray<T>& other);
    void operator^=(const std::valarray<T>& other);
    void operator<<=(const std::valarray<T>& other);
    void operator>>=(const std::valarray<T>& other);
};

template<class T>
class mask_array {
public:
    typedef T value_type;

    mask_array(const mask_array& other);
    mask_array() = delete;
    ~mask_array();

    void operator=(const T& value) const;
    void operator=(const std::valarray<T>& val_arr) const;
#if CPPREFERENCE_STDVER>= 2011
    const mask_array& operator=(const mask_array& sl_arr) const;
#endif

    void operator+=(const std::valarray<T>& other);
    void operator-=(const std::valarray<T>& other);
    void operator*=(const std::valarray<T>& other);
    void operator/=(const std::valarray<T>& other);
    void operator%=(const std::valarray<T>& other);
    void operator&=(const std::valarray<T>& other);
    void operator|=(const std::valarray<T>& other);
    void operator^=(const std::valarray<T>& other);
    void operator<<=(const std::valarray<T>& other);
    void operator>>=(const std::valarray<T>& other);
};

template<class T>
class indirect_array {
public:
    typedef T value_type;

    indirect_array(const indirect_array& other);
    indirect_array() = delete;
    ~indirect_array();

    void operator=(const T& value) const;
    void operator=(const std::valarray<T>& val_arr) const;
#if CPPREFERENCE_STDVER>= 2011
    const indirect_array& operator=(const indirect_array& sl_arr) const;
#endif

    void operator+=(const std::valarray<T>& other);
    void operator-=(const std::valarray<T>& other);
    void operator*=(const std::valarray<T>& other);
    void operator/=(const std::valarray<T>& other);
    void operator%=(const std::valarray<T>& other);
    void operator&=(const std::valarray<T>& other);
    void operator|=(const std::valarray<T>& other);
    void operator^=(const std::valarray<T>& other);
    void operator<<=(const std::valarray<T>& other);
    void operator>>=(const std::valarray<T>& other);
};

} // namespace std

#endif // CPPREFERENCE_VALARRAY_H