Common mathematical functions | |||||||||||||||||||||||||||||||
Mathematical special functions(C++17) | |||||||||||||||||||||||||||||||
Mathematical constants(C++20) | |||||||||||||||||||||||||||||||
Basic linear algebra algorithms(C++26) | |||||||||||||||||||||||||||||||
Data-parallel types (SIMD)(C++26) | |||||||||||||||||||||||||||||||
Floating-point environment(C++11) | |||||||||||||||||||||||||||||||
Complex numbers | |||||||||||||||||||||||||||||||
Numeric array (valarray ) | |||||||||||||||||||||||||||||||
Pseudo-random number generation | |||||||||||||||||||||||||||||||
Bit manipulation(C++20) | |||||||||||||||||||||||||||||||
Saturation arithmetic(C++26) | |||||||||||||||||||||||||||||||
Factor operations | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
Interpolations | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
Generic numeric operations | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
C-style checked integer arithmetic | |||||||||||||||||||||||||||||||
|
Defined in header <valarray> | ||
class slice; | ||
std::slice
is the selector class that identifies a subset ofstd::valarray similar toBLAS slice. An object of typestd::slice
holds three values: the starting index, the stride, and the total number of values in the subset. Objects of typestd::slice
can be used as indices with valarray'soperator[].
Contents |
(constructor) | constructs a slice (public member function) |
startsizestride | returns the parameters of the slice (public member function) |
slice() | (1) | |
slice(std::size_t start,std::size_t size,std::size_t stride); | (2) | |
slice(const slice& other); | (3) | |
Constructs a new slice.
start | - | the position of the first element |
size | - | the number of elements in the slice |
stride | - | the number of positions between successive elements in the slice |
other | - | another slice to copy |
std::size_t start()const; | (1) | |
std::size_t size()const; | (2) | |
std::size_t stride()const; | (3) | |
Returns the parameters passed to the slice on construction - start, size and stride respectively.
(none)
The parameters of the slice -- start, size and stride respectively.
Constant.
operator==(std::slice) (C++20) | checks if two slices are equal (function) |
friendbool operator==(const slice& lhs,const slice& rhs); | (since C++20) | |
Checks if the parameters oflhs andrhs - start, size and stride are equal respectively.
This function is not visible to ordinaryunqualified orqualified lookup, and can only be found byargument-dependent lookup when std::slice is an associated class of the arguments.
The!=
operator issynthesized fromoperator==
.
lhs, rhs | - | slices to compare |
lhs.start()== rhs.start()&& lhs.size()== rhs.size()&& lhs.stride()== rhs.stride()
Barebones valarray-backed Matrix class with atrace calculating function.
#include <iostream>#include <valarray> class Matrix{std::valarray<int> data;int dim;public: Matrix(int r,int c): data(r*c), dim(c){}int& operator()(int r,int c){return data[r* dim+ c];}int trace()const{return data[std::slice(0, dim, dim+1)].sum();}}; int main(){ Matrix m(3,3);int n=0;for(int r=0; r<3;++r)for(int c=0; c<3;++c) m(r, c)=++n;std::cout<<"Trace of the matrix (1,2,3) (4,5,6) (7,8,9) is "<< m.trace()<<'\n';}
Output:
Trace of the matrix (1,2,3) (4,5,6) (7,8,9) is 15
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 543 | C++98 | it was unclear whether a default constructed slice is usable | it is usable (as an empty subset) |
get/set valarray element, slice, or mask (public member function)[edit] | |
generalized slice of a valarray: starting index, set of lengths, set of strides (class)[edit] | |
proxy to a subset of a valarray after applying a slice (class template)[edit] | |
(C++23) | a multi-dimensional non-owning array view (class template)[edit] |