CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Mon, 21 Jul 2025 05:51:39 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: /reference/valarray/valarray/valarray/
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 21 Jul 2025 05:51:39 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"8a3b-t2ZM51nLnYIw6UJOOrDGIFqxzJE"
Content-Encoding: gzip
Constructs a valarray object:
Output:
For others, depends on library implementation (operations may be parallelized).
The move constructor modifies x.
If the function fails to allocate storage it may throw an exception (such as bad_alloc), although this is not mandated.
The move constructor never throws exceptions (no-throw guarantee).
Reference
C library:
- <cassert> (assert.h)
- <cctype> (ctype.h)
- <cerrno> (errno.h)
-
<cfenv> (fenv.h)C++11
- <cfloat> (float.h)
-
<cinttypes> (inttypes.h)C++11
- <ciso646> (iso646.h)
- <climits> (limits.h)
- <clocale> (locale.h)
- <cmath> (math.h)
- <csetjmp> (setjmp.h)
- <csignal> (signal.h)
- <cstdarg> (stdarg.h)
-
<cstdbool> (stdbool.h)C++11
- <cstddef> (stddef.h)
-
<cstdint> (stdint.h)C++11
- <cstdio> (stdio.h)
- <cstdlib> (stdlib.h)
- <cstring> (string.h)
-
<ctgmath> (tgmath.h)C++11
- <ctime> (time.h)
-
<cuchar> (uchar.h)C++11
- <cwchar> (wchar.h)
- <cwctype> (wctype.h)
Containers:
-
<array>C++11
- <deque>
-
<forward_list>C++11
- <list>
- <map>
- <queue>
- <set>
- <stack>
-
<unordered_map>C++11
-
<unordered_set>C++11
- <vector>
-
Input/Output:
Multi-threading:
-
<atomic>C++11
-
<condition_variable>C++11
-
<future>C++11
-
<mutex>C++11
-
<thread>C++11
-
Other:
- <algorithm>
- <bitset>
-
<chrono>C++11
-
<codecvt>C++11
- <complex>
- <exception>
- <functional>
-
<initializer_list>C++11
- <iterator>
- <limits>
- <locale>
- <memory>
- <new>
- <numeric>
-
<random>C++11
-
<ratio>C++11
-
<regex>C++11
- <stdexcept>
- <string>
-
<system_error>C++11
-
<tuple>C++11
-
<type_traits>C++11
-
<typeindex>C++11
- <typeinfo>
- <utility>
- <valarray>
valarray
- valarray::~valarray
- valarray operators
- valarray::valarray
member functions
non-member overloads
-
begin (valarray)C++11
-
end (valarray)C++11
-
swap (valarray)C++11
-
- Reference
- <valarray>
- valarray
- valarray
public member function
<valarray>
std::valarray::valarray
default (1) | valarray(); |
---|---|
size (2) | explicit valarray (size_t n); |
fill (3) | valarray (const T& val, size_t n); |
array (4) | valarray (const T* p, size_t n); |
copy (5) | valarray (const valarray& x); |
sub-array (6) | valarray (const slice_array<T>& sub);valarray (const gslice_array<T>& sub);valarray (const mask_array<T>& sub);valarray (const indirect_array<T>& sub); |
default (1) | valarray(); |
---|---|
size (2) | explicit valarray (size_t n); |
fill (3) | valarray (const T& val, size_t n); |
array (4) | valarray (const T* p, size_t n); |
copy/move (5) | valarray (const valarray& x);valarray (valarray&& x) noexcept; |
sub-array (6) | valarray (const slice_array<T>& sub);valarray (const gslice_array<T>& sub);valarray (const mask_array<T>& sub);valarray (const indirect_array<T>& sub); |
initializer list (7) | valarray (initializer_list<T> il); |
valarray constructor
- (1) default constructor
- Constructs an empty valarray, with no elements. The size can later be modified by calling member resize.
- (2) size-initialization
- Constructs a valarray with n value-initialized elements.
- (3) fill-initialization
- Constructs a valarray with n elements, each initialized to val.
- (4) array-initialization
- Constructs a valarray with n elements, initialized to the values of the elements in the array pointed by p.
- (5) copy / move constructor
- Constructs a valarray with the contents of x.
The move-constructor is guaranteed to operate on constant time, leaving x in an unspecified but valid state. - (6) sub-array
- Constructs a valarray with the contents of a valarray subselection.
- (7) initializer list
- Constructs a valarray with a copy of each of the elements in il, in the same order.
Parameters
- n
- Length of array.
size_t is an unsigned integral type. - val
- Value to which each of the elements is initialized.
- p
- Pointer to an array of elements. The first n elements are used as initial values for the elements in the valarray.
- x
- A valarray object of the same type (with the same class template argument T).
- sub
- The result of a valarray subscripting operation.
- il
- An initializer_list object.
These objects are automatically constructed from initializer list declarators.
Example
|
|
Output:
sixth sums 50 |
Complexity
Constant for default-constructor and move-constructor.For others, depends on library implementation (operations may be parallelized).
Iterator validity
The move constructor invalidates iterators, references and sub-arrays of x.Data races
All elements effectively copied are accessed.The move constructor modifies x.
Exception safety
If any operation performed on the elements throws an exception, it causes undefined behavior.If the function fails to allocate storage it may throw an exception (such as bad_alloc), although this is not mandated.
The move constructor never throws exceptions (no-throw guarantee).
See also
- valarray::operator=
- Assign content (public member function)
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us