| 1 |
/* Copyright (C) 2015 Povilas Kanapickas <[email protected]> |
| 2 |
|
| 3 |
This file is part of cppreference-doc |
| 4 |
|
| 5 |
This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 |
| 6 |
Unported License. To view a copy of this license, visit |
| 7 |
http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative |
| 8 |
Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. |
| 9 |
|
| 10 |
Permission is granted to copy, distribute and/or modify this document |
| 11 |
under the terms of the GNU Free Documentation License, Version 1.3 or |
| 12 |
any later version published by the Free Software Foundation; with no |
| 13 |
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. |
| 14 |
*/ |
| 15 |
|
| 16 |
#ifndef CPPREFERENCE_VALARRAY_H |
| 17 |
#define CPPREFERENCE_VALARRAY_H |
| 18 |
|
| 19 |
namespace std { |
| 20 |
|
| 21 |
template<class T> |
| 22 |
class valarray { |
| 23 |
public: |
| 24 |
typedef T value_type; |
| 25 |
|
| 26 |
valarray(); |
| 27 |
explicit valarray(std::size_t count); |
| 28 |
valarray(const T& val, std::size_t count); |
| 29 |
valarray(const T* vals, std::size_t count); |
| 30 |
valarray(const valarray& other); |
| 31 |
#if CPPREFERENCE_STDVER>= 2011 |
| 32 |
valarray(valarray&& other); |
| 33 |
#endif |
| 34 |
valarray(const std::slice_array<T>& array); |
| 35 |
valarray(const std::gslice_array<T>& array); |
| 36 |
valarray(const std::mask_array<T>& array); |
| 37 |
valarray(const std::indirect_array<T>& array); |
| 38 |
#if CPPREFERENCE_STDVER>= 2011 |
| 39 |
valarray(std::initializer_list<T> ilist); |
| 40 |
#endif |
| 41 |
|
| 42 |
~valarray(); |
| 43 |
|
| 44 |
valarray<T>& operator=(const valarray<T>& other); |
| 45 |
#if CPPREFERENCE_STDVER>= 2011 |
| 46 |
valarray<T>& operator=(valarray<T>&& other); |
| 47 |
#endif |
| 48 |
valarray<T>& operator=(const T& val); |
| 49 |
valarray<T>& operator=(const std::slice_array& other); |
| 50 |
valarray<T>& operator=(const std::gslice_array& other); |
| 51 |
valarray<T>& operator=(const std::mask_array& other); |
| 52 |
valarray<T>& operator=(const std::indirect_array& other); |
| 53 |
#if CPPREFERENCE_STDVER>= 2011 |
| 54 |
valarray<T>& operator=(std::initializer_list<T> il); |
| 55 |
#endif |
| 56 |
|
| 57 |
T operator[](std::size_t pos) const; |
| 58 |
const T& operator[](std::size_t pos) const; |
| 59 |
T& operator[](std::size_t pos); |
| 60 |
std::valarray<T> operator[](std::slice slicearr) const; |
| 61 |
std::slice_array<T> operator[](std::slice slicearr); |
| 62 |
std::valarray<T> operator[](const std::gslice& gslicearr) const; |
| 63 |
std::gslice_array<T> operator[](const std::gslice& gslicearr); |
| 64 |
std::valarray<T> operator[](const valarray<bool>& boolarr) const; |
| 65 |
std::mask_array<T> operator[](const valarray<bool>& boolarr); |
| 66 |
std::valarray<T> operator[](const valarray<std::size_t>& indarr) const; |
| 67 |
std::indirect_array<T> operator[](const valarray<std::size_t>& indarr); |
| 68 |
|
| 69 |
valarray<T> operator+() const; |
| 70 |
valarray<T> operator-() const; |
| 71 |
valarray<T> operator~() const; |
| 72 |
valarray<bool> operator!() const; |
| 73 |
|
| 74 |
valarray<T> operator+=(const valarray<T>& v); |
| 75 |
valarray<T> operator-=(const valarray<T>& v); |
| 76 |
valarray<T> operator*=(const valarray<T>& v); |
| 77 |
valarray<T> operator/=(const valarray<T>& v); |
| 78 |
valarray<T> operator%=(const valarray<T>& v); |
| 79 |
valarray<T> operator&=(const valarray<T>& v); |
| 80 |
valarray<T> operator|=(const valarray<T>& v); |
| 81 |
valarray<T> operator^=(const valarray<T>& v); |
| 82 |
valarray<T> operator<<=(const valarray<T>& v); |
| 83 |
valarray<T> operator>>=(const valarray<T>& v); |
| 84 |
valarray<T> operator+=(const T& val); |
| 85 |
|
| 86 |
valarray<T> operator-=(const T& val); |
| 87 |
valarray<T> operator*=(const T& val); |
| 88 |
valarray<T> operator/=(const T& val); |
| 89 |
valarray<T> operator%=(const T& val); |
| 90 |
valarray<T> operator&=(const T& val); |
| 91 |
valarray<T> operator|=(const T& val); |
| 92 |
valarray<T> operator^=(const T& val); |
| 93 |
valarray<T> operator<<=(const T& val); |
| 94 |
valarray<T> operator>>=(const T& val); |
| 95 |
|
| 96 |
void swap(valarray& other); |
| 97 |
|
| 98 |
std::size_t size() const; |
| 99 |
void resize(std::size_t count, T value = T()); |
| 100 |
|
| 101 |
T sum() const; |
| 102 |
T min() const; |
| 103 |
T max() const; |
| 104 |
|
| 105 |
valarray shift(int count) const; |
| 106 |
valarray cshift(int count) const; |
| 107 |
valarray<T> apply(T func(T)) const; |
| 108 |
valarray<T> apply(T func(const T&)) const; |
| 109 |
}; |
| 110 |
|
| 111 |
template<class T> |
| 112 |
void swap(valarray<T>& lhs, valarray<T>& rhs); |
| 113 |
|
| 114 |
struct __unspecified; |
| 115 |
|
| 116 |
#if CPPREFERENCE_STDVER>= 2011 |
| 117 |
template<class T> |
| 118 |
__unspecified begin(valarray<T>& v); |
| 119 |
|
| 120 |
template<class T> |
| 121 |
__unspecified begin(const valarray<T>& v); |
| 122 |
|
| 123 |
template<class T> |
| 124 |
__unspecified end(valarray<T>& v); |
| 125 |
|
| 126 |
template<class T> |
| 127 |
__unspecified end(const valarray<T>& v); |
| 128 |
#endif |
| 129 |
|
| 130 |
template <class T> std::valarray<T> operator+ (const std::valarray<T>& lhs, const std::valarray<T>& rhs); |
| 131 |
template <class T> std::valarray<T> operator- (const std::valarray<T>& lhs, const std::valarray<T>& rhs); |
| 132 |
template <class T> std::valarray<T> operator* (const std::valarray<T>& lhs, const std::valarray<T>& rhs); |
| 133 |
template <class T> std::valarray<T> operator/ (const std::valarray<T>& lhs, const std::valarray<T>& rhs); |
| 134 |
template <class T> std::valarray<T> operator% (const std::valarray<T>& lhs, const std::valarray<T>& rhs); |
| 135 |
template <class T> std::valarray<T> operator& (const std::valarray<T>& lhs, const std::valarray<T>& rhs); |
| 136 |
template <class T> std::valarray<T> operator| (const std::valarray<T>& lhs, const std::valarray<T>& rhs); |
| 137 |
template <class T> std::valarray<T> operator^ (const std::valarray<T>& lhs, const std::valarray<T>& rhs); |
| 138 |
template <class T> std::valarray<T> operator<<(const std::valarray<T>& lhs, const std::valarray<T>& rhs); |
| 139 |
template <class T> std::valarray<T> operator>> (const std::valarray<T>& lhs, const std::valarray<T>& rhs); |
| 140 |
template <class T> std::valarray<bool> operator&&(const std::valarray<T>& lhs, const std::valarray<T>& rhs); |
| 141 |
template <class T> std::valarray<bool> operator||(const std::valarray<T>& lhs, const std::valarray<T>& rhs); |
| 142 |
|
| 143 |
template <class T> std::valarray<T> operator+ (const T& val, const std::valarray<T>& rhs); |
| 144 |
template <class T> std::valarray<T> operator- (const T& val, const std::valarray<T>& rhs); |
| 145 |
template <class T> std::valarray<T> operator* (const T& val, const std::valarray<T>& rhs); |
| 146 |
template <class T> std::valarray<T> operator/ (const T& val, const std::valarray<T>& rhs); |
| 147 |
template <class T> std::valarray<T> operator% (const T& val, const std::valarray<T>& rhs); |
| 148 |
template <class T> std::valarray<T> operator& (const T& val, const std::valarray<T>& rhs); |
| 149 |
template <class T> std::valarray<T> operator| (const T& val, const std::valarray<T>& rhs); |
| 150 |
template <class T> std::valarray<T> operator^ (const T& val, const std::valarray<T>& rhs); |
| 151 |
template <class T> std::valarray<T> operator<<(const T& val, const std::valarray<T>& rhs); |
| 152 |
template <class T> std::valarray<T> operator>> (const T& val, const std::valarray<T>& rhs); |
| 153 |
template <class T> std::valarray<bool> operator&&(const T& val, const std::valarray<T>& rhs); |
| 154 |
template <class T> std::valarray<bool> operator||(const T& val, const std::valarray<T>& rhs); |
| 155 |
|
| 156 |
template <class T> std::valarray<T> operator+ (const std::valarray<T>& lhs, const T& rhs); |
| 157 |
template <class T> std::valarray<T> operator- (const std::valarray<T>& lhs, const T& val); |
| 158 |
template <class T> std::valarray<T> operator* (const std::valarray<T>& lhs, const T& val); |
| 159 |
template <class T> std::valarray<T> operator/ (const std::valarray<T>& lhs, const T& val); |
| 160 |
template <class T> std::valarray<T> operator% (const std::valarray<T>& lhs, const T& val); |
| 161 |
template <class T> std::valarray<T> operator& (const std::valarray<T>& lhs, const T& val); |
| 162 |
template <class T> std::valarray<T> operator| (const std::valarray<T>& lhs, const T& val); |
| 163 |
template <class T> std::valarray<T> operator^ (const std::valarray<T>& lhs, const T& val); |
| 164 |
template <class T> std::valarray<T> operator<<(const std::valarray<T>& lhs, const T& val); |
| 165 |
template <class T> std::valarray<T> operator>> (const std::valarray<T>& lhs, const T& val); |
| 166 |
template <class T> std::valarray<bool> operator&&(const std::valarray<T>& lhs, const T& val); |
| 167 |
template <class T> std::valarray<bool> operator||(const std::valarray<T>& lhs, const T& val); |
| 168 |
|
| 169 |
template<class T> |
| 170 |
valarray<bool> operator==(const valarray<T>& lhs, const valarray<T>& rhs); |
| 171 |
template<class T> |
| 172 |
valarray<bool> operator!=(const valarray<T>& lhs, const valarray<T>& rhs); |
| 173 |
template<class T> |
| 174 |
valarray<bool> operator<(const valarray<T>& lhs, const valarray<T>& rhs); |
| 175 |
template<class T> |
| 176 |
valarray<bool> operator<=(const valarray<T>& lhs, const valarray<T>& rhs); |
| 177 |
template<class T> |
| 178 |
valarray<bool> operator>(const valarray<T>& lhs, const valarray<T>& rhs); |
| 179 |
template<class T> |
| 180 |
valarray<bool> operator>=(const valarray<T>& lhs, const valarray<T>& rhs); |
| 181 |
|
| 182 |
template<class T> |
| 183 |
valarray<bool> operator==(const T& lhsv, const valarray<T>& rhs); |
| 184 |
template<class T> |
| 185 |
valarray<bool> operator!=(const T& lhsv, const valarray<T>& rhs); |
| 186 |
template<class T> |
| 187 |
valarray<bool> operator<(const T& lhsv, const valarray<T>& rhs); |
| 188 |
template<class T> |
| 189 |
valarray<bool> operator<=(const T& lhsv, const valarray<T>& rhs); |
| 190 |
template<class T> |
| 191 |
valarray<bool> operator>(const T& lhsv, const valarray<T>& rhs); |
| 192 |
template<class T> |
| 193 |
valarray<bool> operator>=(const T& lhsv, const valarray<T>& rhs); |
| 194 |
|
| 195 |
template<class T> |
| 196 |
valarray<bool> operator==(const valarray<T>& lhs, const T& rhsv); |
| 197 |
template<class T> |
| 198 |
valarray<bool> operator!=(const valarray<T>& lhs, const T& rhsv); |
| 199 |
template<class T> |
| 200 |
valarray<bool> operator<(const valarray<T>& lhs, const T& rhsv); |
| 201 |
template<class T> |
| 202 |
valarray<bool> operator<=(const valarray<T>& lhs, const T& rhsv); |
| 203 |
template<class T> |
| 204 |
valarray<bool> operator>(const valarray<T>& lhs, const T& rhsv); |
| 205 |
template<class T> |
| 206 |
valarray<bool> operator>=(const valarray<T>& lhs, const T& rhsv); |
| 207 |
|
| 208 |
template<class T> |
| 209 |
valarray<T> abs(const valarray<T>& va); |
| 210 |
template<class T> |
| 211 |
valarray<T> exp(const valarray<T>& va); |
| 212 |
template<class T> |
| 213 |
valarray<T> log(const valarray<T>& va); |
| 214 |
template<class T> |
| 215 |
valarray<T> log10(const valarray<T>& va); |
| 216 |
template<class T> |
| 217 |
valarray<T> pow(const valarray<T>& base, const valarray<T>& exp); |
| 218 |
template<class T> |
| 219 |
valarray<T> pow(const valarray<T>& base, const T& vexp); |
| 220 |
template<class T> |
| 221 |
valarray<T> pow(const T& vbase, const valarray<T>& exp); |
| 222 |
template<class T> |
| 223 |
valarray<T> sqrt(const valarray<T>& va); |
| 224 |
template<class T> |
| 225 |
valarray<T> sin(const valarray<T>& va); |
| 226 |
template<class T> |
| 227 |
valarray<T> cos(const valarray<T>& va); |
| 228 |
template<class T> |
| 229 |
valarray<T> tan(const valarray<T>& va); |
| 230 |
template<class T> |
| 231 |
valarray<T> asin(const valarray<T>& va); |
| 232 |
template<class T> |
| 233 |
valarray<T> acos(const valarray<T>& va); |
| 234 |
template<class T> |
| 235 |
valarray<T> atan(const valarray<T>& va); |
| 236 |
template<class T> |
| 237 |
valarray<T> atan2(const valarray<T>& y, const valarray<T>& x); |
| 238 |
template<class T> |
| 239 |
valarray<T> atan2(const valarray<T>& y, const T& vx); |
| 240 |
template<class T> |
| 241 |
valarray<T> atan2(const T& vy, const valarray<T>& x); |
| 242 |
template<class T> |
| 243 |
valarray<T> sinh(const valarray<T>& va); |
| 244 |
template<class T> |
| 245 |
valarray<T> tanh(const valarray<T>& va); |
| 246 |
|
| 247 |
|
| 248 |
class slice { |
| 249 |
public: |
| 250 |
slice(); |
| 251 |
slice(std::size_t start, std::size_t size, std::size_t stride); |
| 252 |
slice(const slice& other); |
| 253 |
|
| 254 |
size_t start() const; |
| 255 |
size_t size() const; |
| 256 |
size_t stride() const; |
| 257 |
}; |
| 258 |
|
| 259 |
template<class T> |
| 260 |
class slice_array { |
| 261 |
public: |
| 262 |
typedef T value_type; |
| 263 |
|
| 264 |
slice_array() = delete; |
| 265 |
slice_array(const slice_array& other); |
| 266 |
~slice_array(); |
| 267 |
|
| 268 |
void operator+=(const std::valarray<T>& other); |
| 269 |
void operator-=(const std::valarray<T>& other); |
| 270 |
void operator*=(const std::valarray<T>& other); |
| 271 |
void operator/=(const std::valarray<T>& other); |
| 272 |
void operator%=(const std::valarray<T>& other); |
| 273 |
void operator&=(const std::valarray<T>& other); |
| 274 |
void operator|=(const std::valarray<T>& other); |
| 275 |
void operator^=(const std::valarray<T>& other); |
| 276 |
void operator<<=(const std::valarray<T>& other); |
| 277 |
void operator>>=(const std::valarray<T>& other); |
| 278 |
|
| 279 |
void operator=(const T& value) const; |
| 280 |
void operator=(const std::valarray<T>& val_arr) const; |
| 281 |
#if CPPREFERENCE_STDVER>= 2011 |
| 282 |
const slice_array& operator=(const slice_array& sl_arr) const; |
| 283 |
#endif |
| 284 |
}; |
| 285 |
|
| 286 |
class gslice { |
| 287 |
public: |
| 288 |
gslice(); |
| 289 |
gslice(std::size_t start, const std::valarray<std::size_t>& sizes, |
| 290 |
const std::valarray<std::size_t>& strides); |
| 291 |
gslice(const gslice& other); |
| 292 |
|
| 293 |
size_t start() const; |
| 294 |
valarray<size_t> size() const; |
| 295 |
valarray<size_t> stride() const; |
| 296 |
}; |
| 297 |
|
| 298 |
template<class T> |
| 299 |
class gslice_array { |
| 300 |
public: |
| 301 |
typedef T value_type; |
| 302 |
|
| 303 |
gslice_array(const gslice_array& other); |
| 304 |
gslice_array() = delete; |
| 305 |
~gslice_array(); |
| 306 |
|
| 307 |
void operator=(const T& value) const; |
| 308 |
void operator=(const std::valarray<T>& val_arr) const; |
| 309 |
#if CPPREFERENCE_STDVER>= 2011 |
| 310 |
const gslice_array& operator=(const gslice_array& sl_arr) const; |
| 311 |
#endif |
| 312 |
|
| 313 |
void operator+=(const std::valarray<T>& other); |
| 314 |
void operator-=(const std::valarray<T>& other); |
| 315 |
void operator*=(const std::valarray<T>& other); |
| 316 |
void operator/=(const std::valarray<T>& other); |
| 317 |
void operator%=(const std::valarray<T>& other); |
| 318 |
void operator&=(const std::valarray<T>& other); |
| 319 |
void operator|=(const std::valarray<T>& other); |
| 320 |
void operator^=(const std::valarray<T>& other); |
| 321 |
void operator<<=(const std::valarray<T>& other); |
| 322 |
void operator>>=(const std::valarray<T>& other); |
| 323 |
}; |
| 324 |
|
| 325 |
template<class T> |
| 326 |
class mask_array { |
| 327 |
public: |
| 328 |
typedef T value_type; |
| 329 |
|
| 330 |
mask_array(const mask_array& other); |
| 331 |
mask_array() = delete; |
| 332 |
~mask_array(); |
| 333 |
|
| 334 |
void operator=(const T& value) const; |
| 335 |
void operator=(const std::valarray<T>& val_arr) const; |
| 336 |
#if CPPREFERENCE_STDVER>= 2011 |
| 337 |
const mask_array& operator=(const mask_array& sl_arr) const; |
| 338 |
#endif |
| 339 |
|
| 340 |
void operator+=(const std::valarray<T>& other); |
| 341 |
void operator-=(const std::valarray<T>& other); |
| 342 |
void operator*=(const std::valarray<T>& other); |
| 343 |
void operator/=(const std::valarray<T>& other); |
| 344 |
void operator%=(const std::valarray<T>& other); |
| 345 |
void operator&=(const std::valarray<T>& other); |
| 346 |
void operator|=(const std::valarray<T>& other); |
| 347 |
void operator^=(const std::valarray<T>& other); |
| 348 |
void operator<<=(const std::valarray<T>& other); |
| 349 |
void operator>>=(const std::valarray<T>& other); |
| 350 |
}; |
| 351 |
|
| 352 |
template<class T> |
| 353 |
class indirect_array { |
| 354 |
public: |
| 355 |
typedef T value_type; |
| 356 |
|
| 357 |
indirect_array(const indirect_array& other); |
| 358 |
indirect_array() = delete; |
| 359 |
~indirect_array(); |
| 360 |
|
| 361 |
void operator=(const T& value) const; |
| 362 |
void operator=(const std::valarray<T>& val_arr) const; |
| 363 |
#if CPPREFERENCE_STDVER>= 2011 |
| 364 |
const indirect_array& operator=(const indirect_array& sl_arr) const; |
| 365 |
#endif |
| 366 |
|
| 367 |
void operator+=(const std::valarray<T>& other); |
| 368 |
void operator-=(const std::valarray<T>& other); |
| 369 |
void operator*=(const std::valarray<T>& other); |
| 370 |
void operator/=(const std::valarray<T>& other); |
| 371 |
void operator%=(const std::valarray<T>& other); |
| 372 |
void operator&=(const std::valarray<T>& other); |
| 373 |
void operator|=(const std::valarray<T>& other); |
| 374 |
void operator^=(const std::valarray<T>& other); |
| 375 |
void operator<<=(const std::valarray<T>& other); |
| 376 |
void operator>>=(const std::valarray<T>& other); |
| 377 |
}; |
| 378 |
|
| 379 |
} // namespace std |
| 380 |
|
| 381 |
#endif // CPPREFERENCE_VALARRAY_H |